pax-exam 3.0.0 migration ...
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1531736 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
deleted file mode 100644
index 882666d..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
-* 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.felix.dm.test.annotation;
-
-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.systemProperty;
-
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-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.framework.BundleContext;
-import org.osgi.framework.Constants;
-
-/**
- * Use case: Verify Aspect Annotations usage.
- */
-@RunWith(JUnit4TestRunner.class)
-public class AspectAnnotationTest extends AnnotationBase
-{
- @Configuration
- public static Option[] configuration()
- {
- return options(
- systemProperty(DMLOG_PROPERTY).value( "true" ),
- provision(
- mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version(Base.OSGI_SPEC_VERSION),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
- provision(
- new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "AspectTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.aspect")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
- .build()));
- }
-
- @Test
- public void testAspectChain(BundleContext context) throws Throwable
- {
- DependencyManager m = new DependencyManager(context);
- // Activate service consumer
- Component scSequencer = makeSequencer(m, "AspectChainTest.ServiceConsumer");
- m.add(scSequencer);
- // Activate service provider
- Component spSequencer = makeSequencer(m, "AspectChainTest.ServiceProvider");
- m.add(spSequencer);
- // Activate service aspect 2
- Component sa2Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect2");
- m.add(sa2Sequencer);
- // Activate service aspect 3
- Component sa3Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect3");
- m.add(sa3Sequencer);
- // Activate service aspect 1
- Component sa1Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect1");
- m.add(sa1Sequencer);
-
- m_ensure.step();
- m_ensure.waitForStep(6, 10000);
-
- // Deactivate service provider
- m.remove(spSequencer);
- // Make sure that service aspect 1 has been called in ts removed and stop callbacks
- m_ensure.waitForStep(8, 10000);
- m_ensure.ensure();
- }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java
similarity index 67%
rename from dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java
rename to dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java
index ee22c65..dea27bd 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.bundle.annotation.aspect;
+package org.apache.felix.dependencymanager.test2.components;
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.annotation.api.AspectService;
@@ -26,122 +26,107 @@
import org.apache.felix.dm.annotation.api.Inject;
import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.apache.felix.dm.annotation.api.Stop;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-public class AspectChainTest
-{
- public interface ServiceInterface
- {
+public class AspectAnnotation {
+ public interface ServiceInterface {
public void invoke(Runnable run);
}
@Component
- public static class ServiceProvider implements ServiceInterface
- {
- @ServiceDependency(filter="(name=AspectChainTest.ServiceProvider)")
- protected Sequencer m_sequencer;
+ public static class ServiceProvider implements ServiceInterface {
+ @ServiceDependency(filter = "(name=AspectChainTest.ServiceProvider)")
+ protected volatile Ensure m_sequencer;
// Injected by reflection.
- protected ServiceRegistration m_sr;
-
+ protected volatile ServiceRegistration m_sr;
+
@Init
void init() {
System.out.println("ServiceProvider.init");
}
-
+
@Destroy
void destroy() {
System.out.println("ServiceProvider.destroy");
}
- public void invoke(Runnable run)
- {
+ public void invoke(Runnable run) {
run.run();
m_sequencer.step(6);
}
}
-
+
@AspectService(ranking = 20)
- public static class ServiceAspect2 implements ServiceInterface
- {
- @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect2)")
- protected Sequencer m_sequencer;
+ public static class ServiceAspect2 implements ServiceInterface {
+ @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect2)")
+ protected volatile Ensure m_sequencer;
// Injected by reflection.
private volatile ServiceInterface m_parentService;
// Check auto config injections
@Inject
- BundleContext m_bc;
+ volatile BundleContext m_bc;
BundleContext m_bcNotInjected;
-
+
@Inject
- DependencyManager m_dm;
+ volatile DependencyManager m_dm;
DependencyManager m_dmNotInjected;
-
+
@Inject
- org.apache.felix.dm.Component m_component;
+ volatile org.apache.felix.dm.Component m_component;
org.apache.felix.dm.Component m_componentNotInjected;
@Init
void init() {
System.out.println("ServiceAspect2.init");
}
-
+
@Destroy
void destroy() {
System.out.println("ServiceAspect2.destroy");
}
-
- public void invoke(Runnable run)
- {
+
+ public void invoke(Runnable run) {
checkInjectedFields();
m_sequencer.step(3);
m_parentService.invoke(run);
}
-
- private void checkInjectedFields()
- {
- if (m_bc == null)
- {
+
+ private void checkInjectedFields() {
+ if (m_bc == null) {
m_sequencer.throwable(new Exception("Bundle Context not injected"));
return;
}
- if (m_bcNotInjected != null)
- {
+ if (m_bcNotInjected != null) {
m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
return;
}
- if (m_dm == null)
- {
+ if (m_dm == null) {
m_sequencer.throwable(new Exception("DependencyManager not injected"));
return;
}
- if (m_dmNotInjected != null)
- {
+ if (m_dmNotInjected != null) {
m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
return;
}
- if (m_component == null)
- {
+ if (m_component == null) {
m_sequencer.throwable(new Exception("Component not injected"));
return;
}
- if (m_componentNotInjected != null)
- {
+ if (m_componentNotInjected != null) {
m_sequencer.throwable(new Exception("Component must not be injected"));
return;
}
}
}
- @AspectService(ranking = 30, added="add")
- public static class ServiceAspect3 implements ServiceInterface
- {
- @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect3)")
- protected Sequencer m_sequencer;
+ @AspectService(ranking = 30, added = "add")
+ public static class ServiceAspect3 implements ServiceInterface {
+ @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect3)")
+ protected volatile Ensure m_sequencer;
// Injected using add callback.
private volatile ServiceInterface m_parentService;
@@ -149,29 +134,26 @@
void init() {
System.out.println("ServiceAspect3.init");
}
-
+
@Destroy
void destroy() {
System.out.println("ServiceAspect3.destroy");
}
- void add(ServiceInterface si)
- {
+ void add(ServiceInterface si) {
m_parentService = si;
}
-
- public void invoke(Runnable run)
- {
+
+ public void invoke(Runnable run) {
m_sequencer.step(2);
m_parentService.invoke(run);
}
}
- @AspectService(ranking = 10, added="added", removed="removed")
- public static class ServiceAspect1 implements ServiceInterface
- {
- @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect1)")
- protected Sequencer m_sequencer;
+ @AspectService(ranking = 10, added = "added", removed = "removed")
+ public static class ServiceAspect1 implements ServiceInterface {
+ @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect1)")
+ protected volatile Ensure m_sequencer;
// Injected by reflection.
private volatile ServiceInterface m_parentService;
@@ -179,40 +161,35 @@
void init() {
System.out.println("ServiceAspect1.init");
}
-
+
@Destroy
void destroy() {
System.out.println("ServiceAspect1.destroy");
}
- void added(ServiceInterface si)
- {
+ void added(ServiceInterface si) {
m_parentService = si;
}
-
+
@Stop
- void stop()
- {
+ void stop() {
m_sequencer.step(7);
}
-
- void removed(ServiceInterface si)
- {
+
+ void removed(ServiceInterface si) {
m_sequencer.step(8);
}
-
- public void invoke(Runnable run)
- {
+
+ public void invoke(Runnable run) {
m_sequencer.step(4);
m_parentService.invoke(run);
}
}
@Component
- public static class ServiceConsumer implements Runnable
- {
+ public static class ServiceConsumer implements Runnable {
@ServiceDependency(filter = "(name=AspectChainTest.ServiceConsumer)")
- protected Sequencer m_sequencer;
+ protected volatile Ensure m_sequencer;
@ServiceDependency
private volatile ServiceInterface m_service;
@@ -220,34 +197,26 @@
private Thread m_thread;
@Init
- public void init()
- {
+ public void init() {
m_thread = new Thread(this, "ServiceConsumer");
m_thread.start();
}
- public void run()
- {
+ public void run() {
m_sequencer.waitForStep(1, 2000);
- m_service.invoke(new Runnable()
- {
- public void run()
- {
+ m_service.invoke(new Runnable() {
+ public void run() {
m_sequencer.step(5);
}
});
}
-
+
@Destroy
- void destroy()
- {
+ void destroy() {
m_thread.interrupt();
- try
- {
+ try {
m_thread.join();
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
}
}
}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java
new file mode 100644
index 0000000..155578f
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java
@@ -0,0 +1,61 @@
+/*
+* 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.felix.dependencymanager.test2.integration.annotations;
+
+import org.apache.felix.dependencymanager.test2.components.Ensure;
+import org.apache.felix.dependencymanager.test2.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify Aspect Annotations usage.
+ */
+@RunWith(PaxExam.class)
+public class AspectAnnotationTest extends TestBase {
+ @Test
+ public void testAspectChain() throws Throwable {
+ Ensure e = new Ensure();
+ // Activate service consumer
+ ServiceRegistration scSequencer = register(e, "AspectChainTest.ServiceConsumer");
+ // Activate service provider
+ ServiceRegistration spSequencer = register(e, "AspectChainTest.ServiceProvider");
+ // Activate service aspect 2
+ ServiceRegistration sa2Sequencer = register(e, "AspectChainTest.ServiceAspect2");
+ // Activate service aspect 3
+ ServiceRegistration sa3Sequencer = register(e, "AspectChainTest.ServiceAspect3");
+ // Activate service aspect 1
+ ServiceRegistration sa1Sequencer = register(e, "AspectChainTest.ServiceAspect1");
+
+ e.step();
+ e.waitForStep(6, 10000);
+
+ // Deactivate service provider
+ spSequencer.unregister();
+ // Make sure that service aspect 1 has been called in ts removed and stop callbacks
+ e.waitForStep(8, 10000);
+ e.ensure();
+
+ scSequencer.unregister();
+ sa1Sequencer.unregister();
+ sa2Sequencer.unregister();
+ sa3Sequencer.unregister();
+ }
+}