felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r882937 - in /felix/trunk/dependencymanager: ./ src/test/java/org/apache/felix/dependencymanager/test/
Date Sat, 21 Nov 2009 16:27:06 GMT
Author: marrs
Date: Sat Nov 21 16:27:05 2009
New Revision: 882937

URL: http://svn.apache.org/viewvc?rev=882937&view=rev
Log:
Added the first set of integration tests based on Pax Exam.

Added:
    felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/
    felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
    felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
    felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
Modified:
    felix/trunk/dependencymanager/pom.xml

Modified: felix/trunk/dependencymanager/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/pom.xml?rev=882937&r1=882936&r2=882937&view=diff
==============================================================================
--- felix/trunk/dependencymanager/pom.xml (original)
+++ felix/trunk/dependencymanager/pom.xml Sat Nov 21 16:27:05 2009
@@ -1,23 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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
+  <!--
+    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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <groupId>org.apache.felix</groupId>
     <artifactId>felix</artifactId>
@@ -42,6 +40,27 @@
       <version>1.2.0</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-default</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.7</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -54,16 +73,41 @@
           <instructions>
             <Bundle-SymbolicName>org.apache.felix.dependencymanager</Bundle-SymbolicName>
             <Bundle-Name>Apache Felix Dependency Manager</Bundle-Name>
-            <Bundle-Description>A bundle that provides a run-time service dependency
manager.</Bundle-Description>
+            <Bundle-Description>A bundle that provides a run-time
+              service dependency manager.</Bundle-Description>
             <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
             <Export-Package>org.apache.felix.dependencymanager</Export-Package>
             <Import-Package>!org.apache.felix.dependencymanager,*</Import-Package>
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <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>
+        <version>1.2.0</version>
+        <executions>
+          <execution>
+            <id>generate-config</id>
+            <goals>
+              <goal>generate-depends-file</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
-
   <scm>
     <connection>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.dependencymanager-3.0.0</connection>
     <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.dependencymanager-3.0.0</developerConnection>

Added: felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java?rev=882937&view=auto
==============================================================================
--- felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
(added)
+++ felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
Sat Nov 21 16:27:05 2009
@@ -0,0 +1,95 @@
+package org.apache.felix.dependencymanager.test;
+
+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 org.apache.felix.dependencymanager.DependencyManager;
+import org.apache.felix.dependencymanager.Logger;
+import org.apache.felix.dependencymanager.Service;
+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;
+
+@RunWith( JUnit4TestRunner.class )
+public class ComponentLifeCycleTest {
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+            provision(
+                mavenBundle().groupId("org.apache.felix").artifactId("org.osgi.compendium").versionAsInProject(),
+                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+            )
+        );
+    }    
+    
+    @Test
+    public void testComponentLifeCycleCallbacks(BundleContext context) {
+        DependencyManager m = new DependencyManager(context, new Logger(context));
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a simple service component
+        Service s = m.createService().setImplementation(new ComponentInstance(e));
+        // add it, and since it has no dependencies, it should be activated immediately
+        m.add(s);
+        // remove it so it gets destroyed
+        m.remove(s);
+        // ensure we executed all steps inside the component instance
+        e.step(6);
+        
+        // helper class that ensures certain steps get executed in sequence
+        e = new Ensure();
+        // create a simple service component
+        s = m.createService().setImplementation(new CustomComponentInstance(e)).setCallbacks("a",
"b", "c", "d");
+        // add it, and since it has no dependencies, it should be activated immediately
+        m.add(s);
+        // remove it so it gets destroyed
+        m.remove(s);
+        // ensure we executed all steps inside the component instance
+        e.step(6);
+    }
+    
+}
+
+class ComponentInstance {
+    private final Ensure m_ensure;
+    public ComponentInstance(Ensure e) {
+        m_ensure = e;
+        m_ensure.step(1);
+    }
+    public void init() {
+        m_ensure.step(2);
+    }
+    public void start() {
+        m_ensure.step(3);
+    }
+    public void stop() {
+        m_ensure.step(4);
+    }
+    public void destroy() {
+        m_ensure.step(5);
+    }
+}
+
+class CustomComponentInstance {
+    private final Ensure m_ensure;
+    public CustomComponentInstance(Ensure e) {
+        m_ensure = e;
+        m_ensure.step(1);
+    }
+    public void a() {
+        m_ensure.step(2);
+    }
+    public void b() {
+        m_ensure.step(3);
+    }
+    public void c() {
+        m_ensure.step(4);
+    }
+    public void d() {
+        m_ensure.step(5);
+    }
+}

Added: felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java?rev=882937&view=auto
==============================================================================
--- felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
(added)
+++ felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/Ensure.java
Sat Nov 21 16:27:05 2009
@@ -0,0 +1,11 @@
+package org.apache.felix.dependencymanager.test;
+
+import junit.framework.Assert;
+
+public class Ensure {
+    int step = 1;
+    public synchronized void step(int nr) {
+        Assert.assertEquals(nr, step);
+        step++;
+    }
+}

Added: felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java?rev=882937&view=auto
==============================================================================
--- felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
(added)
+++ felix/trunk/dependencymanager/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
Sat Nov 21 16:27:05 2009
@@ -0,0 +1,76 @@
+package org.apache.felix.dependencymanager.test;
+
+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 org.apache.felix.dependencymanager.DependencyManager;
+import org.apache.felix.dependencymanager.Logger;
+import org.apache.felix.dependencymanager.Service;
+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;
+
+@RunWith( JUnit4TestRunner.class )
+public class ServiceDependencyTest {
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+            provision(
+                mavenBundle().groupId("org.apache.felix").artifactId("org.osgi.compendium").versionAsInProject(),
+                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+            )
+        );
+    }    
+
+    @Test
+    public void testServiceRegistrationAndConsumption(BundleContext context) {
+        DependencyManager m = new DependencyManager(context, new Logger(context));
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a service provider and consumer
+        Service sp = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(),
null);
+        Service sc = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+        m.add(sp);
+        m.add(sc);
+        m.remove(sp);
+        m.remove(sc);
+        // ensure we executed all steps inside the component instance
+        e.step(4);
+    }
+}
+
+interface ServiceInterface {
+    public void invoke();
+}
+
+class ServiceProvider implements ServiceInterface {
+    private final Ensure m_ensure;
+    public ServiceProvider(Ensure e) {
+        m_ensure = e;
+    }
+    public void invoke() {
+        m_ensure.step(2);
+    }
+}
+
+class ServiceConsumer {
+    private volatile ServiceInterface m_service;
+    private final Ensure m_ensure;
+
+    public ServiceConsumer(Ensure e) {
+        m_ensure = e;
+    }
+    
+    public void start() {
+        m_ensure.step(1);
+        m_service.invoke();
+    }
+    
+    public void stop() {
+        m_ensure.step(3);
+    }
+}



Mime
View raw message