Author: ivol
Date: Fri Oct 15 14:06:06 2010
New Revision: 174
Log:
[AMDATU-107] Fixed proper working of Unit test and added version resolving
Modified:
trunk/platform-bundles/tenant-service/pom.xml
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/service/TenantManagementServiceImpl.java
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/TenantManagementServiceTest.java
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/mock/TenantDAOMock.java
trunk/pom.xml
Modified: trunk/platform-bundles/tenant-service/pom.xml
==============================================================================
--- trunk/platform-bundles/tenant-service/pom.xml (original)
+++ trunk/platform-bundles/tenant-service/pom.xml Fri Oct 15 14:06:06 2010
@@ -22,6 +22,7 @@
<dependencies>
+ <!-- Test scope dependencies -->
<!-- This is required to be first so that pax-exam classloader is not
messed up with a newer version of felix
which would lead to java.lang.NoSuchMethodError:
org.apache.felix.framework.Logger.<init>(I)V -->
<dependency>
@@ -41,8 +42,33 @@
<artifactId>pax-exam-container-default</artifactId>
<version>${pax.exam.version}</version>
<scope>test</scope>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>filebased-configuration</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>httpcontext</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>config-template-manager</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>shindig-application</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <!-- Regular dependencies -->
<dependency>
<groupId>org.amdatu.platform</groupId>
<artifactId>cassandra-application</artifactId>
@@ -61,7 +87,7 @@
<artifactId>cassandra-listener</artifactId>
<scope>provided</scope>
<type>bundle</type>
- </dependency>
+ </dependency>
</dependencies>
<build>
@@ -85,6 +111,19 @@
<artifactId>maven-antrun-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
Modified:
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/service/TenantManagementServiceImpl.java
==============================================================================
---
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/service/TenantManagementServiceImpl.java
(original)
+++
trunk/platform-bundles/tenant-service/src/main/java/org/amdatu/platform/tenant/service/TenantManagementServiceImpl.java
Fri Oct 15 14:06:06 2010
@@ -49,7 +49,6 @@
public void start() {
try {
// Upon starting this bundle, we load the available tenants into
memory
- System.out.println("Loading tenants");
m_tenants = m_tenantDAO.readAll();
// Register all tenants as service
Modified:
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/TenantManagementServiceTest.java
==============================================================================
---
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/TenantManagementServiceTest.java
(original)
+++
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/TenantManagementServiceTest.java
Fri Oct 15 14:06:06 2010
@@ -49,8 +49,6 @@
* This class provides a Unit test for testing the Tenant Management Service.
* @author ivol
*/
-// TODO: version number are still hard coded since for some reason
versionAsInProject() doesn't work (causes exception)
-// TODO: although not effecting the test, several errors appear in the log
booting Felix, these must be fixed
// TODO: using this test framework must be generalized, move dependencies to
root pom
// TODO: service ranking mechanism to enforce that mock dao is used must be
tested after solving other issues
// TODO: TenantImpl and TenantDAO has to be moved temporarily to the exported
package in order for this test to use them
@@ -63,41 +61,33 @@
@Configuration
public Option[] configure() {
-
- String version = "0.0.5-SNAPSHOT";
return options(
- // Run test in a Felix container
- frameworks(felix()),
-
- // 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"),
+ // Run test in a Felix container
+ frameworks(felix()),
- // I doubt if using mavenBundle is correct. Using mavenBundle
the bundle is loaded from the online
- // maven repository.
+ // 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"),
- // Install bundles we need to execute our test
-
provision(mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.1.0"),
-
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager")
- .version("3.0.0-SNAPSHOT"),
-
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").version(
- "1.2.4"),
-
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version("1.0.0"),
-
mavenBundle().groupId("org.ops4j.pax.web").artifactId("pax-web-jetty-bundle").version("0.7.1"),
-
mavenBundle().groupId("org.ops4j.pax.web").artifactId("pax-web-jsp").version("0.7.1"),
-
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.mime").version(
- "2.1.4"),
-
- // Amdatu platform bundles
-
mavenBundle().groupId("org.amdatu.platform").artifactId("httpcontext").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("loghandler").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("config-template-manager").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-application").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("shindig-application").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-listener").version(version),
-
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-persistencemanager").version(version)),
-
-
mavenBundle().groupId("org.amdatu.platform").artifactId("tenant-service").version(version));
+ // Install bundles we need to execute our test
+
provision(mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").versionAsInProject()),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").versionAsInProject(),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").versionAsInProject(),
+
mavenBundle().groupId("org.ops4j.pax.web").artifactId("pax-web-jetty-bundle").versionAsInProject(),
+
mavenBundle().groupId("org.ops4j.pax.web").artifactId("pax-web-jsp").versionAsInProject(),
+
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.mime").versionAsInProject(),
+
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.osgi").versionAsInProject(),
+
+ // Amdatu platform bundles
+
mavenBundle().groupId("org.amdatu.platform").artifactId("filebased-configuration").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("httpcontext").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("config-template-manager").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-application").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("shindig-application").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-listener").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("cassandra-persistencemanager").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("tenant-service").versionAsInProject());
}
@Test
@@ -118,75 +108,65 @@
(TenantManagementService)
m_bundleContext.getService(tenantMgrSR);
System.out.println("> TESTING: Testing " + tenantManagementService);
- /*try {
+ try {
run(tenantManagementService);
}
catch (TenantException e) {
Assert.fail("An error has occurred: " + e.toString());
e.printStackTrace();
- }*/
+ }
}
- /**
- * @throws TenantException
- * @see IntegrationTest#run
- */
- private void run(TenantManagementService tenantManagementService) throws
TenantException {
- Tenant[] allTenants = tenantManagementService.getAllTenants();
- Assert.assertTrue("There are already tenants",
tenantManagementService.getAllTenants().length == 0);
+ private void run(TenantManagementService tenantService) throws
TenantException {
+ Tenant[] allTenants = tenantService.getAllTenants();
+ Assert
+ .assertTrue("There are already tenants present in the storage",
+ tenantService.getAllTenants().length == 0);
int tenantCount = allTenants.length;
- System.out.println("> TESTING:
"+tenantManagementService.getAllTenants().length);
+ Tenant tenant =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
+ tenantService.updateTenant(tenant);
- Tenant tenant =
tenantManagementService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
- for (Tenant t : tenantManagementService.getAllTenants()) {
- System.out.println(t.getId() + " " + t.getName());
- }
- tenantManagementService.updateTenant(tenant);
-
-
- Assert.assertTrue(tenantManagementService.getAllTenants().length + "
should have been equal to "
- + (tenantCount + 1),
tenantManagementService.getAllTenants().length == tenantCount + 1);
+ Assert.assertTrue("Added and updated 1 tenant, but the Tenant service
now holds "
+ + tenantService.getAllTenants().length + " tenants, expected:
" + (tenantCount + 1), tenantService
+ .getAllTenants().length == tenantCount + 1);
// Try to add a tenant with the same id, should throw an exception
try {
-
tenantManagementService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
+
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
Assert.assertTrue("Tenant with the same id could be created
twice", false);
}
catch (TenantException e) {
}
- tenantManagementService.deleteTenant(tenant);
+ tenantService.deleteTenant(tenant);
- Assert.assertTrue(tenantManagementService.getAllTenants().length ==
tenantCount);
+ Assert.assertTrue(tenantService.getAllTenants().length == tenantCount);
- Tenant tenant1 =
-
tenantManagementService.createTentant("org.amdatu.test.integration.tests.testtenant.1",
"TEST 1");
- Tenant tenant2 =
-
tenantManagementService.createTentant("org.amdatu.test.integration.tests.testtenant.2",
"TEST 2");
- Tenant tenant3 =
-
tenantManagementService.createTentant("org.amdatu.test.integration.tests.testtenant.3",
"TEST 3");
+ Tenant tenant1 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.1",
"TEST 1");
+ Tenant tenant2 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.2",
"TEST 2");
+ Tenant tenant3 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.3",
"TEST 3");
tenant1.getProperties().put("hostname", "localhost");
tenant2.getProperties().put("hostname", "localhost");
tenant3.getProperties().put("hostname", "amdatu.org");
- tenantManagementService.updateTenant(tenant1);
- tenantManagementService.updateTenant(tenant2);
- tenantManagementService.updateTenant(tenant3);
+ tenantService.updateTenant(tenant1);
+ tenantService.updateTenant(tenant2);
+ tenantService.updateTenant(tenant3);
Map<String, String> filter = new HashMap<String, String>();
filter.put("hostname", "localhost");
- Assert.assertTrue(tenantManagementService.getTenants(filter).length ==
2);
+ Assert.assertTrue(tenantService.getTenants(filter).length == 2);
filter.put("hostname", "amdatu.org");
- Assert.assertTrue(tenantManagementService.getTenants(filter).length ==
1);
+ Assert.assertTrue(tenantService.getTenants(filter).length == 1);
- tenantManagementService.deleteTenant(tenant1);
- tenantManagementService.deleteTenant(tenant2);
- tenantManagementService.deleteTenant(tenant3);
+ tenantService.deleteTenant(tenant1);
+ tenantService.deleteTenant(tenant2);
+ tenantService.deleteTenant(tenant3);
// What happens if I remove a tenant that was already removed?
try {
- tenantManagementService.deleteTenant(tenant);
+ tenantService.deleteTenant(tenant);
Assert.assertTrue("Tenant with the same id could be deleted
twice", false);
}
catch (TenantException e) {
Modified:
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/mock/TenantDAOMock.java
==============================================================================
---
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/mock/TenantDAOMock.java
(original)
+++
trunk/platform-bundles/tenant-service/src/test/java/org/amdatu/platform/tenant/test/mock/TenantDAOMock.java
Fri Oct 15 14:06:06 2010
@@ -35,18 +35,22 @@
public Tenant create(String id, String name) throws TenantException {
try {
read(id);
- throw new TenantException("Tenant with id " + id + " already
exists");
}
catch (TenantException e) {
TenantImpl tenant = new TenantImpl(id, name, new HashMap<String,
String>());
m_tenants.add(tenant);
- System.out.println("> TESTING: "+tenant.getId() + " added");
- return tenant;
+ System.out.println("> TESTING: "+ tenant.getId() + " added to "
+m_tenants.hashCode());
+ return copy(tenant);
}
+ throw new TenantException("Tenant with id " + id + " already exists");
}
public List<Tenant> readAll() throws TenantException {
- return m_tenants;
+ List<Tenant> tenantCopy = new ArrayList<Tenant>();
+ for (Tenant tenant : m_tenants) {
+ tenantCopy.add(copy(tenant));
+ }
+ return tenantCopy;
}
public Tenant read(String id) throws TenantException {
@@ -72,4 +76,8 @@
}
throw new TenantException("Tenant with id '" + tenant.getId() + "'
could not be removed");
}
+
+ private Tenant copy(Tenant tenant) {
+ return new TenantImpl(tenant.getId(), tenant.getName(),
tenant.getProperties());
+ }
}
Modified: trunk/pom.xml
==============================================================================
--- trunk/pom.xml (original)
+++ trunk/pom.xml Fri Oct 15 14:06:06 2010
@@ -483,7 +483,14 @@
<version>${platform.version}</version>
<scope>provided</scope>
<type>bundle</type>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>filebased-configuration</artifactId>
+ <version>${platform.version}</version>
+ <scope>provided</scope>
+ <type>bundle</type>
+ </dependency>
<dependency>
<groupId>org.amdatu.platform</groupId>
<artifactId>shindig-application</artifactId>
@@ -504,7 +511,7 @@
<version>${platform.version}</version>
<scope>provided</scope>
<type>bundle</type>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>