You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2013/10/13 22:50:00 UTC
svn commit: r1531749 - in /felix/trunk/dependencymanager:
test/src/main/java/org/apache/felix/dm/test/bundle/annotation/composite/
test/src/test/java/org/apache/felix/dm/test/annotation/
test2/src/main/java/org/apache/felix/dependencymanager/test2/comp...
Author: pderop
Date: Sun Oct 13 20:49:59 2013
New Revision: 1531749
URL: http://svn.apache.org/r1531749
Log:
pax-exam 3.0.0 migration ...
Added:
felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/CompositeAnnotations.java
felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/CompositeAnnotationsTest.java
- copied, changed from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/CompositeAnnotationsTest.java
Removed:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/composite/
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/CompositeAnnotationsTest.java
Added: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/CompositeAnnotations.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/CompositeAnnotations.java?rev=1531749&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/CompositeAnnotations.java (added)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/CompositeAnnotations.java Sun Oct 13 20:49:59 2013
@@ -0,0 +1,181 @@
+/*
+ * 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.components;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Composition;
+import org.apache.felix.dm.annotation.api.Destroy;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.Registered;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.osgi.framework.ServiceRegistration;
+
+public class CompositeAnnotations {
+ public interface C1Service {
+ }
+
+ /**
+ * This service is also composed of the Component object.
+ */
+ @Component
+ public static class C1 implements C1Service {
+ /* We are composed of this object, which will also be injected with our dependencies */
+ private final C2 m_c2 = new C2();
+
+ /* This dependency filter will be configured from our init method */
+ @ServiceDependency(name = "D")
+ public volatile Runnable m_runnable;
+
+ /* Object used to check that methods are called in the proper sequence */
+ @ServiceDependency(filter = "(name=test.compositeAnnotation.c1)")
+ private volatile Ensure m_sequencer;
+
+ /**
+ * Dynamically configure our "D" dependency, using a dependency customization map
+ */
+ @Init
+ Map<String, String> init() {
+ m_sequencer.step(1);
+ // Configure a filter for our dependency whose name is "D"
+ Map<String, String> customization = new HashMap<String, String>();
+ customization.put("D.filter", "(foo=bar2)");
+ customization.put("D.required", "true");
+ return customization;
+ }
+
+ /**
+ * Return the list of object our service is composed of
+ */
+ @Composition
+ Object[] getComposition() {
+ return new Object[]{this, m_c2};
+ }
+
+ /**
+ * Our Service is starting, and our Composites will also be
+ */
+ @Start
+ void start() {
+ m_sequencer.step(3);
+ m_runnable.run(); /* step 4 */
+ // Our Component.start() method should be called once this method returns.
+ }
+
+ /**
+ * Our provided service has been registered into the OSGi service registry.
+ */
+ @Registered
+ void registered(ServiceRegistration sr) {
+ m_sequencer.step(7);
+ }
+
+ /**
+ * Our Service is stopping, and our Composites will also be
+ */
+ @Stop
+ void stop() {
+ m_sequencer.step(9);
+ // Our Component.stop() method should be called once this method returns.
+ }
+
+ /**
+ * Our Service is destroying, and our Composites will also be.
+ */
+ @Destroy
+ void destroy() {
+ m_sequencer.step(11);
+ // Our Component.destroy() method should be called once this method returns.
+ }
+ }
+
+ /**
+ * The CompositeService is also made up of this Class.
+ */
+ public static class C2 {
+ // Injected dependency (from CompositeService)
+ private volatile Ensure m_sequencer;
+
+ // Injected dependency (from CompositeService)
+ public volatile Runnable m_runnable;
+
+ // lifecycle callback (same method as the one from CompositeService)
+ void init() {
+ m_sequencer.step(2);
+ }
+
+ // lifecycle callback (same method as the one from CompositeService)
+ void start() {
+ m_sequencer.step(5);
+ m_runnable.run(); /* step 6 */
+ }
+
+ void registered(ServiceRegistration sr) {
+ if (sr == null) {
+ m_sequencer.throwable(new Exception("null service registration"));
+ }
+ m_sequencer.step(8);
+ }
+
+ // lifecycle callback (same method as the one from CompositeService)
+ void stop() {
+ m_sequencer.step(10);
+ }
+
+ // lifecycle callback (same method as the one from CompositeService)
+ void destroy() {
+ m_sequencer.step(12);
+ }
+ }
+
+ @Component(properties = @Property(name = "foo", value = "bar1"))
+ public static class Dependency1 implements Runnable {
+ @ServiceDependency(filter = "(name=test.compositeAnnotation.dependency1)")
+ volatile Ensure m_sequencer;
+
+ @Start
+ void start() {
+ System.out.println("Dependency1.start");
+ }
+
+ public void run() {
+ m_sequencer.step(Integer.MAX_VALUE); // Makes the test fail.
+ }
+ }
+
+ @Component(properties = @Property(name = "foo", value = "bar2"))
+ public static class Dependency2 implements Runnable {
+ @ServiceDependency(filter = "(name=test.compositeAnnotation.dependency2)")
+ volatile Ensure m_sequencer;
+
+ @Start
+ void start() {
+ System.out.println("Dependency2.start");
+ }
+
+ public void run() {
+ m_sequencer.step();
+ }
+ }
+}
Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/CompositeAnnotationsTest.java (from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/CompositeAnnotationsTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/CompositeAnnotationsTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/CompositeAnnotationsTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/CompositeAnnotationsTest.java&r1=1531247&r2=1531749&rev=1531749&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/CompositeAnnotationsTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/CompositeAnnotationsTest.java Sun Oct 13 20:49:59 2013
@@ -16,62 +16,31 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.annotation;
+package org.apache.felix.dependencymanager.test2.integration.annotations;
-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.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
+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.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;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
/**
* Use case: Verify Composite annotated services.
*/
-@RunWith(JUnit4TestRunner.class)
-public class CompositeAnnotationsTest 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, "CompositeAnnotationsTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.composite")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin;log=warn")
- .build()));
- }
-
+@RunWith(PaxExam.class)
+public class CompositeAnnotationsTest extends TestBase {
@Test
- public void testComposite(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer service to the "Component" service.
- m.add(makeSequencer(m, "C1"));
- m.add(makeSequencer(m, "Dependency1"));
- m.add(makeSequencer(m, "Dependency2"));
- // Check if the components have been initialized orderly
- m_ensure.waitForStep(4, 10000);
- // Stop the bundle
- stopBundle("CompositeAnnotationsTest", context);
- // And check if the components lifecycle callbacks are called orderly
- m_ensure.waitForStep(12, 10000);
+ public void testComposite() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr1 = register(e, "test.compositeAnnotation.c1");
+ ServiceRegistration sr2 = register(e, "test.compositeAnnotation.dependency1");
+ ServiceRegistration sr3 = register(e, "test.compositeAnnotation.dependency2");
+ e.waitForStep(4, 10000);
+ stopTestComponentsBundle();
+ e.waitForStep(12, 10000);
+ sr3.unregister();
+ sr2.unregister();
+ sr1.unregister();
}
}