You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2009/04/16 08:33:10 UTC

svn commit: r765484 - in /felix/trunk/ipojo/tests/api: ./ src/test/java/org/apache/felix/ipojo/tests/api/

Author: clement
Date: Thu Apr 16 06:33:10 2009
New Revision: 765484

URL: http://svn.apache.org/viewvc?rev=765484&view=rev
Log:
Improve tests.

Removed:
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/AppTest.java
Modified:
    felix/trunk/ipojo/tests/api/pom.xml
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java
    felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java

Modified: felix/trunk/ipojo/tests/api/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/pom.xml?rev=765484&r1=765483&r2=765484&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/api/pom.xml (original)
+++ felix/trunk/ipojo/tests/api/pom.xml Thu Apr 16 06:33:10 2009
@@ -17,6 +17,19 @@
 					<target>1.5</target>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.apache.servicemix.tooling</groupId>
+				<artifactId>depends-maven-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>generate-depends-file</id>
+						<goals>
+							<goal>generate-depends-file</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			
 			<!--  <plugin>
 				<groupId>org.ops4j.pax.exam</groupId>
 				<artifactId>maven-paxexam-plugin</artifactId>

Modified: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java?rev=765484&r1=765483&r2=765484&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java (original)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java Thu Apr 16 06:33:10 2009
@@ -32,7 +32,7 @@
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-
+import static org.ops4j.pax.exam.MavenUtils.*;
 
 
 @RunWith( JUnit4TestRunner.class )
@@ -61,9 +61,9 @@
     public static Option[] configure() {    
         Option[] opt =  options(
                 provision(
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version("1.3.0-SNAPSHOT"),
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.composite").version("1.3.0-SNAPSHOT"),
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version("1.3.0-SNAPSHOT")
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.composite").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version(asInProject())
                     )
                 );
         return opt;
@@ -143,9 +143,7 @@
            .addSubService(new InstantiatedService().setSpecification(Foo.class.getName()).setOptional(true));
        
        ComponentInstance ci = type.createInstance();
-       
-       System.out.println(ci.getInstanceDescription().getDescription());
-       
+              
        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
        
        // Stop prov
@@ -204,9 +202,7 @@
            .addSubService(new ImportedService().setSpecification(Foo.class.getName()).setOptional(true));
        
        ComponentInstance ci = type.createInstance();
-       
-       System.out.println(ci.getInstanceDescription().getDescription());
-       
+              
        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
        
        // Stop prov
@@ -236,8 +232,6 @@
        
        ComponentInstance ci = type.createInstance();
        
-       System.out.println(ci.getInstanceDescription().getDescription());
-
        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
        assertThat("c is valid", c.getState(), is(ComponentInstance.VALID));
        
@@ -271,14 +265,6 @@
         .addDependency(new Dependency().setField("myFoo"))
         .setValidateMethod("start");
     }
-    
-    private PrimitiveComponentType createAnOptionalConsumer() {
-        return new PrimitiveComponentType()
-        .setBundleContext(context)
-        .setClassName(org.example.service.impl.MyComponentImpl.class.getName())
-        .addDependency(new Dependency().setField("myFoo").setOptional(true))
-        .setValidateMethod("start");
-    }
 
 
 

Modified: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java?rev=765484&r1=765483&r2=765484&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java (original)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java Thu Apr 16 06:33:10 2009
@@ -3,14 +3,17 @@
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.nullValue;
-
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 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.MavenUtils.asInProject;
 
 import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
 import org.apache.felix.ipojo.api.Dependency;
 import org.apache.felix.ipojo.api.PrimitiveComponentType;
 import org.apache.felix.ipojo.api.Service;
@@ -56,65 +59,57 @@
     public static Option[] configure() {    
         Option[] opt =  options(
                 provision(
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version("1.3.0-SNAPSHOT"),
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version("1.3.0-SNAPSHOT")
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version(asInProject())
                     )
                 );
         return opt;
     }
 
     @Test
