Author: ivol
Date: Thu Oct 21 13:45:04 2010
New Revision: 200

Log:
[AMDATU-110] Moved java.io.tmpdir directory to ${basedir}/target. This ensures 
tmp files of Pax Exam to be cleaned up, which is necessary to test changes in 
cassandra.yaml for example. See also http://www.mail-archive.com/dev at 
felix.apache.org/msg15625.html. 
This should fix build problems on Bamboo, which are probably caused by outdated 
temporary files that are never removed by Pax Exam.

Added:
   trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
      - copied, changed from r199, 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
      - copied, changed from r199, 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
Removed:
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
Modified:
   trunk/integration-tests/pom.xml
   
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java

Modified: trunk/integration-tests/pom.xml
==============================================================================
--- trunk/integration-tests/pom.xml     (original)
+++ trunk/integration-tests/pom.xml     Thu Oct 21 13:45:04 2010
@@ -160,7 +160,13 @@
               <goal>test</goal>
             </goals>
             <configuration>
-               <skip>false</skip>
+              <systemProperties>
+                <property>
+                  <name>java.io.tmpdir</name>
+                  <value>${basedir}/target/temp</value>
+                </property>
+              </systemProperties>
+              <skip>false</skip>
             </configuration>
           </execution>
         </executions>

