You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/07/18 12:00:43 UTC

[07/10] git commit: Add tests

Add tests

  * Catalog item does not leak bundles to child catalog items
  * Catalog item DOES leak bundles to URL referenced YAMLs


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

Branch: refs/heads/master
Commit: f1425269dab14b386da5870ab010572a66b12d38
Parents: 2250609
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Jul 16 13:55:04 2014 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Jul 17 18:54:29 2014 +0300

----------------------------------------------------------------------
 .../brooklyn/camp/brooklyn/CatalogYamlTest.java | 39 +++++++++++++++++++-
 .../camp/brooklyn/ReferencedYamlTest.java       | 29 +++++++++++++++
 .../yaml-ref-bundle-without-libraries.yaml      | 19 ++++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f1425269/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
index 592160c..78f7c0d 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/CatalogYamlTest.java
@@ -51,7 +51,7 @@ public class CatalogYamlTest extends AbstractYamlTest {
         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";
@@ -140,6 +140,43 @@ public class CatalogYamlTest extends AbstractYamlTest {
         }
     }
 
+    /**
+     * Tests that a catalog item referenced by another
+     * catalog item won't have access to the parent's bundles.
+     */
+    @Test
+    public void testParentCatalogDoesNotLeakBundlesToChildCatalogItems() throws Exception {
+        String childCatalogId = "my.catalog.app.id.no_bundles";
+        String parentCatalogId = "my.catalog.app.id.parent";
+        addCatalogItem(
+                "brooklyn.catalog:",
+                "  id: " + childCatalogId,
+                "",
+                "services:",
+                "- type: " + SIMPLE_ENTITY_TYPE);
+        
+        addCatalogItem(
+                "brooklyn.catalog:",
+                "  id: " + parentCatalogId,
+                "  libraries:",
+                "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+                "",
+                "services:",
+                "- type: " + childCatalogId);
+        
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- type: " + parentCatalogId);
+        } catch (UnsupportedOperationException e) {
+            assertTrue(e.getMessage().endsWith("cannot be matched"));
+            assertTrue(e.getMessage().contains(SIMPLE_ENTITY_TYPE));
+        }
+
+        deleteCatalogEntity(parentCatalogId);
+        deleteCatalogEntity(childCatalogId);
+    }
+
     private void registerAndLaunchAndAssertSimpleEntity(String registeredTypeName, String serviceType) throws Exception {
         addCatalogOSGiEntity(registeredTypeName, serviceType);
         try {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f1425269/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
index b2ad68b..05bb8c0 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.BasicApplication;
 import brooklyn.entity.basic.BasicEntity;
+import brooklyn.management.osgi.OsgiStandaloneTest;
 
 import com.google.common.collect.Iterables;
 
@@ -123,6 +124,34 @@ public class ReferencedYamlTest extends AbstractYamlTest {
         checkChildEntitySpec(app, entityName);
     }
 
+    /**
+     * Tests that a YAML referenced by URL from a catalog item
+     * will have access to the catalog item's bundles.
+     */
+    @Test
+    public void testCatalogLeaksBundlesToReferencedYaml() throws Exception {
+        String parentCatalogId = "my.catalog.app.id.url.parent";
+        addCatalogItem(
+            "brooklyn.catalog:",
+            "  id: " + parentCatalogId,
+            "  libraries:",
+            "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "",
+            "services:",
+            "- type: classpath://yaml-ref-bundle-without-libraries.yaml");
+
+        Entity app = createAndStartApplication(
+            "services:",
+                "- type: " + parentCatalogId);
+        
+        Collection<Entity> children = app.getChildren();
+        Assert.assertEquals(children.size(), 1);
+        Entity child = Iterables.getOnlyElement(children);
+        Assert.assertEquals(child.getEntityType().getName(), "brooklyn.osgi.tests.SimpleEntity");
+
+        deleteCatalogEntity(parentCatalogId);
+    }
+
     private void checkChildEntitySpec(Entity app, String entityName) {
         Collection<Entity> children = app.getChildren();
         Assert.assertEquals(children.size(), 1);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f1425269/usage/camp/src/test/resources/yaml-ref-bundle-without-libraries.yaml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/yaml-ref-bundle-without-libraries.yaml b/usage/camp/src/test/resources/yaml-ref-bundle-without-libraries.yaml
new file mode 100644
index 0000000..f2ae9cb
--- /dev/null
+++ b/usage/camp/src/test/resources/yaml-ref-bundle-without-libraries.yaml
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+services:
+- type: brooklyn.osgi.tests.SimpleEntity