incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r894697 - in /incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx: AbstractIntegrationTest.java framework/FrameworkMBeanTest.java test/blueprint/BlueprintMBeanTest.java
Date Wed, 30 Dec 2009 19:28:42 GMT
Author: gawor
Date: Wed Dec 30 19:28:42 2009
New Revision: 894697

URL: http://svn.apache.org/viewvc?rev=894697&view=rev
Log:
fixes for ibm jdk and better code reuse between tests

Modified:
    incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
    incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
    incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java

Modified: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java?rev=894697&r1=894696&r2=894697&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
Wed Dec 30 19:28:42 2009
@@ -16,8 +16,10 @@
  */
 package org.apache.aries.jmx;
 
-import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
 import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import static org.junit.Assert.*;
 
 import javax.management.MBeanServer;
@@ -31,7 +33,6 @@
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -48,7 +49,7 @@
     
     ServiceRegistration registration;
     ServiceReference reference;
-    MBeanServer mbeanServer;
+    protected MBeanServer mbeanServer;
 
     @Inject
     protected BundleContext bundleContext;
@@ -89,4 +90,22 @@
         return mbean;
     }
 
+    public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId)
{
+        return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+    }
+
+    protected static Option[] updateOptions(Option[] options) {
+        // We need to add pax-exam-junit here when running with the ibm
+        // jdk to avoid the following exception during the test run:
+        // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+        if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+            Option[] ibmOptions = options(
+                wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
+            );
+            options = combine(ibmOptions, options);
+        }
+
+        return options;
+    }
+
 }
\ No newline at end of file

