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 2014/11/04 15:30:06 UTC

[12/18] git commit: tidy up osgi test bundles, in prep for writing more bundles and more tests

tidy up osgi test bundles, in prep for writing more bundles and more tests


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

Branch: refs/heads/master
Commit: a76208af1fe0eaa287430515beb0a750f7bfaa2b
Parents: 642c7ff
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Sat Nov 1 11:41:07 2014 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Nov 3 18:57:20 2014 +0000

----------------------------------------------------------------------
 .../src/test/dependencies/osgi/entities/pom.xml |   2 +
 .../management/osgi/OsgiEntitiesTest.java       |  92 +++++++++++++++++++
 .../management/osgi/OsgiStandaloneTest.java     |  61 +++---------
 .../management/osgi/OsgiTestResources.java      |  43 +++++++++
 core/src/test/resources/brooklyn/osgi/README.md |   8 +-
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 14663 -> 12378 bytes
 6 files changed, 156 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/core/src/test/dependencies/osgi/entities/pom.xml
----------------------------------------------------------------------
diff --git a/core/src/test/dependencies/osgi/entities/pom.xml b/core/src/test/dependencies/osgi/entities/pom.xml
index 7818229..41551f4 100644
--- a/core/src/test/dependencies/osgi/entities/pom.xml
+++ b/core/src/test/dependencies/osgi/entities/pom.xml
@@ -22,7 +22,9 @@
     <modelVersion>4.0.0</modelVersion>
     <packaging>jar</packaging>
 
+    <groupId>org.apache.brooklyn.test.resources.osgi</groupId>
     <artifactId>brooklyn-test-osgi-entities</artifactId>
