Author: angelo.vandersijpt at luminis.eu
Date: Thu Nov 11 16:03:00 2010
New Revision: 408

Log:
AMDATU-132 Updated the tests for the new felix-bundle situation, and cleaned up 
a number of the other integration tests.

Modified:
   trunk/integration-tests/pom.xml
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
   trunk/pom.xml

Modified: trunk/integration-tests/pom.xml
==============================================================================
--- trunk/integration-tests/pom.xml     (original)
+++ trunk/integration-tests/pom.xml     Thu Nov 11 16:03:00 2010
@@ -157,42 +157,9 @@
   </dependencies>
   
   <build>
-    <!-- Set the default source directory to match our generated sources 
directory -->
-    <testSourceDirectory>target/filtered-sources/java</testSourceDirectory>
 
     <plugins>
       <plugin>
-        <artifactId>maven-resources-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>process-filtered-java-source-files</id>
-            <phase>process-test-sources</phase>
-            <goals>
-              <goal>copy-resources</goal>
-            </goals>
-            <configuration>
-              <outputDirectory>target/filtered-sources/java</outputDirectory>
-              <resources>
-                <resource>
-                  <directory>src/test/java</directory>
-                  <filtering>false</filtering>
-                  <excludes>
-                    <exclude>org/amdatu/test/integration/base/**</exclude>
-                  </excludes>
-                </resource>
-                <resource>
-                  <directory>src/test/java</directory>
-                  <filtering>true</filtering>
-                  <includes>
-                    <include>org/amdatu/test/integration/base/**</include>
-                  </includes>
-                </resource>                
-              </resources>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
     (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
     Thu Nov 11 16:03:00 2010
@@ -61,11 +61,6 @@
     public final static String TEST_PREFIX = ">  TESTING:  ";
     public final static int SERVICE_TIMEOUT = 30;
 
-    // Hostname and portnumber to use during integration tests. These 
variables are interpolated
-    // by the maven-resources-plugin during the process-test-sources lifecycle 
phase (see pom.xml).
-    public final static String HOST_NAME = "${server.hostname}";
-    public final static int PORT_NR = Integer.parseInt("${server.port}");
-
     @Inject
     protected BundleContext m_bundleContext;
 
@@ -85,12 +80,6 @@
                 // Setting this system property unfortunately is necessary 
with the current Cassandra implementation
                 
systemProperty("org.osgi.framework.system.packages.extra").value("sun.misc,com.sun.management"),
 
-                // Set System property to enable Jetty for the Felix http 
bundle
-                
systemProperty("org.apache.felix.http.jettyEnabled").value("true"),
-                
systemProperty("org.apache.felix.http.whiteboardEnabled").value("true"),
-                
systemProperty("org.osgi.service.http.hostname").value(HOST_NAME),
-                systemProperty("org.osgi.service.http.port").value(new 
Integer(PORT_NR).toString()),
-
                 new VMOption("-Xmx1g"),
                 // Enable this line to allow a remote debugger to attach to 
the VM in which Pax Exam runs
                 //new 
VMOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
@@ -134,6 +123,10 @@
      * Gets a list of Component objects which should be started before
      * the test can start. You can include the test class in this too, so
      * you can get the services you depend on injected.
+     *
+     * Note that you <em>can</em> add components to the dependency manager 
directly,
+     * but the test will only wait for them if you return them in this method. 
If you do,
+     * you should not add them to the dependency manager yourself.
      */
     protected Component[] getDependencies(DependencyManager manager) {
         return new Component[0];
@@ -332,8 +325,12 @@
         return 
mavenBundle().groupId("org.ops4j.base").artifactId("ops4j-base-lang").versionAsInProject();
     }
 
