Author: [email protected]
Date: Wed Feb  1 18:21:41 2012
New Revision: 2048

Log:
AMDATU-548: create new tenant-test project.

Added:
   trunk/amdatu-core/itest/tenant-test/
   trunk/amdatu-core/itest/tenant-test/pom.xml   (contents, props changed)
   trunk/amdatu-core/itest/tenant-test/src/
   trunk/amdatu-core/itest/tenant-test/src/main/
   trunk/amdatu-core/itest/tenant-test/src/main/java/
   trunk/amdatu-core/itest/tenant-test/src/main/java/org/
   trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/
   trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/
   trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependencyService.java
   (contents, props changed)
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependentService.java
   (contents, props changed)
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependencyServiceImpl.java
   (contents, props changed)
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependentServiceImpl.java
   (contents, props changed)
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/osgi/
   
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/osgi/MyTenancyActivator.java
   (contents, props changed)
Modified:
   trunk/amdatu-core/itest/pom.xml
   trunk/amdatu-core/itest/tests/pom.xml
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/MultiTenantTest.java
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/mock/MyDependencyService.java
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/mock/MyDependencyServiceImpl.java
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/mock/MyDependentService.java
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/mock/MyDependentServiceImpl.java
   
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/mock/MyTenancyActivator.java
   trunk/amdatu-core/tenant/pom.xml

Modified: trunk/amdatu-core/itest/pom.xml
==============================================================================
--- trunk/amdatu-core/itest/pom.xml     (original)
+++ trunk/amdatu-core/itest/pom.xml     Wed Feb  1 18:21:41 2012
@@ -48,6 +48,7 @@
   <modules>
     <module>base</module>
     <module>tests</module>
+    <module>tenant-test</module>
   </modules>
 
   <dependencyManagement>
@@ -365,4 +366,4 @@
     </dependency>
   </dependencies>
 
-</project>
\ No newline at end of file
+</project>

Added: trunk/amdatu-core/itest/tenant-test/pom.xml
==============================================================================
--- (empty file)
+++ trunk/amdatu-core/itest/tenant-test/pom.xml Wed Feb  1 18:21:41 2012
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.verning permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.amdatu.core</groupId>
+    <artifactId>org.amdatu.core.itest</artifactId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>org.amdatu.core.itest.tenant-test</artifactId>
+  <packaging>bundle</packaging>
+  <name>Amdatu Core - (Temporary) Multi-tenancy integration test code.</name>
+
+  <!--
+    This module exists due to PAXEXAM-345; which currently prohibits us from
+    having our mock-tenant code together with our integration test.
+  -->
+
+  <dependencyManagement>
+    <dependencies>
+      <!--
+        Amdatu Web itest base to be used by the tests.
+      -->
+      <dependency>
+        <groupId>org.amdatu.core</groupId>
+        <artifactId>org.amdatu.core.itest.base</artifactId>
+        <version>${project.version}</version>
+        <scope>provided</scope>
+        <type>bundle</type>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <!--
+      See explanation in the dependencyManagement section above.
+    -->
+    <dependency>
+      <groupId>org.amdatu.core</groupId>
+      <artifactId>org.amdatu.core.itest.base</artifactId>
+      <type>bundle</type>
+    </dependency>
+  </dependencies>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                   
<X-MultiTenant-Bundle-Activator>org.amdatu.core.itest.tenant.osgi.MyTenancyActivator</X-MultiTenant-Bundle-Activator>
+                                   
<X-MultiTenant-Scope>BOTH</X-MultiTenant-Scope>
+                                   
<Bundle-Activator>org.amdatu.tenant.adapter.MultiTenantBundleActivator</Bundle-Activator>
+                                               <Export-Package>
+                                                       
org.amdatu.core.itest.tenant;version=1.0.0
+                                               </Export-Package>
+                                               <Import-Package>
+                                                       
org.amdatu.core.itest.tenant,
+                                                       org.amdatu.tenant,
+                                                       
org.amdatu.tenant.adapter,
+                                                       org.osgi.service.log,
+                                                       org.osgi.framework,
+                                                       org.apache.felix.dm,
+                                                       junit.framework
+                                               </Import-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>

