brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [10/45] git commit: Adds version to catalogue items and tests deserialisation
Date Fri, 04 Jul 2014 09:50:52 GMT
Adds version to catalogue items and tests deserialisation


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

Branch: refs/heads/master
Commit: 45e1494f74ffe1829b0ded954a450846c3cef2a3
Parents: 494291d
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Mon Jun 30 15:23:35 2014 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Tue Jul 1 13:37:37 2014 +0100

----------------------------------------------------------------------
 .../main/java/brooklyn/catalog/CatalogItem.java |  4 ++
 .../catalog/internal/CatalogItemDo.java         |  8 ++++
 .../internal/CatalogItemDtoAbstract.java        |  5 +++
 .../catalog/internal/CatalogXmlSerializer.java  |  1 +
 .../catalog/internal/CatalogLoadTest.java       | 46 ++++++++++++++++++++
 .../brooklyn/catalog/internal/osgi-catalog.xml  | 11 +++++
 6 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/api/src/main/java/brooklyn/catalog/CatalogItem.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/catalog/CatalogItem.java b/api/src/main/java/brooklyn/catalog/CatalogItem.java
index ab01496..b9ae3c0 100644
--- a/api/src/main/java/brooklyn/catalog/CatalogItem.java
+++ b/api/src/main/java/brooklyn/catalog/CatalogItem.java
@@ -1,6 +1,7 @@
 package brooklyn.catalog;
 
 import java.util.List;
+import javax.annotation.Nonnull;
 
 public interface CatalogItem<T> {
     
@@ -20,6 +21,9 @@ public interface CatalogItem<T> {
     public String getName();
     public String getDescription();
     public String getIconUrl();
+    public String getVersion();
+
+    @Nonnull
     public CatalogItemContext getContext();
 
     public String toXmlString();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
index d576c0a..91ed93a 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
@@ -1,5 +1,7 @@
 package brooklyn.catalog.internal;
 
+import javax.annotation.Nonnull;
+
 import com.google.common.base.Preconditions;
 
 import brooklyn.catalog.CatalogItem;
@@ -57,6 +59,12 @@ public class CatalogItemDo<T> implements CatalogItem<T> {
     }
 
     @Override
+    public String getVersion() {
+        return itemDto.getVersion();
+    }
+
+    @Nonnull
+    @Override
     public CatalogItemContext getContext() {
         return itemDto.getContext();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
index 043758b..a774930 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
@@ -21,6 +21,7 @@ public abstract class CatalogItemDtoAbstract<T> implements CatalogItem<T>
{
     String name;
     String description;
     String iconUrl;
+    String version;
     CatalogItemContext context;
     
     public String getId() {
@@ -44,6 +45,10 @@ public abstract class CatalogItemDtoAbstract<T> implements CatalogItem<T>
{
         return iconUrl;
     }
 
+    public String getVersion() {
+        return version;
+    }
+
     @Nonnull
     @Override
     public CatalogItemContext getContext() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/core/src/main/java/brooklyn/catalog/internal/CatalogXmlSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogXmlSerializer.java b/core/src/main/java/brooklyn/catalog/internal/CatalogXmlSerializer.java
index 9cdbffe..63c2382 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogXmlSerializer.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogXmlSerializer.java
@@ -28,6 +28,7 @@ public class CatalogXmlSerializer extends XmlSerializer<Object> {
 
         xstream.useAttributeFor(CatalogItemDtoAbstract.class, "type");
         xstream.useAttributeFor(CatalogItemDtoAbstract.class, "name");
+        xstream.useAttributeFor(CatalogItemDtoAbstract.class, "version");
 
         xstream.useAttributeFor(CatalogClasspathDto.class, "scan");
         xstream.addImplicitCollection(CatalogClasspathDto.class, "entries", "entry", String.class);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
new file mode 100644
index 0000000..46394c7
--- /dev/null
+++ b/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
@@ -0,0 +1,46 @@
+package brooklyn.catalog.internal;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+import brooklyn.util.ResourceUtils;
+
+public class CatalogLoadTest {
+
+    CatalogXmlSerializer serializer;
+
+    @BeforeMethod
+    public void setUp() {
+        serializer = new CatalogXmlSerializer();
+    }
+
+    private String loadFile(String file) {
+        return ResourceUtils.create(this).getResourceAsString(file);
+    }
+
+    @Test
+    public void testLoadCatalog() {
+        CatalogDto catalog = (CatalogDto) serializer.fromString(
+                loadFile("classpath://brooklyn/catalog/internal/osgi-catalog.xml"));
+        assertNotNull(catalog);
+        assertEquals(catalog.name, "OSGi catalogue");
+        assertEquals(catalog.entries.size(), 1, "Catalog entries = " + Joiner.on(", ").join(catalog.entries));
+
+        CatalogItemDtoAbstract<?> template = Iterables.getOnlyElement(catalog.entries);
+        assertEquals(template.getName(), "Entity name");
+        assertEquals(template.getVersion(), "9.1.3");
+        assertEquals(template.getJavaType(), "com.example.ExampleApp");
+        assertEquals(template.getContext().getBundles().size(), 2,
+                "Template bundles=" + Joiner.on(", ").join(template.getContext().getBundles()));
+        assertEquals(Sets.newHashSet(template.getContext().getBundles()),
+                Sets.newHashSet("file://path/to/bundle.jar", "http://www.url.com/for/bundle.jar"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/45e1494f/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml b/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml
new file mode 100644
index 0000000..c8ea685
--- /dev/null
+++ b/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml
@@ -0,0 +1,11 @@
+<catalog>
+    <name>OSGi catalogue</name>
+
+    <template name="Entity name" version="9.1.3" type="com.example.ExampleApp">
+        <description>An example application</description>
+        <context class="context">
+            <bundle>file://path/to/bundle.jar</bundle>
+            <bundle>http://www.url.com/for/bundle.jar</bundle>
+        </context>
+    </template>
+</catalog>


Mime
View raw message