Author: [email protected] Date: Wed May 4 12:13:45 2011 New Revision: 1087
Log: AMDATU-379 First drop of core itest framework with some basic tests Added: trunk/amdatu-core/itest/ (props changed) trunk/amdatu-core/itest/base/ (props changed) trunk/amdatu-core/itest/base/pom.xml trunk/amdatu-core/itest/base/src/ trunk/amdatu-core/itest/base/src/main/ trunk/amdatu-core/itest/base/src/main/java/ trunk/amdatu-core/itest/base/src/main/java/org/ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/CoreFixture.java trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/TestContext.java trunk/amdatu-core/itest/base/src/test/ trunk/amdatu-core/itest/base/src/test/java/ trunk/amdatu-core/itest/pom.xml trunk/amdatu-core/itest/tests/ (props changed) trunk/amdatu-core/itest/tests/pom.xml trunk/amdatu-core/itest/tests/src/ trunk/amdatu-core/itest/tests/src/main/ trunk/amdatu-core/itest/tests/src/main/java/ trunk/amdatu-core/itest/tests/src/test/ trunk/amdatu-core/itest/tests/src/test/java/ trunk/amdatu-core/itest/tests/src/test/java/org/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/CoreServicesTest.java trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestService.java trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestServiceImpl.java Modified: trunk/amdatu-core/pom.xml Added: trunk/amdatu-core/itest/base/pom.xml ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/base/pom.xml Wed May 4 12:13:45 2011 @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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.2.1-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.core.itest.base</artifactId> + <packaging>bundle</packaging> + <name>Amdatu Core - Integration Tests base</name> + + <!-- + This modules is intended to contain Amdatu Core integration test + fixture and utility logic that will be provisioned as a bundle + into the PaxExam integration tests runtime. It is used by the + Amdatu Core tests module and possibly other itest modules that + depend on Amdatu Core. + --> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> + <Export-Package>${pom.artifactId}</Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/CoreFixture.java ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/CoreFixture.java Wed May 4 12:13:45 2011 @@ -0,0 +1,193 @@ +/* + * 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. + */ +package org.amdatu.core.itest.base; + +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.provision; + +import java.util.Properties; + +import org.amdatu.core.loghandler.service.ConsoleLogHandler; +import org.amdatu.core.tenant.TenantManagementService; +import org.amdatu.core.tenant.TenantStorageProvider; +import org.amdatu.core.useradminstore.fs.service.FSUserAdminStorageConfigImpl; +import org.ops4j.pax.exam.Option; + +/** + * Amdatu Core integration test fixture providing provisioning and configuration + * for tests. + */ +public final class CoreFixture { + + /** + * Example configure method for Amdatu Core feature. To be extended.. + * + * @param testContext + * @throws Exception + */ + public void configureDefaults(TestContext testContext) throws Exception { + configureLogHandler(testContext); + configureConfigTemplateManager(testContext); + configureUserAdminStorageProvider(testContext); + configureTenantStorageProvider(testContext); + configureTenantManagementService(testContext); + } + + public String logHandlerPID() { + return ConsoleLogHandler.PID; + } + + public Properties logHandlerCnf() { + Properties properties = new Properties(); + properties.put("console.mininum.loglevel", "INFO"); // fixme private/missing constants + return properties; + } + + public void configureLogHandler(TestContext testContext) throws Exception { + testContext.updateConfig(logHandlerPID(), logHandlerCnf()); + } + + public String configTemplateManagerPID() { + return ConsoleLogHandler.PID; + } + + public Properties configTemplateManagerCnf() { + Properties properties = new Properties(); + properties.put("workdir", "config-template-manager"); // fixme private/missing constants + properties.put("hostname", "localhost"); // fixme private/missing constants + properties.put("port", "8080"); // fixme private/missing constants + return properties; + } + + public void configureConfigTemplateManager(TestContext testContext) throws Exception { + testContext.updateConfig(configTemplateManagerPID(), configTemplateManagerCnf()); + } + + public String userAdminStorageProviderPID() { + return FSUserAdminStorageConfigImpl.CONFIGURATION_PID; + } + + public Properties userAdminStorageProviderCnf() { + Properties properties = new Properties(); + properties.put(FSUserAdminStorageConfigImpl.DATA_DIRECTORY, "work/useradminstore"); + return properties; + } + + public void configureUserAdminStorageProvider(TestContext testContext) throws Exception { + testContext.updateConfig(userAdminStorageProviderPID(), userAdminStorageProviderCnf()); + } + + public String tenantStorageProviderPID() { + return TenantStorageProvider.CONFIGURATION_PID; + } + + public Properties tenantStorageProviderCnf() { + Properties properties = new Properties(); + properties.put(TenantStorageProvider.DATA_DIRECTORY, "work/tenantstore"); + return properties; + } + + public void configureTenantStorageProvider(TestContext testContext) throws Exception { + testContext.updateConfig(tenantStorageProviderPID(), tenantStorageProviderCnf()); + } + + public String tenantManagementServicePID() { + return TenantManagementService.PID; + } + + public Properties tenantManagementServiceCnf() { + Properties properties = new Properties(); + properties.put("tenant1.id", "Default"); + properties.put("tenant1.name", "Default Tenant"); + properties.put("tenant1.properties.hostname", "localhost"); + return properties; + } + + public void configureTenantManagementService(TestContext testContext) throws Exception { + testContext.updateConfig(tenantManagementServicePID(), tenantManagementServiceCnf()); + } + + /** + * Provides Pax Exam ProvisionOptions for Amdatu Core feature wothout storage providers storage + * + * @return the provision option + */ + public Option provisionWithoutStorage() { + return provision( + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.itest.base").versionAsInProject(), + + 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.amdatu.core").artifactId("org.amdatu.core.config.templates") + .versionAsInProject(), + + mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin") + .versionAsInProject(), + + mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").versionAsInProject(), + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.loghandler").versionAsInProject(), + + mavenBundle().groupId("org.ops4j.pax.useradmin").artifactId("pax-useradmin-service") + .versionAsInProject(), + + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.tenant").versionAsInProject(), + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.tenantuseradmindecorator") + .versionAsInProject()); + } + + /** + * Provides Pax Exam ProvisionOptions for Amdatu Core feature including filesystem storage providers. + * + * @return the provision option + */ + public Option provisionWithFsStorage() { + return provision( + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.itest.base").versionAsInProject(), + + 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.amdatu.core").artifactId("org.amdatu.core.config.templates") + .versionAsInProject(), + + mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.eventadmin") + .version("1.2.2"), + + mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").versionAsInProject(), + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.loghandler").versionAsInProject(), + + mavenBundle().groupId("org.ops4j.pax.useradmin").artifactId("pax-useradmin-service") + .versionAsInProject(), + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.useradminstore.fs") + .versionAsInProject(), + + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.tenant").versionAsInProject(), + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.tenantuseradmindecorator") + .versionAsInProject(), + + mavenBundle().groupId("org.amdatu.core").artifactId("org.amdatu.core.tenantstore.fs") + .versionAsInProject()); + } +} Added: trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/TestContext.java ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/base/src/main/java/org/amdatu/core/itest/base/TestContext.java Wed May 4 12:13:45 2011 @@ -0,0 +1,133 @@ +/* + * 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. + */ +package org.amdatu.core.itest.base; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.assertThat; + +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.apache.felix.dm.Component; +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.util.tracker.ServiceTracker; + +/** + * Amdatu Core integration test utility class for tests providing utilities + * to easily and safely write tests. + */ +public class TestContext { + + private static final int SERVICE_LOOKUP_TIMEOUT = 10000; + + private final List<ServiceTracker> m_serviceTrackers = new LinkedList<ServiceTracker>(); + private final List<Component> m_components = new LinkedList<Component>(); + + private BundleContext m_bundleContext; + private DependencyManager m_dependencyManager; + + public TestContext(BundleContext bundleContext) { + m_bundleContext = bundleContext; + m_dependencyManager = new DependencyManager(m_bundleContext); + } + + public void tearDown() { + for (ServiceTracker serviceTracker : m_serviceTrackers) { + serviceTracker.close(); + } + } + + public BundleContext getBundleContext() { + return m_bundleContext; + } + + public DependencyManager getDependencyManager() { + return m_dependencyManager; + } + + public void addComponent(Component component) { + m_components.add(component); + m_dependencyManager.add(component); + } + + public void removeComponent(Component component) { + m_components.remove(component); + m_dependencyManager.remove(component); + } + + public <T> T getService(Class<T> serviceClass) throws Exception { + return getService(serviceClass, SERVICE_LOOKUP_TIMEOUT); + } + + public <T> T getService(Class<T> serviceClass, long timeout) throws Exception { + return getService(serviceClass, null, timeout); + } + + public <T> T getService(Class<T> serviceClass, String extraFilterExpression) + throws Exception { + return getService(serviceClass, extraFilterExpression, SERVICE_LOOKUP_TIMEOUT); + } + + public <T> T getService(Class<T> serviceClass, String extraFilterExpression, long timeout) + throws Exception { + String filterExpression = "(" + Constants.OBJECTCLASS + "=" + serviceClass.getName() + ")"; + if (extraFilterExpression != null) { + filterExpression = + "(&" + filterExpression + extraFilterExpression + ")"; + } + ServiceTracker serviceTracker = + new ServiceTracker(m_bundleContext, m_bundleContext.createFilter(filterExpression), null); + serviceTracker.open(); + m_serviceTrackers.add(serviceTracker); + + T serviceInstance = null; + try { + serviceInstance = (T) serviceTracker.waitForService(timeout); + } + catch (InterruptedException e) {} + return serviceInstance; + } + + public void updateConfig(String pid, Properties properties) throws Exception { + + // FIXME the getService(clas) option does not work!? Only when we explicitly use the + // ConfigurationAdmin class in the actual test resulting in it being imported in the + // probe it seems to work. + ServiceReference sr = m_bundleContext.getServiceReference(ConfigurationAdmin.class.getName()); + assertThat("ConfigurationAdmin serviceReference unavailable", sr, is(notNullValue())); + + ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) m_bundleContext.getService(sr); + assertThat("ConfigurationAdmin service unavailable", configurationAdmin, is(notNullValue())); + + Configuration configuration = + configurationAdmin.getConfiguration(pid, null); + assertThat("Configuration not found for PID: " + pid, configuration, is(notNullValue())); + configuration.update(properties); + + m_bundleContext.ungetService(sr); + } + + public ConfigurationAdmin getConfigurationAdmin() throws Exception { + return getService(ConfigurationAdmin.class); + } +} Added: trunk/amdatu-core/itest/pom.xml ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/pom.xml Wed May 4 12:13:45 2011 @@ -0,0 +1,237 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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.2.1-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.core.itest</artifactId> + <packaging>pom</packaging> + <name>Amdatu Core - Integration Tests reactor</name> + + <properties> + <pax.exam.version>2.0.0-RC4</pax.exam.version> + <org.apache.felix.framework.version>3.2.0</org.apache.felix.framework.version> + <org.slf4j.simple.version>1.6.1</org.slf4j.simple.version> + <pax.useradmin.version>0.0.1-amdatu1</pax.useradmin.version> + <org.apache.felix.configadmin.version>1.2.4</org.apache.felix.configadmin.version> + <org.apache.felix.eventadmin.version>1.2.2</org.apache.felix.eventadmin.version> + <org.apache.felix.log.version>1.0.0</org.apache.felix.log.version> + <org.apache.felix.main.version>3.0.2</org.apache.felix.main.version> + </properties> + + <modules> + <module>base</module> + <module>tests</module> + </modules> + + <dependencyManagement> + <dependencies> + + <!-- + Artifacts that make up the PaxExam based integration test + framework. + --> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-native</artifactId> + <version>${pax.exam.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + <version>${pax.exam.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-link-mvn</artifactId> + <version>${pax.exam.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>${org.apache.felix.framework.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jmock</groupId> + <artifactId>jmock-junit4</artifactId> + <version>${jmock.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>${org.apache.felix.framework.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>${org.slf4j.simple.version}</version> + <scope>compile</scope> + </dependency> + + <!-- + Artifacts that make up the Amdatu Core feature crosscutting for both the + base and tests modules. Scopes are intentionally set to compile in this + section so that depending (on the base) itest modules will in turn recieve + these transitive dependencies. + --> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.eventadmin</artifactId> + <version>${org.apache.felix.eventadmin.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.configadmin</artifactId> + <version>${org.apache.felix.configadmin.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.log</artifactId> + <version>${org.apache.felix.log.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.useradmin</groupId> + <artifactId>pax-useradmin-service</artifactId> + <version>${pax.useradmin.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.useradminstore.fs</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.config.templates</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.loghandler</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenant</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenantuseradmindecorator</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenantstore.fs</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + <type>bundle</type> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <!-- + See explanation in the dependencyManagement section above. + --> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-native</artifactId> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-link-mvn</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + </dependency> + + <!-- + See explanation in the dependencyManagement section above. + --> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.eventadmin</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.configadmin</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.log</artifactId> + </dependency> + <dependency> + <groupId>org.ops4j.pax.useradmin</groupId> + <artifactId>pax-useradmin-service</artifactId> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.useradminstore.fs</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.config.templates</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.loghandler</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenant</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenantuseradmindecorator</artifactId> + <type>bundle</type> + </dependency> + <dependency> + <groupId>org.amdatu.core</groupId> + <artifactId>org.amdatu.core.tenantstore.fs</artifactId> + <type>bundle</type> + </dependency> + </dependencies> + +</project> \ No newline at end of file Added: trunk/amdatu-core/itest/tests/pom.xml ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/tests/pom.xml Wed May 4 12:13:45 2011 @@ -0,0 +1,144 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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.2.1-SNAPSHOT</version> + </parent> + <artifactId>org.amdatu.core.itest.tests</artifactId> + <packaging>jar</packaging> + <name>Amdatu Core - Integration Tests tests</name> + + <!-- + This modules is solely intended to contain Amdatu Core integration + tests. It should not be extended depended upon. The test classes will + be deployed by PaxExam into the runtime as a probe. + --> + + <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>test</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> + <!-- + Outside the itest profile just skip surefire. + --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <!-- + Outside the itest profile show some help. + --> + <profile> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <defaultGoal>initialize</defaultGoal> + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>show-help</id> + <phase>initialize</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <tasks> + <echo> + <![CDATA[ +================================================ +Please activate the "itest" profile if you whish +to run the Amdatu Core integration tests +================================================ + ]]> + </echo> + </tasks> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <!-- + In the itest profile launch surefire in the + integration-test phase. + --> + <profile> + <id>itest</id> + <build> + <plugins> + <plugin> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>maven-paxexam-plugin</artifactId> + <executions> + <execution> + <phase>integration-test</phase> + <id>generate-depends-file</id> + <goals> + <goal>generate-depends-file</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>run-integration-test</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <systemPropertyVariables> + </systemPropertyVariables> + <skip>false</skip> + </configuration> + </execution> + </executions> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> \ No newline at end of file Added: trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/CoreServicesTest.java ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/CoreServicesTest.java Wed May 4 12:13:45 2011 @@ -0,0 +1,156 @@ +/* + * 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. + */ +package org.amdatu.core.itest.tests; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; +import static org.junit.Assert.assertThat; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.LibraryOptions.junitBundles; + +import java.util.Properties; + +import org.amdatu.core.itest.base.CoreFixture; +import org.amdatu.core.itest.base.TestContext; +import org.amdatu.core.itest.tests.mock.TestService; +import org.amdatu.core.itest.tests.mock.TestServiceImpl; +import org.amdatu.core.tenant.TenantManagementService; +import org.amdatu.core.tenant.TenantStorageProvider; +import org.apache.felix.dm.Component; +import org.apache.felix.dm.ServiceDependency; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.ExamReactorStrategy; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.log.LogService; +import org.osgi.service.useradmin.UserAdmin; + +@RunWith(JUnit4TestRunner.class) +@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) +public class CoreServicesTest { + + private CoreFixture m_coreFixture = new CoreFixture(); + + @Configuration + public Option[] config() { + return options( + junitBundles(), + m_coreFixture.provisionWithFsStorage()); + } + + private TestContext testContextSetUp(BundleContext bundleContext) throws Exception { + assertThat(bundleContext, is(notNullValue())); + TestContext testContext = new TestContext(bundleContext); + + // FIXME quickfix to let startlevel complete to + // prevent felix bundle locking issues + Thread.sleep(1000); + + // Run the default configurations + m_coreFixture.configureDefaults(testContext); + + // FIXME quickfix to let configadmin settle to + // prevent felix dropping configs + Thread.sleep(1000); + + return testContext; + } + + /** + * Test availablility of core non tenant aware services that shoudl always be available. + * + * @param bundleContext the injected context + * @throws Exception when things go bad + */ + @Test + public void testCoreServicesAvailable(BundleContext bundleContext) throws Exception { + TestContext testContext = testContextSetUp(bundleContext); + LogService logService = testContext.getService(LogService.class); + assertThat("Expected a LogService to be available", logService, is(notNullValue())); + ConfigurationAdmin configurationAdmin = testContext.getService(ConfigurationAdmin.class); + assertThat("Expected a ConfigurationAdmin to be available", configurationAdmin, is(notNullValue())); + EventAdmin eventAdmin = testContext.getService(EventAdmin.class); + assertThat("Expected a EventAdmin to be available", eventAdmin, is(notNullValue())); + TenantStorageProvider tenantStorageProvider = testContext.getService(TenantStorageProvider.class); + assertThat("Expected a TenantStorageProvider to be available", tenantStorageProvider, is(notNullValue())); + TenantManagementService tenantManagementService = testContext.getService(TenantManagementService.class); + assertThat("Expected a TenantManagementService to be available", tenantManagementService, is(notNullValue())); + testContext.tearDown(); + } + + /** + * Test DependencyManager usages. Shows how to use Components. Is work in progress. + * + * @param bundleContext + * @throws Exception + */ + @Test + public void testWithServiceDependencies(BundleContext bundleContext) throws Exception { + TestContext testContext = testContextSetUp(bundleContext); + + Component component = testContext.getDependencyManager().createComponent(); + component.setInterface(TestService.class.getName(), null); + component.setImplementation(TestServiceImpl.class); + + ServiceDependency serviceDependency = testContext.getDependencyManager().createServiceDependency(); + serviceDependency.setService(LogService.class); + serviceDependency.setRequired(true); + component.add(serviceDependency); + testContext.addComponent(component); + + TestService testInterface = testContext.getService(TestService.class); + assertThat(testInterface, is(notNullValue())); + + testContext.tearDown(); + } + + /** + * Testing tenant aware behavior for UserAdmin. Shows how a test can update configuration. + * + * @param bundleContext injected bundleContext + * @throws Exception when things go bad + */ + @Test + public void testTenantAwareUserAdminAvailable(BundleContext bundleContext) throws Exception { + TestContext testContext = testContextSetUp(bundleContext); + + Properties properties = new Properties(); + properties.put("tenant1.id", "tenant@localhost"); + properties.put("tenant1.name", "Tenant localhost"); + properties.put("tenant1.properties.hostname", "localhost"); + properties.put("tenant2.id", "[email protected]"); + properties.put("tenant2.name", "Tenant 127.0.0.1"); + properties.put("tenant2.properties.hostname", "127.0.0.1"); + + testContext.updateConfig(m_coreFixture.tenantManagementServicePID(), properties); + + UserAdmin userAdmin1 = testContext.getService(UserAdmin.class, "(tenant_id=tenant@localhost)"); + assertThat("Expected a UserAdmin for tenant@localhost to be available", userAdmin1, is(notNullValue())); + + UserAdmin userAdmin2 = testContext.getService(UserAdmin.class, "([email protected])"); + assertThat("Expected a UserAdmin for [email protected] to be available", userAdmin2, is(notNullValue())); + + UserAdmin userAdmin3 = testContext.getService(UserAdmin.class, "(tenant_id=tenant@overtherainbow)"); + assertThat("Expected no UserAdmin for tenant@overtherainbow to be available", userAdmin3, is(nullValue())); + } +} Added: trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestService.java ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestService.java Wed May 4 12:13:45 2011 @@ -0,0 +1,20 @@ +/* + * 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. + */ +package org.amdatu.core.itest.tests.mock; + +public interface TestService { + +} Added: trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestServiceImpl.java ============================================================================== --- (empty file) +++ trunk/amdatu-core/itest/tests/src/test/java/org/amdatu/core/itest/tests/mock/TestServiceImpl.java Wed May 4 12:13:45 2011 @@ -0,0 +1,31 @@ +/* + * 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. + */ +package org.amdatu.core.itest.tests.mock; + +public class TestServiceImpl implements TestService { + + public void init() { + } + + public void start() { + } + + public void stop() { + } + + public void destroy() { + } +} Modified: trunk/amdatu-core/pom.xml ============================================================================== --- trunk/amdatu-core/pom.xml (original) +++ trunk/amdatu-core/pom.xml Wed May 4 12:13:45 2011 @@ -70,5 +70,6 @@ <module>tenantstore-fs</module> <module>useradmincache</module> <module>useradminstore-fs</module> + <module>itest</module> </modules> </project> \ No newline at end of file _______________________________________________ Amdatu-commits mailing list [email protected] http://lists.amdatu.org/mailman/listinfo/amdatu-commits