Added: 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependencyService.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependencyService.java
     Wed Feb  1 18:21:41 2012
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.amdatu.core.itest.tenant;
+
+/**
+ * Provides a dependency for another service.
+ * 
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public interface MyDependencyService {
+    String saySomething();
+}

Added: 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependentService.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/MyDependentService.java
      Wed Feb  1 18:21:41 2012
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.amdatu.core.itest.tenant;
+
+/**
+ * Provides a "mock" multi-tenant aware service, that has a dependency on 
another service.
+ * 
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public interface MyDependentService {
+    String sayIt();
+}

Added: 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependencyServiceImpl.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependencyServiceImpl.java
    Wed Feb  1 18:21:41 2012
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.amdatu.core.itest.tenant.impl;
+
+import org.amdatu.core.itest.tenant.MyDependencyService;
+import org.amdatu.tenant.TenantConstants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public class MyDependencyServiceImpl implements MyDependencyService {
+    private volatile ServiceRegistration m_serviceReg;
+
+    /**
+     * @see org.amdatu.core.itest.tenant.MyDependencyService#saySomething()
+     */
+    public String saySomething() {
+        return String.format("[%s]", 
+            m_serviceReg.getReference().getProperty(TenantConstants.PID_KEY));
+    }
+}

Added: 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependentServiceImpl.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/impl/MyDependentServiceImpl.java
     Wed Feb  1 18:21:41 2012
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.amdatu.core.itest.tenant.impl;
+
+import org.amdatu.core.itest.tenant.MyDependencyService;
+import org.amdatu.core.itest.tenant.MyDependentService;
+import org.amdatu.tenant.TenantConstants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Test implementation of {@link MyDependentService}.
+ * 
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public class MyDependentServiceImpl implements MyDependentService {
+    private volatile ServiceRegistration m_serviceReg;
+    private volatile MyDependencyService m_dependency;
+
+    /**
+     * @see org.amdatu.core.itest.tenant.MyDependencyService#sayIt()
+     */
+    public String sayIt() {
+        return String.format("[%s] %s", 
+            m_serviceReg.getReference().getProperty(TenantConstants.PID_KEY),
+            m_dependency.saySomething());
+    }
+}

