Author: angelos
Date: Tue Jan 25 19:22:33 2011
New Revision: 1063409
URL: http://svn.apache.org/viewvc?rev=1063409&view=rev
Log:
ACE-79 Ported the first integration test. The integration test don't run with the Maven build
yet.
Added:
incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/ExampleTest.java
incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/
incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
Modified:
incubator/ace/trunk/ace-integrationtests/pom.xml
Modified: incubator/ace/trunk/ace-integrationtests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/pom.xml?rev=1063409&r1=1063408&r2=1063409&view=diff
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/pom.xml (original)
+++ incubator/ace/trunk/ace-integrationtests/pom.xml Tue Jan 25 19:22:33 2011
@@ -28,12 +28,11 @@
<relativePath>../pom/</relativePath>
</parent>
+ <name>Apache ACE - IT</name>
<groupId>org.apache.ace</groupId>
<artifactId>ace-integrationtests</artifactId>
<version>0.8.0-SNAPSHOT</version>
- <name>Apache ACE - IT</name>
-
<properties>
<exam.it.version>1.2.2</exam.it.version>
</properties>
@@ -62,21 +61,142 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1</version>
- <scope>test</scope>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
</dependency>
+
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.7</version>
- <scope>test</scope>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-jetty-bundle</artifactId>
+ <version>0.7.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.dependencymanager</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.prefs</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.knopflerfish.bundle.useradmin</groupId>
+ <artifactId>useradmin_all</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.knopflerfish.bundle.log</groupId>
+ <artifactId>log_all</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-scheduler</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-httplistener</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-repository-api</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-repository-ext</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-repository-impl</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-repository-servlet</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-repository-task</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-resourceprocessor-useradmin</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-configurator-serveruseradmin</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-configurator-useradmin-task</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-range-api</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ace</groupId>
+ <artifactId>ace-deployment-provider-api</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <useDefaultManifestFile>false</useDefaultManifestFile>
+ <compilerArgument>-g</compilerArgument>
+ <compilerVersion>1.5</compilerVersion>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default-testCompile</id>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>maven-paxexam-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-config</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+
</project>
\ No newline at end of file
Added: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/ExampleTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/ExampleTest.java?rev=1063409&view=auto
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/ExampleTest.java
(added)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/ExampleTest.java
Tue Jan 25 19:22:33 2011
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.ace.it;
+
+import org.apache.felix.dm.Component;
+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.JUnit4TestRunner;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+import java.io.IOException;
+
+import static org.apache.ace.it.Options.*;
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+/**
+ * This class serves as a minimal example of our integration tests. Also, if this test fails,
something is likely
+ * wrong with the environment
+ */
+@RunWith(JUnit4TestRunner.class)
+public class ExampleTest extends IntegrationTestBase {
+
+ @Configuration
+ public Option[] configuration() {
+ return options(
+ // you can add additional directives, e.g. systemProperty or VMOptions here
+ provision(
+ Osgi.compendium(),
+ Felix.dependencyManager()
+ // add additional bundles here
+ )
+ );
+ }
+
+ protected void before() throws IOException {
+ // configure the services you need; you cannot use the injected members yet
+ }
+
+ protected Component[] getDependencies() {
+ return new Component[] {
+ // create Dependency Manager components that should be started before the
+ // test starts.
+ createComponent()
+ .setImplementation(this)
+ .add(createServiceDependency()
+ .setService(PackageAdmin.class)
+ .setRequired(true))
+ };
+ }
+
+ // You can inject services as usual.
+ private volatile PackageAdmin m_packageAdmin;
+
+ @Test
+ public void exampleTest() {
+ assertEquals("Hey, who stole my package!",
+ 0,
+ m_packageAdmin.getExportedPackage("org.osgi.framework").getExportingBundle().getBundleId());
+ }
+}
Added: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java?rev=1063409&view=auto
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
(added)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
Tue Jan 25 19:22:33 2011
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.ace.it;
+
+import org.apache.felix.dm.*;
+import org.junit.Before;
+import org.ops4j.pax.exam.Inject;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.fail;
+
+/**
+ * Base class for integration tests. There is no technical reason to use this, but it might
make
+ * your life easier.<br>
+ * <br>
+ * {@link org.apache.ace.it.ExampleTest} shows a minimal example of an integration test.
+ *
+ */
+public class IntegrationTestBase {
+ /**
+ * If we have to wait for a service, wait this amount of seconds.
+ */
+ private static final int SERVICE_TIMEOUT = 5;
+
+ @Inject
+ protected BundleContext m_bundleContext;
+ protected DependencyManager m_dependencyManager;
+
+ /**
+ * The 'before' callback will be called after the components from {@link #getDependencies}
have been
+ * added, but you cannot necessarily rely on injected members here. You can use the {@link
#configure} and
+ * {@link #configureFactory} methods, as well as the {@link #getService} methods.<br>
+ * <br>
+ * The {@link #before} callback is most useful for configuring services that have been
provisioned
+ * in the 'configuration' method.
+ */
+ protected void before() throws Exception {}
+
+ /**
+ * Gets a list of components that must be started before the test is started; this useful
to
+ * (a) add additional services, e.g. services that should be picked up by the service
under
+ * test, or (b) to declare 'this' as a component, and get services injected.
+ */
+ protected Component[] getDependencies() {
+ return new Component[0];
+ }
+
+ /**
+ * Write configuration for a single service. For example,
+ * <pre>
+ * configure("org.apache.felix.http",
+ * "org.osgi.service.http.port", "1234");
+ * </pre>
+ */
+ protected void configure(String pid, String... configuration) throws IOException {
+ Properties props = properties(configuration);
+ Configuration config = getConfiguration(pid);
+ config.update(props);
+ }
+
+ /**
+ * Creates a factory configuration with the given properties, just like {@link #configure}.
+ * @return The PID of newly created configuration.
+ */
+ protected String configureFactory(String factoryPid, String... configuration) throws
IOException {
+ Properties props = properties(configuration);
+ Configuration config = createFactoryConfiguration(factoryPid);
+ config.update(props);
+ return config.getPid();
+ }
+
+ @Before
+ public void setupTest() throws Exception {
+ m_dependencyManager = new DependencyManager(m_bundleContext);
+ Component[] components = getDependencies();
+ ComponentCounter listener = new ComponentCounter(components);
+
+ // Register our listener for all the services...
+ for (Component component : components) {
+ component.addStateListener(listener);
+ }
+
+ // Then give them to the dependency manager...
+ for (Component component : components) {
+ m_dependencyManager.add(component);
+ }
+
+ // Call back the implementation...
+ before();
+
+ // And wait for all components to come online.
+ try {
+ if (!listener.waitForEmpty(SERVICE_TIMEOUT, SECONDS)) {
+ fail("Not all components were started. Still missing the following:\n" +
listener.componentsString());
+ }
+ }
+ catch (InterruptedException e) {
+ fail("Interrupted while waiting for services to get started.");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T getService(Class<T> serviceClass, String filterString) throws
InvalidSyntaxException {
+ T serviceInstance = null;
+
+ ServiceTracker serviceTracker;
+ if (filterString == null) {
+ serviceTracker = new ServiceTracker(m_bundleContext, serviceClass.getName(),
null);
+ }
+ else {
+ String classFilter = "(" + Constants.OBJECTCLASS + "=" + serviceClass.getName()
+ ")";
+ filterString = "(&" + classFilter + filterString + ")";
+ serviceTracker = new ServiceTracker(m_bundleContext, m_bundleContext.createFilter(filterString),
null);
+ }
+ serviceTracker.open();
+ try {
+ serviceInstance = (T) serviceTracker.waitForService(SERVICE_TIMEOUT * 1000);
+
+ if (serviceInstance == null) {
+ fail(serviceClass + " service not found.");
+ }
+ else {
+ return serviceInstance;
+ }
+ }
+ catch (InterruptedException e) {
+ e.printStackTrace();
+ fail(serviceClass + " service not available: " + e.toString());
+ }
+
+ return serviceInstance;
+ }
+
+ protected <T> T getService(Class<T> serviceClass) {
+ try {
+ return getService(serviceClass, null);
+ }
+ catch (InvalidSyntaxException e) {
+ return null;
+ // Will not happen, since we don't pass in a filter.
+ }
+ }
+
+ private Configuration getConfiguration(String pid) throws IOException {
+ ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
+ return admin.getConfiguration(pid, null);
+ }
+
+ private Configuration createFactoryConfiguration(String factoryPid) throws IOException
{
+ ConfigurationAdmin admin = getService(ConfigurationAdmin.class);
+ return admin.createFactoryConfiguration(factoryPid, null);
+ }
+
+ private static Properties properties(String... values) {
+ Properties props = new Properties();
+ for (int i = 0; i < values.length; i += 2) {
+ props.put(values[i], values[i+1]);
+ }
+ return props;
+ }
+
+ // Dependency Manager bridge methods
+
+ protected Component createComponent() {
+ return m_dependencyManager.createComponent();
+ }
+
+ protected ServiceDependency createServiceDependency() {
+ return m_dependencyManager.createServiceDependency();
+ }
+
+
+ private static class ComponentCounter implements ComponentStateListener {
+ private final List<Component> m_components = new ArrayList<Component>();
+ private final CountDownLatch m_latch;
+
+ public ComponentCounter(Component[] components) {
+ m_components.addAll(Arrays.asList(components));
+ m_latch = new CountDownLatch(components.length);
+ }
+
+ public void starting(Component component) {
+ }
+
+ public void started(Component component) {
+ m_components.remove(component);
+ m_latch.countDown();
+ }
+
+ public void stopping(Component component) {
+ }
+
+ public void stopped(Component component) {
+ }
+
+ public boolean waitForEmpty(long timeout, TimeUnit unit) throws InterruptedException
{
+ return m_latch.await(timeout, unit);
+ }
+
+ public String componentsString() {
+ StringBuilder result = new StringBuilder();
+ for (Component component : m_components) {
+ result.append(component).append('\n');
+ for (ComponentDependencyDeclaration dependency : (List<ComponentDependencyDeclaration>)
component.getDependencies()) {
+ result.append(" ")
+ .append(dependency.toString())
+ .append(" ")
+ .append(ComponentDependencyDeclaration.STATE_NAMES[dependency.getState()])
+ .append('\n');
+ }
+ result.append('\n');
+ }
+ return result.toString();
+ }
+ };
+}
Added: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java?rev=1063409&view=auto
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
(added)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
Tue Jan 25 19:22:33 2011
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.ace.it;
+
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+/**
+ * This class contains a set of Pax Exam options, intended for typo-free provisioning of
bundles.
+ */
+public class Options {
+ public static class Osgi {
+ public static MavenArtifactProvisionOption compendium() {
+ return maven("org.osgi.compendium");
+ }
+
+ private static MavenArtifactProvisionOption maven(String artifactId) {
+ return Options.maven("org.osgi", artifactId);
+ }
+ }
+
+ public static class Felix {
+ public static MavenArtifactProvisionOption preferences() {
+ return maven("org.apache.felix.prefs");
+ }
+
+ public static MavenArtifactProvisionOption dependencyManager() {
+ return maven("org.apache.felix.dependencymanager");
+ }
+
+ public static MavenArtifactProvisionOption configAdmin() {
+ return maven("org.apache.felix.configadmin");
+ }
+
+ private static MavenArtifactProvisionOption maven(String artifactId) {
+ return Options.maven("org.apache.felix", artifactId);
+ }
+ }
+
+ public static class Ace {
+ public static MavenArtifactProvisionOption rangeApi() {
+ return maven("ace-range-api");
+ }
+
+ public static MavenArtifactProvisionOption scheduler() {
+ return maven("ace-scheduler");
+ }
+
+ public static MavenArtifactProvisionOption httplistener() {
+ return maven("ace-httplistener");
+ }
+
+ public static MavenArtifactProvisionOption repositoryApi() {
+ return maven("ace-repository-api");
+ }
+
+ public static MavenArtifactProvisionOption repositoryExt() {
+ return maven("ace-repository-ext");
+ }
+
+ public static MavenArtifactProvisionOption repositoryImpl() {
+ return maven("ace-repository-impl");
+ }
+
+ public static MavenArtifactProvisionOption repositoryServlet() {
+ return maven("ace-repository-servlet");
+ }
+
+ public static MavenArtifactProvisionOption repositoryTask() {
+ return maven("ace-repository-task");
+ }
+
+ public static MavenArtifactProvisionOption resourceprocessorUseradmin() {
+ return maven("ace-resourceprocessor-useradmin");
+ }
+
+ public static MavenArtifactProvisionOption configuratorServeruseradmin() {
+ return maven("ace-configurator-serveruseradmin");
+ }
+
+ public static MavenArtifactProvisionOption configuratorUseradminTask() {
+ return maven("ace-configurator-useradmin-task");
+ }
+
+ public static MavenArtifactProvisionOption deploymentProviderApi() {
+ return maven("ace-deployment-provider-api");
+ }
+
+ private static MavenArtifactProvisionOption maven(String artifactId) {
+ return Options.maven("org.apache.ace", artifactId);
+ }
+
+ }
+
+ public static class Knopflerfish {
+ public static MavenArtifactProvisionOption useradmin() {
+ return maven("org.knopflerfish.bundle.useradmin", "useradmin_all");
+ }
+ public static MavenArtifactProvisionOption log() {
+ return maven("org.knopflerfish.bundle.log", "log_all");
+ }
+ }
+
+ public static MavenArtifactProvisionOption jetty() {
+ return maven("org.ops4j.pax.web", "pax-web-jetty-bundle");
+ }
+
+ private static MavenArtifactProvisionOption maven(String groupId, String artifactId)
{
+ return mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+ }
+}
Added: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java?rev=1063409&view=auto
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
(added)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
Tue Jan 25 19:22:33 2011
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.ace.it.useradminconfigurator;
+
+import org.apache.ace.it.IntegrationTestBase;
+import org.apache.ace.repository.Repository;
+import org.apache.ace.repository.impl.constants.RepositoryConstants;
+import org.apache.ace.test.constants.TestConstants;
+import org.apache.felix.dm.Component;
+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.JUnit4TestRunner;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import static org.apache.ace.it.Options.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+@RunWith(JUnit4TestRunner.class)
+public class ConfiguratorTest extends IntegrationTestBase {
+
+ @Configuration
+ public Option[] configuration() {
+ return options(
+ systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
+ provision(
+ Osgi.compendium(),
+ jetty(),
+ Felix.preferences(),
+ Felix.dependencyManager(),
+ Felix.configAdmin(),
+ Knopflerfish.useradmin(),
+ Knopflerfish.log(),
+ Ace.rangeApi(),
+ Ace.scheduler(),
+ Ace.httplistener(),
+ Ace.repositoryApi(),
+ Ace.repositoryImpl(),
+ Ace.repositoryServlet(),
+ Ace.resourceprocessorUseradmin(),
+ Ace.configuratorUseradminTask(),
+ Ace.deploymentProviderApi()
+ )
+ );
+ }
+
+ protected Component[] getDependencies() {
+ return new Component[] {
+ createComponent()
+ .setImplementation(this)
+ .add(createServiceDependency()
+ .setService(UserAdmin.class)
+ .setRequired(true))
+ .add(createServiceDependency()
+ .setService(Repository.class, "(&(" + RepositoryConstants.REPOSITORY_NAME
+ "=users)(" + RepositoryConstants.REPOSITORY_CUSTOMER + "=apache))")
+ .setRequired(true))
+ };
+ }
+
+ protected void before() throws IOException {
+ configureFactory("org.apache.ace.server.repository.factory",
+ RepositoryConstants.REPOSITORY_NAME, "users",
+ RepositoryConstants.REPOSITORY_CUSTOMER, "apache",
+ RepositoryConstants.REPOSITORY_MASTER, "true");
+ configure("org.apache.ace.repository.servlet.RepositoryServlet",
+ "org.apache.ace.server.servlet.endpoint", "/repository");
+ configure("org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask",
+ "repositoryName", "users",
+ "repositoryCustomer", "apache",
+ "repositoryLocation", "http://localhost:" + TestConstants.PORT + "/repository");
+ configure("org.apache.ace.scheduler",
+ "org.apache.ace.configurator.useradmin.task.UpdateUserAdminTask", "1000");
+ }
+
+ private volatile Repository m_repository;
+ private volatile UserAdmin m_userAdmin;
+
+ /**
+ * Creates a file in the repository, waits for the UserAdmin to have a new user
+ * present, and inspects that user.
+ */
+ @Test
+ public void configuratorTest() throws IllegalArgumentException, IOException, InterruptedException
{
+ ByteArrayInputStream bis = new ByteArrayInputStream((
+ "<roles>" +
+ " <user name=\"TestUser\">" +
+ " <properties>" +
+ " <email>testUser@apache.org</email>" +
+ " </properties>" +
+ " <credentials>" +
+ " <password type=\"String\">swordfish</password>" +
+ " <certificate type=\"byte[]\">42</certificate>" +
+ " </credentials>" +
+ " </user>" +
+ "</roles>").getBytes());
+
+ assertTrue("Committing test user data failed.", m_repository.commit(bis, m_repository.getRange().getHigh()));
+
+ User user = (User) m_userAdmin.getRole("TestUser");
+ int count = 0;
+ while ((user == null) && (count < 60)) {
+ Thread.sleep(250);
+ user = (User) m_userAdmin.getRole("TestUser");
+ count++;
+ }
+
+ assertNotNull("Even after fifteen seconds, our user is not present.", user);
+
+ boolean foundPassword = false;
+ boolean foundCertificate = false;
+ count = 0;
+ while (!foundPassword & !foundCertificate && (count < 20)) {
+ // Note: there is a window between the creation of the user and the setting of
the properties.
+ Thread.sleep(50);
+ foundPassword = user.hasCredential("password", "swordfish");
+ foundCertificate = user.hasCredential("certificate", new byte[] {'4', '2'});
+ }
+
+ assertTrue("A second after our user becoming available, there is no (correct) password.",
foundPassword);
+ assertTrue("A second after our user becoming available, there is no (correct) certificate.",
foundCertificate);
+ }
+}
|