You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/02/26 12:27:33 UTC
[5/6] incubator-brooklyn git commit: Tests for old-style catalog
items when loaded from external classpath or OSGi bundle
Tests for old-style catalog items when loaded from external classpath or OSGi bundle
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8523e112
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8523e112
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8523e112
Branch: refs/heads/master
Commit: 8523e112dd783c9a516782b04d7c1dfb75498db9
Parents: e7b9a74
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Feb 25 18:08:48 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Feb 25 18:08:48 2015 +0200
----------------------------------------------------------------------
.../management/osgi/OsgiTestResources.java | 1 +
.../catalog/AbstractCatalogXmlTest.java | 107 +++++++++++++++++++
.../brooklyn/catalog/CatalogXmlOsgiTest.java | 37 +++++++
.../brooklyn/catalog/CatalogXmlVersionTest.java | 28 ++---
usage/camp/src/test/resources/osgi-catalog.xml | 29 +++++
.../camp/src/test/resources/simple-catalog.xml | 22 ++--
6 files changed, 195 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java b/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
index 48d01dc..ef0321d 100644
--- a/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
@@ -41,6 +41,7 @@ public class OsgiTestResources {
* defines an entity and an application, to confirm it can be read and used by brooklyn
*/
public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
+ public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_APPLICATION = "brooklyn.osgi.tests.SimpleApplication";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY = "brooklyn.osgi.tests.SimpleEntity";
public static final String BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_POLICY = "brooklyn.osgi.tests.SimplePolicy";
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
new file mode 100644
index 0000000..44ea9a8
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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 io.brooklyn.camp.brooklyn.catalog;
+
+import io.brooklyn.camp.brooklyn.AbstractYamlTest;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringReader;
+
+import brooklyn.config.BrooklynProperties;
+import brooklyn.config.BrooklynServerConfig;
+import brooklyn.entity.Entity;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.management.osgi.OsgiTestResources;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.ResourceUtils;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.os.Os;
+import brooklyn.util.stream.ReaderInputStream;
+import brooklyn.util.stream.Streams;
+
+import com.google.common.io.ByteStreams;
+
+public class AbstractCatalogXmlTest extends AbstractYamlTest {
+
+ private String catalogUrl;
+
+ public AbstractCatalogXmlTest(String catalogUrl) {
+ this.catalogUrl = catalogUrl;
+ }
+
+ @Override
+ protected LocalManagementContext newTestManagementContext() {
+ ResourceUtils ru = new ResourceUtils(this);
+ File jar = createJar(ru);
+ File catalog = createCatalog(ru, jar);
+
+ BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
+ properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, catalog.toURI().toString());
+ return LocalManagementContextForTests.builder(true)
+ .useProperties(properties)
+ .disableOsgi(false)
+ .build();
+ }
+
+ protected Entity startApp(String type) throws Exception {
+ String yaml = "name: simple-app-yaml\n" +
+ "location: localhost\n" +
+ "services: \n" +
+ " - type: " + type;
+ return createAndStartApplication(yaml);
+ }
+
+ private File createCatalog(ResourceUtils ru, File tmpJar) {
+ String catalogTemplate = ru.getResourceAsString(catalogUrl);
+ String catalog = catalogTemplate.replace("${osgi-entities-path}", tmpJar.toURI().toString());
+ File catalogTmp = Os.newTempFile("simple-catalog-", ".xml");
+ copy(catalog, catalogTmp);
+ return catalogTmp;
+ }
+
+ private File createJar(ResourceUtils ru) {
+ File tmpJar = Os.newTempFile("osgi-entities-", ".jar");
+ InputStream in = ru.getResourceFromUrl("classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+ copy(in, tmpJar);
+ return tmpJar;
+ }
+
+ private void copy(String src, File dst) {
+ try {
+ copy(new ReaderInputStream(new StringReader(src), "UTF-8"), dst);
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+
+ private void copy(InputStream in, File tmpJar) {
+ try {
+ OutputStream out = new FileOutputStream(tmpJar);
+ ByteStreams.copy(in, out);
+ Streams.closeQuietly(in);
+ Streams.closeQuietly(out);
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
new file mode 100644
index 0000000..bac2991
--- /dev/null
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlOsgiTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 io.brooklyn.camp.brooklyn.catalog;
+
+import org.testng.annotations.Test;
+
+public class CatalogXmlOsgiTest extends AbstractCatalogXmlTest {
+
+ public CatalogXmlOsgiTest(String catalogUrl) {
+ super("classpath://osgi-catalog.xml");
+ }
+
+ //OSGi libraries not supported with old-style catalog items
+ //We treat those catalog items just as an alias to the java type they hold.
+ //No loader wrapping their libraries is ever created.
+ @Test(expectedExceptions=IllegalStateException.class)
+ public void testOsgiItem() throws Exception {
+ startApp("OsgiApp");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
index cf1e211..93e23e6 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogXmlVersionTest.java
@@ -19,23 +19,16 @@
package io.brooklyn.camp.brooklyn.catalog;
import static org.testng.Assert.assertTrue;
-import io.brooklyn.camp.brooklyn.AbstractYamlTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import brooklyn.config.BrooklynProperties;
-import brooklyn.config.BrooklynServerConfig;
import brooklyn.entity.Entity;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.test.entity.LocalManagementContextForTests;
-public class CatalogXmlVersionTest extends AbstractYamlTest {
- @Override
- protected LocalManagementContext newTestManagementContext() {
- BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
- properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://simple-catalog.xml");
- return LocalManagementContextForTests.newInstance(properties);
+public class CatalogXmlVersionTest extends AbstractCatalogXmlTest {
+
+ public CatalogXmlVersionTest(String catalogUrl) {
+ super("classpath://simple-catalog.xml");
}
@DataProvider(name = "types")
@@ -44,9 +37,10 @@ public class CatalogXmlVersionTest extends AbstractYamlTest {
{"brooklyn.entity.basic.BasicApplication"},
{"brooklyn.entity.basic.BasicApplication:0.0.0.SNAPSHOT"},
{"brooklyn.entity.basic.BasicApplication:2.0"},
- {"BasicApp"},
+ {"BasicApp"}, // test that items with symbolicName not matching the type work
{"BasicApp:0.0.0.SNAPSHOT"},
- {"BasicApp:2.0"}
+ {"BasicApp:2.0"},
+ {"brooklyn.osgi.tests.SimpleApplication"}, //test that classpath is used
};
}
@@ -61,12 +55,4 @@ public class CatalogXmlVersionTest extends AbstractYamlTest {
assertTrue(entity instanceof TestBasicApp, "Entity is not a " + TestBasicApp.class.getName() + ", instead the type is " + entity.getEntityType().getName());
}
- private Entity startApp(String type) throws Exception {
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - type: " + type;
- return createAndStartApplication(yaml);
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/resources/osgi-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/osgi-catalog.xml b/usage/camp/src/test/resources/osgi-catalog.xml
new file mode 100644
index 0000000..f409a52
--- /dev/null
+++ b/usage/camp/src/test/resources/osgi-catalog.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<catalog>
+ <name>OSGi catalogue</name>
+ <template name="Osgi App" type="brooklyn.osgi.tests.SimpleApplication">
+ <symbolicName>OsgiApp</symbolicName>
+ <libraries>
+ <bundle>${osgi-entities-path}</bundle>
+ </libraries>
+ </template>
+</catalog>
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8523e112/usage/camp/src/test/resources/simple-catalog.xml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/simple-catalog.xml b/usage/camp/src/test/resources/simple-catalog.xml
index e3a1214..242478c 100644
--- a/usage/camp/src/test/resources/simple-catalog.xml
+++ b/usage/camp/src/test/resources/simple-catalog.xml
@@ -20,22 +20,28 @@
<catalog>
<name>Simple catalogue</name>
- <template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
- <description>An example application</description>
- </template>
- <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
- <description>An example application</description>
- </template>
+ <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" />
+ <template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0" />
<template name="Basic App" type="brooklyn.entity.basic.BasicApplication">
<symbolicName>BasicApp</symbolicName>
- <description>An example application</description>
</template>
<template name="Basic App" type="brooklyn.entity.basic.BasicApplication" version="2.0">
<symbolicName>BasicApp</symbolicName>
- <description>An example application</description>
</template>
<template name="Custom App" type="brooklyn.entity.basic.BasicApplication">
<symbolicName>io.brooklyn.camp.brooklyn.catalog.TestBasicApp</symbolicName>
<!-- Tests that "java:" prefix won't load an old-style catalog item with the same id -->
</template>
+ <template name="Osgi App" type="brooklyn.osgi.tests.SimpleApplication">
+ <symbolicName>OsgiApp</symbolicName>
+ <libraries>
+ <bundle>${osgi-entities-path}</bundle>
+ </libraries>
+ </template>
+ <catalog>
+ <template name="Simple App" type="brooklyn.osgi.tests.SimpleApplication" />
+ <classpath>
+ <entry>${osgi-entities-path}</entry>
+ </classpath>
+ </catalog>
</catalog>