Added: 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/osgi/MyTenancyActivator.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-core/itest/tenant-test/src/main/java/org/amdatu/core/itest/tenant/osgi/MyTenancyActivator.java
 Wed Feb  1 18:21:41 2012
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2010-2012 The Amdatu Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.amdatu.core.itest.tenant.osgi;
+
+import org.amdatu.core.itest.tenant.MyDependencyService;
+import org.amdatu.core.itest.tenant.MyDependentService;
+import org.amdatu.core.itest.tenant.impl.MyDependencyServiceImpl;
+import org.amdatu.core.itest.tenant.impl.MyDependentServiceImpl;
+import org.amdatu.tenant.TenantConstants;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.ComponentStateListener;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
+
+/**
+ * Test activator for {@link MyDependentService}.
+ * 
+ * @author <a href="mailto:[email protected]";>Amdatu Project 
Team</a>
+ */
+public class MyTenancyActivator extends DependencyActivatorBase implements 
ComponentStateListener {
+    private volatile LogService m_logService;
+
+    /**
+     * @see 
org.apache.felix.dm.DependencyActivatorBase#init(org.osgi.framework.BundleContext,
 org.apache.felix.dm.DependencyManager)
+     */
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+        manager.add(createComponent()
+            .setImplementation(this)
+            .add(createServiceDependency()
+                .setService(LogService.class)
+                .setRequired(false))
+            );
+
+        Component dependencyComp = createComponent()
+            .setInterface(MyDependencyService.class.getName(), null)
+            .setImplementation(new MyDependencyServiceImpl());
+        dependencyComp.addStateListener(this);
+
+        Component dependentComp = createComponent()
+            .setInterface(MyDependentService.class.getName(), null)
+            .setImplementation(new MyDependentServiceImpl())
+            .add(createServiceDependency()
+                .setService(MyDependencyService.class)
+                .setRequired(true)
+            );
+        dependentComp.addStateListener(this);
+
+        manager.add(dependencyComp);
+        manager.add(dependentComp);
+    }
+
+    /**
+     * @see 
org.apache.felix.dm.DependencyActivatorBase#destroy(org.osgi.framework.BundleContext,
 org.apache.felix.dm.DependencyManager)
+     */
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
+        // NO-op
+    }
+
+    /**
+     * @see 
org.apache.felix.dm.ComponentStateListener#starting(org.apache.felix.dm.Component)
+     */
+    public void starting(Component component) {
+        // NO-op
+    }
+
+    /**
+     * @see 
org.apache.felix.dm.ComponentStateListener#started(org.apache.felix.dm.Component)
+     */
+    public void started(Component component) {
+        ServiceRegistration sr = component.getServiceRegistration();
+        String name = 
component.getService().getClass().getInterfaces()[0].getSimpleName();
+        m_logService.log(LogService.LOG_INFO, 
getMTServiceTag(sr.getReference(), name + ":START"));
+    }
+
+    /**
+     * @see 
org.apache.felix.dm.ComponentStateListener#stopping(org.apache.felix.dm.Component)
+     */
+    public void stopping(Component component) {
+        ServiceRegistration sr = component.getServiceRegistration();
+        String name = 
component.getService().getClass().getInterfaces()[0].getSimpleName();
+        m_logService.log(LogService.LOG_INFO, 
getMTServiceTag(sr.getReference(), name + ":STOP"));
+    }
+
+    /**
+     * @see 
org.apache.felix.dm.ComponentStateListener#stopped(org.apache.felix.dm.Component)
+     */
+    public void stopped(Component component) {
+        component.removeStateListener(this);
+    }
+
+    /**
+     * @param serviceRef
+     * @return
+     */
+    static String getMTServiceTag(ServiceReference serviceRef, String id) {
+        StringBuilder sb = new StringBuilder("MTL:");
+        sb.append(id);
+        if (serviceRef != null) {
+            sb.append("{").append(TenantConstants.PID_KEY).append(";")
+                
.append(serviceRef.getProperty(TenantConstants.PID_KEY)).append("}");
+        }
+        return sb.toString();
+    }
+
+}

Modified: trunk/amdatu-core/itest/tests/pom.xml
==============================================================================
--- trunk/amdatu-core/itest/tests/pom.xml       (original)
+++ trunk/amdatu-core/itest/tests/pom.xml       Wed Feb  1 18:21:41 2012
@@ -45,6 +45,13 @@
         <scope>provided</scope>
         <type>bundle</type>
       </dependency>
+      <dependency>
+        <groupId>org.amdatu.core</groupId>
+        <artifactId>org.amdatu.core.itest.tenant-test</artifactId>
+        <version>${project.version}</version>
+        <scope>provided</scope>
+        <type>bundle</type>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 
@@ -57,6 +64,11 @@
       <artifactId>org.amdatu.core.itest.base</artifactId>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.core</groupId>
+      <artifactId>org.amdatu.core.itest.tenant-test</artifactId>
+      <type>bundle</type>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/MultiTenantTest.java
==============================================================================
--- 
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/MultiTenantTest.java
 (original)
+++ 
trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/tenant/MultiTenantTest.java
 Wed Feb  1 18:21:41 2012
@@ -15,24 +15,17 @@
  */
 package org.amdatu.core.itest.tests.tenant;
 
