You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/01/15 00:54:16 UTC

[02/24] incubator-brooklyn git commit: test (failing) for setting the plan yaml on a spec when it comes from a template registry item

test (failing) for setting the plan yaml on a spec when it comes from a template registry item


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

Branch: refs/heads/master
Commit: 09351a664665056b8a47a233f6eefdbc65769288
Parents: d058158
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Jan 13 11:28:03 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Jan 13 11:28:03 2016 +0000

----------------------------------------------------------------------
 .../catalog/CatalogYamlTemplateTest.java        | 22 ++++++++++++++++++++
 .../apache/brooklyn/core/mgmt/BrooklynTags.java | 14 +++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/09351a66/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
index c3dbc48..c5ea96f 100644
--- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
+++ b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java
@@ -18,13 +18,23 @@
  */
 package org.apache.brooklyn.camp.brooklyn.catalog;
 
+import java.util.List;
+
+import org.apache.brooklyn.api.entity.Application;
+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.TestUtils;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
+import org.python.google.common.collect.Iterables;
 import org.testng.Assert;
 import org.testng.TestListenerAdapter;
 import org.testng.TestNG;
@@ -63,6 +73,18 @@ public class CatalogYamlTemplateTest extends AbstractYamlTest {
         deleteCatalogEntity("t1");
     }
 
+    @Test
+    public void testSpecFromItem() throws Exception {
+        makeItem();
+        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");
+    }
+    
     private RegisteredType makeItem() {
         TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/09351a66/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTags.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTags.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTags.java
index e8d7915..ffed4f8 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTags.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTags.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.core.mgmt;
 import java.io.Serializable;
 import java.util.List;
 
+import org.apache.brooklyn.util.collections.MutableList;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.codehaus.jackson.annotate.JsonProperty;
 
@@ -73,7 +74,7 @@ public class BrooklynTags {
         public boolean equals(Object o) {
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
-            ListTag that = (ListTag) o;
+            ListTag<?> that = (ListTag<?>) o;
             return list == null ? that.list == null : list.equals(that.list);
         }
 
@@ -117,5 +118,14 @@ public class BrooklynTags {
         }
         return null;
     }
-    
+
+    public static List<NamedStringTag> findAll(String kind, Iterable<Object> tags) {
+        List<NamedStringTag> result = MutableList.of();
+        for (Object object: tags) {
+            if (object instanceof NamedStringTag && kind.equals(((NamedStringTag)object).kind))
+                result.add( (NamedStringTag) object );
+        }
+        return result;
+    }
+
 }