+    <version>0.1.0</version>
 
     <name>OSGi bundled test entities</name>
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/core/src/test/java/brooklyn/management/osgi/OsgiEntitiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/osgi/OsgiEntitiesTest.java b/core/src/test/java/brooklyn/management/osgi/OsgiEntitiesTest.java
new file mode 100644
index 0000000..9b92b0c
--- /dev/null
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiEntitiesTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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 brooklyn.management.osgi;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.proxying.InternalEntityFactory;
+import brooklyn.entity.proxying.InternalPolicyFactory;
+import brooklyn.management.internal.ManagementContextInternal;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.os.Os;
+import brooklyn.util.osgi.Osgis;
+
+
+/** 
+ * Tests that OSGi entities load correctly and have the right catalog information set.
+ *     
+ */
+public class OsgiEntitiesTest {
+   
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH;
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_URL = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_URL;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+    }
+
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws BundleException, IOException, InterruptedException {
+    }
+    
+    /**
+     * Test fix for
+     * java.lang.NoClassDefFoundError: brooklyn.event.AttributeSensor not found by io.brooklyn.brooklyn-test-osgi-entities [41]
+     */
+    @Test
+    public void testEntityProxy() throws Exception {
+        File storageTempDir = Os.newTempDir("osgi-standalone");
+        Framework framework = Osgis.newFrameworkStarted(storageTempDir.getAbsolutePath(), true, null);
+        
+        try {
+        ManagementContextInternal managementContext;
+        InternalEntityFactory factory;
+
+        managementContext = new LocalManagementContextForTests();
+        InternalPolicyFactory policyFactory = new InternalPolicyFactory(managementContext);
+        factory = new InternalEntityFactory(managementContext, managementContext.getEntityManager().getEntityTypeRegistry(), policyFactory);
+
+        Bundle bundle = Osgis.install(framework, BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        @SuppressWarnings("unchecked")
+        Class<? extends Entity> bundleCls = (Class<? extends Entity>) bundle.loadClass("brooklyn.osgi.tests.SimpleEntityImpl");
+        @SuppressWarnings("unchecked")
+        Class<? extends Entity> bundleInterface = (Class<? extends Entity>) bundle.loadClass("brooklyn.osgi.tests.SimpleEntity");
+
+        @SuppressWarnings("unchecked")
+        EntitySpec<Entity> spec = (EntitySpec<Entity>) (((EntitySpec<Entity>)EntitySpec.create(bundleInterface))).impl(bundleCls);
+        Entity entity = bundleCls.newInstance();
+        factory.createEntityProxy(spec, entity);
+
+        if (managementContext != null) Entities.destroyAll(managementContext);
+        } finally {
+            OsgiStandaloneTest.tearDownOsgiFramework(framework, storageTempDir);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java b/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
index 87320f6..c2f9d51 100644
--- a/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiStandaloneTest.java
@@ -39,12 +39,6 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.proxying.InternalEntityFactory;
-import brooklyn.entity.proxying.InternalPolicyFactory;
-import brooklyn.management.internal.ManagementContextInternal;
-import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.ResourceUtils;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.maven.MavenArtifact;
@@ -55,24 +49,19 @@ import brooklyn.util.osgi.Osgis;
 import brooklyn.util.osgi.Osgis.ManifestHelper;
 import brooklyn.util.stream.Streams;
 
-/** tests some assumptions about OSGi behaviour, in standalone mode (not part of brooklyn).
- * 
- * relies on the following bundles, which exist in the classpath (and contain their sources):
- * 
- * <li>brooklyn-osgi-test-a_0.1.0 -
- *     defines TestA which has a "times" method and a static multiplier field;
- *     we set the multiplier to determine when we are sharing versions and when not
- *     
- *  */
+/** 
+ * Tests some assumptions about OSGi behaviour, in standalone mode (not part of brooklyn).
+ * See {@link OsgiTestResources} for description of test resources.
+ */
 public class OsgiStandaloneTest {
 
     private static final Logger log = LoggerFactory.getLogger(OsgiStandaloneTest.class);
 
-    public static final String BROOKLYN_OSGI_TEST_A_0_1_0_URL = "classpath:/brooklyn/osgi/brooklyn-osgi-test-a_0.1.0.jar";
-    
-    public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
-    public static final String BROOKLYN_TEST_OSGI_ENTITIES_URL = "classpath:"+BROOKLYN_TEST_OSGI_ENTITIES_PATH;
-    
+    public static final String BROOKLYN_OSGI_TEST_A_0_1_0_URL = OsgiTestResources.BROOKLYN_OSGI_TEST_A_0_1_0_URL;
+
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH;
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_URL = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_URL;
+
     protected Framework framework = null;
     private File storageTempDir;
 
@@ -84,6 +73,10 @@ public class OsgiStandaloneTest {
 
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws BundleException, IOException, InterruptedException {
+        tearDownOsgiFramework(framework, storageTempDir);
+    }
+
+    public static void tearDownOsgiFramework(Framework framework, File storageTempDir) throws BundleException, InterruptedException, IOException {
         if (framework!=null) {
             framework.stop();
             Assert.assertEquals(framework.waitForStop(1000).getType(), FrameworkEvent.STOPPED);
@@ -141,34 +134,6 @@ public class OsgiStandaloneTest {
         Assert.assertTrue(Osgis.isExtensionBundle(bundle));
     }
 
-
-    /**
-     * Test fix for
-     * java.lang.NoClassDefFoundError: brooklyn.event.AttributeSensor not found by io.brooklyn.brooklyn-test-osgi-entities [41]
-     */
-    @Test
-    public void testEntityProxy() throws Exception {
-        ManagementContextInternal managementContext;
-        InternalEntityFactory factory;
-
-        managementContext = new LocalManagementContextForTests();
-        InternalPolicyFactory policyFactory = new InternalPolicyFactory(managementContext);
-        factory = new InternalEntityFactory(managementContext, managementContext.getEntityManager().getEntityTypeRegistry(), policyFactory);
-
-        Bundle bundle = install(BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-        @SuppressWarnings("unchecked")
-        Class<? extends Entity> bundleCls = (Class<? extends Entity>) bundle.loadClass("brooklyn.osgi.tests.SimpleEntityImpl");
-        @SuppressWarnings("unchecked")
-        Class<? extends Entity> bundleInterface = (Class<? extends Entity>) bundle.loadClass("brooklyn.osgi.tests.SimpleEntity");
-
-        @SuppressWarnings("unchecked")
-        EntitySpec<Entity> spec = (EntitySpec<Entity>) (((EntitySpec<Entity>)EntitySpec.create(bundleInterface))).impl(bundleCls);
-        Entity entity = bundleCls.newInstance();
-        factory.createEntityProxy(spec, entity);
-
-        if (managementContext != null) Entities.destroyAll(managementContext);
-    }
-
     @Test
     public void testAMultiplier() throws Exception {
         Bundle bundle = install(BROOKLYN_OSGI_TEST_A_0_1_0_URL);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/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
new file mode 100644
index 0000000..3ab2055
--- /dev/null
+++ b/core/src/test/java/brooklyn/management/osgi/OsgiTestResources.java
@@ -0,0 +1,43 @@
+/*
+ * 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 brooklyn.management.osgi;
+
+/**
+* Many OSGi tests require OSGi bundles (of course). Test bundles have been collected here
+* for convenience and clarity. Available bundles (on the classpath, with source code
+* either embedded or in /src/dependencies) are:
+* <p>
+* <li>brooklyn-osgi-test-a_0.1.0 -
+*     defines TestA which has a "times" method and a static multiplier field;
+*     we set the multiplier to determine when we are sharing versions and when not
+*     
+* <li>brooklyn-test-osgi-entities (also version 0.1.0) -
+*     defines an entity and an application, to confirm it can be read and used by brooklyn
+* <p>
+* Some of these bundles are also used in REST API tests, as that stretches catalog further
+* (using CAMP) and that is one area where OSGi is heavily used. 
+*/
+public class OsgiTestResources {
+
+    public static final String BROOKLYN_OSGI_TEST_A_0_1_0_URL = "classpath:/brooklyn/osgi/brooklyn-osgi-test-a_0.1.0.jar";
+
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_PATH = "/brooklyn/osgi/brooklyn-test-osgi-entities.jar";
+    public static final String BROOKLYN_TEST_OSGI_ENTITIES_URL = "classpath:"+BROOKLYN_TEST_OSGI_ENTITIES_PATH;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/core/src/test/resources/brooklyn/osgi/README.md
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/osgi/README.md b/core/src/test/resources/brooklyn/osgi/README.md
index 7225e90..4109080 100644
--- a/core/src/test/resources/brooklyn/osgi/README.md
+++ b/core/src/test/resources/brooklyn/osgi/README.md
@@ -1,4 +1,7 @@
-Sample OSGi bundle files included here, either are built from /src/dependencies in this project, or contain their sources, or both.
+This directory contains OSGi bundle files used for testing.
+
+Source code including pom.xml is contained in the bundles,
+or in /src/dependencies, or both.
 
 ----
 Licensed to the Apache Software Foundation (ASF) under one
@@ -16,4 +19,5 @@ 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.
\ No newline at end of file
+under the License.
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a76208af/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 42d842c..494de30 100644
Binary files a/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/core/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