-import static 
org.amdatu.tenant.adapter.TenantAdapterConstants.MULTITENANT_BUNDLE_ACTIVATOR_KEY;
-import static 
org.amdatu.tenant.adapter.TenantAdapterConstants.MULTITENANT_SCOPE_KEY;
-import static 
org.amdatu.tenant.adapter.TenantAdapterConstants.MULTITENANT_SCOPE_VALUE_BOTH;
-import static 
org.amdatu.tenant.adapter.TenantAdapterConstants.MULTITENANT_VERSION_KEY;
-import static 
org.amdatu.tenant.adapter.TenantAdapterConstants.MULTITENANT_VERSION_VALUE;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemTimeout;
-import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
 
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -43,18 +36,12 @@
 import org.amdatu.core.itest.base.CoreBundles;
 import org.amdatu.core.itest.base.CoreConfigs;
 import org.amdatu.core.itest.base.TestContext;
-import org.amdatu.core.itest.tests.tenant.mock.MyDependencyService;
-import org.amdatu.core.itest.tests.tenant.mock.MyDependencyServiceImpl;
-import org.amdatu.core.itest.tests.tenant.mock.MyDependentService;
-import org.amdatu.core.itest.tests.tenant.mock.MyDependentServiceImpl;
-import org.amdatu.core.itest.tests.tenant.mock.MyTenancyActivator;
+import org.amdatu.core.itest.tenant.MyDependentService;
 import org.amdatu.tenant.Tenant;
 import org.amdatu.tenant.TenantConstants;
-import org.amdatu.tenant.adapter.MultiTenantBundleActivator;
 import org.apache.felix.dm.DependencyManager;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -62,7 +49,6 @@
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
@@ -109,6 +95,8 @@
         }
     }
 
+    private static final String SERVICE_NAME = 
org.amdatu.core.itest.tenant.MyDependentService.class.getName();
+
     @Inject
     private BundleContext m_bundleContext;
     private TestContext m_testContext;
@@ -136,10 +124,10 @@
      * @param filter the optional filter to search for, can be 
<code>null</code>.
      * @return a service registration count, >= 0.
      */
