aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1144949 [4/5] - in /aries/trunk: application/application-itests/ application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/ blueprint/blueprint-annotation-itest/ blueprint/blueprint-annotation-itest/src/test/...
Date Sun, 10 Jul 2011 20:05:10 GMT
Modified: aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/quiesce/itest/QuiesceJPATest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/quiesce/itest/QuiesceJPATest.java?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/quiesce/itest/QuiesceJPATest.java (original)
+++ aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/quiesce/itest/QuiesceJPATest.java Sun Jul 10 20:05:08 2011
@@ -18,13 +18,8 @@ package org.apache.aries.jpa.quiesce.ite
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
-import static org.ops4j.pax.exam.OptionUtils.combine;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+import static org.apache.aries.itest.ExtraOptions.*;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -35,6 +30,7 @@ import javax.persistence.PersistenceCont
 import javax.sql.DataSource;
 import javax.transaction.UserTransaction;
 
+import org.apache.aries.itest.AbstractIntegrationTest;
 import org.apache.aries.jpa.container.PersistenceUnitConstants;
 import org.apache.aries.jpa.container.context.PersistenceContextProvider;
 import org.apache.aries.quiesce.manager.QuiesceCallback;
@@ -42,25 +38,15 @@ import org.apache.aries.quiesce.particip
 import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.options.BootDelegationOption;
-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.util.tracker.ServiceTracker;
 
 @RunWith(JUnit4TestRunner.class)
