Author: cschneider
Date: Tue May 27 15:13:00 2014
New Revision: 1597802

URL: http://svn.apache.org/r1597802
Log:
ARIES-1197 Update web integration tests to pax exam 3

Modified:
    
aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
    aries/trunk/web/web-itests/pom.xml
    
aries/trunk/web/web-itests/src/test/java/org/apache/aries/web/converter/itest/WabConverterITest.java

Modified: 
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=1597802&r1=1597801&r2=1597802&view=diff
==============================================================================
--- 
aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
 (original)
+++ 
aries/trunk/testsupport/testsupport-unit/src/main/java/org/apache/aries/itest/AbstractIntegrationTest.java
 Tue May 27 15:13:00 2014
@@ -39,4 +39,12 @@ public abstract class AbstractIntegratio
     public RichBundleContext context() {
         return new RichBundleContext(bundleContext);
     }
+    
+    public String getLocalRepo() {
+       String localRepo = System.getProperty("maven.repo.local");
+       if (localRepo == null) {
+               localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
+       }
+       return localRepo;
+    }
 }

Modified: aries/trunk/web/web-itests/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/web/web-itests/pom.xml?rev=1597802&r1=1597801&r2=1597802&view=diff
==============================================================================
--- aries/trunk/web/web-itests/pom.xml (original)
+++ aries/trunk/web/web-itests/pom.xml Tue May 27 15:13:00 2014
@@ -33,19 +33,14 @@
          
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/aries/trunk/web/web-itests</developerConnection>
          <url>http://svn.apache.org/viewvc/aries/trunk/web/web-itests</url>
      </scm>
+     
+    <properties>
+        <exam.version>3.4.0</exam.version>
+        <url.version>1.6.0</url.version>
+    </properties>
 
     <dependencies>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
              <groupId>org.ow2.asm</groupId>
             <artifactId>asm-all</artifactId>
             <version>4.0</version>
@@ -54,7 +49,7 @@
             <groupId>org.apache.aries.testsupport</groupId>
             <artifactId>org.apache.aries.testsupport.unit</artifactId>
             <scope>test</scope>
-            <version>1.0.0</version>
+            <version>2.0.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
@@ -101,42 +96,78 @@
             <scope>test</scope>
             <version>1.0.0</version>
         </dependency>
+        
+        <!-- pax exam -->
         <dependency>
-            <groupId>org.ops4j.pax.logging</groupId>
-            <artifactId>pax-logging-api</artifactId>
-            <scope>test</scope>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.7</version>
         </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.logging</groupId>
