brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [3/9] brooklyn-server git commit: Split CatalogYamlTemplateTest for non-osgi and osgi
Date Mon, 13 Feb 2017 06:26:43 GMT
Split CatalogYamlTemplateTest for non-osgi and osgi


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

Branch: refs/heads/master
Commit: 27ad37cd39b7b133a454f6e9b5d05eaedc0dc3d6
Parents: f2ea02d
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Feb 10 14:50:26 2017 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Feb 10 22:16:02 2017 +0000

----------------------------------------------------------------------
 .../catalog/CatalogOsgiYamlTemplateTest.java    | 113 +++++++++++++++++++
 .../catalog/CatalogYamlTemplateTest.java        |  43 +++----
 2 files changed, 130 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/27ad37cd/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlTemplateTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlTemplateTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlTemplateTest.java
new file mode 100644
index 0000000..8b2a561
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlTemplateTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+package org.apache.brooklyn.camp.brooklyn.catalog;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
+import org.apache.brooklyn.core.mgmt.BrooklynTags;
+import org.apache.brooklyn.core.mgmt.BrooklynTags.NamedStringTag;
+import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
+import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.osgi.OsgiTestResources;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+
+public class CatalogOsgiYamlTemplateTest extends AbstractYamlTest {
+    
+    private static final String SIMPLE_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
+
+    @Override
+    protected boolean disableOsgi() {
+        return false;
+    }
+
+    @Test
+    public void testAddCatalogItemOsgi() throws Exception {
+        RegisteredType item = makeItem("t1", SIMPLE_ENTITY_TYPE);
+        Assert.assertTrue(RegisteredTypePredicates.IS_APPLICATION.apply(item), "item: "+item);
+        String yaml = RegisteredTypes.getImplementationDataStringForSpec(item);
+        Assert.assertTrue(yaml.indexOf("sample comment")>=0,
+            "YAML did not include original comments; it was:\n"+yaml);
+        Assert.assertFalse(yaml.indexOf("description")>=0,
+            "YAML included metadata which should have been excluded; it was:\n"+yaml);
+
+        // Confirm can deploy an app using this template catalog item
+        Entity app = createAndStartApplication(
+                "services:",
+                "- type: t1");
+        waitForApplicationTasks(app);
+        
+        Entity entity = Iterables.getOnlyElement(app.getChildren());
+        assertEquals(entity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+        
+        deleteCatalogEntity("t1");
+    }
+
+    @Test
+    public void testMetadataOnSpecCreatedFromItem() throws Exception {
+        makeItem("t1", SIMPLE_ENTITY_TYPE);
+        EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(mgmt(),

+            "services: [ { type: t1 } ]\n" +
+            "location: localhost");
+        
+        List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND,
spec.getTags());
+        Assert.assertEquals(yamls.size(), 1, "Expected 1 yaml tag; instead had: "+yamls);
+        String yaml = Iterables.getOnlyElement(yamls).getContents();
+        Asserts.assertStringContains(yaml, "services:", "t1", "localhost");
+        
+        EntitySpec<?> child = Iterables.getOnlyElement( spec.getChildren() );
+        Assert.assertEquals(child.getType().getName(), SIMPLE_ENTITY_TYPE);
+        Assert.assertEquals(child.getCatalogItemId(), "t1:"+TEST_VERSION);
+    }
+    
+    private RegisteredType makeItem(String symbolicName, String templateType) {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  id: " + symbolicName,
+            "  itemType: template",
+            "  name: My Catalog App",
+            "  description: My description",
+            "  icon_url: classpath://path/to/myicon.jpg",
+            "  version: " + TEST_VERSION,
+            "  libraries:",
+            "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "  item:",
+            "    services:",
+            "    # this sample comment should be included",
+            "    - type: " + templateType);
+
+        return mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/27ad37cd/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
index 954d38d..cb585e0 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
@@ -32,36 +32,27 @@ import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.mgmt.BrooklynTags;
 import org.apache.brooklyn.core.mgmt.BrooklynTags.NamedStringTag;
 import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
-import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.entity.group.DynamicCluster;
 import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.test.Asserts;
-import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.testng.Assert;
 import org.testng.TestListenerAdapter;
 import org.testng.TestNG;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Joiner;
 import com.google.common.collect.Iterables;
 
 
 public class CatalogYamlTemplateTest extends AbstractYamlTest {
     
-    private static final String SIMPLE_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
-
-    @Override
-    protected boolean disableOsgi() {
-        return false;
-    }
-
     @Test
     public void testAddCatalogItem() throws Exception {
-        RegisteredType item = makeItem();
+        RegisteredType item = addCatalogItem("t1", TestEntity.class.getName());
         Assert.assertTrue(RegisteredTypePredicates.IS_APPLICATION.apply(item), "item: "+item);
         String yaml = RegisteredTypes.getImplementationDataStringForSpec(item);
         Assert.assertTrue(yaml.indexOf("sample comment")>=0,
@@ -74,10 +65,10 @@ public class CatalogYamlTemplateTest extends AbstractYamlTest {
 
     @Test
     public void testAddCatalogItemAndCheckSource() throws Exception {
-        // this will fail with the Eclipse TestNG plugin -- use the static main instead to
run in eclipse!
+        // this may fail with old Eclipse TestNG plugins -- use the static main instead to
run in eclipse!
         // see Yamls.KnownClassVersionException for details
         
-        RegisteredType item = makeItem();
+        RegisteredType item = addCatalogItem("t1", TestEntity.class.getName());
         String yaml = RegisteredTypes.getImplementationDataStringForSpec(item);
         Assert.assertTrue(yaml.indexOf("sample comment")>=0,
             "YAML did not include original comments; it was:\n"+yaml);
@@ -201,10 +192,14 @@ public class CatalogYamlTemplateTest extends AbstractYamlTest {
 
     @Test
     public void testMetadataOnSpecCreatedFromItem() throws Exception {
-        makeItem();
-        EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(mgmt(),

-            "services: [ { type: t1 } ]\n" +
-            "location: localhost");
+        addCatalogItem("t1", TestEntity.class.getName());
+
+        EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(
+                mgmt(),
+                Joiner.on("\n").join(
+                        "location: localhost",
+                        "services:",
+                        "- type: t1"));
         
         List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND,
spec.getTags());
         Assert.assertEquals(yamls.size(), 1, "Expected 1 yaml tag; instead had: "+yamls);
@@ -212,7 +207,7 @@ public class CatalogYamlTemplateTest extends AbstractYamlTest {
         Asserts.assertStringContains(yaml, "services:", "t1", "localhost");
         
         EntitySpec<?> child = Iterables.getOnlyElement( spec.getChildren() );
-        Assert.assertEquals(child.getType().getName(), SIMPLE_ENTITY_TYPE);
+        Assert.assertEquals(child.getType().getName(), TestEntity.class.getName());
         Assert.assertEquals(child.getCatalogItemId(), "t1:"+TEST_VERSION);
     }
     
@@ -255,25 +250,21 @@ public class CatalogYamlTemplateTest extends AbstractYamlTest {
         Assert.assertEquals(spec.getCatalogItemId(), "app1r:1");
     }
     
-    private RegisteredType makeItem() {
-        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-        
+    private RegisteredType addCatalogItem(String symbolicName, String templateType) {
         addCatalogItems(
             "brooklyn.catalog:",
-            "  id: t1",
+            "  id: " + symbolicName,
             "  itemType: template",
             "  name: My Catalog App",
             "  description: My description",
             "  icon_url: classpath://path/to/myicon.jpg",
             "  version: " + TEST_VERSION,
-            "  libraries:",
-            "  - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
             "  item:",
             "    services:",
             "    # this sample comment should be included",
-            "    - type: " + SIMPLE_ENTITY_TYPE);
+            "    - type: " + templateType);
 
-        return mgmt().getTypeRegistry().get("t1", TEST_VERSION);
+        return mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
     }
 
     // convenience for running in eclipse when the TestNG plugin drags in old version of
snake yaml


Mime
View raw message