You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/04/29 15:11:41 UTC
svn commit: r769780 - in /geronimo/sandbox/blueprint: ./ blueprint-itests/
blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/
blueprint-itests/src/test/resources/org/
Author: gnodet
Date: Wed Apr 29 13:11:40 2009
New Revision: 769780
URL: http://svn.apache.org/viewvc?rev=769780&view=rev
Log:
Switch to pax-exam for integration tests (enabling testing on equinox, felix, etc...)
Added:
geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/AbstractIntegrationTest.java
Removed:
geronimo/sandbox/blueprint/blueprint-itests/src/test/resources/org/
Modified:
geronimo/sandbox/blueprint/blueprint-itests/pom.xml
geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestBlueprintContext.java
geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
geronimo/sandbox/blueprint/pom.xml
Modified: geronimo/sandbox/blueprint/blueprint-itests/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/pom.xml?rev=769780&r1=769779&r2=769780&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/pom.xml Wed Apr 29 13:11:40 2009
@@ -29,11 +29,6 @@
<dependencies>
<dependency>
- <groupId>org.apache.servicemix.kernel.testing</groupId>
- <artifactId>org.apache.servicemix.kernel.testing.support</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.apache.geronimo</groupId>
<artifactId>blueprint-bundle</artifactId>
<scope>test</scope>
@@ -43,8 +38,53 @@
<artifactId>blueprint-sample</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit-extender-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <repositories>
+ <repository>
+ <id>ops4j.releases</id>
+ <url>http://repository.ops4j.org/maven2</url>
+ </repository>
+ <repository>
+ <id>ops4j.snapshots</id>
+ <url>http://repository.ops4j.org/mvn-snapshots</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>ops4j.releases</id>
+ <url>http://repository.ops4j.org/maven2</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+
<build>
<plugins>
<plugin>
Added: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/AbstractIntegrationTest.java?rev=769780&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/AbstractIntegrationTest.java (added)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/AbstractIntegrationTest.java Wed Apr 29 13:11:40 2009
@@ -0,0 +1,86 @@
+package org.apache.geronimo.blueprint.itests;
+
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.blueprint.context.BlueprintContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class AbstractIntegrationTest {
+
+ public static final long DEFAULT_TIMEOUT = 30000;
+
+ @Inject
+ protected BundleContext bundleContext;
+
+ protected BlueprintContext getBlueprintContextForBundle(String symbolicName) throws Exception {
+ return getBlueprintContextForBundle(symbolicName, DEFAULT_TIMEOUT);
+ }
+
+ protected BlueprintContext getBlueprintContextForBundle(String symbolicName, long timeout) throws Exception {
+ return getOsgiService(BlueprintContext.class, "(osgi.blueprint.context.symbolicname=" + symbolicName + ")", timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, long timeout) {
+ return getOsgiService(type, null, timeout);
+ }
+
+ protected <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, null, DEFAULT_TIMEOUT);
+ }
+
+ protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+ ServiceTracker tracker = null;
+ try {
+ String flt;
+ if (filter != null) {
+ if (filter.startsWith("(")) {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+ } else {
+ flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+ }
+ } else {
+ flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+ }
+ Filter osgiFilter = FrameworkUtil.createFilter(flt);
+ tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+ tracker.open();
+ // Note that the tracker is not closed to keep the reference
+ // This is buggy, has the service reference may change i think
+ Object svc = type.cast(tracker.waitForService(timeout));
+ if (svc == null) {
+ throw new RuntimeException("Gave up waiting for service " + flt);
+ }
+ return type.cast(svc);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Invalid filter", e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected Bundle installBundle(String groupId, String artifactId) throws Exception {
+ MavenArtifactProvisionOption mvnUrl = mavenBundle(groupId, artifactId);
+ return bundleContext.installBundle(mvnUrl.getURL());
+ }
+
+ protected Bundle getInstalledBundle(String symbolicName) {
+ for (Bundle b : bundleContext.getBundles()) {
+ if (b.getSymbolicName().equals(symbolicName)) {
+ return b;
+ }
+ }
+ return null;
+ }
+
+ public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+ return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+ }
+
+}
Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestBlueprintContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestBlueprintContext.java?rev=769780&r1=769779&r2=769780&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestBlueprintContext.java (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestBlueprintContext.java Wed Apr 29 13:11:40 2009
@@ -18,47 +18,49 @@
*/
package org.apache.geronimo.blueprint.itests;
-import java.net.URLDecoder;
-import java.util.Properties;
-import java.util.Hashtable;
-import java.util.Currency;
-import java.util.List;
-import java.util.ArrayList;
import java.text.SimpleDateFormat;
+import java.util.Currency;
+import java.util.Hashtable;
-import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
-import org.apache.servicemix.kernel.testing.support.Counter;
-import org.apache.geronimo.blueprint.sample.Foo;
import org.apache.geronimo.blueprint.sample.Bar;
-import org.apache.geronimo.blueprint.sample.InterfaceA;
-import org.apache.geronimo.blueprint.sample.CurrencyTypeConverter;
+import org.apache.geronimo.blueprint.sample.Foo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceEvent;
import org.osgi.service.blueprint.context.BlueprintContext;
-import org.osgi.service.blueprint.context.ServiceUnavailableException;
-import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.Configuration;
-import org.osgi.util.tracker.ServiceTracker;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
-import org.springframework.osgi.util.OsgiFilterUtils;
-import org.springframework.osgi.util.OsgiListenerUtils;
+import org.osgi.service.cm.ConfigurationAdmin;
+@RunWith(JUnit4TestRunner.class)
public class TestBlueprintContext extends AbstractIntegrationTest {
+ @Test
public void test() throws Exception {
// Create a config to check the property placeholder
ConfigurationAdmin ca = getOsgiService(ConfigurationAdmin.class);
- Configuration cf = ca.getConfiguration("blueprint-sample");
+ Configuration cf = ca.getConfiguration("blueprint-sample", null);
Hashtable props = new Hashtable();
props.put("key.b", "10");
cf.update(props);
- Resource res = locateBundle(getBundle("org.apache.geronimo", "blueprint-sample"));
- Bundle bundle = installBundle(res);
+ Bundle bundle = getInstalledBundle("blueprint-sample");
assertNotNull(bundle);
bundle.start();
@@ -108,101 +110,31 @@
assertTrue(foo.isDestroyed());
}
- protected BlueprintContext getBlueprintContextForBundle(String symbolicName, long timeout) throws Exception {
- return getOsgiService(BlueprintContext.class, "(osgi.blueprint.context.symbolicname=" + symbolicName + ")", timeout);
- }
-
- public <T> T getOsgiService(Class<T> type, String filter, long timeout) {
- // translate from seconds to miliseconds
- long time = timeout * 1000;
-
- // use the counter to make sure the threads block
- final Counter counter = new Counter("waitForOsgiService on bnd=" + type.getName());
-
- counter.increment();
-
- final List<T> services = new ArrayList<T>();
-
- ServiceListener listener = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- if (event.getType() == ServiceEvent.REGISTERED) {
- services.add((T) bundleContext.getService(event.getServiceReference()));
- counter.decrement();
- }
- }
- };
-
- String flt = OsgiFilterUtils.unifyFilter(type.getName(), filter);
- OsgiListenerUtils.addServiceListener(bundleContext, listener, flt);
-
- if (logger.isDebugEnabled())
- logger.debug("start waiting for OSGi service=" + type.getName());
-
- try {
- if (counter.waitForZero(time)) {
- logger.warn("waiting for OSGi service=" + type.getName() + " timed out");
- throw new RuntimeException("Gave up waiting for OSGi service '" + type.getName() + "' to be created");
- }
- else if (logger.isDebugEnabled()) {
- logger.debug("found OSGi service=" + type.getName());
- }
- return services.get(0);
- }
- finally {
- // inform waiting thread
- bundleContext.removeServiceListener(listener);
- }
- }
-
- /**
- * The manifest to use for the "virtual bundle" created
- * out of the test classes and resources in this project
- *
- * This is actually the boilerplate manifest with one additional
- * import-package added. We should provide a simpler customization
- * point for such use cases that doesn't require duplication
- * of the entire manifest...
- */
- protected String getManifestLocation() {
- return "classpath:org/apache/geronimo/blueprint/MANIFEST.MF";
- }
-
- /**
- * The location of the packaged OSGi bundles to be installed
- * for this test. Values are Spring resource paths. The bundles
- * we want to use are part of the same multi-project maven
- * build as this project is. Hence we use the localMavenArtifact
- * helper method to find the bundles produced by the package
- * phase of the maven build (these tests will run after the
- * packaging phase, in the integration-test phase).
- *
- * JUnit, commons-logging, spring-core and the spring OSGi
- * test bundle are automatically included so do not need
- * to be specified here.
- */
- protected String[] getTestBundlesNames() {
- return new String[] {
- getBundle("org.apache.geronimo", "blueprint-bundle"),
- };
- }
-
- private Bundle installBundle(Resource location) throws Exception {
- Assert.notNull(bundleContext);
- Assert.notNull(location);
- if (logger.isDebugEnabled())
- logger.debug("Installing bundle from location " + location.getDescription());
-
- String bundleLocation;
-
- try {
- bundleLocation = URLDecoder.decode(location.getURL().toExternalForm(), "UTF-8");
- }
- catch (Exception ex) {
- // the URL cannot be created, fall back to the description
- bundleLocation = location.getDescription();
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // install log service using pax runners profile abstraction (there are more profiles, like DS)
+ logProfile(),
+ configProfile(),
+ profile("url"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // Bundles
+ mavenBundle("org.apache.geronimo", "blueprint-bundle"),
+ mavenBundle("org.apache.geronimo", "blueprint-sample").noStart(),
+
+ felix(), equinox() //, knopflerfish()
+ );
+
+ // use config generated by the Maven plugin (until PAXEXAM-62/64 get resolved)
+ if (TestBlueprintContext.class.getClassLoader().getResource("META-INF/maven/paxexam-config.args") != null) {
+ options = OptionUtils.combine(options, mavenConfiguration());
}
- return bundleContext.installBundle(bundleLocation, location.getInputStream());
+ return options;
}
}
Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java?rev=769780&r1=769779&r2=769780&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java Wed Apr 29 13:11:40 2009
@@ -18,24 +18,39 @@
*/
package org.apache.geronimo.blueprint.itests;
-import java.net.URLDecoder;
import java.util.Hashtable;
import java.util.List;
import org.apache.geronimo.blueprint.sample.BindingListener;
import org.apache.geronimo.blueprint.sample.InterfaceA;
-import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
-import org.osgi.framework.Bundle;
+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 org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
+import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.blueprint.context.BlueprintContext;
import org.osgi.service.blueprint.context.ServiceUnavailableException;
-import org.osgi.util.tracker.ServiceTracker;
-import org.springframework.core.io.Resource;
-import org.springframework.util.Assert;
+@RunWith(JUnit4TestRunner.class)
public class TestReferences extends AbstractIntegrationTest {
+ @Test
public void testUnaryReference() throws Exception {
BlueprintContext blueprintContext = getBlueprintContextForBundle("blueprint-sample");
assertNotNull(blueprintContext);
@@ -88,6 +103,7 @@
}
}
+ @Test
public void testListReferences() throws Exception {
BlueprintContext blueprintContext = getBlueprintContextForBundle("blueprint-sample");
assertNotNull(blueprintContext);
@@ -114,63 +130,30 @@
}
- protected BlueprintContext getBlueprintContextForBundle(String symbolicName) throws Exception {
- String filter = "(&(" + Constants.OBJECTCLASS + "=" + BlueprintContext.class.getName() + ")(osgi.blueprint.context.symbolicname=" + symbolicName + "))";
- ServiceTracker tracker = new ServiceTracker(bundleContext, org.osgi.framework.FrameworkUtil.createFilter(filter), null);
- tracker.open();
- return (BlueprintContext) tracker.waitForService(5000);
- }
-
- /**
- * The manifest to use for the "virtual bundle" created
- * out of the test classes and resources in this project
- *
- * This is actually the boilerplate manifest with one additional
- * import-package added. We should provide a simpler customization
- * point for such use cases that doesn't require duplication
- * of the entire manifest...
- */
- protected String getManifestLocation() {
- return "classpath:org/apache/geronimo/blueprint/MANIFEST.MF";
- }
-
- /**
- * The location of the packaged OSGi bundles to be installed
- * for this test. Values are Spring resource paths. The bundles
- * we want to use are part of the same multi-project maven
- * build as this project is. Hence we use the localMavenArtifact
- * helper method to find the bundles produced by the package
- * phase of the maven build (these tests will run after the
- * packaging phase, in the integration-test phase).
- *
- * JUnit, commons-logging, spring-core and the spring OSGi
- * test bundle are automatically included so do not need
- * to be specified here.
- */
- protected String[] getTestBundlesNames() {
- return new String[] {
- getBundle("org.apache.geronimo", "blueprint-bundle"),
- getBundle("org.apache.geronimo", "blueprint-sample"),
- };
- }
-
- private Bundle installBundle(Resource location) throws Exception {
- Assert.notNull(bundleContext);
- Assert.notNull(location);
- if (logger.isDebugEnabled())
- logger.debug("Installing bundle from location " + location.getDescription());
-
- String bundleLocation;
-
- try {
- bundleLocation = URLDecoder.decode(location.getURL().toExternalForm(), "UTF-8");
- }
- catch (Exception ex) {
- // the URL cannot be created, fall back to the description
- bundleLocation = location.getDescription();
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // install log service using pax runners profile abstraction (there are more profiles, like DS)
+ logProfile(),
+ configProfile(),
+ profile("url"),
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+ // Bundles
+ mavenBundle("org.apache.geronimo", "blueprint-bundle"),
+ mavenBundle("org.apache.geronimo", "blueprint-sample"),
+
+ felix(), equinox() //, knopflerfish()
+ );
+
+ // use config generated by the Maven plugin (until PAXEXAM-62/64 get resolved)
+ if (TestBlueprintContext.class.getClassLoader().getResource("META-INF/maven/paxexam-config.args") != null) {
+ options = OptionUtils.combine(options, mavenConfiguration());
}
- return bundleContext.installBundle(bundleLocation, location.getInputStream());
+ return options;
}
}
\ No newline at end of file
Modified: geronimo/sandbox/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/pom.xml?rev=769780&r1=769779&r2=769780&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/pom.xml (original)
+++ geronimo/sandbox/blueprint/pom.xml Wed Apr 29 13:11:40 2009
@@ -76,7 +76,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.5</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
@@ -104,9 +104,24 @@
<version>1.5.6</version>
</dependency>
<dependency>
- <groupId>org.apache.servicemix.kernel.testing</groupId>
- <artifactId>org.apache.servicemix.kernel.testing.support</artifactId>
- <version>1.1.0</version>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit-extender-impl</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>