Author: ivol37 at gmail.com
Date: Wed Feb  2 15:07:11 2011
New Revision: 744

Log:
[AMDATU-84] Fixed integration tests using dispatcher instead of Felix 
whiteboard. Enhanced UserAdminREST test with multi-tenancy case. Fixed bug in 
FS tenant storage provider for multi tenancy.


Modified:
   
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/TenantManagementService.java
   
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
   
branches/amdatu-dispatcher/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/osgi/FSUserAdminStorageProviderActivator.java
   branches/amdatu-dispatcher/integration-tests/pom.xml
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/OAuthTestBase.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/RESTTestBase.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminRESTTest.java
   
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/util/Login.java

Modified: 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/TenantManagementService.java
==============================================================================
--- 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/TenantManagementService.java
     (original)
+++ 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/TenantManagementService.java
     Wed Feb  2 15:07:11 2011
@@ -52,7 +52,22 @@
      * @throws TenantException in case a tenant with the specified id already 
exists.
      */
     TenantEntity createTenant(String id, String name) throws TenantException;
+    
+    /**
+     * Creates a new tenant with the specified id, name and properties.
+     * @param id The id of the new tenant
+     * @param name The name of the new tenant
+     * @param properties The properties of the new tenant
+     * @return The created tenant
+     * @throws TenantException in case a tenant with the specified id already 
exists.
+     */
+    TenantEntity createTenant(String id, String name, Map<String, String> 
properties) throws TenantException;
 
+    /**
+     * Updates an existing tenant.
+     * @param tenant
+     * @throws TenantException
+     */
     void updateTenant(TenantEntity tenant) throws TenantException;
 
     void deleteTenant(TenantEntity tenant) throws TenantException;

Modified: 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
==============================================================================
--- 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
 (original)
+++ 
branches/amdatu-dispatcher/amdatu-core/tenant/src/main/java/org/amdatu/core/tenant/service/TenantManagementServiceImpl.java
 Wed Feb  2 15:07:11 2011
@@ -23,6 +23,9 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
 
 import org.amdatu.core.tenant.Tenant;
 import org.amdatu.core.tenant.TenantEntity;
@@ -37,178 +40,241 @@
 
 public class TenantManagementServiceImpl implements TenantManagementService, 
