Improve tests.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@765484 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/api/pom.xml b/ipojo/tests/api/pom.xml
index 6424e52..4d8faed 100644
--- a/ipojo/tests/api/pom.xml
+++ b/ipojo/tests/api/pom.xml
@@ -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>
diff --git a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/AppTest.java b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/AppTest.java
deleted file mode 100644
index fc6e827..0000000
--- a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/AppTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.apache.felix.ipojo.tests.api;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}
diff --git a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java
index e9f1aa1..e2b3128 100644
--- a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java
+++ b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/CompositeTest.java
@@ -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");
- }
diff --git a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java
index 66b9789..a0a3761 100644
--- a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java
+++ b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/PrimitiveComponentTest.java
@@ -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
diff --git a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java
index 7eb54c8..ecb9923 100644
--- a/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java
+++ b/ipojo/tests/api/src/test/java/org/apache/felix/ipojo/tests/api/SingletonComponentTest.java
@@ -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