brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [08/11] git commit: Move catalog YAML test from rest-server to brooklyn-camp.
Date Mon, 14 Jul 2014 15:36:04 GMT
Move catalog YAML test from rest-server to brooklyn-camp.

The test doesn't rely on REST in any way.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/aff8601a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/aff8601a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/aff8601a

Branch: refs/heads/master
Commit: aff8601aebb86c8225d7c1e875a73fb38dce59c5
Parents: d767d78
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Fri Jul 11 13:56:02 2014 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Fri Jul 11 13:56:02 2014 +0300

----------------------------------------------------------------------
 .../camp/brooklyn/AbstractYamlTest.java         |   5 +
 .../brooklyn/camp/brooklyn/CatalogYamlTest.java | 138 ++++++++++++++
 .../resources/CatalogBundleResourceTest.java    | 178 -------------------
 3 files changed, 143 insertions(+), 178 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aff8601a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java
index 012eccf..95d655e 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/AbstractYamlTest.java
@@ -22,6 +22,7 @@ import io.brooklyn.camp.spi.Assembly;
 import io.brooklyn.camp.spi.AssemblyTemplate;
 
 import java.io.Reader;
+import java.io.StringReader;
 import java.util.Set;
 
 import org.slf4j.Logger;
@@ -91,6 +92,10 @@ public abstract class AbstractYamlTest {
             builder.append("\n").append(l);
         return createAndStartApplication(Streams.newReaderWithContents(builder.toString()));
     }
