Author: ivol
Date: Mon Oct 18 12:21:04 2010
New Revision: 179
Log:
[AMDATU-107] Moved user admin test to integration test bundle
Added:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
- copied, changed from r178,
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/TenantManagementServiceTest.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/
- copied from r178,
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/mock/
Removed:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/TenantManagementServiceTest.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/mock/
trunk/platform-bundles/tenant-service/src/test/
trunk/test-bundles/
Modified:
trunk/integration-tests/pom.xml
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/TenantDAOMock.java
trunk/pom.xml
Modified: trunk/integration-tests/pom.xml
==============================================================================
--- trunk/integration-tests/pom.xml (original)
+++ trunk/integration-tests/pom.xml Mon Oct 18 12:21:04 2010
@@ -84,15 +84,21 @@
<scope>test</scope>
<type>bundle</type>
</dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>useradmin-cassandra-store</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>wink-application</artifactId>
+ <scope>test</scope>
+ <type>bundle</type>
+ </dependency>
</dependencies>
<build>
- <resources>
- <resource>
- <directory>src/test/java/org/amdatu/test/integration/tenant</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
@@ -100,7 +106,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Activator>org.amdatu.test.osgi</Bundle-Activator>
+ <Bundle-Activator>org.amdatu.test.osgi.Activator</Bundle-Activator>
<Bundle-SymbolicName>org.amdatu.test</Bundle-SymbolicName>
</instructions>
</configuration>
Added:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
==============================================================================
--- (empty file)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
Mon Oct 18 12:21:04 2010
@@ -0,0 +1,98 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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;
+
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.frameworks;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.File;
+import java.io.FileFilter;
+
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Base class for integration tests.
+ * @author ivol
+ */
+public abstract class IntegrationTestRunner {
+ public final static String TEST_PREFIX = "> TESTING: ";
+
+ @Inject
+ protected BundleContext m_bundleContext;
+
+ @Configuration
+ public Option[] configure() {
+ // First get our own JAR
+ FileFilter ff = new FileFilter (){
+ public boolean accept(File pathname) {
+ return
pathname.getName().startsWith("org.amdatu.platform.integration-tests-")
+ && pathname.getName().endsWith(".jar");
+ }
+ };
+ File integrationTestJarFile = new File("target").listFiles(ff)[0];
+ System.out.println("> TESTING: Deploy integration test file: '" +
integrationTestJarFile.getAbsolutePath() + "'");
+
+ return options(
+ mavenConfiguration(),
+
+ // 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"),
+
+ // 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.ops4j.pax.useradmin").artifactId("pax-useradmin-service").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
+ // TODO: this works fine when running 'mvn install' since the
artifacts will then be deployed to the maven
+ // repository prior to running this integration test. With
'mvn integration-test' however, artifacts will
+ // not be deployed and so this will only work when artifacts
have been deployed to the maven repository
+ // before, possibly using outdated artifacts.
+
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(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("useradmin-cassandra-store").versionAsInProject(),
+
mavenBundle().groupId("org.amdatu.platform").artifactId("wink-application").versionAsInProject(),
+
+ // And finally deploy ourselves
+ bundle(integrationTestJarFile.toURI().toString())));
+ }
+}
Copied:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
(from r178,
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/TenantManagementServiceTest.java)
==============================================================================
---
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/TenantManagementServiceTest.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/TenantManagementServiceTest.java
Mon Oct 18 12:21:04 2010
@@ -14,19 +14,8 @@
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.tenant;
+package org.amdatu.test.integration;
-import static org.ops4j.pax.exam.CoreOptions.bundle;
-import static org.ops4j.pax.exam.CoreOptions.felix;
-import static org.ops4j.pax.exam.CoreOptions.frameworks;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.provision;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
-import java.io.File;
-import java.io.FileFilter;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -37,13 +26,10 @@
import org.amdatu.platform.tenant.TenantDAO;
import org.amdatu.platform.tenant.TenantException;
import org.amdatu.platform.tenant.TenantManagementService;
-import org.amdatu.test.integration.tenant.mock.TenantDAOMock;
+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;
@@ -51,155 +37,105 @@
import org.osgi.framework.ServiceReference;
/**
- * This class provides a Unit test for testing the Tenant Management Service.
+ * This class provides an integration test for testing the Tenant Management
Service.
* @author ivol
*/
-// 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
@RunWith(JUnit4TestRunner.class)
-public class TenantManagementServiceTest {
- @Inject
- protected BundleContext m_bundleContext;
-
- @Configuration
- public Option[] configure() {
- // First get our own JAR
- FileFilter ff = new FileFilter (){
- public boolean accept(File pathname) {
- return
pathname.getName().startsWith("org.amdatu.platform.integration-tests-")
- && pathname.getName().endsWith(".jar");
- }
- };
- File integrationTestJarFile = new File("target").listFiles(ff)[0];
- System.out.println("> TESTING: Deploy integration test file: '" +
integrationTestJarFile.getAbsolutePath() + "'");
-
- return options(
- mavenConfiguration(),
-
- // 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"),
-
- // 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
- // TODO: this works fine when running 'mvn install' since the
artifacts will then be deployed to the maven
- // repository prior to running this integration test. With
'mvn integration-test' however, artifacts will
- // not be deployed and so this will only work when artifacts
have been deployed to the maven repository
- // before, possibly using outdated artifacts.
-
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(),
-
- // And finally deploy ourselves
- bundle(integrationTestJarFile.toURI().toString())));
- }
-
+public class TenantManagementServiceTest extends IntegrationTestRunner {
@Test
- public void crudTest() {
- System.out.println("> TESTING: ************ Running Tenant CRUD test
************");
+ public void testTenantManagementService() {
+ System.out.println(TEST_PREFIX + "************ Running Tenant
Management Service test ************");
+ run(m_bundleContext);
+ System.out.println(TEST_PREFIX + "************ Finished Tenant
Management Service test ************");
+ }
+
+ public void run(BundleContext bundleContext) {
+ // TODO: in the integration test we should use the regular
TenantManagementService. With the current Cassandra
+ // implementation, this however cannot work because of the way the
dynamic registration of ColumnFamily's was
+ // implemented. However, since this will be replaced by Cassandra 0.7
which supports dynamic registration of
+ // keyspaces and columnfamily's this will be fixed in future releases.
Until that, we can use this approach.
// First we register a new Mocked TenantDAO service and register it
with a higher service rank then the default
// Cassandra DAO such that our test framework will pick it up
- DependencyManager depMgr = new DependencyManager(m_bundleContext);
+ DependencyManager depMgr = new DependencyManager(bundleContext);
Hashtable<String, Integer> ht = new Hashtable<String, Integer>();
ht.put(Constants.SERVICE_RANKING, 1);
depMgr.add(depMgr.createComponent().setImplementation(TenantDAOMock.class).setInterface(
TenantDAO.class.getName(), ht));
- System.out.println("> TESTING: TenantDAOMock service registered");
+ System.out.println(TEST_PREFIX + "TenantDAOMock service registered");
try {
- ServiceReference[] tenantDAOs =
m_bundleContext.getServiceReferences(TenantDAO.class.getName(), null);
+ ServiceReference[] tenantDAOs =
bundleContext.getServiceReferences(TenantDAO.class.getName(), null);
for (ServiceReference ref : tenantDAOs) {
- System.out.println("> TESTING: Tenant DAO = "
+m_bundleContext.getService(ref));
+ System.out.println(TEST_PREFIX + "Tenant DAO = " +
bundleContext.getService(ref));
}
} catch (InvalidSyntaxException e) {
-
}
- ServiceReference tenantMgrSR =
m_bundleContext.getServiceReference(TenantManagementService.class.getName());
- TenantManagementService tenantManagementService =
- (TenantManagementService) m_bundleContext.getService(tenantMgrSR);
- System.out.println("> TESTING: Testing " + tenantManagementService);
+ ServiceReference tenantMgrSR =
bundleContext.getServiceReference(TenantManagementService.class.getName());
+ TenantManagementService tenantService = (TenantManagementService)
bundleContext.getService(tenantMgrSR);
+ System.out.println(TEST_PREFIX + "Testing " + tenantService);
try {
- run(tenantManagementService);
- }
- catch (TenantException e) {
- Assert.fail("An error has occurred: " + e.toString());
- e.printStackTrace();
- }
- }
-
- 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;
- Tenant tenant =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
- tenantService.updateTenant(tenant);
-
- 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 {
-
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
- Assert.assertTrue("Tenant with the same id could be created
twice", false);
- }
- catch (TenantException e) {
- }
+ Tenant[] allTenants = tenantService.getAllTenants();
+ Assert
+ .assertTrue("There are already tenants present in the storage",
+ tenantService.getAllTenants().length == 0);
+
+ int tenantCount = allTenants.length;
+ Tenant tenant =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
+ tenantService.updateTenant(tenant);
+
+ 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 {
+
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
+ Assert.assertTrue("Tenant with the same id could be created
twice", false);
+ }
+ catch (TenantException e) {
+ }
- tenantService.deleteTenant(tenant);
+ tenantService.deleteTenant(tenant);
- Assert.assertTrue(tenantService.getAllTenants().length == tenantCount);
+ Assert.assertTrue(tenantService.getAllTenants().length ==
tenantCount);
- 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");
- tenantService.updateTenant(tenant1);
- tenantService.updateTenant(tenant2);
- tenantService.updateTenant(tenant3);
-
- Map<String, String> filter = new HashMap<String, String>();
- filter.put("hostname", "localhost");
- Assert.assertTrue(tenantService.getTenants(filter).length == 2);
-
- filter.put("hostname", "amdatu.org");
- Assert.assertTrue(tenantService.getTenants(filter).length == 1);
-
- tenantService.deleteTenant(tenant1);
- tenantService.deleteTenant(tenant2);
- tenantService.deleteTenant(tenant3);
+ 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");
+ tenantService.updateTenant(tenant1);
+ tenantService.updateTenant(tenant2);
+ tenantService.updateTenant(tenant3);
+
+ Map<String, String> filter = new HashMap<String, String>();
+ filter.put("hostname", "localhost");
+ Assert.assertTrue(tenantService.getTenants(filter).length == 2);
+
+ filter.put("hostname", "amdatu.org");
+ Assert.assertTrue(tenantService.getTenants(filter).length == 1);
+
+ tenantService.deleteTenant(tenant1);
+ tenantService.deleteTenant(tenant2);
+ tenantService.deleteTenant(tenant3);
+
+ // What happens if I remove a tenant that was already removed?
+ try {
+ tenantService.deleteTenant(tenant);
+ Assert.assertTrue("Tenant with the same id could be deleted
twice", false);
+ }
+ catch (TenantException e) {
+ }
- // What happens if I remove a tenant that was already removed?
- try {
- tenantService.deleteTenant(tenant);
- Assert.assertTrue("Tenant with the same id could be deleted
twice", false);
}
catch (TenantException e) {
+ Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
+ e.printStackTrace();
}
}
}
Added:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
==============================================================================
--- (empty file)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/UserAdminStoreTest.java
Mon Oct 18 12:21:04 2010
@@ -0,0 +1,190 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.
+ * @author ivol
+ */
+ at RunWith(JUnit4TestRunner.class)
+public class UserAdminStoreTest extends IntegrationTestRunner {
+ private UserAdmin m_userAdmin;
+
+ @Test
+ public void testUserAdminStore() {
+ System.out.println(TEST_PREFIX + "************ Running User Admin
Store test ************");
+ new UserAdminStoreTest().run(m_bundleContext);
+ System.out.println(TEST_PREFIX + "************ Finished User Admin
Store test ************");
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(BundleContext bundleContext) {
+ ServiceTracker serviceTracker = new ServiceTracker(bundleContext,
UserAdmin.class.getName(), null);
+ serviceTracker.open();
+ try {
+ System.out.println(TEST_PREFIX + "Waiting for UserAdmin service to
become available (timeout = 30 seconds)");
+ serviceTracker.waitForService(30000);
+ }
+ catch (InterruptedException e) {
+ e.printStackTrace();
+ Assert.fail(TEST_PREFIX + "UserAdmin service not available: " +
e.toString());
+ }
+
+ // First get the UserAdmin service
+ ServiceReference servRef =
bundleContext.getServiceReference(UserAdmin.class.getName());
+ m_userAdmin = (UserAdmin) bundleContext.getService(servRef);
+
+ try {
+ // Start the test, first remove all existing roles
+ Role[] allRoles = m_userAdmin.getRoles(null);
+ if (allRoles != null) {
+ for (Role role : allRoles) {
+ String roleName = role.getName();
+ m_userAdmin.removeRole(roleName);
+ Assert.assertTrue("Role '" + roleName + "' removed but
still returned", m_userAdmin.getRole(roleName) == null);
+ }
+ }
+
+ // Test if all roles have been removed
+ Assert.assertTrue("All roles were removed, but getRoles() still
returns roles", m_userAdmin.getRoles(null) == null
+ || m_userAdmin.getRoles(null).length == 0);
+
+ // Create three test users and set the credentials
+ User adminUser = (User)
m_userAdmin.createRole("TestAdministrator", Role.USER);
+ User editorUser = (User) m_userAdmin.createRole("TestEditor",
Role.USER);
+ User guestUser = (User) m_userAdmin.createRole("TestGuest",
Role.USER);
+
+ Assert.assertTrue("All users were removed, but still creating a
user failed since it already exists",
+ adminUser != null && editorUser != null && guestUser != null);
+ adminUser.getCredentials().put("password", "adminpasswd");
+ editorUser.getCredentials().put("password", "editorpasswd");
+ guestUser.getCredentials().put("password", "guestpasswd");
+
+ // Now see if we can find these users from credentials
+ Assert.assertTrue("TestAdmin user could not be found",
m_userAdmin.getUser("name", "TestAdministrator") != null);
+ Assert.assertTrue("TestEditor user could not be found",
m_userAdmin.getUser("name", "TestEditor") != null);
+ Assert.assertTrue("TestGuest user could not be found",
m_userAdmin.getUser("name", "TestGuest") != null);
+
+ // Set user properties of admin
+ adminUser.getProperties().put("firstName", "John".getBytes());
+ adminUser.getProperties().put("lastName", "Doe".getBytes());
+
+ // And check if they were set correctly
+ byte[] firstName = (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("firstName");
+ Assert.assertTrue("firstName not properly set", new
String(firstName, "UTF-8").equals("John"));
+ byte[] lastName = (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("lastName");
+ Assert.assertTrue("lastName not properly set", new
String(lastName, "UTF-8").equals("Doe"));
+
+ // Remove last name
+ adminUser.getProperties().remove("lastName");
+ Assert.assertTrue("lastName not properly removed from property
set", m_userAdmin.getUser("name", "TestAdministrator")
+ .getProperties().get("lastName") == null);
+
+ // Now create "Administrator", "Editor" and "Guest" group and do
some assignments
+ Group adminGroup = (Group)
m_userAdmin.createRole("TestAdminUsers", Role.GROUP);
+ Group editorGroup = (Group)
m_userAdmin.createRole("TestEditUsers", Role.GROUP);
+ Group guestGroup = (Group)
m_userAdmin.createRole("TestGuestUsers", Role.GROUP);
+ adminGroup.addMember(adminUser);
+ adminGroup.addRequiredMember(adminUser);
+ editorGroup.addMember(adminUser);
+ editorGroup.addMember(editorUser);
+ editorGroup.addRequiredMember(adminUser);
+ editorGroup.addRequiredMember(editorUser);
+ guestGroup.addMember(adminUser);
+ guestGroup.addMember(editorUser);
+ guestGroup.addMember(guestUser);
+
+ assertBasicMemberCount("TestAdminUsers", 1);
+ assertRequiredMemberCount("TestAdminUsers", 1);
+ assertBasicMemberCount("TestEditUsers", 2);
+ assertRequiredMemberCount("TestEditUsers", 2);
+ assertBasicMemberCount("TestGuestUsers", 3);
+ assertRequiredMemberCount("TestGuestUsers", 0);
+
+ // Now remove some members
+ guestGroup.removeMember(adminUser);
+ assertBasicMemberCount("TestGuestUsers", 2);
+
+ // Remove the editor user, is it removed from the admin group?
+ m_userAdmin.removeRole("TestEditor");
+ Assert.assertTrue("EditUsers should have had 2 basic members",
((Group) m_userAdmin.getRole("TestEditUsers"))
+ .getMembers().length == 2);
+
+ // Finally, remove all test users and groups
+ allRoles = m_userAdmin.getRoles(null);
+ if (allRoles != null) {
+ for (Role role : allRoles) {
+ String roleName = role.getName();
+ m_userAdmin.removeRole(roleName);
+ Assert.assertTrue("Role '" + roleName + "' removed but
still returned", m_userAdmin.getRole(roleName) == null);
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
+ e.printStackTrace();
+ }
+ catch (UnsupportedEncodingException e) {
+ Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
+ e.printStackTrace();
+ }
+ }
+
+ private void assertBasicMemberCount(String group, int expected) {
+ int count = ((Group) m_userAdmin.getRole(group)).getMembers().length;
+ if (count != expected) {
+ Role[] members = ((Group) m_userAdmin.getRole(group)).getMembers();
+ String sMembers = "";
+ for (Role role : members) {
+ sMembers += role.getName() + " ";
+ }
+ Assert.assertTrue("Group '" + group + "' has " + count + " basic
members. Expected: " + expected
+ + ". Members found: " + sMembers, false);
+ }
+ }
+
+ private void assertRequiredMemberCount(String group, int expected) {
+ int count =
+ ((Group) m_userAdmin.getRole(group)).getRequiredMembers() != null
? ((Group) m_userAdmin.getRole(group))
+ .getRequiredMembers().length
+ : 0;
+ if (count != expected) {
+ Role[] members = ((Group)
m_userAdmin.getRole(group)).getRequiredMembers();
+ String sMembers = "";
+ for (Role role : members) {
+ sMembers += role.getName() + " ";
+ }
+ Assert.assertTrue("Group '" + group + "' has " + count
+ " required members. Expected: " + expected
+ + ". Members found: " + sMembers, false);
+ }
+ }
+}
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/TenantDAOMock.java
==============================================================================
---
/trunk/integration-tests/src/test/java/org/amdatu/test/integration/tenant/mock/TenantDAOMock.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/mock/TenantDAOMock.java
Mon Oct 18 12:21: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.tenant.mock;
+package org.amdatu.test.integration.mock;
import java.util.ArrayList;
import java.util.HashMap;
Modified: trunk/pom.xml
==============================================================================
--- trunk/pom.xml (original)
+++ trunk/pom.xml Mon Oct 18 12:21:04 2010
@@ -514,6 +514,13 @@
<type>bundle</type>
</dependency>
<dependency>
+ <groupId>org.amdatu.platform</groupId>
+ <artifactId>useradmin-cassandra-store</artifactId>
+ <version>${platform.version}</version>
+ <scope>provided</scope>
+ <type>bundle</type>
+ </dependency>
+ <dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
<version>${org.apache.wink.version}</version>