-            <artifactId>pax-logging-service</artifactId>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <version>${exam.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam</artifactId>
+            <artifactId>pax-exam-container-forked</artifactId>
+            <version>${exam.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-junit</artifactId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${exam.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-container-default</artifactId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${exam.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.swissbox</groupId>
-            <artifactId>pax-swissbox-tinybundles</artifactId>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+            <version>${url.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.ops4j.pax.url</groupId>
-            <artifactId>pax-url-mvn</artifactId>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>0.9.29</version>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>0.9.29</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.tinybundles</groupId>
+            <artifactId>tinybundles</artifactId>
+            <version>2.0.0</version>
+            <exclusions>
+               <exclusion>
+                       <artifactId>org.osgi.core</artifactId>
+                       <groupId>org.osgi</groupId>
+               </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse</groupId>
+            <artifactId>org.eclipse.osgi</artifactId>
+            <version>3.8.0.v20120529-1548</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.aries.web</groupId>
             <artifactId>org.apache.aries.web.urlhandler</artifactId>
             <scope>provided</scope>
@@ -152,6 +183,7 @@
                 <version>1.2</version>
                 <executions>
                     <execution>
+                       <phase>generate-resources</phase>
                         <id>generate-depends-file</id>
                         <goals>
                             <goal>generate-depends-file</goal>
@@ -159,6 +191,14 @@
                     </execution>
                 </executions>
             </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <forkMode>pertest</forkMode>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

Modified: 
aries/trunk/web/web-itests/src/test/java/org/apache/aries/web/converter/itest/WabConverterITest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/web/web-itests/src/test/java/org/apache/aries/web/converter/itest/WabConverterITest.java?rev=1597802&r1=1597801&r2=1597802&view=diff
==============================================================================
--- 
aries/trunk/web/web-itests/src/test/java/org/apache/aries/web/converter/itest/WabConverterITest.java
 (original)
+++ 
aries/trunk/web/web-itests/src/test/java/org/apache/aries/web/converter/itest/WabConverterITest.java
 Tue May 27 15:13:00 2014
@@ -19,228 +19,123 @@ package org.apache.aries.web.converter.i
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 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.CoreOptions.vmOption;
+import static org.ops4j.pax.exam.CoreOptions.when;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Dictionary;
-import java.util.List;
 
+import javax.inject.Inject;
+
+import org.apache.aries.itest.AbstractIntegrationTest;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
 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.junit.PaxExam;
 import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
 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.Version;
-import org.osgi.service.url.URLStreamHandlerService;
-import org.osgi.util.tracker.ServiceTracker;
-
-@RunWith(JUnit4TestRunner.class)
-public class WabConverterITest {
-  public static final long DEFAULT_TIMEOUT = 60000;
-
-  @Inject
-  protected BundleContext bundleContext;
-  
-  private List<ServiceTracker> srs;
-
-  @Before
-  public void setUp() throws Exception {
-    srs = new ArrayList<ServiceTracker>();
-    
-    ZipFixture testWar = ArchiveFixture.newJar()
-      .binary("WEB-INF/classes/org/apache/aries/web/test/TestClass.class", 
-        
getClass().getClassLoader().getResourceAsStream("org/apache/aries/web/test/TestClass.class"));
-    
-    FileOutputStream fout = new FileOutputStream("test.war");
-    testWar.writeOut(fout);
-    fout.close();
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    new File("test.war").delete();
-    for (ServiceTracker st : srs) {
-        if (st != null) {
-            st.close();
-        }  
-    }
-  }
-
-  @Test
-  public void getStarted() throws Exception {
-    
-    File testWar = new File("test.war");
-    String baseUrl = "webbundle:" + testWar.toURI().toURL().toExternalForm() ;
-
-    assertTrue("Time out waiting for webbundle URL handler", 
waitForURLHandler(baseUrl));
-    
-    Bundle converted = bundleContext.installBundle(baseUrl + 
"?Bundle-SymbolicName=test.war.bundle&Web-ContextPath=foo");
-    
-    assertNotNull(converted);
-    Dictionary<String,String> man = converted.getHeaders();
-    
-    assertEquals("test.war.bundle", man.get(Constants.BUNDLE_SYMBOLICNAME)); 
-    assertEquals("/foo", man.get("Web-ContextPath"));
-    assertTrue(man.get(Constants.IMPORT_PACKAGE).contains("javax.naming"));
-  }
-
-  private boolean waitForURLHandler(String url) {
-      int maxRepetition = 100;
-      for (int i = 0; i < maxRepetition; i++) {
-          try {
-              new URL(url);
-              return true;
-          } catch (MalformedURLException e) {
-              try {
-                  Thread.sleep(100);
-              } catch (InterruptedException ee) {
-                  return false;
-              }
-          }
-      }
-      return false;
-  }
-
-  @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"),
-
-        // Bundles
-        mavenBundle("org.apache.aries.web","org.apache.aries.web.urlhandler"),
-        mavenBundle("org.apache.aries", "org.apache.aries.util"),
-        mavenBundle("org.ow2.asm", "asm-all"),
-        mavenBundle("org.apache.aries.proxy", "org.apache.aries.proxy"),
-        mavenBundle("org.apache.aries.blueprint", 
"org.apache.aries.blueprint"), 
-        mavenBundle("org.osgi", "org.osgi.compendium"),
-        mavenBundle("org.apache.aries.testsupport", 
"org.apache.aries.testsupport.unit"),
-       
-
-        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();
-      
-      // add tracker to the list of trackers we close at tear down
-      srs.add(tracker);
-      
-      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);
-    }
-  }
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class WabConverterITest extends AbstractIntegrationTest {
+       @Inject
+       protected BundleContext bundleContext;
+
+       private void createTestWar(File warFile) throws IOException {
+               ZipFixture testWar = ArchiveFixture.newJar().binary(
+                               
"WEB-INF/classes/org/apache/aries/web/test/TestClass.class",
+                               getClass().getClassLoader().getResourceAsStream(
+                                               
"org/apache/aries/web/test/TestClass.class"));
+
+               FileOutputStream fout = new FileOutputStream(warFile);
+               testWar.writeOut(fout);
+               fout.close();
+       }
+
+       @Test
+       public void getStarted() throws Exception {
+               File testWar = File.createTempFile("test", ".war");
+               createTestWar(testWar);
+               String baseUrl = "webbundle:"
+                               + testWar.toURI().toURL().toExternalForm();
+               assertTrue("Time out waiting for webbundle URL handler",
+                               waitForURLHandler(baseUrl));
+
+               Bundle converted = bundleContext.installBundle(baseUrl
+                               + 
"?Bundle-SymbolicName=test.war.bundle&Web-ContextPath=foo");
+
+               assertNotNull(converted);
+               Dictionary<String, String> man = converted.getHeaders();
+
+               assertEquals("test.war.bundle", 
man.get(Constants.BUNDLE_SYMBOLICNAME));
+               assertEquals("/foo", man.get("Web-ContextPath"));
+               
assertTrue(man.get(Constants.IMPORT_PACKAGE).contains("javax.naming"));
+               new File("test.war").delete();
+       }
+
+       private boolean waitForURLHandler(String url) {
+               int maxRepetition = 100;
+               for (int i = 0; i < maxRepetition; i++) {
+                       try {
+                               new URL(url);
+                               return true;
+                       } catch (MalformedURLException e) {
+                               try {
+                                       Thread.sleep(100);
+                               } catch (InterruptedException ee) {
+                                       return false;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       public Option baseOptions() {
+               String localRepo = getLocalRepo();
+               return composite(
+                               junitBundles(),
+                               
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+                               when(localRepo != null).useOptions(
+                                               
vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + localRepo)));
+       }
+
+       @Configuration
+       public Option[] configuration() {
+               return options(
+                               // bootDelegation(),
+                               baseOptions(),
+                               mavenBundle("org.osgi", "org.osgi.compendium"),
+                               mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin"),
+
+                               // Bundles
+                               mavenBundle("org.apache.aries.web", 
"org.apache.aries.web.urlhandler"),
+                               mavenBundle("org.apache.aries", 
"org.apache.aries.util"),
+                               mavenBundle("org.ow2.asm", "asm-all"),
+                               mavenBundle("org.apache.aries.proxy", 
"org.apache.aries.proxy"),
+                               mavenBundle("org.apache.aries.blueprint", 
"org.apache.aries.blueprint"),
+                               mavenBundle("org.apache.aries.testsupport",     
"org.apache.aries.testsupport.unit"));
+       }
+
+       private MavenArtifactProvisionOption mavenBundle(String groupId,
+                       String artifactId) {
+               return CoreOptions.mavenBundle().groupId(groupId)
+                               .artifactId(artifactId).versionAsInProject();
+       }
+
 }


Reply via email to