Index: src/test/java/org/glassfish/admin/rest/ApplicationTest.java =================================================================== --- src/test/java/org/glassfish/admin/rest/ApplicationTest.java (revision 47331) +++ src/test/java/org/glassfish/admin/rest/ApplicationTest.java (working copy) @@ -53,7 +53,6 @@ import java.util.Map; import org.junit.Test; import static org.junit.Assert.*; -import static org.junit.Assert.*; /** * @@ -68,32 +67,22 @@ @Test public void testApplicationDeployment() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - Map newApp = new HashMap() {{ - put("id", getFile("test.war")); - put("contextroot", appName); - put("name", appName); - }}; + try { - Map deployedApp = deployApp(newApp); + Map deployedApp = deployApp(getFile("test.war"), appName, appName); assertEquals(appName, deployedApp.get("name")); assertEquals("/" + appName, deployedApp.get("contextRoot")); } finally { - undeployApp(newApp); + undeployApp(appName); } } - + @Test public void deployCodiApp() throws URISyntaxException, MalformedURLException, IOException { try { final String appName = "testApp" + generateRandomString(); - Map newApp = new HashMap() {{ - put("id", downloadFile(new URL(URL_CODI_SAMPLE))); - put("contextroot", appName); - put("name", appName); - }}; - Map params = new HashMap(); params.put("name", "CloudBeesDS"); params.put("poolName", "DerbyPool"); @@ -101,12 +90,12 @@ ClientResponse response = post (JdbcTest.BASE_JDBC_RESOURCE_URL, params); assertTrue(isSuccess(response)); - Map deployedApp = deployApp(newApp); + Map deployedApp = deployApp(downloadFile(new URL(URL_CODI_SAMPLE)), appName, appName); assertEquals(appName, deployedApp.get("name")); assertEquals("/" + appName, deployedApp.get("contextRoot")); - undeployApp(newApp); + undeployApp(appName); } finally { delete(JdbcTest.BASE_JDBC_RESOURCE_URL + "/CloudBeesDS"); } @@ -115,13 +104,8 @@ @Test public void testApplicationDisableEnable() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - Map newApp = new HashMap() {{ - put("id", getFile("test.war")); - put("contextroot", appName); - put("name", appName); - }}; - Map deployedApp = deployApp(newApp); + Map deployedApp = deployApp(getFile("test.war"), appName, appName); assertEquals(appName, deployedApp.get("name")); assertEquals("/" + appName, deployedApp.get("contextRoot")); @@ -131,33 +115,28 @@ ClientResponse response = get(appUrl); assertEquals ("Test", response.getEntity(String.class).trim()); - response = post(URL_APPLICATION_DEPLOY + "/" + newApp.get("name") + "/disable"); + response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/disable"); checkStatusForSuccess(response); response = get(appUrl); assertFalse("Response was " + response.getStatus(), isSuccess(response)); - response = post(URL_APPLICATION_DEPLOY + "/" + newApp.get("name") + "/enable"); + response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/enable"); checkStatusForSuccess(response); response = get(appUrl); assertEquals ("Test", response.getEntity(String.class).trim()); } finally { - undeployApp(newApp); + undeployApp(appName); } } @Test public void listSubComponents() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - Map newApp = new HashMap() {{ - put("id", getFile("stateless-simple.ear")); - put("contextroot", appName); - put("name", appName); - }}; try { - deployApp(newApp); + deployApp(getFile("stateless-simple.ear"), appName, appName); ClientResponse response = get(URL_SUB_COMPONENTS + "?id=" + appName); checkStatusForSuccess(response); String subComponents = response.getEntity(String.class); @@ -167,10 +146,8 @@ checkStatusForSuccess(response); subComponents = response.getEntity(String.class); assertTrue(subComponents.contains("GreeterServlet")); - } catch (Exception e) { - e.printStackTrace(); } finally { - undeployApp(newApp); + undeployApp(appName); } } @@ -179,11 +156,7 @@ final String instanceName = "instance_" + generateRandomString(); final String appName = "testApp" + generateRandomString(); final String appRefUrl = "/domain/servers/server/" + instanceName + "/application-ref"; - Map newApp = new HashMap() {{ - put("id", getFile("test.war")); - put("contextroot", appName); - put("name", appName); - }}; + Map newInstance = new HashMap() {{ put("id", instanceName); put("node", "localhost-domain1"); @@ -197,14 +170,14 @@ ClientResponse response = post(URL_CREATE_INSTANCE, newInstance); checkStatusForSuccess(response); - deployApp(newApp); + deployApp(getFile("test.war"), appName, appName); response = post (appRefUrl, applicationRef); checkStatusForSuccess(response); response = get(appRefUrl + "/" + appName); checkStatusForSuccess(response); - + response = delete(appRefUrl + "/" + appName, new HashMap() {{ put("target", instanceName); }}); checkStatusForSuccess(response); } finally { @@ -212,21 +185,16 @@ checkStatusForSuccess(response); response = get("/domain/servers/server/" + instanceName); assertFalse(isSuccess(response)); - undeployApp(newApp); + undeployApp(appName); } } @Test public void testGetContextRoot() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - Map newApp = new HashMap() {{ - put("id", getFile("stateless-simple.ear")); - put("contextroot", appName); - put("name", appName); - }}; try { - Map deployedApp = deployApp(newApp); + Map deployedApp = deployApp(getFile("stateless-simple.ear"), appName, appName); assertEquals(appName, deployedApp.get("name")); Map contextRootPayload = new HashMap() {{ put("appname", appName); @@ -237,19 +205,14 @@ checkStatusForSuccess(response); assertTrue(response.getEntity(String.class).contains("helloworld")); } finally { - undeployApp(newApp); + undeployApp(appName); } } - + @Test public void testUndeploySubActionWarnings() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); final String serverName = "in" + generateRandomNumber(); - Map newApp = new HashMap() {{ - put("id", getFile("test.war")); - put("contextroot", appName); - put("name", appName); - }}; try { ClientResponse response = post ("/domain/create-instance", new HashMap() {{ put("id", serverName); @@ -259,13 +222,13 @@ response = post("/domain/servers/server/" + serverName + "/start-instance"); checkStatusForSuccess(response); - - deployApp(newApp); + + deployApp(getFile("test.war"), appName, appName); addAppRef(appName, serverName); - + response = post("/domain/servers/server/" + serverName + "/stop-instance"); checkStatusForSuccess(response); - + response = delete ("/domain/applications/application/"+appName, new HashMap() {{ put("target", "domain"); }}); @@ -281,7 +244,7 @@ final URL resource = getClass().getResource("/" + fileName); return new File(resource.toURI()); } - + protected File downloadFile(URL url) throws IOException { String urlText = url.getFile(); String fileName = urlText.substring(urlText.lastIndexOf("/")+1); @@ -299,29 +262,39 @@ } bout.close(); in.close(); - + return file; } - protected Map deployApp(Map app) { + public Map deployApp (final String fileName, final String contextRoot, final String name) throws URISyntaxException { + return deployApp(getFile(fileName), contextRoot, name); + } + + public Map deployApp (final File archive, final String contextRoot, final String name) { + Map app = new HashMap() {{ + put("id", archive); + put("contextroot", contextRoot); + put("name", name); + }}; + ClientResponse response = postWithUpload(URL_APPLICATION_DEPLOY, app); checkStatusForSuccess(response); return getEntityValues(get(URL_APPLICATION_DEPLOY + "/" + app.get("name"))); } - - protected void addAppRef(final String applicationName, final String targetName){ + + public void addAppRef(final String applicationName, final String targetName){ ClientResponse cr = post("/domain/servers/server/" + targetName + "/application-ref", new HashMap() {{ put("id", applicationName); put("target", targetName); }}); checkStatusForSuccess(cr); } - - protected ClientResponse undeployApp(Map app) { - ClientResponse response = delete(URL_APPLICATION_DEPLOY + "/" + app.get("name")); + + public ClientResponse undeployApp(String appName) { + ClientResponse response = delete(URL_APPLICATION_DEPLOY + "/" + appName); checkStatusForSuccess(response); - + return response; } } Index: src/test/java/org/glassfish/admin/rest/ElementStarTest.java =================================================================== --- src/test/java/org/glassfish/admin/rest/ElementStarTest.java (revision 0) +++ src/test/java/org/glassfish/admin/rest/ElementStarTest.java (revision 0) @@ -0,0 +1,125 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package org.glassfish.admin.rest; + +import java.util.Map; +import java.net.URISyntaxException; +import org.junit.After; +import com.sun.jersey.api.client.ClientResponse; +import java.util.HashMap; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * This class tests the changes to the handling of @Element("*") instances + * @author jasonlee + */ +public class ElementStarTest extends RestTestBase { + protected static final String URL_CREATE_INSTANCE = "/domain/servers/server"; + + protected String instanceName1; + protected String instanceName2; + + @Before + public void before() { + instanceName1 = "instance_" + generateRandomString(); + instanceName2 = "instance_" + generateRandomString(); + + ClientResponse response = post(URL_CREATE_INSTANCE, new HashMap() {{ put("id", instanceName1); put("node", "localhost-domain1"); }}); + assertTrue(isSuccess(response)); + response = post(URL_CREATE_INSTANCE, new HashMap() {{ put("id", instanceName2); put("node", "localhost-domain1"); }}); + assertTrue(isSuccess(response)); + } + + @After + public void after() { + ClientResponse response = delete("/domain/servers/server/" + instanceName1); + assertTrue(isSuccess(response)); + response = delete("/domain/servers/server/" + instanceName2); + assertTrue(isSuccess(response)); + } + + @Test + public void testApplications() throws URISyntaxException { + ApplicationTest at = getTestClass(ApplicationTest.class); + final String app1 = "app" + generateRandomString(); + final String app2 = "app" + generateRandomString(); + + at.deployApp("test.war", app1, app1); + at.deployApp("test.war", app2, app2); + at.addAppRef(app1, instanceName1); + at.addAppRef(app2, instanceName1); + + ClientResponse response = get("/domain/servers/server/"+instanceName1+"/application-ref"); + Map children = this.getChildResources(response); + assertEquals(2, children.size()); + } + + @Test + public void testResources() { + // The DAS should already have two resource-refs (jdbc/__TimerPool and jdbc/__default) + ClientResponse response = get ("/domain/servers/server/server/resource-ref"); + Map children = this.getChildResources(response); + assertTrue(children.size() >= 2); + } + + @Test + public void testLoadBalancerConfigs() { + final String lbName = "lbconfig-" + generateRandomString(); + ClientResponse response = post ("/domain/lb-configs/lb-config/", + new HashMap() {{ + put("id", lbName); + put("target", instanceName1); + }}); + assertTrue(isSuccess(response)); + + response = post("/domain/lb-configs/lb-config/" + lbName + "/create-http-lb-ref", + new HashMap() {{ + put ("id", instanceName2); + }}); + assertTrue(isSuccess(response)); + + response = get ("/domain/lb-configs/lb-config/" + lbName + "/server-ref"); + Map children = this.getChildResources(response); + assertEquals(2, children.size()); + } +} \ No newline at end of file Index: src/main/java/org/glassfish/admin/rest/generator/CommandResourceMetaData.java =================================================================== --- src/main/java/org/glassfish/admin/rest/generator/CommandResourceMetaData.java (revision 47331) +++ src/main/java/org/glassfish/admin/rest/generator/CommandResourceMetaData.java (working copy) @@ -307,7 +307,7 @@ {"JmsService", "list-jms-hosts", "GET", "list-jms-hosts", "list-jms-hosts"}, {"JmsService", "list-jms-resources", "GET", "list-jms-resources", "list-jms-resources"}, {"JmsHost", "delete-jms-host", "DELETE", "delete-jms-host", "Delete JMS Host", "id=$parent"}, - {"LbConfig", "create-http-lb-ref", "POST", "create-http-lb-ref", "create-http-lb-ref"}, + {"LbConfig", "create-http-lb-ref", "POST", "create-http-lb-ref", "create-http-lb-ref", "config=$parent"}, {"LbConfig", "create-http-listener", "POST", "create-http-listener", "create-http-listener"}, {"LbConfig", "delete-http-lb-ref", "POST", "delete-http-lb-ref", "delete-http-lb-ref"}, {"LbConfig", "delete-http-listener", "POST", "delete-http-listener", "delete-http-listener"}, Index: src/main/java/org/glassfish/admin/rest/generator/ResourcesGeneratorBase.java =================================================================== --- src/main/java/org/glassfish/admin/rest/generator/ResourcesGeneratorBase.java (revision 47331) +++ src/main/java/org/glassfish/admin/rest/generator/ResourcesGeneratorBase.java (working copy) @@ -109,7 +109,7 @@ ConfigModel childModel = node.getModel(); List subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, domDocument); for (ConfigModel subChildConfigModel : subChildConfigModels) { - if (ResourceUtil.isOnlyATag(childModel)) { + if (ResourceUtil.isOnlyATag(subChildConfigModel)) { String childResourceClassName = getClassName(ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName)); String childPath = subChildConfigModel.getTagName(); classWriter.createGetChildResource(childPath, childResourceClassName);