Author: cschneider
Date: Wed Jun 25 08:06:37 2014
New Revision: 1605288

URL: http://svn.apache.org/r1605288
Log:
Simplify customizer tests

Modified:
    
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BaseBlueprintContainerBTCustomizerTest.java
    
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
    
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java

Modified: 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BaseBlueprintContainerBTCustomizerTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BaseBlueprintContainerBTCustomizerTest.java?rev=1605288&r1=1605287&r2=1605288&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BaseBlueprintContainerBTCustomizerTest.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BaseBlueprintContainerBTCustomizerTest.java
 Wed Jun 25 08:06:37 2014
@@ -26,7 +26,10 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
+import javax.inject.Inject;
+
 import org.apache.aries.itest.RichBundleContext;
+import org.junit.Assert;
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.osgi.framework.Bundle;
@@ -35,10 +38,15 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.Constants;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
 
+@SuppressWarnings("deprecation")
 public abstract class BaseBlueprintContainerBTCustomizerTest extends 
AbstractBlueprintIntegrationTest 
 {
+       @Inject
+       CompositeBundleFactory cbf;
+
     protected Map<String, String> getCompositeManifest() {
         Map<String, String> compositeManifest = new HashMap<String, String>();
         compositeManifest.put(Constants.BUNDLE_SYMBOLICNAME, "test-composite");
@@ -52,25 +60,9 @@ public abstract class BaseBlueprintConta
         return compositeManifest;
     }
     
-    protected Bundle installConfigurationAdmin(BundleContext ctx) throws 
Exception {
-        
-        Bundle configAdminBundle = null;
-        // make sure we don't have a config admin already present
-        @SuppressWarnings({ "rawtypes", "unchecked" })
-        ServiceTracker tracker = new ServiceTracker(ctx, ctx.createFilter("(" 
+ Constants.OBJECTCLASS + "=" + ConfigurationAdmin.class.getName() + ")"), 
null);
-        tracker.open();
-            Object cfgAdminService = tracker.waitForService(5000);
-        tracker.close();
-        
-        if (cfgAdminService == null) {
-            MavenArtifactProvisionOption cfgAdminOption = 
CoreOptions.mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin").versionAsInProject();
-            InputStream cfgAdminStream = new 
URL(cfgAdminOption.getURL()).openStream();
-            
-            configAdminBundle = ctx.installBundle(cfgAdminOption.getURL(), 
cfgAdminStream);            
-        }
-
-        return configAdminBundle;
-    }
+    protected MavenArtifactProvisionOption configAdminOption() {
+               return CoreOptions.mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin").versionAsInProject();
+       }
     
     protected void applyCommonConfiguration(BundleContext ctx) throws 
Exception {
         ConfigurationAdmin ca = (new 
RichBundleContext(ctx)).getService(ConfigurationAdmin.class);        
@@ -80,11 +72,22 @@ public abstract class BaseBlueprintConta
         cf.update(props);
     }
     
-    protected Bundle installTestBundle(BundleContext compositeBundleContext) 
throws IOException, MalformedURLException, BundleException {
-        // install the blueprint sample onto the framework associated with the 
composite bundle
-        MavenArtifactProvisionOption mapo = 
CoreOptions.mavenBundle("org.apache.aries.blueprint", 
"org.apache.aries.blueprint.sample").versionAsInProject();
+    protected Bundle installBundle(BundleContext bundleContext, String url) 
throws IOException, MalformedURLException, BundleException {
         // let's use input stream to avoid invoking mvn url handler which 
isn't avail in the child framework.
-        InputStream is = new URL(mapo.getURL()).openStream();
-        return compositeBundleContext.installBundle(mapo.getURL(), is);
+        InputStream is = new URL(url).openStream();
+        Bundle bundle = bundleContext.installBundle(url, is);
+        Assert.assertNotNull(bundle);
+        return bundle;
     }
+
+       protected MavenArtifactProvisionOption testBundleOption() {
+               return CoreOptions.mavenBundle("org.apache.aries.blueprint", 
"org.apache.aries.blueprint.sample").versionAsInProject();
+       }
+
+       protected CompositeBundle createCompositeBundle() throws 
BundleException {
+               Map<String, String> frameworkConfig = new HashMap<String, 
String>();
+           Map<String, String> compositeManifest = getCompositeManifest();
+           CompositeBundle cb = cbf.installCompositeBundle(frameworkConfig, 
"test-composite", compositeManifest);
+               return cb;
+       }
 }

Modified: 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java?rev=1605288&r1=1605287&r2=1605288&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainer2BTCustomizerTest.java
 Wed Jun 25 08:06:37 2014
@@ -18,11 +18,6 @@
  */
 package org.apache.aries.blueprint.itests;
 
-import static org.junit.Assert.assertNotNull;
-
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.aries.itest.RichBundleContext;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -33,9 +28,7 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.framework.CompositeBundle;
-import org.osgi.service.framework.CompositeBundleFactory;
 
 /**
  * This test is based on the BlueprintContainerBTCustomizerTest.  but this 
test starts the
@@ -47,34 +40,13 @@ import org.osgi.service.framework.Compos
 @RunWith(PaxExam.class)
 public class BlueprintContainer2BTCustomizerTest extends 
BaseBlueprintContainerBTCustomizerTest {
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    @Test
+       @Test
     @Ignore // This test crashes the vm when run from maven. It works fine 
when run from eclipse
     public void test() throws Exception {
-        
-        ServiceReference sr = 
bundleContext.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
-        if (sr == null) {
-            return;
-        }
-
-        // install blueprint.sample into the composite context
-        CompositeBundleFactory cbf = 
(CompositeBundleFactory)bundleContext.getService(sr);
-        
-        Map<String, String> frameworkConfig = new HashMap<String, String>();
-        // turn on the line below to enable telnet localhost 10000 to the 
child framework osgi console
-        // frameworkConfig.put("osgi.console", "10000");
-        
-        // construct composite bundle information
-        Map<String, String> compositeManifest = getCompositeManifest();
-        
-        CompositeBundle cb = cbf.installCompositeBundle(frameworkConfig, 
"test-composite", compositeManifest);
-
+        CompositeBundle cb = createCompositeBundle();
         BundleContext compositeBundleContext = 
cb.getCompositeFramework().getBundleContext();
-        Bundle bundle = installTestBundle(compositeBundleContext);
-        assertNotNull(bundle);
-        // install and start the cfg admin bundle in the isolated framework
-        Bundle configAdminBundle = 
installConfigurationAdmin(compositeBundleContext);
-        assertNotNull(configAdminBundle);
+        Bundle bundle = installBundle(compositeBundleContext, 
testBundleOption().getURL());
+        Bundle configAdminBundle = installBundle(compositeBundleContext, 
configAdminOption().getURL());
         
         // start the composite bundle, config admin then the blueprint sample
         cb.start();
@@ -87,9 +59,6 @@ public class BlueprintContainer2BTCustom
 
         // do the test
         Helper.testBlueprintContainer(new 
RichBundleContext(compositeBundleContext), bundle);
-        
-        // unget the service
-        bundleContext.ungetService(sr);
     }
 
     // start the blueprint bundle and it should detect the previously started 
blueprint sample

Modified: 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java?rev=1605288&r1=1605287&r2=1605288&view=diff
==============================================================================
--- 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java
 (original)
+++ 
aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/BlueprintContainerBTCustomizerTest.java
 Wed Jun 25 08:06:37 2014
@@ -18,11 +18,6 @@
  */
 package org.apache.aries.blueprint.itests;
 
-import static org.junit.Assert.assertNotNull;
-
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.aries.itest.RichBundleContext;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -31,9 +26,7 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.framework.CompositeBundle;
-import org.osgi.service.framework.CompositeBundleFactory;
 
 /**
  * This test is based on the BlueprintContainerTest.  The difference is that 
in this test,
@@ -46,49 +39,25 @@ import org.osgi.service.framework.Compos
 @RunWith(PaxExam.class)
 public class BlueprintContainerBTCustomizerTest extends 
BaseBlueprintContainerBTCustomizerTest {
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void test() throws Exception {
-        
-        ServiceReference sr = 
bundleContext.getServiceReference("org.osgi.service.framework.CompositeBundleFactory");
-        if (sr == null) {
-            return;
-        }
-
-        // install blueprint.sample into the composite context
-        CompositeBundleFactory cbf = 
(CompositeBundleFactory)bundleContext.getService(sr);
-        
-        Map<String, String> frameworkConfig = new HashMap<String, String>();
-        // turn on the line below to enable telnet localhost 10000 to the 
child framework osgi console
-        // frameworkConfig.put("osgi.console", "10000");
-        
-        // construct composite bundle information
-        Map<String, String> compositeManifest = getCompositeManifest();
-        
-        CompositeBundle cb = cbf.installCompositeBundle(frameworkConfig, 
"test-composite", compositeManifest);
+        CompositeBundle cb = createCompositeBundle();
 
         BundleContext compositeBundleContext = 
cb.getCompositeFramework().getBundleContext();
-        Bundle bundle = installTestBundle(compositeBundleContext);
-        assertNotNull(bundle);
-        // install and start the cfg admin bundle in the isolated framework
-        Bundle configAdminBundle = 
installConfigurationAdmin(compositeBundleContext);
-        assertNotNull(configAdminBundle);
-        
+        Bundle testBundle = installBundle(compositeBundleContext, 
testBundleOption().getURL());
+        Bundle configAdminBundle = installBundle(compositeBundleContext, 
configAdminOption().getURL());
         // start the composite bundle, config admin then the blueprint sample
         cb.start();
         configAdminBundle.start();
         // create a config to check the property placeholder
         applyCommonConfiguration(compositeBundleContext);
-        bundle.start();
+        testBundle.start();
 
         // do the test
-        Helper.testBlueprintContainer(new 
RichBundleContext(compositeBundleContext), bundle);
-        
-        // unget the service
-        bundleContext.ungetService(sr);
+        Helper.testBlueprintContainer(new 
RichBundleContext(compositeBundleContext), testBundle);
     }
 
-    @Configuration
+       @Configuration
     public Option[] configuration() {
         return new Option[] {
             baseOptions(),


Reply via email to