felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1531748 - in /felix/trunk/dependencymanager: test/src/main/java/org/apache/felix/dm/test/bundle/annotation/bundledependency/ test/src/test/java/org/apache/felix/dm/test/annotation/ test2/src/main/java/org/apache/felix/dependencymanager/tes...
Date Sun, 13 Oct 2013 20:39:21 GMT
Author: pderop
Date: Sun Oct 13 20:39:21 2013
New Revision: 1531748

URL: http://svn.apache.org/r1531748
Log:
pax-exam 3.0.0 migration ...

Added:
    felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleDependencyAnnotation.java
    felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/BundleDependencyAnnotationTest.java
      - copied, changed from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java
Removed:
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/bundledependency/
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java

Added: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleDependencyAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleDependencyAnnotation.java?rev=1531748&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleDependencyAnnotation.java
(added)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleDependencyAnnotation.java
Sun Oct 13 20:39:21 2013
@@ -0,0 +1,163 @@
+/*
+* 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 org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.BundleAdapterService;
+import org.apache.felix.dm.annotation.api.BundleDependency;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Inject;
+import org.apache.felix.dm.annotation.api.Property;
+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.Bundle;
+import org.osgi.framework.BundleContext;
+
+public class BundleDependencyAnnotation {
+    public interface ServiceInterface extends Runnable {
+    }
+
+    /**
+     * Simple Consumer which has a BundleDependency dependency.
+     */
+    @Component
+    public static class Consumer {
+        protected volatile boolean m_added;
+        protected volatile boolean m_removed;
+
+        @ServiceDependency(filter = "(name=bundleDependencyTest.consumer)")
+        private volatile Ensure m_sequencer;
+
+        @BundleDependency(required = false, removed = "removed", filter = "(Bundle-SymbolicName=org.apache.felix.dependencymanager)")
+        public void add(Bundle b) {
+            if (b != null && b.getSymbolicName().equals("org.apache.felix.dependencymanager"))
{
+                m_added = true;
+            }
+        }
+
+        protected void removed(Bundle b) {
+            m_removed = true;
+        }
+
+        @Start
+        public void start() {
+            m_sequencer.step(1);
+        }
+
+        @Stop
+        public void stop() {
+            if (!m_added) {
+                throw new IllegalStateException("Did not get DependencyManager bundle");
+            }
+
+            if (!m_removed) {
+                throw new IllegalStateException("Did not remove DependencyManager bundle");
+            }
+            m_sequencer.step(2);
+        }
+    }
+
+    /**
+     * ServiceInterface Consumer.
+     */
+    @Component
+    public static class ServiceConsumer {
+        @ServiceDependency(filter = "(name=bundleDependencyTest.adapter)")
+        volatile Ensure m_sequencer;
+
+        @ServiceDependency
+        volatile ServiceInterface m_service;
+
+        @Start
+        void start() {
+            m_sequencer.step(2);
+            m_service.run();
+        }
+    }
+
+    /**
+     * A BundleAdapter test, which adapts the dependency manager bundle to the ServiceInterface
service.
+     */
+    @BundleAdapterService(filter = "(Bundle-SymbolicName=org.apache.felix.dependencymanager)",
stateMask = Bundle.INSTALLED
+            | Bundle.RESOLVED | Bundle.ACTIVE, propagate = true, properties = {@Property(name
= "foo", value = "bar")})
+    public static class ServiceProvider implements ServiceInterface {
+        // Adapted bundle (injected by reflection).
+        protected volatile Bundle m_bundle;
+
+        // Our Sequencer required dependency
+        @ServiceDependency(filter = "(name=bundleDependencyTest.adapter)")
+        volatile Ensure m_sequencer;
+
+        // Check auto config injections
+        @Inject
+        volatile BundleContext m_bc;
+        BundleContext m_bcNotInjected;
+
+        @Inject
+        volatile DependencyManager m_dm;
+        DependencyManager m_dmNotInjected;
+
+        @Inject
+        volatile org.apache.felix.dm.Component m_component;
+        org.apache.felix.dm.Component m_componentNotInjected;
+
+        @Start
+        void start() {
+            checkInjectedFields();
+            m_sequencer.step(1);
+        }
+
+        public void run() {
+            if (m_bundle == null || !m_bundle.getSymbolicName().equals("org.apache.felix.dependencymanager"))
{
+                throw new IllegalStateException("ServiceProvider did not get proper bundle:
" + m_bundle);
+            }
+            m_sequencer.step(3);
+        }
+
+        private void checkInjectedFields() {
+            if (m_bc == null) {
+                m_sequencer.throwable(new Exception("Bundle Context not injected"));
+                return;
+            }
+            if (m_bcNotInjected != null) {
+                m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
+                return;
+            }
+
+            if (m_dm == null) {
+                m_sequencer.throwable(new Exception("DependencyManager not injected"));
+                return;
+            }
+            if (m_dmNotInjected != null) {
+                m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
+                return;
+            }
+
+            if (m_component == null) {
+                m_sequencer.throwable(new Exception("Component not injected"));
+                return;
+            }
+            if (m_componentNotInjected != null) {
+                m_sequencer.throwable(new Exception("Component must not be injected"));
+                return;
+            }
+        }
+    }
+}

Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/BundleDependencyAnnotationTest.java
(from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/BundleDependencyAnnotationTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/BundleDependencyAnnotationTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java&r1=1531247&r2=1531748&rev=1531748&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java
(original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/BundleDependencyAnnotationTest.java
Sun Oct 13 20:39:21 2013
@@ -16,79 +16,43 @@
 * 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 java.util.Properties;
-
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+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 Bundle Dependency annotations usage.
  */
-@RunWith(JUnit4TestRunner.class)
-public class BundleDependencyAnnotationTest 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, "BundleDependencyTest")
-                    .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
-                    .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.bundledependency")
-                    .set("Import-Package", "*")
-                    .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
-                    .build()));           
-    }
-
+@RunWith(PaxExam.class)
+public class BundleDependencyAnnotationTest extends TestBase {
     /**
      * Tests a simple Consumer, which has a BundleDependency over the dependency manager
bundle.
-     * @param context
      */
     @Test
-    public void testBundleDependencyAnnotation(BundleContext context)
-    {
-        DependencyManager m = new DependencyManager(context);
-        Properties props = new Properties() {{ put("test", "consumer"); }};
-        m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(),
props));
-        m_ensure.waitForStep(1, 10000);
-        super.stopBundle("BundleDependencyTest", context);
-        m_ensure.waitForStep(2, 10000);
+    public void testBundleDependencyAnnotation() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, "bundleDependencyTest.consumer");        
+        e.waitForStep(1, 10000);
+        stopTestComponentsBundle();
+        e.waitForStep(2, 10000);
+        sr.unregister();
     }
-    
+
     /**
      * Tests a Bundle Adapter, which adapts the dependency manager bundle to a "ServiceInterface"
service.
-     * @param context
      * @throws Throwable 
      */
     @Test
-    public void testBundleAdapterServiceAnnotation(BundleContext context) throws Throwable
-    {
-        DependencyManager m = new DependencyManager(context);
-        Properties props = new Properties() {{ put("test", "adapter"); }};
-        m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(),
props));
-        m_ensure.waitForStep(3, 10000);
-        m_ensure.ensure();
-    }    
+    public void testBundleAdapterServiceAnnotation() throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, "bundleDependencyTest.adapter");        
+        e.waitForStep(3, 10000);
+        e.ensure();
+        sr.unregister();
+    }
 }



Mime
View raw message