ManagedService {
        private volatile LogService m_logService;
-    private volatile DependencyManager m_manager;
-    private volatile TenantStorageProvider m_tenantStorageProvider;
+       private volatile DependencyManager m_manager;
+       private volatile TenantStorageProvider m_tenantStorageProvider;
 
-    private Map<Tenant, Component> m_tenantComponents = new HashMap<Tenant, 
Component>();
+       private Map<Tenant, Component> m_tenantComponents = new HashMap<Tenant, 
Component>();
 
-    // List of tenants provisioned from config admin
-    List<TenantEntity> m_tenants = null;
+       // List of tenants provisioned from config admin
+       List<TenantEntity> m_tenants = null;
 
-    // We currently use all-exclusive access.
-    private Object m_lock = new Object();
-
-    public void init() throws TenantException {
-        // Loop over the tenants provisioned by config admin and add or update 
the tenants. We do not
-        // remove existing tenants if they are not covered by an entry in 
config admin (yet).
-       m_logService.log(LogService.LOG_INFO, "Initializing 
TenantManagementService with tenants '" + m_tenants + "'.");
-        if (m_tenants != null) {
-            for (TenantEntity tenant : m_tenants) {
-                TenantEntity persTenant = getTenantById(tenant.getId());
-                if (persTenant == null) {
-                    // Tenant does not yet exist, persist it, but without 
registering it as Tenant service yet
-                    persTenant = storeTenant(tenant.getId(), tenant.getName());
-                }
-                persTenant.setName(tenant.getName());
-                for (String propKey : tenant.getProperties().keySet()) {
-                    String propValue = tenant.getProperties().get(propKey);
-                    persTenant.putProperty(propKey, propValue);
-                }
-                m_tenantStorageProvider.store(persTenant);
-                m_logService.log(LogService.LOG_INFO, "Tenant '" + 
tenant.getId() + "' added.");
-            }
-        }
-    }
-
-    /**
-     * Invoked by the Felix dependency manager.
-     */
-    public void start() throws TenantException {
-        // TODO if we cannot get our tenants now, should we retry later?
-        synchronized (m_lock) {
-            for (TenantEntity tenant : getTenants()) {
-                createTenantService(tenant);
-            }
-        }
-        m_logService.log(LogService.LOG_INFO, "TenantManagementService 
started.");
-    }
-
-    public List<TenantEntity> getTenants() throws TenantException {
-        synchronized (m_lock) {
-            return m_tenantStorageProvider.getAll();
-        }
-    }
-
-    public TenantEntity getTenantById(String id) throws TenantException {
-        synchronized (m_lock) {
-            return m_tenantStorageProvider.getById(id);
-        }
-    }
-
-    public List<TenantEntity> getTenants(Map<String, String> properties) 
throws TenantException {
-        synchronized (m_lock) {
-            List<TenantEntity> matchingTenants = new ArrayList<TenantEntity>();
-            for (TenantEntity tenant : getTenants()) {
-                if (tenant.matches(properties)) {
-                    matchingTenants.add(tenant);
-                }
-            }
-            return matchingTenants;
-        }
-    }
-
-    public TenantEntity createTenant(String id, String name) throws 
TenantException {
-        synchronized (m_lock) {
-            if (getTenantById(id) != null) {
-                throw new TenantException("Tenant with id '" + id + "' already 
exists");
-            }
-            TenantEntity tenant = new TenantEntity(id, name);
-            m_tenantStorageProvider.store(tenant);
-            createTenantService(tenant);
-            return tenant;
-        }
-    }
-    
-    // Does the same as createTenant, but without registration of the stored 
tenant as Tenant
-    // service. Invoked in the init() method since tenant services are 
registared in the start() method.
-    private TenantEntity storeTenant(String id, String name) throws 
TenantException {
-        synchronized (m_lock) {
-             if (getTenantById(id) != null) {
-                 throw new TenantException("Tenant with id '" + id + "' 
already exists");
-             }
-             TenantEntity tenant = new TenantEntity(id, name);
-             m_tenantStorageProvider.store(tenant);
-             return tenant;
-         }
-    }
-
-    public void updateTenant(TenantEntity tenant) throws TenantException {
-        synchronized (m_lock) {
-            m_tenantStorageProvider.store(tenant);
-            updateTenantService(tenant);
-        }
-    }
-
-    public void deleteTenant(TenantEntity tenant) throws TenantException {
-        synchronized (m_lock) {
-            if (getTenantById(tenant.getId()) == null) {
-                throw new TenantException("Tenant with id '" + tenant.getId() 
+ "' does not exist, thus cannot be deleted.");
-            }
-            m_tenantStorageProvider.delete(tenant);
-            removeTenantService(tenant);
-        }
-    }
-
-    private void createTenantService(TenantEntity tenant) {
-        Component component = m_manager.createComponent()
-        .setImplementation(tenant)
-        .setInterface(Tenant.class.getName(), createServiceProperties(tenant));
-        m_manager.add(component);
-        m_tenantComponents.put(tenant, component);
-    }
-
-    private void updateTenantService(TenantEntity tenant) {
-        Component component = m_tenantComponents.get(tenant);
-        component.setServiceProperties(createServiceProperties(tenant));
-    }
-
-    private void removeTenantService(TenantEntity tenant) {
-        m_manager.remove(m_tenantComponents.remove(tenant));
-    }
-
-    private Properties createServiceProperties(TenantEntity tenant) {
-        Properties properties = new Properties();
-        Map<String, String> tenantProperties = tenant.getProperties();
-        for (Map.Entry<String, String> entry : tenantProperties.entrySet()) {
-            properties.put(Tenant.SERVICE_PREFIX + entry.getKey(), 
entry.getValue());
-        }
-        properties.put(Tenant.SERVICE_PREFIX + "id", tenant.getId());
-        properties.put(Tenant.SERVICE_PREFIX + "name", tenant.getName());
-
-        return properties;
-    }
-
-    @SuppressWarnings("unchecked")
-    public void updated(Dictionary properties) throws ConfigurationException {
-        if (properties != null) {
-            // Build a list of tenants from the configuration file
-            m_tenants = new ArrayList<TenantEntity>();
-            Enumeration<String> keys = properties.keys();
-            while (keys.hasMoreElements()) {
-                String key = keys.nextElement();
-                if (key.endsWith(".id")) {
-                    m_tenants.add(getTenant(properties, key));
-                }
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private TenantEntity getTenant(Dictionary dictionary, String idKey) {
-        String nameKey = idKey.substring(0, idKey.lastIndexOf(".id")) + 
".name";
-        String propertiesKey = idKey.substring(0, idKey.lastIndexOf(".id")) + 
".properties";
-        String id = (String) dictionary.get(idKey);
-        String name = (String) dictionary.get(nameKey);
-        Map<String, String> properties = new HashMap<String, String>();
-        Enumeration<String> keys = dictionary.keys();
-        while (keys.hasMoreElements()) {
-            String key = keys.nextElement();
-            if (key.startsWith(propertiesKey)) {
-                String propName = key.substring(propertiesKey.length() + 1);
-                String propValue = (String) dictionary.get(key);
-                properties.put(propName, propValue);
-            }
-        }
-        return new TenantEntity(id, name, properties);
-    }
+       // We currently use all-exclusive access.
+       private ReentrantReadWriteLock m_lock = new ReentrantReadWriteLock();
+
+       public synchronized void init() throws TenantException {
+               // Loop over the tenants provisioned by config admin and add or 
update the tenants. We do not
+               // remove existing tenants if they are not covered by an entry 
in config admin (yet).
+               m_logService.log(LogService.LOG_INFO, "Initializing 
TenantManagementService with tenants '" + m_tenants + "'.");
+               if (m_tenants != null) {
+                       for (TenantEntity tenant : m_tenants) {
+                               TenantEntity persTenant = 
getTenantById(tenant.getId());
+                               if (persTenant == null) {
+                                       // Tenant does not yet exist, persist 
it, but without registering it as Tenant service yet
+                                       persTenant = 
storeTenant(tenant.getId(), tenant.getName());
+                               }
+                               persTenant.setName(tenant.getName());
+                               for (String propKey : 
tenant.getProperties().keySet()) {
+                                       String propValue = 
tenant.getProperties().get(propKey);
+                                       persTenant.putProperty(propKey, 
propValue);
+                               }
+                               m_tenantStorageProvider.store(persTenant);
+                               m_logService.log(LogService.LOG_INFO, "Tenant 
'" + tenant.getId() + "' added.");
+                       }
+               }
+       }
+
+       /**
+        * Invoked by the Felix dependency manager.
+        */
+       public synchronized void start() throws TenantException {
+               // TODO if we cannot get our tenants now, should we retry later?
+               for (TenantEntity tenant : getTenants()) {
+                       createTenantService(tenant);
+               }    
+               m_logService.log(LogService.LOG_INFO, "TenantManagementService 
started.");
+       }
+
+       public List<TenantEntity> getTenants() throws TenantException {
+               ReadLock lock = m_lock.readLock();
+               try {
+                       lock.lock();
+                       return m_tenantStorageProvider.getAll();
+               } finally {
+                       lock.unlock();
+               }
+       }
+
+       public TenantEntity getTenantById(String id) throws TenantException {
+               ReadLock lock = m_lock.readLock();
+               try {
+                       lock.lock();
+                       return m_tenantStorageProvider.getById(id);
+               } finally {
+                       lock.unlock();
+               }
+       }
+
+       public List<TenantEntity> getTenants(Map<String, String> properties) 
throws TenantException {
+               ReadLock lock = m_lock.readLock();
+               try {
+                       lock.lock();
+                       List<TenantEntity> matchingTenants = new 
ArrayList<TenantEntity>();
+                       for (TenantEntity tenant : getTenants()) {
+                               if (tenant.matches(properties)) {
+                                       matchingTenants.add(tenant);
+                               }
+                       }
+                       return matchingTenants;
+               } finally {
+                       lock.unlock();
+               }
+       }
+
+       public TenantEntity createTenant(String id, String name) throws 
TenantException {
+               return createTenant(id, name, null);
+       }
+
+       public TenantEntity createTenant(String id, String name, Map<String, 
String> properties) throws TenantException {
+               WriteLock writeLock = m_lock.writeLock();
+               writeLock.lock();
+               try {
+                       if (getTenantById(id) != null) {
+                               throw new TenantException("Tenant with id '" + 
id + "' already exists");
+                       }
+                       TenantEntity tenant = new TenantEntity(id, name);
+                       if (properties != null) {
+                               for (String key : properties.keySet()) {
+                                       tenant.putProperty(key, 
properties.get(key));
+                               }
+                       }
+                       m_tenantStorageProvider.store(tenant);
+
+                       // Downgrade write to read lock
+                       ReadLock readLock = m_lock.readLock();
+                       try {
+                               readLock.lock();
+                               writeLock.unlock();
+                               createTenantService(tenant);
+                               return tenant;
+                       } finally {
+                               readLock.unlock();
+                       }
+               } finally {
+                       if (writeLock.isHeldByCurrentThread()) {
+                               writeLock.unlock();
+                       }
+               }
+       }
+
+       // Does the same as createTenant, but without registration of the 
stored tenant as Tenant
+       // service. Invoked in the init() method since tenant services are 
registared in the start() method.
+       private synchronized TenantEntity storeTenant(String id, String name) 
throws TenantException {
+               if (getTenantById(id) != null) {
+                       throw new TenantException("Tenant with id '" + id + "' 
already exists");
+               }
+               TenantEntity tenant = new TenantEntity(id, name);
+               m_tenantStorageProvider.store(tenant);
+               return tenant;
+       }
+
+       public void updateTenant(TenantEntity tenant) throws TenantException {
+               WriteLock writeLock = m_lock.writeLock();
+               writeLock.lock();
+               try {
+                       m_tenantStorageProvider.store(tenant);
+
+                       // Downgrade write to read lock
+                       ReadLock readLock = m_lock.readLock();
+                       try {
+                               readLock.lock();
+                               writeLock.unlock();
+                               reregisterTenantService(tenant);
+                       } finally {
+                               readLock.unlock();
+                       }
+               } finally {
+                       if (writeLock.isHeldByCurrentThread()) {
+                               writeLock.unlock();
+                       }
+               }
+       }
+
+       public void deleteTenant(TenantEntity tenant) throws TenantException {
+               WriteLock writeLock = m_lock.writeLock();
+               writeLock.lock();
+               try {
+                       if (getTenantById(tenant.getId()) == null) {
+                               throw new TenantException("Tenant with id '" + 
tenant.getId() + "' does not exist, thus cannot be deleted.");
+                       }
+                       m_tenantStorageProvider.delete(tenant);
+
+                       // Downgrade write to read lock
+                       ReadLock readLock = m_lock.readLock();
+                       try {
+                               readLock.lock();
+                               writeLock.unlock();
+                               removeTenantService(tenant);
+                       } finally {
+                               readLock.unlock();
+                       }
+               } finally {
+                       if (writeLock.isHeldByCurrentThread()) {
+                               writeLock.unlock();
+                       }
+               }
+       }
+
+       private void createTenantService(TenantEntity tenant) {
+               Component component = m_manager.createComponent()
+               .setImplementation(tenant)
+               .setInterface(Tenant.class.getName(), 
createServiceProperties(tenant));
+               m_manager.add(component);
+               m_tenantComponents.put(tenant, component);
+       }
+
+       private void reregisterTenantService(TenantEntity tenant) {
+               Component component = m_tenantComponents.get(tenant);
+               m_manager.remove(component);
+               createTenantService(tenant);
+       }
+
+       private void removeTenantService(TenantEntity tenant) {
+               m_manager.remove(m_tenantComponents.remove(tenant));
+       }
+
+       private Properties createServiceProperties(TenantEntity tenant) {
+               Properties properties = new Properties();
+               Map<String, String> tenantProperties = tenant.getProperties();
+               for (Map.Entry<String, String> entry : 
tenantProperties.entrySet()) {
+                       properties.put(Tenant.SERVICE_PREFIX + entry.getKey(), 
entry.getValue());
+               }
+               properties.put(Tenant.SERVICE_PREFIX + "id", tenant.getId());
+               properties.put(Tenant.SERVICE_PREFIX + "name", 
tenant.getName());
+
+               return properties;
+       }
+
+       @SuppressWarnings("unchecked")
+       public void updated(Dictionary properties) throws 
ConfigurationException {
+               if (properties != null) {
+                       // Build a list of tenants from the configuration file
+                       m_tenants = new ArrayList<TenantEntity>();
+                       Enumeration<String> keys = properties.keys();
+                       while (keys.hasMoreElements()) {
+                               String key = keys.nextElement();
+                               if (key.endsWith(".id")) {
+                                       m_tenants.add(getTenant(properties, 
key));
+                               }
+                       }
+               }
+       }
+
+       @SuppressWarnings("unchecked")
+       private TenantEntity getTenant(Dictionary dictionary, String idKey) {
+               String nameKey = idKey.substring(0, idKey.lastIndexOf(".id")) + 
".name";
+               String propertiesKey = idKey.substring(0, 
idKey.lastIndexOf(".id")) + ".properties";
+               String id = (String) dictionary.get(idKey);
+               String name = (String) dictionary.get(nameKey);
+               Map<String, String> properties = new HashMap<String, String>();
+               Enumeration<String> keys = dictionary.keys();
+               while (keys.hasMoreElements()) {
+                       String key = keys.nextElement();
+                       if (key.startsWith(propertiesKey)) {
+                               String propName = 
key.substring(propertiesKey.length() + 1);
+                               String propValue = (String) dictionary.get(key);
+                               properties.put(propName, propValue);
+                       }
+               }
+               return new TenantEntity(id, name, properties);
+       }
 }

Modified: 
branches/amdatu-dispatcher/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/osgi/FSUserAdminStorageProviderActivator.java
==============================================================================
--- 
branches/amdatu-dispatcher/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/osgi/FSUserAdminStorageProviderActivator.java
      (original)
+++ 
branches/amdatu-dispatcher/amdatu-core/useradminstore-fs/src/main/java/org/amdatu/core/useradminstore/fs/osgi/FSUserAdminStorageProviderActivator.java
      Wed Feb  2 15:07:11 2011
@@ -24,7 +24,6 @@
 import org.amdatu.core.useradminstore.fs.service.FSUserAdminStorageProvider;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
-import org.ops4j.pax.useradmin.service.UserAdminConstants;
 import org.ops4j.pax.useradmin.service.spi.StorageProvider;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -44,7 +43,7 @@
         properties.put(Constants.SERVICE_RANKING, 0);
         manager.add(
             createAdapterService(Tenant.class, null)
-            .setImplementation(new FSUserAdminStorageProvider())
+            .setImplementation(FSUserAdminStorageProvider.class)
             .setInterface(StorageProvider.class.getName(), properties)
             
.add(createConfigurationDependency().setPid(FSUserAdminStorageProvider.CONFIGURATION_PID))
             
.add(createServiceDependency().setService(LogService.class).setRequired(false)));

Modified: branches/amdatu-dispatcher/integration-tests/pom.xml
==============================================================================
--- branches/amdatu-dispatcher/integration-tests/pom.xml        (original)
+++ branches/amdatu-dispatcher/integration-tests/pom.xml        Wed Feb  2 
15:07:11 2011
@@ -157,6 +157,13 @@
       <type>bundle</type>
     </dependency>
     <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>dispatcher</artifactId>
+      <version>${platform.version}</version>
+      <scope>test</scope>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
       <groupId>org.ops4j.pax.useradmin</groupId>
       <artifactId>pax-useradmin-service</artifactId>
       <version>${pax.useradmin.version}</version>
@@ -273,12 +280,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.http.whiteboard</artifactId>
-      <version>${org.apache.felix.http.version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>3.1</version>

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
     (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/ConfigProvider.java
     Wed Feb  2 15:07:11 2011
@@ -43,6 +43,7 @@
  */
 public class ConfigProvider {
     public final static String HOSTNAME = "localhost";
+    public final static String IP = "127.0.0.1";
     public final static String DEFAULT_PORTNR = "8080";
 
     // NB: Due to issue https://issues.apache.org/jira/browse/FELIX-2714 we 
must use the default port for testing

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
        (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/IntegrationTestBase.java
        Wed Feb  2 15:07:11 2011
@@ -301,6 +301,11 @@
 
     // //////////////////////////////////////////////////////////
     // A load of Pax Exam definitions for easier (typo-free) provisioning
+    
+    protected static MavenArtifactProvisionOption amdatuDispatcher() {
+        return 
mavenBundle().groupId("org.amdatu.web").artifactId("dispatcher").versionAsInProject();
+    }
+    
     protected static MavenArtifactProvisionOption amdatuJaxRs() {
         return 
mavenBundle().groupId("org.amdatu.web.rest").artifactId("jaxrs").versionAsInProject();
     }
@@ -416,11 +421,7 @@
     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() {
         return 
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").versionAsInProject();
     }

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/OAuthTestBase.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/OAuthTestBase.java
      (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/OAuthTestBase.java
      Wed Feb  2 15:07:11 2011
@@ -114,7 +114,7 @@
                amdatuTenantService(),
                amdatuTenantUserAdminDecoratorService(),
             felixHttpServiceJetty(),
-            felixHttpServiceWhiteboard(),
+            amdatuDispatcher(),
             slingMime(),
             slingCommons(),
             commonsCodec(),
@@ -153,7 +153,7 @@
     }
 
     protected void login() throws HttpException, IOException {
-        m_cookieHeaderElement = Login.login(TEST_USERNAME, TEST_PASSWORD);
+        m_cookieHeaderElement = Login.login(ConfigProvider.HOSTNAME, 
TEST_USERNAME, TEST_PASSWORD);
     }
 
     protected Map<String, String> getCookieHeader() {

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/RESTTestBase.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/RESTTestBase.java
       (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/base/RESTTestBase.java
       Wed Feb  2 15:07:11 2011
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 
+import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.test.integration.util.Login;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.apache.commons.httpclient.HeaderElement;
@@ -46,12 +47,14 @@
  */
 public abstract class RESTTestBase extends IntegrationTestBase {
     private HeaderElement m_cookieHeaderElement;
+    private String m_host = null;
     private String m_baseUrl = null;
 
     @Inject
     private volatile ConfigurationAdmin m_configAdmin;
     protected volatile LogService m_logService;
-
+    protected volatile TenantManagementService m_tenantService;
+    
     @Configuration
     public Option[] configure() {
         return super.configure();
@@ -65,7 +68,7 @@
                 amdatuTenantService(),
                 amdatuTenantUserAdminDecoratorService(),
                 felixHttpServiceJetty(),
-                felixHttpServiceWhiteboard(),
+                amdatuDispatcher(),
                 amdatuHttpContext(),
                 amdatuJaxRs(),
                 amdatuWink(),
@@ -87,10 +90,12 @@
         return manager.createComponent().setImplementation(this)
         
.add(manager.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
         
.add(manager.createServiceDependency().setService(HttpService.class).setRequired(true))
+        
.add(manager.createServiceDependency().setService(TenantManagementService.class).setRequired(true))
         
.add(manager.createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true));
     }
 
     protected void initConfiguration() throws IOException {
+       m_host = ConfigProvider.HOSTNAME;
         m_configAdmin = getService(ConfigurationAdmin.class);
         m_logService = getService(LogService.class);
 
@@ -111,6 +116,10 @@
         }
         return m_baseUrl;
     }
+    
+    protected void switchHost(String newHostName) {
+       m_baseUrl = "http://"; + newHostName + ":" + ConfigProvider.PORTNR + 
"/rest";
+    }
 
     protected String invokeRestApi(String urlPostfix, String httpMethod, int 
expectedStatus) throws Exception {
         String url = getBaseUrl() + urlPostfix;
@@ -142,7 +151,7 @@
     }
 
     protected void loginAsAdministrator() throws HttpException, IOException {
-        m_cookieHeaderElement = Login.login(ConfigProvider.ADMIN_USERNAME, 
ConfigProvider.ADMIN_PASSWORD);
+        m_cookieHeaderElement = Login.login(m_host, 
ConfigProvider.ADMIN_USERNAME, ConfigProvider.ADMIN_PASSWORD);
     }
 
     protected void addCookieHeader(HttpMethod method) {

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
   (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/HttpServiceTest.java
   Wed Feb  2 15:07:11 2011
@@ -86,7 +86,6 @@
     protected Option provisionBundles() {
         return provision(
             felixHttpServiceJetty(),
-            felixHttpServiceWhiteboard(),
             slingCommons(),
             slingMime(),
             commonsHttpClient(),

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminRESTTest.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminRESTTest.java
 (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminRESTTest.java
 Wed Feb  2 15:07:11 2011
@@ -19,7 +19,10 @@
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
+import org.amdatu.core.tenant.TenantEntity;
 import org.amdatu.test.integration.base.ConfigProvider;
 import org.amdatu.test.integration.base.RESTTestBase;
 import org.apache.commons.httpclient.HttpStatus;
@@ -29,7 +32,9 @@
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
 import org.osgi.service.useradmin.UserAdmin;
 
 @RunWith(JUnit4TestRunner.class)
@@ -71,7 +76,45 @@
         // -4- Retrieve the user
         invokeRestApi(url,  javax.ws.rs.HttpMethod.GET, HttpStatus.SC_OK);
 
-        // -5- Delete the user
+        // -5- Delete the user and verify that it has been removed
         invokeRestApi(url,  javax.ws.rs.HttpMethod.DELETE, HttpStatus.SC_OK);
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.GET, 
HttpStatus.SC_NOT_FOUND);
+        
+        // -6- Now create a new tenant associated with 127.0.0.1
+        m_logService.log(LogService.LOG_DEBUG, "Adding test tenant");
+        Map<String, String> properties = new HashMap<String, String>();
+        properties.put("hostname", ConfigProvider.IP);
+        TenantEntity tenant = m_tenantService.createTenant("testtenant", 
"Second Test Tenant", properties);
+        m_logService.log(LogService.LOG_DEBUG, "Test tenant added, switching 
from host '" + ConfigProvider.HOSTNAME + "' to '" + ConfigProvider.IP + "'");
+        
+        // Give some time for tenant adapter services to register
+        Thread.sleep(3000);
+        
+        switchHost(ConfigProvider.IP); // Switch to host by IP address
+        waitForURL(getBaseUrl() + "/users/status", HttpStatus.SC_OK);
+        m_logService.log(LogService.LOG_DEBUG, "UserAdmin REST service on '" + 
getBaseUrl() + "' now available");
+
+        // -7- Now verify that for this new tenant a new user 'Administrator' 
should have been created, verify that.
+        // FIXME: Note that since the token provider is not yet tenant 
specific, using the same token for this
+        // request will work just fine
+        url = "/users/Administrator";
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.GET, HttpStatus.SC_OK);
+        
+        // -8- Create a new user on '127.0.0.1' and verify that this new user 
comes available on this host
+        // and not on 'localhost'
+        url = "/users/" + ConfigProvider.TEST_USERNAME;
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.PUT, HttpStatus.SC_OK);
+        
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.GET, HttpStatus.SC_OK);
+        switchHost(ConfigProvider.HOSTNAME);
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.GET, 
HttpStatus.SC_NOT_FOUND);
+        
+        // -9- Remove the test user
+        switchHost(ConfigProvider.IP);
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.DELETE, HttpStatus.SC_OK);
+        
+        // -10- Remove the tenant and verify that a GET returns a 404
+        m_tenantService.deleteTenant(tenant);
+        invokeRestApi(url,  javax.ws.rs.HttpMethod.DELETE, 
HttpStatus.SC_NOT_FOUND);
     }
 }

Modified: 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/util/Login.java
==============================================================================
--- 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/util/Login.java
      (original)
+++ 
branches/amdatu-dispatcher/integration-tests/src/test/java/org/amdatu/test/integration/util/Login.java
      Wed Feb  2 15:07:11 2011
@@ -1,6 +1,5 @@
 package org.amdatu.test.integration.util;
 
-import static org.amdatu.test.integration.base.ConfigProvider.HOSTNAME;
 import static org.amdatu.test.integration.base.ConfigProvider.PORTNR;
 
 import java.io.IOException;
@@ -15,8 +14,8 @@
 import org.junit.Assert;
 
 public class Login {
-    public static HeaderElement login(String username, String password) throws 
HttpException, IOException {
-        String loginUrl = "http://"; + HOSTNAME + ":" + PORTNR + 
"/rest/authorization/login";
+    public static HeaderElement login(String host, String username, String 
password) throws HttpException, IOException {
+        String loginUrl = "http://"; + host + ":" + PORTNR + 
"/rest/authorization/login";
         HttpClient httpClient = new HttpClient();
         PostMethod postMethod = null;
         try {

Reply via email to