-    public void createAServiceProvider()
-    {
+    public void createAServiceProvider() throws Exception {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            PrimitiveComponentType type = createAProvider();
-            ci = type.createInstance();
-            assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
-            ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( notNullValue() ) );
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+
+        PrimitiveComponentType type = createAProvider();
+        ci = type.createInstance();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+
     }
     
     @Test
-    public void killTheFactory()
-    {
+    public void killTheFactory() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            PrimitiveComponentType type = createAProvider();
-            ci = type.createInstance();
-            assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
-            ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( notNullValue() ) );
-            type.stop();
-            assertThat("Ci is disposed", ci.getState(), is(ComponentInstance.DISPOSED));
-            ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( nullValue() ) );
-            
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+
+        PrimitiveComponentType type = createAProvider();
+        ci = type.createInstance();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+        type.stop();
+        assertThat("Ci is disposed", ci.getState(),
+                is(ComponentInstance.DISPOSED));
+        ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci
+                .getInstanceName());
+        assertThat(ref, is(nullValue()));
+
     }
     
     @Test
-    public void createAServiceCons()
-    {
+    public void createAServiceCons() throws Exception {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            PrimitiveComponentType type = createAConsumer();
-            ci = type.createInstance();
-            assertThat("Ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+
+        PrimitiveComponentType type = createAConsumer();
+        ci = type.createInstance();
+        assertThat("Ci is invalid", ci.getState(),
+                is(ComponentInstance.INVALID));
+
     }
     
     @Test

Modified: felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java?rev=765484&r1=765483&r2=765484&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java (original)
+++ felix/trunk/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java Thu Apr 16 06:33:10 2009
@@ -10,6 +10,9 @@
 import static org.ops4j.pax.exam.CoreOptions.provision;
 
 import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
 import org.apache.felix.ipojo.api.Dependency;
 import org.apache.felix.ipojo.api.PrimitiveComponentType;
 import org.apache.felix.ipojo.api.Service;
@@ -28,7 +31,7 @@
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-
+import static org.ops4j.pax.exam.MavenUtils.*;
 
 
 @RunWith( JUnit4TestRunner.class )
@@ -57,65 +60,56 @@
     public static Option[] configure() {    
         Option[] opt =  options(
                 provision(
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version("1.3.0-SNAPSHOT"),
-                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version("1.3.0-SNAPSHOT")
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
+                        mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.api").version(asInProject())
                     )
                 );
         return opt;
     }
 
     @Test
-    public void createAServiceProvider()
+    public void createAServiceProvider() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException
     {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            SingletonComponentType type = createAProvider();
-            ci = type.create();
-            assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
-            ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( notNullValue() ) );
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+
+        SingletonComponentType type = createAProvider();
+        ci = type.create();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+
     }
     
     @Test
-    public void killTheFactory()
-    {
+    public void killTheFactory() throws Exception {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            SingletonComponentType type = createAProvider();
-            ci = type.create();
-            assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
-            ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( notNullValue() ) );
-            type.stop();
-            assertThat("Ci is disposed", ci.getState(), is(ComponentInstance.DISPOSED));
-            ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
-            assertThat( ref, is( nullValue() ) );
-            
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+        SingletonComponentType type = createAProvider();
+        ci = type.create();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojo.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+        type.stop();
+        assertThat("Ci is disposed", ci.getState(),
+                is(ComponentInstance.DISPOSED));
+        ref = ipojo.getServiceReferenceByName(Foo.class.getName(), ci
+                .getInstanceName());
+        assertThat(ref, is(nullValue()));
     }
     
     @Test
-    public void createAServiceCons()
-    {
+    public void createAServiceCons() throws Exception {
         assertThat( context, is( notNullValue() ) );
         ComponentInstance ci = null;
-        
-        try {
-            SingletonComponentType type = createAConsumer();
-            ci = type.create();
-            assertThat("Ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
-        } catch (Exception e) {
-            fail(e.getMessage());
-        }
+
+        SingletonComponentType type = createAConsumer();
+        ci = type.create();
+        assertThat("Ci is invalid", ci.getState(),
+                is(ComponentInstance.INVALID));
+
     }
     
     @Test