-public class QuiesceJPATest {
+public class QuiesceJPATest extends AbstractIntegrationTest {
   
   private static class TestQuiesceCallback implements QuiesceCallback{
 
@@ -85,8 +71,8 @@ public class QuiesceJPATest {
     public void bundleQuiesced(Bundle... arg0) {
       if(++calls == 1)
         try {
-          getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-              + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+          context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+              + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
         } catch (Throwable t){
           contextFirst = false;
           if(t instanceof RuntimeException)
@@ -106,23 +92,17 @@ public class QuiesceJPATest {
   }
   
   
-  public static final long DEFAULT_TIMEOUT = 10000;
-
-  @Inject
-  protected BundleContext bundleContext;
- 
-  
   @After
   public void restartTestBundles() throws BundleException {
-    Bundle b = getBundle("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
+    Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
     b.stop();
     b.start();
     
-    b = getBundle("org.apache.aries.jpa.container");
+    b = context().getBundleByName("org.apache.aries.jpa.container");
     b.stop();
     b.start();
     
-    b = getBundle("org.apache.aries.jpa.container.context");
+    b = context().getBundleByName("org.apache.aries.jpa.container.context");
     b.stop();
     b.start();
   }
@@ -131,15 +111,15 @@ public class QuiesceJPATest {
   public void testSimpleContextQuiesce() throws Exception {
 
     //Get a managed context registered
-    PersistenceContextProvider provider = getOsgiService(PersistenceContextProvider.class);
+    PersistenceContextProvider provider = context().getService(PersistenceContextProvider.class);
     
     HashMap<String, Object> props = new HashMap<String, Object>();
     props.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE, PersistenceContextType.TRANSACTION);
     provider.registerContext("test-unit", bundleContext.getBundle(), props);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
           + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
     //Quiesce it
@@ -147,7 +127,7 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
@@ -161,34 +141,34 @@ public class QuiesceJPATest {
     assertNull("No context should exist",refs);
     
     //Restart the bundle to check the context gets re-registered
-    Bundle b = getBundle("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
+    Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
     b.stop();
     b.start();
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
   }
 
   @Test
   public void testComplexContextQuiesce() throws Exception {
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
     // Get a managed context registered
-    PersistenceContextProvider provider = getOsgiService(PersistenceContextProvider.class);
+    PersistenceContextProvider provider = context().getService(PersistenceContextProvider.class);
     
     HashMap<String, Object> props = new HashMap<String, Object>();
     props.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE, PersistenceContextType.TRANSACTION);
     provider.registerContext("test-unit", bundleContext.getBundle(), props);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
           + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
     //Set up a transaction so we can check the Quiesce waits properly
-    UserTransaction tm = getOsgiService(UserTransaction.class);
+    UserTransaction tm = context().getService(UserTransaction.class);
     
     tm.begin();
     
@@ -198,16 +178,16 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     tm.commit();
     
@@ -222,13 +202,13 @@ public class QuiesceJPATest {
     
     //Restart the bundle to check the context gets re-registered, then ensure it isn't
     //tidied up immediately again!
-    Bundle b = getBundle("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
+    Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
     b.stop();
     b.start();
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     tm.begin();
     
@@ -238,7 +218,7 @@ public class QuiesceJPATest {
     
     Thread.sleep(1000);
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
       "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", 100);
     
@@ -250,14 +230,14 @@ public class QuiesceJPATest {
     
     callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
       "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", 100);
     
@@ -276,20 +256,20 @@ public class QuiesceJPATest {
   @Test
   public void testContextRuntimeQuiesce() throws Exception {
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
-    PersistenceContextProvider provider = getOsgiService(PersistenceContextProvider.class);
+    PersistenceContextProvider provider = context().getService(PersistenceContextProvider.class);
     
     HashMap<String, Object> props = new HashMap<String, Object>();
     props.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE, PersistenceContextType.TRANSACTION);
     provider.registerContext("test-unit", bundleContext.getBundle(), props);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
           + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
-    UserTransaction tm = getOsgiService(UserTransaction.class);
+    UserTransaction tm = context().getService(UserTransaction.class);
     
     tm.begin();
     
@@ -299,16 +279,16 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.container.context")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce not finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     tm.commit();
     
@@ -324,15 +304,14 @@ public class QuiesceJPATest {
   @Test
   public void testSimpleUnitQuiesce() throws Exception {
 
-    
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     QuiesceParticipant participant = getParticipant("org.apache.aries.jpa.container");
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
@@ -345,21 +324,21 @@ public class QuiesceJPATest {
     assertNull("No unit should exist",refs);
     
     //Restart the bundle to check the unit gets re-registered
-    Bundle b = getBundle("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
+    Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
     b.stop();
     b.start();
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
   }
 
   @Test
   public void testComplexUnitQuiesce() throws Exception {
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     EntityManager em = emf.createEntityManager();
     
@@ -367,15 +346,15 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     em.close();
     
@@ -387,17 +366,17 @@ public class QuiesceJPATest {
     assertNull("No context should exist",refs);
     
     //Restart the bundle to check the unit gets re-registered and is not immediately unregistered
-    Bundle b = getBundle("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
+    Bundle b = context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle");
     b.stop();
     b.start();
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     em = emf.createEntityManager();
     em.close();
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", 100);
     
     //Test a second time to make sure state isn't held
@@ -406,15 +385,15 @@ public class QuiesceJPATest {
     
     callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     em.close();
     
@@ -429,10 +408,10 @@ public class QuiesceJPATest {
   @Test
   public void testContainerRuntimeQuiesce() throws Exception {
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+          + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     
     EntityManager em = emf.createEntityManager();
@@ -441,15 +420,15 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback callback = new TestQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.container")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished early", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
 
     em.close();
     
@@ -465,22 +444,22 @@ public class QuiesceJPATest {
   public void testComplexQuiesceInteraction() throws Exception {
 
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
     // Get a managed context registered
-    PersistenceContextProvider provider = getOsgiService(PersistenceContextProvider.class);
+    PersistenceContextProvider provider = context().getService(PersistenceContextProvider.class);
     
     HashMap<String, Object> props = new HashMap<String, Object>();
     props.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE, PersistenceContextType.TRANSACTION);
     provider.registerContext("test-unit", bundleContext.getBundle(), props);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
           + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
     //Set up a transaction so we can check the Quiesce waits properly
-    UserTransaction tm = getOsgiService(UserTransaction.class);
+    UserTransaction tm = context().getService(UserTransaction.class);
     
     tm.begin();
     
@@ -491,16 +470,16 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback unitCallback = new TestQuiesceCallback();
     
-    participant.quiesce(unitCallback, Collections.singletonList(getBundle(
+    participant.quiesce(unitCallback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", unitCallback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
     //Quiesce the context, still nothing
@@ -509,7 +488,7 @@ public class QuiesceJPATest {
     
     TestQuiesceCallback contextCallback = new TestQuiesceCallback();
     
-    participant.quiesce(contextCallback, Collections.singletonList(getBundle(
+    participant.quiesce(contextCallback, Collections.singletonList(context().getBundleByName(
     "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
@@ -517,14 +496,14 @@ public class QuiesceJPATest {
     assertFalse("Quiesce finished", unitCallback.bundleClearedUp());
     assertFalse("Quiesce finished", contextCallback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     //Keep the unit alive
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
   
   
     EntityManager em = emf.createEntityManager();
@@ -540,8 +519,8 @@ public class QuiesceJPATest {
     assertNull("No context should exist",refs);
     
     //Still a unit
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     em.close();
     
@@ -556,22 +535,22 @@ public class QuiesceJPATest {
   @Test
   public void testComplexQuiesceInteraction2() throws Exception {
     //This is load bearing. we have to wait to create the EntityManager until the DataSource is available
-    getOsgiService(DataSource.class);
+    context().getService(DataSource.class);
     
     // Get a managed context registered
-    PersistenceContextProvider provider = getOsgiService(PersistenceContextProvider.class);
+    PersistenceContextProvider provider = context().getService(PersistenceContextProvider.class);
     
     HashMap<String, Object> props = new HashMap<String, Object>();
     props.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE, PersistenceContextType.TRANSACTION);
     provider.registerContext("test-unit", bundleContext.getBundle(), props);
     
-    EntityManagerFactory emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    EntityManagerFactory emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
           + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+        "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
     
     //Set up a transaction so we can check the Quiesce waits properly
-    UserTransaction tm = getOsgiService(UserTransaction.class);
+    UserTransaction tm = context().getService(UserTransaction.class);
     
     tm.begin();
     
@@ -582,25 +561,25 @@ public class QuiesceJPATest {
     
     MultiQuiesceCallback callback = new MultiQuiesceCallback();
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
+    participant.quiesce(callback, Collections.singletonList(context().getBundleByName(
         "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     //Quiesce the context, still nothing
     participant = getParticipant("org.apache.aries.jpa.container.context");
     
-    participant.quiesce(callback, Collections.singletonList(getBundle(
-       "org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
+    participant.quiesce(callback, Collections.singletonList(
+            context().getBundleByName("org.apache.aries.jpa.org.apache.aries.jpa.container.itest.bundle")));
     
     Thread.sleep(1000);
     
     assertFalse("Quiesce finished", callback.bundleClearedUp());
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
         + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true)" +
-      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))", DEFAULT_TIMEOUT);
+      "(" + PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE + "=*))");
     
-    emf = getOsgiService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
-        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))", DEFAULT_TIMEOUT);
+    emf = context().getService(EntityManagerFactory.class, "(&(osgi.unit.name=test-unit)(" 
+        + PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT + "=true))");
     
     
     tm.commit();
@@ -632,21 +611,9 @@ public class QuiesceJPATest {
 
   @org.ops4j.pax.exam.junit.Configuration
   public static Option[] configuration() {
-    Option[] options = options(
-        bootDelegationPackages("javax.transaction", "javax.transaction.*"),
-        vmOption("-Dorg.osgi.framework.system.packages=javax.accessibility,javax.activation,javax.activity,javax.annotation,javax.annotation.processing,javax.crypto,javax.crypto.interfaces,javax.crypto.spec,javax.imageio,javax.imageio.event,javax.imageio.metadata,javax.imageio.plugins.bmp,javax.imageio.plugins.jpeg,javax.imageio.spi,javax.imageio.stream,javax.jws,javax.jws.soap,javax.lang.model,javax.lang.model.element,javax.lang.model.type,javax.lang.model.util,javax.management,javax.management.loading,javax.management.modelmbean,javax.management.monitor,javax.management.openmbean,javax.management.relation,javax.management.remote,javax.management.remote.rmi,javax.management.timer,javax.naming,javax.naming.directory,javax.naming.event,javax.naming.ldap,javax.naming.spi,javax.net,javax.net.ssl,javax.print,javax.print.attribute,javax.print.attribute.standard,javax.print.event,javax.rmi,javax.rmi.CORBA,javax.rmi.ssl,javax.script,javax.security.auth,javax.security.auth.callback,
 javax.security.auth.kerberos,javax.security.auth.login,javax.security.auth.spi,javax.security.auth.x500,javax.security.cert,javax.security.sasl,javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi,javax.sql,javax.sql.rowset,javax.sql.rowset.serial,javax.sql.rowset.spi,javax.swing,javax.swing.border,javax.swing.colorchooser,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.plaf.multi,javax.swing.plaf.synth,javax.swing.table,javax.swing.text,javax.swing.text.html,javax.swing.text.html.parser,javax.swing.text.rtf,javax.swing.tree,javax.swing.undo,javax.tools,javax.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,javax.xml.bind.attachment,javax.xml.bind.helpers,javax.xml.bind.util,javax.xml.crypto,javax.xml.crypto.dom,javax.xml.crypto.dsig,javax.xml.crypto.dsig.dom,javax.xml.crypto.dsig.keyinfo,javax.xml.crypto.dsig.spec,javax.xml.datatype,javax.xml.name
 space,javax.xml.parsers,javax.xml.soap,javax.xml.stream,javax.xml.stream.events,javax.xml.stream.util,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,javax.xml.ws.handler,javax.xml.ws.handler.soap,javax.xml.ws.http,javax.xml.ws.soap,javax.xml.ws.spi,javax.xml.xpath,org.ietf.jgss,org.omg.CORBA,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA.TypeCodePackage,org.omg.CORBA.portable,org.omg.CORBA_2_3,org.omg.CORBA_2_3.portable,org.omg.CosNaming,org.omg.CosNaming.NamingContextExtPackage,org.omg.CosNaming.NamingContextPackage,org.omg.Dynamic,org.omg.DynamicAny,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage,org.omg.IOP,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage,org.omg.Messaging,org.omg.PortableInterceptor,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.PortableServer,org.omg.PortableServer.CurrentPackage,org.omg.
 PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.ServantLocatorPackage,org.omg.PortableServer.portable,org.omg.SendingContext,org.omg.stub.java.rmi,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c.dom.css,org.w3c.dom.events,org.w3c.dom.html,org.w3c.dom.ls,org.w3c.dom.ranges,org.w3c.dom.stylesheets,org.w3c.dom.traversal,org.w3c.dom.views,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers,javax.transaction;partial=true;mandatory:=partial,javax.transaction.xa;partial=true;mandatory:=partial"),
-        
-        // Log
-        mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
-        mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
-        // Felix Config Admin
-        mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
-        // Felix mvn url handler
-        mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
-
-        // this is how you set the default log level when using pax
-        // logging (logProfile)
-        systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+    return testOptions(
+        transactionBootDelegation(),
+        paxLogging("DEBUG"),
 
         // Bundles
         mavenBundle("org.osgi", "org.osgi.compendium"),
@@ -680,95 +647,5 @@ public class QuiesceJPATest {
         mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.itest.bundle"),
         
         equinox().version("3.5.0"));
-    options = updateOptions(options);
-    return options;
-  }
-  
-  
-  protected Bundle getBundle(String symbolicName) {
-    return getBundle(symbolicName, null);
-  }
-
-  protected Bundle getBundle(String bundleSymbolicName, String version) {
-    Bundle result = null;
-    for (Bundle b : bundleContext.getBundles()) {
-      if (b.getSymbolicName().equals(bundleSymbolicName)) {
-        if (version == null
-            || b.getVersion().equals(Version.parseVersion(version))) {
-          result = b;
-          break;
-        }
-      }
-    }
-    return result;
-  }
-
-  public static BootDelegationOption bootDelegation() {
-    return new BootDelegationOption("org.apache.aries.unittest.fixture");
-  }
-  
-  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;
-  }
-
-  protected <T> T getOsgiService(Class<T> type, long timeout) {
-    return getOsgiService(type, null, timeout);
-  }
-
-  protected <T> T getOsgiService(Class<T> type) {
-    return getOsgiService(type, null, DEFAULT_TIMEOUT);
-  }
-  
-  protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
-    return getOsgiService(null, type, filter, timeout);
-  }
-
-  protected <T> T getOsgiService(BundleContext bc, Class<T> type,
-      String filter, long timeout) {
-    ServiceTracker tracker = null;
-    try {
-      String flt;
-      if (filter != null) {
-        if (filter.startsWith("(")) {
-          flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"
-              + filter + ")";
-        } else {
-          flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")("
-              + filter + "))";
-        }
-      } else {
-        flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
-      }
-      Filter osgiFilter = FrameworkUtil.createFilter(flt);
-      tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter,
-          null);
-      tracker.open();
-      // Note that the tracker is not closed to keep the reference
-      // This is buggy, has the service reference may change i think
-      Object svc = type.cast(tracker.waitForService(timeout));
-      if (svc == null) {
-        throw new RuntimeException("Gave up waiting for service " + flt);
-      }
-      return type.cast(svc);
-    } catch (InvalidSyntaxException e) {
-      throw new IllegalArgumentException("Invalid filter", e);
-    } catch (InterruptedException e) {
-      throw new RuntimeException(e);
-    }
   }
 }

Modified: aries/trunk/proxy/proxy-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-itests/pom.xml?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-itests/pom.xml (original)
+++ aries/trunk/proxy/proxy-itests/pom.xml Sun Jul 10 20:05:08 2011
@@ -69,6 +69,12 @@
             <version>0.4-SNAPSHOT</version>
         </dependency>
         <dependency>
+          <groupId>org.apache.aries.testsupport</groupId>
+          <artifactId>org.apache.aries.testsupport.unit</artifactId>
+          <version>0.3.1-SNAPSHOT</version>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam</artifactId>
             <scope>test</scope>

Modified: aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java (original)
+++ aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java Sun Jul 10 20:05:08 2011
@@ -4,10 +4,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-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 java.lang.reflect.Method;
 import java.util.AbstractList;
 import java.util.ArrayList;
@@ -15,18 +11,14 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.Callable;
 
+import org.apache.aries.itest.AbstractIntegrationTest;
 import org.apache.aries.proxy.InvocationListener;
 import org.apache.aries.proxy.ProxyManager;
 import org.junit.Test;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
 
-public class AbstractProxyTest {
+public class AbstractProxyTest extends AbstractIntegrationTest {
 
   public final static class TestCallable implements Callable<Object> {
     private Object list = new ArrayList<Object>();
@@ -115,37 +107,10 @@ public class AbstractProxyTest {
     }
   }
 
-  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;
-  }
-
-  protected <T> T getService(Class<T> clazz) {
-    BundleContext ctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
-    ServiceReference ref = ctx.getServiceReference(ProxyManager.class.getName());
-    if (ref != null) {
-      return clazz.cast(ctx.getService(ref));
-    }
-    return null;
-  }
-
   @SuppressWarnings("unchecked")
   @Test
   public void testEquals() throws Exception {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     
     TestCallable c = new TestCallable();
@@ -166,7 +131,7 @@ public class AbstractProxyTest {
 
   @Test
   public void testDelegation() throws Exception {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     
     TestCallable c = new TestCallable();
@@ -186,7 +151,7 @@ public class AbstractProxyTest {
   
   @Test
   public void testInterception() throws Exception {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     
     TestDelegate td = new TestDelegate("Hello");
@@ -227,7 +192,7 @@ public class AbstractProxyTest {
   
   @Test
   public void testDelegationAndInterception() throws Exception {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     
     

Modified: aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java (original)
+++ aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java Sun Jul 10 20:05:08 2011
@@ -21,8 +21,7 @@ package org.apache.aries.proxy.itests;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.apache.aries.itest.ExtraOptions.*;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -49,7 +48,7 @@ public class BasicProxyTest extends Abst
   @Test
   public void checkProxyFinalClass() throws UnableToProxyException
   {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     Callable<Object> c = new TestCallable();
     Collection<Class<?>> classes = new ArrayList<Class<?>>();
@@ -70,7 +69,7 @@ public class BasicProxyTest extends Abst
   @Test
   public void checkProxyFinalMethods() throws UnableToProxyException
   {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     Callable<Object> c = new TestCallable();
     Collection<Class<?>> classes = new ArrayList<Class<?>>();
@@ -88,18 +87,8 @@ public class BasicProxyTest extends Abst
   
   @org.ops4j.pax.exam.junit.Configuration
   public static Option[] configuration() {
-      Option[] options = options(
-          // Log
-          mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
-          mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
-          // Felix Config Admin
-          mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
-          // Felix mvn url handler
-          mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
-
-
-          // this is how you set the default log level when using pax logging (logProfile)
-          systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+      return testOptions(
+          paxLogging("DEBUG"),
 
           // Bundles
           mavenBundle("org.apache.aries", "org.apache.aries.util"),
@@ -112,8 +101,5 @@ public class BasicProxyTest extends Abst
 
           equinox().version("3.5.0")
       );
-
-      options = updateOptions(options);
-      return options;
   }
 }
\ No newline at end of file

Modified: aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java (original)
+++ aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java Sun Jul 10 20:05:08 2011
@@ -21,8 +21,7 @@ package org.apache.aries.proxy.itests;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.apache.aries.itest.ExtraOptions.*;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -50,7 +49,7 @@ public class WeavingProxyTest extends Ab
   @Test
   public void checkProxyFinalClass() throws Exception
   {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     TestCallable dispatcher = new TestCallable();
     TestCallable template = new TestCallable();
@@ -74,7 +73,7 @@ public class WeavingProxyTest extends Ab
   @Test
   public void checkProxyFinalMethods() throws Exception
   {
-    ProxyManager mgr = getService(ProxyManager.class);
+    ProxyManager mgr = context().getService(ProxyManager.class);
     Bundle b = FrameworkUtil.getBundle(this.getClass());
     Callable<Object> c = new TestCallable();
     Collection<Class<?>> classes = new ArrayList<Class<?>>();
@@ -90,18 +89,8 @@ public class WeavingProxyTest extends Ab
    
   @org.ops4j.pax.exam.junit.Configuration
   public static Option[] configuration() {
-      Option[] options = options(
-          // Log
-          mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
-          mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
-          // Felix Config Admin
-          mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
-          // Felix mvn url handler
-          mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
-
-
-          // this is how you set the default log level when using pax logging (logProfile)
-          systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+      return testOptions(
+          paxLogging("DEBUG"),
 
           // Bundles
           mavenBundle("org.apache.aries", "org.apache.aries.util"),
@@ -115,8 +104,5 @@ public class WeavingProxyTest extends Ab
 
           equinox().version("3.7.0.v20110304")
       );
-
-      options = updateOptions(options);
-      return options;
   }
 }
\ No newline at end of file

Modified: aries/trunk/quiesce/quiesce-manager-itest/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager-itest/pom.xml?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/quiesce/quiesce-manager-itest/pom.xml (original)
+++ aries/trunk/quiesce/quiesce-manager-itest/pom.xml Sun Jul 10 20:05:08 2011
@@ -45,6 +45,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+          <groupId>org.apache.aries.testsupport</groupId>
+          <artifactId>org.apache.aries.testsupport.unit</artifactId>
+          <version>0.3.1-SNAPSHOT</version>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: aries/trunk/quiesce/quiesce-manager-itest/src/test/java/org/apache/aries/quiesce/manager/itest/QuiesceManagerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager-itest/src/test/java/org/apache/aries/quiesce/manager/itest/QuiesceManagerTest.java?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/quiesce/quiesce-manager-itest/src/test/java/org/apache/aries/quiesce/manager/itest/QuiesceManagerTest.java (original)
+++ aries/trunk/quiesce/quiesce-manager-itest/src/test/java/org/apache/aries/quiesce/manager/itest/QuiesceManagerTest.java Sun Jul 10 20:05:08 2011
@@ -17,12 +17,7 @@ package org.apache.aries.quiesce.manager
 
 import static org.junit.Assert.*;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
-import static org.ops4j.pax.exam.OptionUtils.combine;
-//import org.ops4j.pax.exam.container.def.options.VMOption;
-//import org.ops4j.pax.exam.options.TimeoutOption
+import static org.apache.aries.itest.ExtraOptions.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -31,31 +26,19 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
+import org.apache.aries.itest.AbstractIntegrationTest;
 import org.apache.aries.quiesce.manager.QuiesceManager;
 import org.apache.aries.quiesce.participant.QuiesceParticipant;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.ops4j.pax.exam.options.BootDelegationOption;
-import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.Version;
-import org.osgi.util.tracker.ServiceTracker;
 
 @RunWith(JUnit4TestRunner.class)
-public class QuiesceManagerTest {
-    public static final long DEFAULT_TIMEOUT = 60000;
+public class QuiesceManagerTest extends AbstractIntegrationTest {
     private QuiesceManager manager;
     private Bundle b1;
     private Bundle b2;
@@ -67,12 +50,9 @@ public class QuiesceManagerTest {
     private MockQuiesceParticipant participant3;
 
 
-    @Inject
-    protected BundleContext bundleContext;
-
     @Before
     public void setup() {
-        manager = getOsgiService(QuiesceManager.class);
+        manager = context().getService(QuiesceManager.class);
         b1 = bundleContext.getBundle(5);
         b2 = bundleContext.getBundle(6);
         b3 = bundleContext.getBundle(10);
@@ -288,20 +268,8 @@ public class QuiesceManagerTest {
 
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration() {
-        Option[] options = options(
-                bootDelegation(),
-
-                // Log
-                mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
-                mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
-                // Felix Config Admin
-                mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
-                // Felix mvn url handler
-                mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
-
-                // this is how you set the default log level when using pax
-                // logging (logProfile)
-                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+        return testOptions(
+                paxLogging("DEBUG"),
 
                 // Bundles
                 mavenBundle("org.osgi", "org.osgi.compendium"),
@@ -317,95 +285,5 @@ public class QuiesceManagerTest {
                 //new TimeoutOption( 0 ),
 
                 equinox().version("3.5.0"));
-        options = updateOptions(options);
-        return options;
-    }
-
-
-    protected Bundle getBundle(String symbolicName) {
-        return getBundle(symbolicName, null);
-    }
-
-    protected Bundle getBundle(String bundleSymbolicName, String version) {
-        Bundle result = null;
-        for (Bundle b : bundleContext.getBundles()) {
-            if (b.getSymbolicName().equals(bundleSymbolicName)) {
-                if (version == null
-                        || b.getVersion().equals(Version.parseVersion(version))) {
-                    result = b;
-                    break;
-                }
-            }
-        }
-        return result;
-    }
-
-    public static BootDelegationOption bootDelegation() {
-        return new BootDelegationOption("org.apache.aries.unittest.fixture");
-    }
-
-    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;
-    }
-
-    protected <T> T getOsgiService(Class<T> type, long timeout) {
-        return getOsgiService(type, null, timeout);
-    }
-
-    protected <T> T getOsgiService(Class<T> type) {
-        return getOsgiService(type, null, DEFAULT_TIMEOUT);
-    }
-
-    protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
-        return getOsgiService(null, type, filter, timeout);
-    }
-
-    protected <T> T getOsgiService(BundleContext bc, Class<T> type,
-            String filter, long timeout) {
-        ServiceTracker tracker = null;
-        try {
-            String flt;
-            if (filter != null) {
-                if (filter.startsWith("(")) {
-                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"
-                    + filter + ")";
-                } else {
-                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")("
-                    + filter + "))";
-                }
-            } else {
-                flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
-            }
-            Filter osgiFilter = FrameworkUtil.createFilter(flt);
-            tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter,
-                    null);
-            tracker.open();
-            // Note that the tracker is not closed to keep the reference
-            // This is buggy, has the service reference may change i think
-            Object svc = type.cast(tracker.waitForService(timeout));
-            if (svc == null) {
-                throw new RuntimeException("Gave up waiting for service " + flt);
-            }
-            return type.cast(svc);
-        } catch (InvalidSyntaxException e) {
-            throw new IllegalArgumentException("Invalid filter", e);
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        }
     }
 }

Modified: aries/trunk/testsupport/testsupport-unit/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/testsupport/testsupport-unit/pom.xml?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/testsupport/testsupport-unit/pom.xml (original)
+++ aries/trunk/testsupport/testsupport-unit/pom.xml Sun Jul 10 20:05:08 2011
@@ -47,10 +47,15 @@
             org.apache.aries.unittest.fixture,
             org.apache.aries.mocks;uses:="junit.framework,org.osgi.framework,org.apache.aries.unittest.mocks,org.junit,org.apache.aries.unittest.mocks.ann otations,javax.naming,javax.naming.spi",
             org.apache.aries.unittest.mocks.annotations;version="0.3.0",org.apache.aries.unittest.mocks;uses:="junit.framework,org.apache.aries.unittest.mocks.annotations",
-            org.apache.aries.unittest.junit;uses:="org.junit"
+            org.apache.aries.unittest.junit;uses:="org.junit",
+            org.apache.aries.itest
         </aries.osgi.export.pkg>
         <aries.osgi.private.pkg />
-        <aries.osgi.import.pkg>*</aries.osgi.import.pkg>
+        <!-- Don't import org.ops4j.pax.exam.container.def because it is only used for setup -->
+        <aries.osgi.import.pkg>
+          org.ops4j.pax.exam.container.def*;resolution:=optional,
+          *
+        </aries.osgi.import.pkg>
     </properties>
 
    <dependencies>
@@ -64,6 +69,19 @@
       <artifactId>org.osgi.core</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <scope>provided</scope>      
+    </dependency>
+    <dependency>
+        <groupId>org.ops4j.pax.exam</groupId>
+        <artifactId>pax-exam</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>org.ops4j.pax.exam</groupId>
+        <artifactId>pax-exam-container-default</artifactId>
+    </dependency>
   </dependencies>
 
 </project>

Added: aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java?rev=1144949&view=auto
==============================================================================
--- aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java (added)
+++ aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java Sun Jul 10 20:05:08 2011
@@ -0,0 +1,41 @@
+/*
+ * 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 WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.itest;
+
+import org.ops4j.pax.exam.Inject;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Base class for Pax Exam 1.2.x based unit tests
+ * 
+ * Contains the injection point and various utilities used in most tests
+ */
+public abstract class AbstractIntegrationTest {
+
+    /** Gateway to the test OSGi framework */
+    @Inject
+    protected BundleContext bundleContext;
+    
+    /**
+     * Get a richer version of {@link BundleContext}
+     */
+    public RichBundleContext context() {
+        return new RichBundleContext(bundleContext);
+    }
+}

Added: aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/ExtraOptions.java
URL: http://svn.apache.org/viewvc/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/ExtraOptions.java?rev=1144949&view=auto
==============================================================================
--- aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/ExtraOptions.java (added)
+++ aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/ExtraOptions.java Sun Jul 10 20:05:08 2011
@@ -0,0 +1,183 @@
+/*
+ * 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 WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.itest;
+
+import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+
+public class ExtraOptions {
+    public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+        return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+    }
+    
+    /**
+     * For use in the actual test code, which runs in OSGi and has no normal access to the configuration options
+     * @param groupId
+     * @param artifactId
+     * @return
+     */
+    public static MavenArtifactProvisionOption mavenBundleInTest(ClassLoader loader, String groupId, String artifactId) {
+        return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId)
+            .version(getArtifactVersion(loader, groupId, artifactId));
+    }
+
+    //TODO getArtifactVersion and getFileFromClasspath are borrowed and modified from pax-exam.  They should be moved back ASAP.
+    private static String getArtifactVersion( ClassLoader loader, final String groupId, final String artifactId )
+    {
+        final Properties dependencies = new Properties();
+        try
+        {
+            InputStream in = getFileFromClasspath(loader, "META-INF/maven/dependencies.properties");
+            try {
+                dependencies.load(in);
+            } finally {
+                in.close();
+            }
+            final String version = dependencies.getProperty( groupId + "/" + artifactId + "/version" );
+            if( version == null )
+            {
+                throw new RuntimeException(
+                    "Could not resolve version. Do you have a dependency for " + groupId + "/" + artifactId
+                    + " in your maven project?"
+                );
+            }
+            return version;
+        }
+        catch( IOException e )
+        {
+            // TODO throw a better exception
+            throw new RuntimeException(
+                "Could not resolve version. Did you configured the plugin in your maven project?"
+                + "Or maybe you did not run the maven build and you are using an IDE?"
+            );
+        }
+    }
+
+
+    private static InputStream getFileFromClasspath(ClassLoader loader,  final String filePath )
+        throws FileNotFoundException
+    {
+        try
+        {
+            URL fileURL = loader.getResource( filePath );
+            if( fileURL == null )
+            {
+                throw new FileNotFoundException( "File [" + filePath + "] could not be found in classpath" );
+            }
+            return fileURL.openStream();
+        }
+        catch (IOException e)
+        {
+            throw new FileNotFoundException( "File [" + filePath + "] could not be found: " + e.getMessage() );
+        }
+    }    
+    
+    /**
+     * Add the pax logging provider with the given default logging level
+     */
+    public static Option[] paxLogging(String defaultLogLevel) {
+        return flatOptions(
+                bundles("org.ops4j.pax.logging/pax-logging-api",
+                        "org.ops4j.pax.logging/pax-logging-service"),
+                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value(defaultLogLevel)
+        );
+    }
+    
+    public static Option[] transactionBootDelegation() {
+        return options(
+                bootDelegationPackages("javax.transaction", "javax.transaction.*"),
+                vmOption("-Dorg.osgi.framework.system.packages=javax.accessibility,javax.activation,javax.activity,javax.annotation,javax.annotation.processing,javax.crypto,javax.crypto.interfaces,javax.crypto.spec,javax.imageio,javax.imageio.event,javax.imageio.metadata,javax.imageio.plugins.bmp,javax.imageio.plugins.jpeg,javax.imageio.spi,javax.imageio.stream,javax.jws,javax.jws.soap,javax.lang.model,javax.lang.model.element,javax.lang.model.type,javax.lang.model.util,javax.management,javax.management.loading,javax.management.modelmbean,javax.management.monitor,javax.management.openmbean,javax.management.relation,javax.management.remote,javax.management.remote.rmi,javax.management.timer,javax.naming,javax.naming.directory,javax.naming.event,javax.naming.ldap,javax.naming.spi,javax.net,javax.net.ssl,javax.print,javax.print.attribute,javax.print.attribute.standard,javax.print.event,javax.rmi,javax.rmi.CORBA,javax.rmi.ssl,javax.script,javax.security.auth,javax.security.auth.c
 allback,javax.security.auth.kerberos,javax.security.auth.login,javax.security.auth.spi,javax.security.auth.x500,javax.security.cert,javax.security.sasl,javax.sound.midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi,javax.sql,javax.sql.rowset,javax.sql.rowset.serial,javax.sql.rowset.spi,javax.swing,javax.swing.border,javax.swing.colorchooser,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.plaf.multi,javax.swing.plaf.synth,javax.swing.table,javax.swing.text,javax.swing.text.html,javax.swing.text.html.parser,javax.swing.text.rtf,javax.swing.tree,javax.swing.undo,javax.tools,javax.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.adapters,javax.xml.bind.attachment,javax.xml.bind.helpers,javax.xml.bind.util,javax.xml.crypto,javax.xml.crypto.dom,javax.xml.crypto.dsig,javax.xml.crypto.dsig.dom,javax.xml.crypto.dsig.keyinfo,javax.xml.crypto.dsig.spec,javax.xml.datatype,javax.
 xml.namespace,javax.xml.parsers,javax.xml.soap,javax.xml.stream,javax.xml.stream.events,javax.xml.stream.util,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stax,javax.xml.transform.stream,javax.xml.validation,javax.xml.ws,javax.xml.ws.handler,javax.xml.ws.handler.soap,javax.xml.ws.http,javax.xml.ws.soap,javax.xml.ws.spi,javax.xml.xpath,org.ietf.jgss,org.omg.CORBA,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg.CORBA.TypeCodePackage,org.omg.CORBA.portable,org.omg.CORBA_2_3,org.omg.CORBA_2_3.portable,org.omg.CosNaming,org.omg.CosNaming.NamingContextExtPackage,org.omg.CosNaming.NamingContextPackage,org.omg.Dynamic,org.omg.DynamicAny,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage,org.omg.IOP,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage,org.omg.Messaging,org.omg.PortableInterceptor,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.PortableServer,org.omg.PortableServer.CurrentPackage,
 org.omg.PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.ServantLocatorPackage,org.omg.PortableServer.portable,org.omg.SendingContext,org.omg.stub.java.rmi,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c.dom.css,org.w3c.dom.events,org.w3c.dom.html,org.w3c.dom.ls,org.w3c.dom.ranges,org.w3c.dom.stylesheets,org.w3c.dom.traversal,org.w3c.dom.views,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers,javax.transaction;partial=true;mandatory:=partial,javax.transaction.xa;partial=true;mandatory:=partial")                
+        );
+    }
+    
+    /**
+     * Convert a list of options or Option[] into a flat list of options
+     * @param params
+     * @return
+     */
+    public static Option[] flatOptions(Object ... params) {
+        List<Option> result = new ArrayList<Option>();
+        
+        for (Object p : params) {
+            if (p instanceof Option) {
+                result.add((Option) p);
+            } else if (p.getClass().isArray()) {
+                result.addAll(Arrays.asList(flatOptions((Object[]) p)));
+            }
+        }
+        
+        return result.toArray(new Option[0]);
+    }
+    
+    /**
+     * Top level option combinator that adds platform fixes as needed
+     * @param params
+     * @return
+     */
+    public static Option[] testOptions(Object ... params) {
+        return combine(flatOptions(params),
+                when("IBM Corporation".equals(System.getProperty("java.vendor")))
+                    .useOptions(wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))),
+                mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit")
+        );
+    }
+    
+    /**
+     * Specify a collection of bundles
+     * @param specs Bundle specs of the format &lt;group&gt;/&lt;artifact&gt;[/&lt;version&gt;]
+     * @return
+     */
+    public static Option[] bundles(String ... specs) {
+        List<Option> result = new ArrayList<Option>();
+        
+        for (String spec : specs) {
+            String[] parts = spec.split("/");
+            
+            if (parts.length == 2) {
+                result.add(mavenBundle(parts[0], parts[1]));
+            } else if (parts.length == 3) {
+                result.add(CoreOptions.mavenBundle(parts[0], parts[1], parts[2]));
+            } else {
+                throw new IllegalArgumentException(
+                        "Ill-formatted bundle spec: '"+spec+"'. Expected format <group>/<artifact>[/<version>].");
+            }
+        }
+        
+        return result.toArray(new Option[0]);
+    }
+
+}

Added: aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/RichBundleContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/RichBundleContext.java?rev=1144949&view=auto
==============================================================================
--- aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/RichBundleContext.java (added)
+++ aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/RichBundleContext.java Sun Jul 10 20:05:08 2011
@@ -0,0 +1,209 @@
+/*
+ * 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 WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.itest;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * {@link BundleContext} wrapper that adds a couple of additional utilities
+ * @author vmahrwald
+ *
+ */
+public class RichBundleContext implements BundleContext {
+    public static final long DEFAULT_TIMEOUT = 15000;
+    
+    private final BundleContext delegate;
+
+    public RichBundleContext(BundleContext delegate) {
+        this.delegate = delegate;
+    }
+    
+
+    public <T> T getService(Class<T> type) {
+        return getService(type, null, DEFAULT_TIMEOUT);
+    }
+    
+    public <T> T getService(Class<T> type, long timeout) {
+        return getService(type, null, timeout);
+    }
+    
+    public <T> T getService(Class<T> type, String filter) {
+        return getService(type, filter, DEFAULT_TIMEOUT);
+    }
+    
+    public <T> T getService(Class<T> type, String filter, long timeout) {
+        ServiceTracker tracker = null;
+        try {
+            String flt;
+            if (filter != null) {
+                if (filter.startsWith("(")) {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+                } else {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+                }
+            } else {
+                flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+            }
+            Filter osgiFilter = FrameworkUtil.createFilter(flt);
+            tracker = new ServiceTracker(delegate, osgiFilter, null);
+            tracker.open();
+            
+            Object svc = type.cast(tracker.waitForService(timeout));
+            if (svc == null) {
+                System.out.println("Could not obtain a service in time, service-ref="+ 
+                  tracker.getServiceReference()+
+                  ", time="+System.currentTimeMillis());
+                throw new RuntimeException("Gave up waiting for service " + flt);
+            }
+            return type.cast(svc);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter", e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    
+    public Bundle getBundleByName(String symbolicName) {
+        for (Bundle b : delegate.getBundles()) {
+            if (b.getSymbolicName().equals(symbolicName)) {
+                return b;
+            }
+        }
+        return null;
+    }
+
+    
+    
+    /*
+     * Delegate methods
+     */
+    
+    public String getProperty(String key) {
+        return delegate.getProperty(key);
+    }
+
+    public Bundle getBundle() {
+        return delegate.getBundle();
+    }
+
+    public Bundle installBundle(String location, InputStream input)
+            throws BundleException {
+        return delegate.installBundle(location, input);
+    }
+
+    public Bundle installBundle(String location) throws BundleException {
+        return delegate.installBundle(location);
+    }
+
+    public Bundle getBundle(long id) {
+        return delegate.getBundle(id);
+    }
+
+    public Bundle[] getBundles() {
+        return delegate.getBundles();
+    }
+
+    public void addServiceListener(ServiceListener listener, String filter)
+            throws InvalidSyntaxException {
+        delegate.addServiceListener(listener, filter);
+    }
+
+    public void addServiceListener(ServiceListener listener) {
+        delegate.addServiceListener(listener);
+    }
+
+    public void removeServiceListener(ServiceListener listener) {
+        delegate.removeServiceListener(listener);
+    }
+
+    public void addBundleListener(BundleListener listener) {
+        delegate.addBundleListener(listener);
+    }
+
+    public void removeBundleListener(BundleListener listener) {
+        delegate.removeBundleListener(listener);
+    }
+
+    public void addFrameworkListener(FrameworkListener listener) {
+        delegate.addFrameworkListener(listener);
+    }
+
+    public void removeFrameworkListener(FrameworkListener listener) {
+        delegate.removeFrameworkListener(listener);
+    }
+
+    public ServiceRegistration registerService(String[] clazzes,
+            Object service, Dictionary properties) {
+        return delegate.registerService(clazzes, service, properties);
+    }
+
+    public ServiceRegistration registerService(String clazz, Object service,
+            Dictionary properties) {
+        return delegate.registerService(clazz, service, properties);
+    }
+
+    public ServiceReference[] getServiceReferences(String clazz, String filter)
+            throws InvalidSyntaxException {
+        return delegate.getServiceReferences(clazz, filter);
+    }
+
+    public ServiceReference[] getAllServiceReferences(String clazz,
+            String filter) throws InvalidSyntaxException {
+        return delegate.getAllServiceReferences(clazz, filter);
+    }
+
+    public ServiceReference getServiceReference(String clazz) {
+        return delegate.getServiceReference(clazz);
+    }
+
+    public Object getService(ServiceReference reference) {
+        return delegate.getService(reference);
+    }
+
+    public boolean ungetService(ServiceReference reference) {
+        return delegate.ungetService(reference);
+    }
+
+    public File getDataFile(String filename) {
+        return delegate.getDataFile(filename);
+    }
+
+    public Filter createFilter(String filter) throws InvalidSyntaxException {
+        return delegate.createFilter(filter);
+    }
+    
+    
+}

Modified: aries/trunk/transaction/transaction-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/pom.xml?rev=1144949&r1=1144948&r2=1144949&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/pom.xml (original)
+++ aries/trunk/transaction/transaction-itests/pom.xml Sun Jul 10 20:05:08 2011
@@ -129,6 +129,12 @@
             <version>0.3.1-SNAPSHOT</version>
         </dependency>
         <dependency>
+          <groupId>org.apache.aries.testsupport</groupId>
+          <artifactId>org.apache.aries.testsupport.unit</artifactId>
+          <version>0.3.1-SNAPSHOT</version>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
             <scope>provided</scope>



Mime
View raw message