Modified: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
==============================================================================
--- 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
        (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
        Thu Oct 21 13:45:04 2010
@@ -28,19 +28,33 @@
 import java.io.File;
 import java.io.FileFilter;
 
+import org.apache.felix.dm.tracker.ServiceTracker;
+import org.junit.Assert;
+import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 
 /**
  * Base class for integration tests.
+ * 
  * @author ivol
  */
-abstract class IntegrationTestRunner {
+public abstract class IntegrationTestRunner {
     public final static String TEST_PREFIX = ">  TESTING:  ";
-    
+
     private static final int FRAMEWORK_STARTUP_WAIT = 10000;
-   
+
     private final static String MARKER = "*****************";
 
+    @Inject
+    protected BundleContext m_bundleContext;
+
+    /**
+     * Inherited tests need to implement this method.
+     */
+    public abstract void run();
+
     public Option[] configure() {
         // First get our own JAR
         FileFilter ff = new FileFilter() {
@@ -56,7 +70,7 @@
         return options(
             mavenConfiguration(),
 
-            // Run test in a Felix container
+        // Run test in a Felix container
             frameworks(felix()),
 
             // Setting this system property unfortunately is necessary with 
the current Cassandra implementation
@@ -124,5 +138,34 @@
         System.out.println(TEST_PREFIX + MARKER + "  Finished integration 
test: " + testName + "  " + MARKER);
     }
 
-    abstract void run();
+    @SuppressWarnings("unchecked")
+    public <T> T getService(Class<T> serviceClass) {
+        T serviceInstance = null;
+
+        // First open a service tracker and wait let the service tracker wait 
for the availability of our service
+        ServiceTracker serviceTracker = new ServiceTracker(m_bundleContext, 
serviceClass.getName(), null);
+        serviceTracker.open();
+        try {
+            System.out.println(TEST_PREFIX + "Waiting for " + serviceClass + " 
to become available "
+                + "(timeout = 30 seconds)");
+            serviceInstance = (T) serviceTracker.waitForService(30000);
+            System.out.println(TEST_PREFIX + serviceClass.getName() + " 
available: " + serviceInstance);
+        }
+        catch (InterruptedException e) {
+            e.printStackTrace();
+            Assert.fail(TEST_PREFIX + serviceClass + " service not available: 
" + e.toString());
+        }
+
+        // Sometimes the service tracker is lying when he says that the 
service is available, so check it!
+        ServiceReference serviceRef = 
m_bundleContext.getServiceReference(serviceClass.getName());
+        if (serviceRef == null) {
+            Assert.fail("Service " + serviceClass + " not available, quitting 
integration test");
+        }
+        else {
+            serviceInstance = (T) m_bundleContext.getService(serviceRef);
+        }
+
+        return serviceInstance;
+    }
+
 }

Copied: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
 (from r199, 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java)
==============================================================================
--- 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
 (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
    Thu Oct 21 13:45:04 2010
@@ -14,7 +14,7 @@
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-package org.amdatu.test.integration;
+package org.amdatu.test.integration.tests;
 
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -26,40 +26,37 @@
 import org.amdatu.platform.tenant.TenantDAO;
 import org.amdatu.platform.tenant.TenantException;
 import org.amdatu.platform.tenant.TenantManagementService;
+import org.amdatu.test.integration.IntegrationTestRunner;
 import org.amdatu.test.integration.mock.TenantDAOMock;
 import org.apache.felix.dm.DependencyManager;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.useradmin.UserAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * This class provides an integration test for testing the Tenant Management 
Service.
+ * 
  * @author ivol
  */
 @RunWith(JUnit4TestRunner.class)
 public class TenantManagementServiceTest extends IntegrationTestRunner {
-    @Inject
-    protected BundleContext m_bundleContext;
-    
+
     @Configuration
     public Option[] configure() {
         return super.configure();
     }
-    
+
     @Test
     public void testTenantManagementService() {
         super.runTest("Tenant Management Service");
     }
-    
+
     public void run() {
         // First we register a new in-memory TenantDAO service and register it 
with a higher service rank then the default
         // Cassandra DAO such that our test framework will pick it up
@@ -75,37 +72,15 @@
             for (ServiceReference ref : tenantDAOs) {
                 System.out.println(TEST_PREFIX + "Tenant DAO = " + 
m_bundleContext.getService(ref).getClass());
             }
-        } catch (InvalidSyntaxException e) {
-        }
-        
-        TenantManagementService tenantService = null;
-        ServiceTracker serviceTracker = new ServiceTracker(m_bundleContext, 
TenantManagementService.class.getName(), null);
-        serviceTracker.open();
-        try {
-            System.out
-                .println(TEST_PREFIX + "Waiting for TenantManagementService to 
become available (timeout = 30 seconds)");
-            tenantService = (TenantManagementService) 
serviceTracker.waitForService(30000);
-            System.out.println(TEST_PREFIX + "TenantManagementService 
available: " + tenantService);
-        }
-        catch (InterruptedException e) {
-            e.printStackTrace();
-            Assert.fail(TEST_PREFIX + "TenantManagementService service not 
available: " + e.toString());
         }
+        catch (InvalidSyntaxException e) {}
 
-        ServiceReference tenantMgrSR = 
m_bundleContext.getServiceReference(TenantManagementService.class.getName());
-        if (tenantMgrSR == null) {
-            System.out.println("TenantManagementService not available in 
BundleContext, but it is using a ServiceTracker");
-        } else {
-            tenantService = (TenantManagementService) 
m_bundleContext.getService(tenantMgrSR);
-        }
-        
-        System.out.println(TEST_PREFIX + "Testing " + tenantService);
+        TenantManagementService tenantService = 
getService(TenantManagementService.class);
+        System.out.println(TEST_PREFIX + "Testing " + 
tenantService.getClass().getName());
 
         try {
-
             Tenant[] allTenants = tenantService.getAllTenants();
-            Assert
-            .assertTrue("There are already tenants present in the storage",
+            Assert.assertTrue("There are already tenants present in the 
storage",
                 tenantService.getAllTenants().length == 0);
 
             int tenantCount = allTenants.length;
@@ -121,8 +96,7 @@
                 
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant", 
"sdfsdfd");
                 Assert.assertTrue("Tenant with the same id could be created 
twice", false);
             }
-            catch (TenantException e) {
-            }
+            catch (TenantException e) {}
 
             tenantService.deleteTenant(tenant);
 
@@ -154,8 +128,7 @@
                 tenantService.deleteTenant(tenant);
                 Assert.assertTrue("Tenant with the same id could be deleted 
twice", false);
             }
-            catch (TenantException e) {
-            }
+            catch (TenantException e) {}
 
         }
         catch (TenantException e) {

Copied: 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
 (from r199, 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java)
==============================================================================
--- 
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
  (original)
+++ 
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
     Thu Oct 21 13:45:04 2010
@@ -14,12 +14,13 @@
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-package org.amdatu.test.integration;
+package org.amdatu.test.integration.tests;
 
 import java.io.UnsupportedEncodingException;
 
 import junit.framework.Assert;
 
+import org.amdatu.test.integration.IntegrationTestRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Inject;
@@ -28,12 +29,10 @@
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.useradmin.Group;
 import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
-import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * This class provides an integration test for testing the User Admin store.
@@ -59,27 +58,8 @@
 
     @SuppressWarnings("unchecked")
     public void run() {
-        ServiceTracker serviceTracker = new ServiceTracker(m_bundleContext, 
UserAdmin.class.getName(), null);
-        serviceTracker.open();
-        try {
-            System.out
-                .println(TEST_PREFIX + "Waiting for UserAdmin service to 
become available (timeout = 30 seconds)");
-            m_userAdmin = (UserAdmin) serviceTracker.waitForService(30000);
-            System.out.println(TEST_PREFIX + "UserAdmin service available: " + 
m_userAdmin);
-        }
-        catch (InterruptedException e) {
-            e.printStackTrace();
-            Assert.fail(TEST_PREFIX + "UserAdmin service not available: " + 
e.toString());
-        }
+        m_userAdmin = getService(UserAdmin.class);
 
-        // First get the UserAdmin service
-        ServiceReference servRef = 
m_bundleContext.getServiceReference(UserAdmin.class.getName());
-        if (servRef == null) {
-            System.out.println("UserAdmin service not available in 
BundleContext, but it is using a ServiceTracker");
-        } else {
-            m_userAdmin = (UserAdmin) m_bundleContext.getService(servRef);
-        }
-        
         try {
             // Start the test, first remove all existing roles
             Role[] allRoles = m_userAdmin.getRoles(null);
@@ -198,7 +178,7 @@
         Assert.assertTrue("Group '" + group + "' is unknown by UserAdmin", 
m_userAdmin.getRole(group) != null);
         int count =
             ((Group) m_userAdmin.getRole(group)).getMembers() != null ? 
((Group) m_userAdmin.getRole(group))
-                .getMembers().length : 0;
+            .getMembers().length : 0;
         if (count != expected) {
             Role[] members = ((Group) m_userAdmin.getRole(group)).getMembers();
             String sMembers = "";
@@ -214,7 +194,7 @@
         Assert.assertTrue("Group '" + group + "' is unknown by UserAdmin", 
m_userAdmin.getRole(group) != null);
         int count =
             ((Group) m_userAdmin.getRole(group)).getRequiredMembers() != null 
? ((Group) m_userAdmin.getRole(group))
-                .getRequiredMembers().length : 0;
+            .getRequiredMembers().length : 0;
         if (count != expected) {
             Role[] members = ((Group) 
m_userAdmin.getRole(group)).getRequiredMembers();
             String sMembers = "";

Reply via email to