-    private static int countAllServices(BundleContext context, Class<?> 
service, String filter) {
+    private static int countServices(BundleContext context, String 
serviceName, String filter) {
         ServiceReference[] serviceReferences = null;
         try {
-            serviceReferences = 
context.getAllServiceReferences(service.getName(), filter);
+            serviceReferences = context.getServiceReferences(serviceName, 
filter);
         }
         catch (InvalidSyntaxException exception) {
             throw new RuntimeException("null-filter is incorrect?!");
@@ -154,8 +142,8 @@
      * @param service the service to count.
      * @return a service registration count, >= 0.
      */
-    private static int countAllServices(BundleContext context, Class<?> 
service) {
-        return countAllServices(context, service, null /* filter */);
+    private static int countServices(BundleContext context, String 
serviceName) {
+        return countServices(context, serviceName, null /* filter */);
     }
 
     /**
@@ -165,30 +153,13 @@
      */
     @org.ops4j.pax.exam.junit.Configuration
     public Option[] config() {
-        InputStream mtBundle =
-            bundle()
-                .add(MyTenancyActivator.class)
-                .add(MyDependentService.class)
-                .add(MyDependentServiceImpl.class)
-                .add(MyDependencyService.class)
-                .add(MyDependencyServiceImpl.class)
-                .set(MULTITENANT_SCOPE_KEY, MULTITENANT_SCOPE_VALUE_BOTH)
-                .set(MULTITENANT_VERSION_KEY, MULTITENANT_VERSION_VALUE)
-                .set(MULTITENANT_BUNDLE_ACTIVATOR_KEY, 
MyTenancyActivator.class.getName())
-                .set(Constants.BUNDLE_ACTIVATOR, 
MultiTenantBundleActivator.class.getName())
-                .set(Constants.BUNDLE_SYMBOLICNAME, "My Tenancy Bundle")
-                .set(Constants.EXPORT_PACKAGE, 
"org.amdatu.core.itest.tests.tenant.mock")
-                .set(Constants.IMPORT_PACKAGE,
-                    
"org.amdatu.core.itest.tests.tenant.mock,org.amdatu.tenant,org.amdatu.tenant.adapter,"
 +
-                        
"org.osgi.service.log,org.osgi.framework,org.apache.felix.dm,junit.framework")
-                .build();
-
         return options(
             cleanCaches(),
             junitBundles(),
             CoreBundles.provisionAll(),
-            provision(mtBundle),
-            systemTimeout(300000));
+            
provision(mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.itest.tenant-test")
+                .versionAsInProject()),
+            systemTimeout(1000000));
     }
 
     /**
@@ -250,7 +221,7 @@
         int expectedServiceCount = getConfigurationCount();
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
     }
 
     /**
@@ -264,7 +235,7 @@
         int expectedServiceCount = getConfigurationCount();
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
     }
 
     /**
@@ -284,45 +255,69 @@
         msg = m_eventHandler.getMessages();
         assertNotNull(msg);
         assertEquals(2, msg.size());
-        assertStringFound(msg, "START");
-        assertStringFound(msg, "START{" + TenantConstants.PID_KEY + ";" + 
tenantId + "}");
+        assertStringFound(msg, "MyDependencyService:START{" + 
TenantConstants.PID_KEY + ";" + tenantId + "}");
+        assertStringFound(msg, "MyDependentService:START{" + 
TenantConstants.PID_KEY + ";" + tenantId + "}");
     }
 
     /**
-     * Tests that when a non-multi-tenant service (= this test case) tries to 
obtain a multi-tenant aware service, this would fail.
+     * Tests that you can retrieve the multi-tenant-aware <em>tenant</em> 
service if you explicitly ask for it.
      * 
      * @throws Exception not part of this test case.
      */
     @Test
-    public void 
testObtainMultiTenantServiceInstanceFailsForNonMultiTenantService() throws 
Exception {
+    public void 
testObtainTenantSpecificServiceInstanceSucceedsForNonMultiTenantService() 
throws Exception {
         String tenantId = generateTenantId();
 
         Properties properties = createTenantConfiguration(tenantId);
         addTenantConfig(properties);
 
-        ServiceReference[] serviceRefs =
-            
m_bundleContext.getServiceReferences(MyDependentService.class.getName(),
-                String.format("(%1$s=%2$s)", TenantConstants.PID_KEY, 
tenantId));
-        assertNull(serviceRefs);
+        ServiceReference[] serviceRefs = 
m_bundleContext.getServiceReferences(SERVICE_NAME,
+            String.format("(%1$s=%2$s)", TenantConstants.PID_KEY, tenantId));
+        assertNotNull(serviceRefs);
+        assertEquals(1, serviceRefs.length);
+
+        MyDependentService service = (MyDependentService) 
m_bundleContext.getService(serviceRefs[0]);
+        assertEquals(String.format("[%1$s] [%1$s]", tenantId), 
service.sayIt());
     }
 
     /**
-     * Tests that when a non-multi-tenant service (= this test case) tries to 
obtain a multi-tenant aware service, this would fail.
+     * Tests that you can retrieve the multi-tenant-aware <em>platform</em> 
service if you explicitly ask for it.
      * 
      * @throws Exception not part of this test case.
      */
-    @Ignore("Cannot work until PAX-EXAM allows us to exclude classes from its 
test-probes. See PAXEXAM-345.")
     @Test
-    public void 
testObtainPlatformServiceInstanceSucceedsForNonMultiTenantService() throws 
Exception {
+    public void 
testObtainPlatformSpecificServiceInstanceSucceedsForNonMultiTenantService() 
throws Exception {
         String tenantId = generateTenantId();
 
         Properties properties = createTenantConfiguration(tenantId);
         addTenantConfig(properties);
 
-        ServiceReference[] serviceRef =
-            
m_bundleContext.getServiceReferences(MyDependentService.class.getName(),
-                String.format("(%1$s=%2$s)", TenantConstants.PID_KEY, "*"));
+        ServiceReference[] serviceRefs = 
m_bundleContext.getServiceReferences(SERVICE_NAME,
+            String.format("(%1$s=%2$s)", TenantConstants.PID_KEY, 
TenantConstants.PID_VALUE_PLATFORM));
+        assertNotNull("Failed to obtain the MT-platform service?!", 
serviceRefs);
+        assertEquals(1, serviceRefs.length);
+
+        MyDependentService service = (MyDependentService) 
m_bundleContext.getService(serviceRefs[0]);
+        assertEquals(String.format("[%1$s] [%1$s]", 
TenantConstants.PID_VALUE_PLATFORM), service.sayIt());
+    }
+
+    /**
+     * Tests that when not specifying a filter on which multi-tenant-aware 
service you want to obtain, you'll always get the platform service.
+     * 
+     * @throws Exception not part of this test case.
+     */
+    @Test
+    public void 
testObtainMultiTenancyAwareServiceWithoutFilterYieldsPlatformInstance() throws 
Exception {
+        String tenantId = generateTenantId();
+
+        Properties properties = createTenantConfiguration(tenantId);
+        addTenantConfig(properties);
+
+        ServiceReference serviceRef = 
m_bundleContext.getServiceReference(SERVICE_NAME);
         assertNotNull("Failed to obtain the MT-platform service?!", 
serviceRef);
+
+        MyDependentService service = (MyDependentService) 
m_bundleContext.getService(serviceRef);
+        assertEquals(String.format("[%1$s] [%1$s]", 
TenantConstants.PID_VALUE_PLATFORM), service.sayIt());
     }
 
     /**
@@ -341,7 +336,7 @@
         int expectedServiceCount = getConfigurationCount();
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
 
         List<String> msg = m_eventHandler.getMessages();
 
@@ -349,13 +344,13 @@
         removeTenantConfig(config);
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount - 1, 
countAllServices(m_bundleContext, MyDependentService.class));
+        assertEquals(expectedServiceCount - 1, countServices(m_bundleContext, 
SERVICE_NAME));
 
         msg = m_eventHandler.getMessages();
 
         assertEquals(2, msg.size());
-        assertStringFound(msg, "STOP");
-        assertStringFound(msg, "STOP{" + TenantConstants.PID_KEY + ";" + 
tenantId + "}");
+        assertStringFound(msg, "MyDependencyService:STOP{" + 
TenantConstants.PID_KEY + ";" + tenantId + "}");
+        assertStringFound(msg, "MyDependentService:STOP{" + 
TenantConstants.PID_KEY + ";" + tenantId + "}");
     }
 
     /**
@@ -374,7 +369,7 @@
         int expectedServiceCount = getConfigurationCount();
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
 
         properties.setProperty(TenantConstants.PID_KEY, "foo-bar-key");
 
@@ -382,10 +377,10 @@
         updateTenantConfig(config, properties);
 
         // Check that we can still find back our existing services...
-        assertEquals(1, countAllServices(m_bundleContext, Tenant.class, "(" + 
TenantConstants.PID_KEY
+        assertEquals(1, countServices(m_bundleContext, Tenant.class.getName(), 
"(" + TenantConstants.PID_KEY
             + "=" + tenantId + ")"));
         // Check that the "old" tenant is really gone...
-        assertEquals(0, countAllServices(m_bundleContext, Tenant.class, "(" + 
TenantConstants.PID_KEY
+        assertEquals(0, countServices(m_bundleContext, Tenant.class.getName(), 
"(" + TenantConstants.PID_KEY
             + "=foo-bar-key)"));
     }
 
@@ -407,10 +402,10 @@
         int expectedServiceCount = getConfigurationCount();
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
 
         // Verify the tenant can be found by its current name...
-        assertEquals(1, countAllServices(m_bundleContext, Tenant.class, "(" + 
TenantConstants.NAME_KEY
+        assertEquals(1, countServices(m_bundleContext, Tenant.class.getName(), 
"(" + TenantConstants.NAME_KEY
             + "=" + oldTenantName + ")"));
 
         msg = m_eventHandler.getMessages();
@@ -422,7 +417,7 @@
         updateTenantConfig(config, properties);
 
         // A non-MT aware bundle should be able to see *all* service 
registrations...
-        assertEquals(expectedServiceCount, countAllServices(m_bundleContext, 
MyDependentService.class));
+        assertEquals(expectedServiceCount, countServices(m_bundleContext, 
SERVICE_NAME));
 
         msg = m_eventHandler.getMessages();
 
@@ -430,10 +425,10 @@
         assertTrue(msg.isEmpty());
 
         // Check that we can find back our newly named tenant...
-        assertEquals(1, countAllServices(m_bundleContext, Tenant.class, "(" + 
TenantConstants.NAME_KEY
+        assertEquals(1, countServices(m_bundleContext, Tenant.class.getName(), 
"(" + TenantConstants.NAME_KEY
             + "=" + newTenantName + ")"));
         // Check that the "old" tenant is really gone...
-        assertEquals(0, countAllServices(m_bundleContext, Tenant.class, "(" + 
TenantConstants.NAME_KEY
+        assertEquals(0, countServices(m_bundleContext, Tenant.class.getName(), 
"(" + TenantConstants.NAME_KEY
             + "=" + oldTenantName + ")"));
     }
 

Modified: trunk/amdatu-core/tenant/pom.xml
==============================================================================
--- trunk/amdatu-core/tenant/pom.xml    (original)
+++ trunk/amdatu-core/tenant/pom.xml    Wed Feb  1 18:21:41 2012
@@ -1,39 +1,47 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (c) 2010, 2011 The Amdatu Foundation Licensed under the Apache 
-       License, Version 2.0 (the "License"); you may not use this file except 
in 
-       compliance with the License. You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0 
-       Unless required by applicable law or agreed to in writing, software 
distributed 
-       under the License is distributed on an "AS IS" BASIS, WITHOUT 
WARRANTIES 
-       OR CONDITIONS OF ANY KIND, either express or implied. See the License 
for 
-       the specific language governing permissions and limitations under the 
License.verning 
-       permissions and limitations under the License. -->
+<!--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.verning permissions and limitations
+  under the License.
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.amdatu.core</groupId>
-    <artifactId>org.amdatu.core</artifactId>
-    <version>0.3.0-SNAPSHOT</version>
-  </parent>
-  <groupId>org.amdatu.tenant</groupId>
-  <artifactId>org.amdatu.tenant</artifactId>
-  <packaging>bundle</packaging>
-  <name>Amdatu Tenant - Tenant API</name>
-  <description>This library bundle provides the Amdatu Tenant API</description>
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.amdatu.core</groupId>
+               <artifactId>org.amdatu.core</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+       <groupId>org.amdatu.tenant</groupId>
+       <artifactId>org.amdatu.tenant</artifactId>
+       <packaging>bundle</packaging>
+       <name>Amdatu Tenant - Tenant API</name>
+       <description>This library bundle provides the Amdatu Tenant 
API</description>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <configuration>
-          <instructions>
-            <Export-Package>
-              org.amdatu.tenant;version=1.0.0
-            </Export-Package>
-          </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                               <Export-Package>
+                                                       
org.amdatu.tenant;version=1.0.0
+                                               </Export-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
 </project>
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to