-    protected static MavenArtifactProvisionOption felixHttpService() {
-        return 
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.http.bundle").versionAsInProject();
+    protected static MavenArtifactProvisionOption felixHttpServiceJetty() {
+        return 
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.http.jetty").versionAsInProject();
+    }
+
+    protected static MavenArtifactProvisionOption felixHttpServiceWhiteboard() 
{
+        return 
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.http.whiteboard").versionAsInProject();
     }
 
     protected static MavenArtifactProvisionOption felixLog() {

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
 (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
 Thu Nov 11 16:03:00 2010
@@ -74,13 +74,7 @@
         return new Component[] { manager.createComponent()
             .setImplementation(this)
             
.add(manager.createServiceDependency().setService(CassandraDaemonService.class).setRequired(true))
-            .add(
-            
manager.createServiceDependency().setService(CassandraPersistenceManager.class, 
filter).setRequired(true)) };
-    }
-
-    @Before
-    public void setUp() throws Exception {
-        m_daemonService = getService(CassandraDaemonService.class);
+            
.add(manager.createServiceDependency().setService(CassandraPersistenceManager.class,
 filter).setRequired(true)) };
     }
 
     @After

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
        (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
        Thu Nov 11 16:03:00 2010
@@ -16,6 +16,7 @@
  */
 package org.amdatu.test.integration.tests;
 
+import static junit.framework.Assert.*;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
 import java.io.IOException;
@@ -52,6 +53,8 @@
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.log.LogService;
 
@@ -68,6 +71,7 @@
 
     private volatile LogService m_logService;
     private volatile HttpContextServiceFactory m_httpContextFactoryService;
+    private volatile BundleContext m_context;
 
     private Component m_httpContextComponent;
     private String m_baseUrl;
@@ -80,7 +84,8 @@
 
     protected Option provisionBundles() {
         return provision(
-            felixHttpService(),
+            felixHttpServiceJetty(),
+            felixHttpServiceWhiteboard(),
             commonsHttpClient(),
             paxSwissbox(),
             ops4jBaseLang(),
@@ -92,11 +97,11 @@
 
     @Before
     public void setUp() throws Exception {
-        m_baseUrl = "http://"; + IntegrationTestBase.HOST_NAME + ":" + 
IntegrationTestBase.PORT_NR;
+        // Note 
+        setupTest();
+        m_baseUrl = "http://localhost:"; + getHttpPortNr();
 
         // Initialize the HTTP Context in which the filter, servlet and JSP 
under test are registered
-        m_testServlet = new TestServlet();
-        m_httpContextFactoryService = 
getService(HttpContextServiceFactory.class);
         m_httpContextComponent = 
m_httpContextFactoryService.create(m_bundleContext, m_testServlet);
     }
 
@@ -107,28 +112,32 @@
         filterProperties.put("pattern", ".*");
         filterProperties.put("contextId", SERVLET_ALIAS);
         filterProperties.put("service.ranking", "0");
-        manager.add(manager.createComponent()
-            .setImplementation(new TestFilter())
-            .setInterface(new String[] { Filter.class.getName(), 
TestFilterInterface.class.getName() },
-            filterProperties));
+        Component filterComponent = manager.createComponent()
+                .setImplementation(new TestFilter())
+                .setInterface(new String[] { Filter.class.getName(), 
TestFilterInterface.class.getName() },
+                        filterProperties);
 
         // Now we register a test servlet, also whiteboard-style
+        m_testServlet = new TestServlet();
         Dictionary<String, String> servletProperties = new Hashtable<String, 
String>();
         servletProperties.put("alias", SERVLET_ALIAS);
         servletProperties.put("contextId", SERVLET_ALIAS);
-        manager.add(manager.createComponent()
-            .setImplementation(m_testServlet)
-            .setInterface(
-            new String[] { Servlet.class.getName(), 
TestServletInterface.class.getName(),
-            ResourceProvider.class.getName() },
-            servletProperties));
-
-        return new Component[] { manager.createComponent()
-            .setImplementation(this)
-            
.add(manager.createServiceDependency().setService(TestFilterInterface.class).setRequired(true))
-            
.add(manager.createServiceDependency().setService(TestServletInterface.class).setRequired(true))
-            
.add(manager.createServiceDependency().setService(LogService.class).setRequired(true))
-            
.add(manager.createServiceDependency().setService(HttpService.class).setRequired(true))
 };
+        Component servletComponent = manager.createComponent()
+                .setImplementation(m_testServlet)
+                .setInterface(
+                        new String[] { Servlet.class.getName(), 
TestServletInterface.class.getName(),
+                                ResourceProvider.class.getName() },
+                        servletProperties);
+
+        Component testComponent = manager.createComponent()
+                .setImplementation(this)
+                
.add(manager.createServiceDependency().setService(TestFilterInterface.class).setRequired(true))
+                
.add(manager.createServiceDependency().setService(TestServletInterface.class).setRequired(true))
+                
.add(manager.createServiceDependency().setService(LogService.class).setRequired(true))
+                
.add(manager.createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
+                
.add(manager.createServiceDependency().setService(HttpService.class).setRequired(true));
+
+        return new Component[] { filterComponent, servletComponent, 
testComponent };
     }
 
     @After
@@ -147,24 +156,24 @@
         try {
             // Execute the method, this should return a 200
             int statusCode = httpClient.executeMethod(method);
-            Assert.assertTrue("HTTP GET to '" + url + "' returned " + 
statusCode, statusCode == HttpStatus.SC_OK);
+            assertTrue("HTTP GET to '" + url + "' returned " + statusCode, 
statusCode == HttpStatus.SC_OK);
 
             // Read the response body.
             byte[] responseBody = method.getResponseBody();
 
             // Check if the response is our test text
-            Assert.assertTrue(TEST_TEXT.equals(new String(responseBody)));
+            assertTrue(TEST_TEXT.equals(new String(responseBody)));
 
             // Now check if the filter did his job properly
             Header[] resHeaders = 
method.getResponseHeaders(TEST_HEADER_BEFORE);
-            Assert.assertEquals("No response header was set by filter before 
filterChain invocation",
+            assertEquals("No response header was set by filter before 
filterChain invocation",
                 resHeaders.length, 1);
-            Assert.assertTrue("Repsonse header was not properly set by filter 
before filterChain invocation",
+            assertTrue("Repsonse header was not properly set by filter before 
filterChain invocation",
                 TEST_HEADER_BEFORE_VALUE.equals(resHeaders[0].getValue()));
             resHeaders = method.getResponseHeaders(TEST_HEADER_AFTER);
-            Assert.assertEquals("No response header was set by filter after 
filterChain invocation", resHeaders.length,
+            assertEquals("No response header was set by filter after 
filterChain invocation", resHeaders.length,
                 1);
-            Assert.assertTrue("Repsonse header was not properly set by filter 
after filterChain invocation",
+            assertTrue("Repsonse header was not properly set by filter after 
filterChain invocation",
                 TEST_HEADER_AFTER_VALUE.equals(resHeaders[0].getValue()));
         }
         finally {
@@ -184,13 +193,13 @@
         try {
             // Execute the method, this should return a 200
             int statusCode = httpClient.executeMethod(method);
-            Assert.assertTrue("HTTP GET to '" + url + "' returned " + 
statusCode, statusCode == HttpStatus.SC_OK);
+            assertTrue("HTTP GET to '" + url + "' returned " + statusCode, 
statusCode == HttpStatus.SC_OK);
 
             // Read the response body.
             String responseBody = new String(method.getResponseBody(), 
"UTF-8");
 
             // Check if the response is our test text
-            Assert.assertTrue(responseBody.indexOf(TEST_JSP_CONTENT) != -1);
+            assertTrue(responseBody.indexOf(TEST_JSP_CONTENT) != -1);
         }
         finally {
             // Release the connection.
@@ -198,6 +207,12 @@
         }
     }
 
+    public String getHttpPortNr() {
+        assertNotNull(m_httpContextFactoryService);
+        ServiceReference reference = 
m_context.getServiceReference(HttpService.class.getName());
+        return (String) reference.getProperty("org.osgi.service.http.port");
+    }
+
     /**
      * A simple TestFilter that sets a header testFilterBefore to 'true' 
before executing the rest of
      * the filter chain and sets testFilterAfter to 'true' afterwards.

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
    (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
    Thu Nov 11 16:03:00 2010
@@ -73,11 +73,11 @@
         Component testComponent = manager.createComponent()
             .setImplementation(this)
             .add(manager.createServiceDependency()
-            .setService(TenantManagementService.class)
-            .setRequired(true))
+                .setService(TenantManagementService.class)
+                .setRequired(true))
             .add(manager.createServiceDependency()
-            .setService(Tenant.class)
-            .setCallbacks("tenantAdded", "tenantRemoved"));
+                .setService(Tenant.class)
+                .setCallbacks("tenantAdded", "tenantRemoved"));
 
         Properties props = new Properties();
         props.put(Constants.SERVICE_RANKING, 1);
@@ -121,7 +121,7 @@
          */
     }
 
-    // @Test
+    @Test
     public void shouldRemoveTenantService() throws TenantException, 
InterruptedException {
         TenantEntity tenant = 
m_tenantManagementService.createTenant("tenant1", "Tenant1");
         waitForTenantServiceAdded();

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
     (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
     Thu Nov 11 16:03:00 2010
@@ -56,7 +56,8 @@
 
     protected Option provisionBundles() {
         return provision(
-            felixHttpService(),
+            felixHttpServiceJetty(),
+            felixHttpServiceWhiteboard(),
             amdatuHttpContext(),
             amdatuJaxRs(),
             amdatuCassandraApplication(),

Modified: trunk/pom.xml
==============================================================================
--- trunk/pom.xml       (original)
+++ trunk/pom.xml       Thu Nov 11 16:03:00 2010
@@ -481,12 +481,12 @@
       <version>${org.apache.felix.http.version}</version>
       <scope>provided</scope>
     </dependency>
-      <dependency>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>org.apache.felix.http.whiteboard</artifactId>
-        <version>${org.apache.felix.http.version}</version>
-        <scope>provided</scope>
-      </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.http.whiteboard</artifactId>
+      <version>${org.apache.felix.http.version}</version>
+      <scope>provided</scope>
+    </dependency>
 
     <!-- Swissbox is used to resolve classloading issues in Jasper -->
     <dependency>

Reply via email to