+    
+    protected Entity createAndStartApplication(String input) throws Exception {
+        return createAndStartApplication(new StringReader(input));
+    }
 
     protected Entity createAndStartApplication(Reader input) throws Exception {
         AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aff8601a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java
new file mode 100644
index 0000000..f6486fc
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java
@@ -0,0 +1,138 @@
+package io.brooklyn.camp.brooklyn;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import org.testng.annotations.Test;
+
+import brooklyn.catalog.CatalogItem;
+import brooklyn.entity.Entity;
+import brooklyn.management.osgi.OsgiStandaloneTest;
+
+import com.google.common.collect.Iterables;
+
+
+public class CatalogYamlTest extends AbstractYamlTest {
+    private static final String SIMPLE_ENTITY_TYPE = "brooklyn.osgi.tests.SimpleEntity";
+
+    @Test
+    public void testAddCatalogItem() throws Exception {
+        String registeredTypeName = "my.catalog.app.id.load";
+        addCatalogOSGiEntity(registeredTypeName);
+        
+        CatalogItem<?, ?> item = mgmt().getCatalog().getCatalogItem(registeredTypeName);
+        assertEquals(item.getRegisteredTypeName(), registeredTypeName);
+        
+    }
+
+    @Test
+    public void testLaunchApplicationReferencingCatalog() throws Exception {
+        String registeredTypeName = "my.catalog.app.id.launch";
+        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, SIMPLE_ENTITY_TYPE);
+    }
+
+    @Test
+    public void testLaunchApplicationWithCatalogReferencingOtherCatalog() throws Exception
{
+        String referencedRegisteredTypeName = "my.catalog.app.id.referenced";
+        String referrerRegisteredTypeName = "my.catalog.app.id.referring";
+        addCatalogOSGiEntity(referencedRegisteredTypeName, SIMPLE_ENTITY_TYPE);
+        addCatalogOSGiEntity(referrerRegisteredTypeName, referencedRegisteredTypeName);
+
+        String yaml = "name: simple-app-yaml\n" +
+                      "location: localhost\n" +
+                      "services: \n" +
+                      "  - serviceType: "+referrerRegisteredTypeName;
+        Entity app = createAndStartApplication(yaml);
+        
+        Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
+        assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+    }
+
+    @Test
+    public void testLaunchApplicationWithTypeUsingJavaColonPrefix() throws Exception {
+        String registeredTypeName = SIMPLE_ENTITY_TYPE;
+        String serviceName = "java:"+SIMPLE_ENTITY_TYPE;
+        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, serviceName);
+    }
+
+    @Test
+    public void testLaunchApplicationLoopWithJavaTypeName() throws Exception {
+        String registeredTypeName = SIMPLE_ENTITY_TYPE;
+        String serviceName = SIMPLE_ENTITY_TYPE;
+        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, serviceName);
+    }
+
+    @Test
+    public void testLaunchApplicationLoopCatalogIdFails() throws Exception {
+        String registeredTypeName = "self.referencing.type";
+        registerAndLaunchFailsWithRecursionError(registeredTypeName, registeredTypeName);
+    }
+
+    private void registerAndLaunchAndAssertSimpleEntity(String registeredTypeName, String
serviceType) throws Exception {
+        addCatalogOSGiEntity(registeredTypeName, serviceType);
+        try {
+            String yaml = "name: simple-app-yaml\n" +
+                          "location: localhost\n" +
+                          "services: \n" +
+                          "  - serviceType: "+registeredTypeName;
+            Entity app = createAndStartApplication(yaml);
+    
+            Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
+            assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+        } finally {
+            deleteCatalogEntity(registeredTypeName);
+        }
+    }
+
+    private void registerAndLaunchFailsWithRecursionError(String registeredTypeName, String
serviceType) throws Exception {
+        addCatalogOSGiEntity(registeredTypeName, serviceType);
+        try {
+            String yaml = "name: simple-app-yaml\n" +
+                          "location: localhost\n" +
+                          "services: \n" +
+                          "  - serviceType: "+registeredTypeName;
+            try {
+                createAndStartApplication(yaml);
+                fail("Expected to throw IllegalStateException");
+            } catch (IllegalStateException e) {
+                assertTrue(e.getMessage().contains("Recursive reference to "+registeredTypeName));
+            }
+        } finally {
+            deleteCatalogEntity(registeredTypeName);
+        }
+    }
+
+    private void addCatalogOSGiEntity(String registeredTypeName) {
+        addCatalogOSGiEntity(registeredTypeName, SIMPLE_ENTITY_TYPE);
+    }
+    
+    private void addCatalogOSGiEntity(String registeredTypeName, String serviceType) {
+        String catalogYaml =
+            "name: "+registeredTypeName+"\n"+
+            // FIXME name above should be unnecessary -- slight problem somewhere currently
+            // as testListApplicationYaml fails without the line above
+            "brooklyn.catalog:\n"+
+            "  id: " + registeredTypeName + "\n"+
+            "  name: My Catalog App\n"+
+            "  description: My description\n"+
+            "  icon_url: classpath://path/to/myicon.jpg\n"+
+            "  version: 0.1.2\n"+
+            "  libraries:\n"+
+            "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL + "\n"+
+            "\n"+
+            "services:\n"+
+            "- type: " + serviceType;
+
+        addCatalogItem(catalogYaml);
+    }
+
+    private void addCatalogItem(String catalogYaml) {
+        mgmt().getCatalog().addItem(catalogYaml);
+    }
+
+    private void deleteCatalogEntity(String catalogItem) {
+        mgmt().getCatalog().deleteCatalogItem(catalogItem);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aff8601a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
deleted file mode 100644
index f9910dc..0000000
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogBundleResourceTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package brooklyn.rest.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.io.InputStream;
-import java.net.URI;
-
-import javax.ws.rs.core.Response;
-
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Application;
-import brooklyn.entity.Entity;
-import brooklyn.management.osgi.OsgiStandaloneTest;
-import brooklyn.rest.domain.ApplicationSummary;
-import brooklyn.rest.domain.CatalogEntitySummary;
-import brooklyn.rest.testing.BrooklynRestResourceTest;
-import brooklyn.util.stream.Streams;
-
-import com.google.common.collect.Iterables;
-import com.sun.jersey.api.client.ClientResponse;
-
-public class CatalogBundleResourceTest extends BrooklynRestResourceTest {
-
-    private static final String SIMPLE_ENTITY_TYPE = "brooklyn.osgi.tests.SimpleEntity";
-
-    @Test
-    public void testListApplicationYaml() throws Exception {
-        String registeredTypeName = "my.catalog.app.id.load";
-        addCatalogOSGiEntity(registeredTypeName);
-        CatalogEntitySummary entityItem = client().resource("/v1/catalog/entities/"+registeredTypeName)
-                .get(CatalogEntitySummary.class);
-
-        assertEquals(entityItem.getRegisteredType(), registeredTypeName);
-        
-    }
-
-    @Test
-    public void testLaunchApplicationYaml() throws Exception {
-        String registeredTypeName = "my.catalog.app.id.launch";
-        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, SIMPLE_ENTITY_TYPE);
-    }
-
-    @Test
-    public void testLaunchApplicationWithCatalogReferencingOtherCatalogYaml() throws Exception
{
-        String referencedRegisteredTypeName = "my.catalog.app.id.referenced";
-        String referrerRegisteredTypeName = "my.catalog.app.id.referring";
-        addCatalogOSGiEntity(referencedRegisteredTypeName, SIMPLE_ENTITY_TYPE);
-        addCatalogOSGiEntity(referrerRegisteredTypeName, referencedRegisteredTypeName);
-
-        String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+referrerRegisteredTypeName+" } ] }";
-        ApplicationSummary appSummary = createAndWaitForApp(yaml);
-
-        String appId = appSummary.getId();
-        assertEquals(appSummary.getSpec().getName(), "simple-app-yaml");
-
-        Application app = (Application) getManagementContext().getEntityManager().getEntity(appId);
-        Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
-        assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
-    }
-
-    @Test
-    public void testLaunchApplicationWithTypeUsingJavaColonPrefixInYaml() throws Exception
{
-        String registeredTypeName = SIMPLE_ENTITY_TYPE;
-        String serviceName = "java:"+SIMPLE_ENTITY_TYPE;
-        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, serviceName);
-    }
-
-    @Test
-    public void testLaunchApplicationLoopWithJavaTypeNameInYaml() throws Exception {
-        String registeredTypeName = SIMPLE_ENTITY_TYPE;
-        String serviceName = SIMPLE_ENTITY_TYPE;
-        registerAndLaunchAndAssertSimpleEntity(registeredTypeName, serviceName);
-    }
-
-    @Test
-    public void testLaunchApplicationLoopCatalogIdInYamlFails() throws Exception {
-        String registeredTypeName = "self.referencing.type";
-        registerAndLaunchFailsWithRecursionError(registeredTypeName, registeredTypeName);
-    }
-
-    private void registerAndLaunchAndAssertSimpleEntity(String registeredTypeName, String
serviceType) {
-        addCatalogOSGiEntity(registeredTypeName, serviceType);
-        try {
-            String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+registeredTypeName+" } ] }";
-            ApplicationSummary appSummary = createAndWaitForApp(yaml);
-    
-            String appId = appSummary.getId();
-            assertEquals(appSummary.getSpec().getName(), "simple-app-yaml");
-    
-            Application app = (Application) getManagementContext().getEntityManager().getEntity(appId);
-            Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
-            assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
-        } finally {
-            deleteCatalogEntity(registeredTypeName);
-        }
-    }
-
-    private void registerAndLaunchFailsWithRecursionError(String registeredTypeName, String
serviceType) {
-        addCatalogOSGiEntity(registeredTypeName, serviceType);
-        try {
-            String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType:
"+registeredTypeName+" } ] }";
-            ClientResponse response = client().resource("/v1/applications")
-                    .entity(yaml, "application/x-yaml")
-                    .post(ClientResponse.class);
-    
-            int responseStatus = response.getStatus();
-            String responseContent = getResponseContentAsString(response);
-    
-            assertFalse(responseStatus/100 == 2, "response="+response+"; content="+responseContent);
-            assertTrue(responseContent.contains("Recursive reference to "+registeredTypeName),
"content="+responseContent);
-        } finally {
-            deleteCatalogEntity(registeredTypeName);
-        }
-    }
-
-    private ApplicationSummary createAndWaitForApp(String yaml) {
-        ClientResponse response = client().resource("/v1/applications")
-                .entity(yaml, "application/x-yaml")
-                .post(ClientResponse.class);
-        assertTrue(response.getStatus()/100 == 2, "response is "+response);
-
-        URI appUri = response.getLocation();
-        waitForApplicationToBeRunning(response.getLocation());
-        
-        return client().resource(appUri).get(ApplicationSummary.class);
-    }
-    
-    private void addCatalogOSGiEntity(String registeredTypeName) {
-        addCatalogOSGiEntity(registeredTypeName, SIMPLE_ENTITY_TYPE);
-    }
-    
-    private void addCatalogOSGiEntity(String registeredTypeName, String serviceType) {
-        String catalogYaml =
-            "name: "+registeredTypeName+"\n"+
-            // FIXME name above should be unnecessary -- slight problem somewhere currently
-            // as testListApplicationYaml fails without the line above
-            "brooklyn.catalog:\n"+
-            "  id: " + registeredTypeName + "\n"+
-            "  name: My Catalog App\n"+
-            "  description: My description\n"+
-            "  icon_url: classpath://path/to/myicon.jpg\n"+
-            "  version: 0.1.2\n"+
-            "  libraries:\n"+
-            "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL + "\n"+
-            "\n"+
-            "services:\n"+
-            "- type: " + serviceType;
-
-        addCatalogEntity(catalogYaml);
-    }
-
-    private void addCatalogEntity(String catalogYaml) {
-        ClientResponse catalogResponse = client().resource("/v1/catalog")
-            .post(ClientResponse.class, catalogYaml);
-
-        assertEquals(catalogResponse.getStatus(), Response.Status.CREATED.getStatusCode());
-    }
-    
-    private void deleteCatalogEntity(String catalogItem) {
-        ClientResponse catalogResponse = client().resource("/v1/catalog/entities/"+catalogItem)
-            .delete(ClientResponse.class);
-
-        assertEquals(catalogResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
-    }
-    
-    private String getResponseContentAsString(ClientResponse response) {
-        InputStream in = null;
-        try {
-            in = response.getEntityInputStream();
-            return new String(Streams.readFully(in));
-        } finally {
-            Streams.closeQuietly(in);
-        }
-    }
-}


Mime
View raw message