Modified: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java?rev=894697&r1=894696&r2=894697&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
Wed Dec 30 19:28:42 2009
@@ -40,10 +40,13 @@
 
     @Configuration
     public static Option[] configuration() {
-        return CoreOptions.options(CoreOptions.equinox(), 
-                CoreOptions.mavenBundle().groupId("org.apache.aries.jmx").artifactId("org.apache.aries.jmx").versionAsInProject()
+        Option[] options = CoreOptions.options(
+            CoreOptions.equinox(), 
+            mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx")
         );
-    }  
+        options = updateOptions(options);
+        return options;
+    }
 
     @Test
     public void testSetBundleStartLevels() throws IOException {

Modified: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java?rev=894697&r1=894696&r2=894697&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/test/blueprint/BlueprintMBeanTest.java
Wed Dec 30 19:28:42 2009
@@ -28,6 +28,7 @@
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
 
+import org.apache.aries.jmx.AbstractIntegrationTest;
 import org.apache.aries.jmx.blueprint.BlueprintMetadataMBean;
 import org.apache.aries.jmx.blueprint.BlueprintStateMBean;
 import org.apache.aries.jmx.test.blueprint.framework.BeanPropertyValidator;
@@ -59,52 +60,42 @@
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintContainer;
 
-@RunWith(JUnit4TestRunner.class)
-public class BlueprintMBeanTest {
+public class BlueprintMBeanTest extends AbstractIntegrationTest {
     
-    @Inject
-    private BundleContext rbc;
-    
-    MBeanServer mbs;
-    ServiceRegistration mbsr;
-    
-    // will run before each test
     @Configuration
-    public static Option[] configuration()
-    {      
-        return CoreOptions.options(CoreOptions.equinox(), 
-                CoreOptions.mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").versionAsInProject(),

-                CoreOptions.mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-service").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.apache.aries").artifactId("org.apache.aries.util").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.apache.aries.blueprint").artifactId("org.apache.aries.blueprint").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.apache.aries.blueprint").artifactId("org.apache.aries.blueprint.sample").versionAsInProject(),
-                CoreOptions.mavenBundle().groupId("org.apache.aries.jmx").artifactId("org.apache.aries.jmx.blueprint").versionAsInProject()
+    public static Option[] configuration() {    
+        Option[] options = CoreOptions.options(
+                CoreOptions.equinox(), 
+                mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+                mavenBundle("org.ops4j.pax.logging", "pax-logging-api"), 
+                mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), 
+                mavenBundle("org.osgi", "org.osgi.compendium") ,
+                mavenBundle("org.apache.aries", "org.apache.aries.util"), 
+                mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),

+                mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample"),

+                mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx.blueprint")
         );
+        options = updateOptions(options);
+        return options;
     }  
 
     @Before
-    public void setup() throws Exception {
-       System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Before Test");
-       
-       // Create a MBean Server
-       //MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-       mbs = MBeanServerFactory.createMBeanServer();
-       
-       // Register as a service, so that the blueprint mbean impl can found the server.
-       mbsr = rbc.registerService(MBeanServer.class.getCanonicalName(), mbs, null);
+    public void setUp() throws Exception {
+        super.setUp();
+        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Before Test");
        
        // Wait MBeans register in server
        int i=0;
-       while (true){
+       while (true) {
            try {
-               mbs.getObjectInstance(new ObjectName(BlueprintStateMBean.OBJECTNAME));
-               mbs.getObjectInstance(new ObjectName(BlueprintMetadataMBean.OBJECTNAME));
+               mbeanServer.getObjectInstance(new ObjectName(BlueprintStateMBean.OBJECTNAME));
+               mbeanServer.getObjectInstance(new ObjectName(BlueprintMetadataMBean.OBJECTNAME));
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Found MBeans");
                break;
-           }catch(InstanceNotFoundException e){
-               if (i==5) throw new Exception(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BlueprintStateMBean & BlueprintMetadataMBean are not found in server");
+           } catch (InstanceNotFoundException e) {
+               if (i == 5) {
+                   throw new Exception(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BlueprintStateMBean & BlueprintMetadataMBean are not found in server");
+               }
            }
            i++;
            Thread.sleep(1000);
@@ -112,17 +103,11 @@
        
        // Wait enough time for osgi framework and blueprint bundles to be set up
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Waiting for bundles to be set up");
-       Thread.sleep(10000);
-       
+       Thread.sleep(10000);       
     }
     
-    @After
-    public void teardown(){
-        if (mbsr!=null) mbsr.unregister();
-    }
-        
     @Test
-    public void BlueprintSample()throws Exception{
+    public void BlueprintSample() throws Exception {
         System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Start Test Blueprint Sample");
         
         //////////////////////////////
@@ -132,7 +117,7 @@
         //find the Blueprint Sample bundle id and the blueprint extender bundle id
         long sampleBundleId = -1;
         long extenderBundleId = -1;     // the blueprint extender bundle "org.apache.geronimo.blueprint.geronimo-blueprint"
is also a blueprint bundle.
-        for (Bundle bundle : rbc.getBundles()){
+        for (Bundle bundle : bundleContext.getBundles()){
             if (bundle.getSymbolicName().equals("org.apache.aries.blueprint.sample")) sampleBundleId
= bundle.getBundleId();
             if (bundle.getSymbolicName().equals("org.apache.aries.blueprint")) extenderBundleId
= bundle.getBundleId();
         }
@@ -140,7 +125,7 @@
         if (-1==extenderBundleId) fail("Blueprint Extender Bundle is not found!");
         
         //retrieve the proxy object
-        BlueprintStateMBean stateProxy = (BlueprintStateMBean) MBeanServerInvocationHandler.newProxyInstance(mbs,
new ObjectName(BlueprintStateMBean.OBJECTNAME), BlueprintStateMBean.class, false);
+        BlueprintStateMBean stateProxy = (BlueprintStateMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
new ObjectName(BlueprintStateMBean.OBJECTNAME), BlueprintStateMBean.class, false);
         
         // test getBlueprintBundleIds
         long[] bpBundleIds = stateProxy.getBlueprintBundleIds();
@@ -158,19 +143,19 @@
         //////////////////////////////
         
         //find the Blueprint Sample bundle's container service id
-        Bundle sampleBundle = rbc.getBundle(sampleBundleId);
+        Bundle sampleBundle = bundleContext.getBundle(sampleBundleId);
         String filter = "(&(osgi.blueprint.container.symbolicname=" // no similar one
in interfaces
                 + sampleBundle.getSymbolicName() + ")(osgi.blueprint.container.version="
+ sampleBundle.getVersion() + "))";
         ServiceReference[] serviceReferences = null;
         try {
-            serviceReferences = rbc.getServiceReferences(BlueprintContainer.class.getName(),
filter);
+            serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(),
filter);
         } catch (InvalidSyntaxException e) {
             throw new RuntimeException(e);
         }
         long sampleBlueprintContainerServiceId = (Long) serviceReferences[0].getProperty(Constants.SERVICE_ID);
         
         //retrieve the proxy object
-        BlueprintMetadataMBean metadataProxy = (BlueprintMetadataMBean) MBeanServerInvocationHandler.newProxyInstance(mbs,
new ObjectName(BlueprintMetadataMBean.OBJECTNAME), BlueprintMetadataMBean.class, false);
+        BlueprintMetadataMBean metadataProxy = (BlueprintMetadataMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
new ObjectName(BlueprintMetadataMBean.OBJECTNAME), BlueprintMetadataMBean.class, false);
         
         // test getBlueprintContainerServiceIds
         long[] bpContainerServiceIds = metadataProxy.getBlueprintContainerServiceIds();
@@ -275,6 +260,5 @@
         bv_circularReference.addPropertyValidators(bpv_list_2);
         bv_circularReference.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId,
"circularReference"));
     }
-    
-        
+            
 }



Mime
View raw message