Refactor tests
Add TIME_FACTOR to invoker
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1479322 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/pom.xml b/ipojo/runtime/core-it/pom.xml
index 9cc5722..800ebf6 100644
--- a/ipojo/runtime/core-it/pom.xml
+++ b/ipojo/runtime/core-it/pom.xml
@@ -87,6 +87,9 @@
<properties>
<exam.version>3.0.1</exam.version>
<url.version>1.5.1</url.version>
+
+
+
</properties>
<dependencies>
@@ -194,7 +197,7 @@
<dependency>
<groupId>org.ow2.chameleon.testing</groupId>
<artifactId>osgi-helpers</artifactId>
- <version>0.6.0</version>
+ <version>0.6.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
@@ -373,6 +376,10 @@
<goal>test</goal>
</goals>
<cloneClean>true</cloneClean>
+ <environmentVariables>
+ <!-- TIME_FACTOR can be set from the command line with -DTIME_FACTOR=9-->
+ <TIME_FACTOR>${TIME_FACTOR}</TIME_FACTOR>
+ </environmentVariables>
</configuration>
<executions>
<execution>
@@ -411,6 +418,10 @@
<goal>test</goal>
</goals>
<cloneClean>true</cloneClean>
+ <environmentVariables>
+ <!-- TIME_FACTOR can be set from the command line with -DTIME_FACTOR=9-->
+ <TIME_FACTOR>${TIME_FACTOR}</TIME_FACTOR>
+ </environmentVariables>
</configuration>
<executions>
<execution>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
index 9c5e78f..ea3cc98 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/Common.java
@@ -39,6 +39,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.BaseTest;
import org.ow2.chameleon.testing.helpers.IPOJOHelper;
import org.ow2.chameleon.testing.helpers.OSGiHelper;
import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
@@ -58,61 +59,13 @@
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- eventadmin(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- osgiHelper.dispose();
- ipojoHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
+ @Override
+ protected Option[] getCustomOptions() {
+ return new Option[] {
+ eventadmin()
+ };
}
public CompositeOption eventadmin() {
@@ -122,129 +75,4 @@
"1.8.0").versionAsInProject());
}
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) { return bundle(out.toURI().toURL().toExternalForm()); }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- for (Bundle bundle : bc.getBundles()) {
- System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
- }
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestAggregateDependency.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestAggregateDependency.java
index 674ced1..9172c4b 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestAggregateDependency.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestAggregateDependency.java
@@ -32,7 +32,8 @@
@Before
public void setUp() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.AggregateDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components" +
+ ".AggregateDependency");
deps = meta.getElements("requires");
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestArchitecture.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestArchitecture.java
index fc57485..0eab45e 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestArchitecture.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestArchitecture.java
@@ -29,7 +29,7 @@
@Test
public void testArch() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components" +
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components" +
".Arch");
String arch = meta.getAttribute("architecture");
assertNotNull("Architecture exists ", arch);
@@ -38,7 +38,7 @@
@Test
public void testNoArch() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components" +
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components" +
".NoArch");
String arch = meta.getAttribute("architecture");
assertNotNull("Architecture exists ", arch);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestCustomAnnotations.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestCustomAnnotations.java
index da40c48..5cd3368 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestCustomAnnotations.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestCustomAnnotations.java
@@ -33,14 +33,14 @@
@Test
public void testThatCustomAnnotationAreCorrectlyAdded() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.CustomAnnotationWithEnum");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.CustomAnnotationWithEnum");
Element[] ann = meta.getElements("IPOJOFoo", "foo.ipojo");
assertNotNull("Annotation exists ", ann);
}
@Test
public void testThatCustomAnnotationAreSupportingEnums() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.CustomAnnotationWithEnum");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.CustomAnnotationWithEnum");
Element[] ann = meta.getElements("IPOJOFoo", "foo.ipojo");
assertNotNull("Annotation exists ", ann);
Element element = ann[0];
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
index afd3c08..aa3be4d 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
@@ -30,7 +30,7 @@
@Test
public void testDependencyDeclaration() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Dependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Dependency");
Element[] deps = meta.getElements("requires");
// Check fs
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
index 9d13a56..b9af5aa 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependencyPolicy.java
@@ -32,7 +32,7 @@
@Before
public void setUp() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.PolicyDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.PolicyDependency");
deps = meta.getElements("requires");
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestEventAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestEventAdmin.java
index 5432835..acad7e8 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestEventAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestEventAdmin.java
@@ -41,9 +41,9 @@
@Before
public void setUp() {
- component = ipojoHelper.getMetadata(testedBundle, type);
- componentDeprecated = ipojoHelper.getMetadata(testedBundle, deprecated);
- componentWithPublishes = ipojoHelper.getMetadata(testedBundle, publishes);
+ component = ipojoHelper.getMetadata(getTestBundle(), type);
+ componentDeprecated = ipojoHelper.getMetadata(getTestBundle(), deprecated);
+ componentWithPublishes = ipojoHelper.getMetadata(getTestBundle(), publishes);
assertNotNull("Check component", component);
assertNotNull("Check deprecated", componentDeprecated);
assertNotNull("Check publishes", componentWithPublishes);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestExtender.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestExtender.java
index 2694650..62ca1b1 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestExtender.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestExtender.java
@@ -33,7 +33,7 @@
@Test
public void testMetadata() {
- Element meta = ipojoHelper.getMetadata(testedBundle, type);
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), type);
assertNotNull("Check meta", meta);
Element[] ext = meta.getElements("extender", namespace);
assertEquals("Check size", 1, ext.length);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFactory.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFactory.java
index 6d195ae..c003138 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFactory.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFactory.java
@@ -31,7 +31,7 @@
@Test
public void testArchDeprecated() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FactoryDeprecated");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FactoryDeprecated");
String fact = meta.getAttribute("public");
String name = meta.getAttribute("name");
assertNotNull("Factory exists ", fact);
@@ -42,7 +42,7 @@
@Test
public void testArch() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Factory");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Factory");
String fact = meta.getAttribute("public");
String name = meta.getAttribute("name");
assertNotNull("Factory exists ", fact);
@@ -53,7 +53,7 @@
@Test
public void testNoArch() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.NoFactory");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.NoFactory");
String fact = meta.getAttribute("public");
String name = meta.getAttribute("name");
assertNotNull("Factory exists ", fact);
@@ -64,7 +64,7 @@
@Test
public void testFactoryMethod() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethod");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethod");
String method = meta.getAttribute("factory-method");
assertNotNull("Method exists ", method);
assertEquals("Method value", "create", method);
@@ -72,7 +72,7 @@
@Test
public void testFactoryMethodDeprecated() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethodDeprecated");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethodDeprecated");
String method = meta.getAttribute("factory-method");
assertNotNull("Method exists ", method);
assertEquals("Method value", "create", method);
@@ -80,7 +80,7 @@
@Test
public void testVersion() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ComponentTypeVersion");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ComponentTypeVersion");
String version = meta.getAttribute("version");
assertNotNull("Version exist", version);
assertEquals("Version value", "1.0.0", version);
@@ -88,7 +88,7 @@
@Test
public void testNoVersion() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethod");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FactoryMethod");
String version = meta.getAttribute("version");
assertNull("No Version", version);
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFilteredDependency.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFilteredDependency.java
index 9a30ff7..27aee56 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFilteredDependency.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestFilteredDependency.java
@@ -35,10 +35,10 @@
@Before
public void setUp() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FilteredDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FilteredDependency");
deps = meta.getElements("requires");
- Element meta2 = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.FromDependency");
+ Element meta2 = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.FromDependency");
froms = meta2.getElements("requires");
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiate.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiate.java
index 2fbb0ee..aed4e25 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiate.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestInstantiate.java
@@ -39,7 +39,7 @@
@Test
public void testInstantiateSimple() {
- Element[] meta = getInstanceMetadata(testedBundle,
+ Element[] meta = getInstanceMetadata(getTestBundle(),
"org.apache.felix.ipojo.runtime.core.test" +
".components" +
".InstantiateSimple");
@@ -52,7 +52,7 @@
@Test
public void testInstantiateWithName() {
// Check instance tag
- Element[] meta = getInstanceMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components" +
+ Element[] meta = getInstanceMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components" +
".InstantiateWithName");
assertNotNull(meta);
assertEquals(1, meta.length);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestJMX.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestJMX.java
index 71bdafa..074a600 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestJMX.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestJMX.java
@@ -30,7 +30,7 @@
@Test
public void testDeprecated() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.jmx.JMXDeprecated");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.jmx.JMXDeprecated");
/*
* org.apache.felix.ipojo.handlers.jmx:config domain="my-domain" usesmosgi="false"
org.apache.felix.ipojo.handlers.jmx:property field="m_foo" name="prop" rights="w" notification="true"
@@ -57,7 +57,7 @@
@Test
public void test() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.jmx.JMXSimple");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.jmx.JMXSimple");
/*
* org.apache.felix.ipojo.handlers.jmx:config domain="my-domain" usesmosgi="false"
org.apache.felix.ipojo.handlers.jmx:property field="m_foo" name="prop" rights="w" notification="true"
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleCallbacks.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleCallbacks.java
index 158a8d2..458e708 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleCallbacks.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleCallbacks.java
@@ -31,7 +31,7 @@
@Test
public void testCallbacks() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Lifecycle");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Lifecycle");
Element[] cbs = meta.getElements("callback");
assertNotNull("Callbacks exists ", cbs);
assertEquals("Callbacks count ", 2, cbs.length);
@@ -47,14 +47,14 @@
@Test
public void testImmediate() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Immediate");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Immediate");
assertNotNull("Immediate attribute", meta.getAttribute("immediate"));
assertEquals("Immediate attribute value", "true", meta.getAttribute("immediate"));
}
@Test
public void testNoImmediate() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.NoImmediate");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.NoImmediate");
assertNotNull("Immediate attribute", meta.getAttribute("immediate"));
assertEquals("Immediate attribute value", "false", meta.getAttribute("immediate"));
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleController.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleController.java
index 6650157..928ecf4 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleController.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestLifecycleController.java
@@ -29,7 +29,7 @@
@Test
public void testLFC() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Lifecycle");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Lifecycle");
Element[] ctrls = meta.getElements("controller");
assertNotNull("Controller exists ", ctrls);
Element ctrl = ctrls[0];
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestOptionalDependency.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestOptionalDependency.java
index e0f444b..0a58108 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestOptionalDependency.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestOptionalDependency.java
@@ -34,7 +34,7 @@
@Before
public void setUp() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.OptionalDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.OptionalDependency");
deps = meta.getElements("requires");
}
@@ -89,7 +89,7 @@
@Test
public void testNullable() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.NullableDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.NullableDependency");
Element[] deps = meta.getElements("requires");
Element fs = getDependencyById(deps, "fs");
String nullable = fs.getAttribute("nullable");
@@ -99,7 +99,7 @@
@Test
public void testNoNullable() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.NullableDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.NullableDependency");
Element[] deps = meta.getElements("requires");
Element fs = getDependencyById(deps, "fs2");
String nullable = fs.getAttribute("nullable");
@@ -109,7 +109,7 @@
@Test
public void testDefaultImplementation() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.DefaultImplementationDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.DefaultImplementationDependency");
Element[] deps = meta.getElements("requires");
Element fs = getDependencyById(deps, "fs");
String di = fs.getAttribute("default-implementation");
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestProperties.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestProperties.java
index 898439f..3f54706 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestProperties.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestProperties.java
@@ -28,7 +28,7 @@
@Test
public void testProperties() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Properties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Properties");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -62,7 +62,7 @@
@Test
public void testAbsentPropagation() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Properties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Properties");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -72,7 +72,7 @@
@Test
public void testPropagation() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Propagation");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Propagation");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -83,7 +83,7 @@
@Test
public void testNoPropagation() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.NoPropagation");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.NoPropagation");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -94,7 +94,7 @@
@Test
public void testPID() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ManagedServicePID");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ManagedServicePID");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -105,7 +105,7 @@
@Test
public void testAbsentPID() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.Properties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Properties");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -115,7 +115,7 @@
@Test
public void testPropagationAndPID() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.PropagationandPID");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.PropagationandPID");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -129,7 +129,7 @@
@Test
public void testPIDAndPropagation() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.PIDandPropagation");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.PIDandPropagation");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -143,7 +143,7 @@
@Test
public void testUpdatedAndPID() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.UpdatedWithManagedService");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.UpdatedWithManagedService");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
@@ -158,7 +158,7 @@
@Test
public void testUpdatedAndProperties() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.UpdatedWithProperties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.UpdatedWithProperties");
Element[] provs = meta.getElements("properties");
assertNotNull("Properties exists ", provs);
Element prov = provs[0];
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestRankedDependency.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestRankedDependency.java
index acd24a4..b1fa4c7 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestRankedDependency.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestRankedDependency.java
@@ -33,7 +33,7 @@
@Before
public void setUp() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.RankedDependency");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.RankedDependency");
deps = meta.getElements("requires");
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestServiceProdiving.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestServiceProdiving.java
index e03c020..14d2f4f 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestServiceProdiving.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestServiceProdiving.java
@@ -33,21 +33,21 @@
@Test
public void testProvidesSimple() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesSimple");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesSimple");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
}
@Test
public void testProvidesDouble() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesDouble");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesDouble");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
}
@Test
public void testProvidesTriple() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesTriple");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesTriple");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
Element prov = provs[0];
@@ -58,7 +58,7 @@
@Test
public void testProvidesQuatro() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesQuatro");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesQuatro");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
Element prov = provs[0];
@@ -70,7 +70,7 @@
@Test
public void testProperties() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesProperties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesProperties");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
Element prov = provs[0];
@@ -101,7 +101,7 @@
@Test
public void testStaticProperties() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.ProvidesStaticProperties");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.ProvidesStaticProperties");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
Element prov = provs[0];
@@ -149,7 +149,7 @@
@Test
public void testServiceController() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.PSServiceController");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.PSServiceController");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
System.out.println(provs[0].toString());
@@ -160,7 +160,7 @@
@Test
public void testServiceControllerWithSpecification() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.PSServiceControllerSpec");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.PSServiceControllerSpec");
Element[] provs = meta.getElements("provides");
assertNotNull("Provides exists ", provs);
System.out.println(provs[0].toString());
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestTemporalDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestTemporalDependencies.java
index be75c38..31dc546 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestTemporalDependencies.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestTemporalDependencies.java
@@ -31,7 +31,7 @@
@Test
public void testSimple() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalSimple");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalSimple");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -45,7 +45,7 @@
@Test
public void testTemporal() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.Temporal");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.Temporal");
Element[] provs = meta.getElements("temporal", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -59,7 +59,7 @@
@Test
public void testDI() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithDI");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithDI");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -73,7 +73,7 @@
@Test
public void testEmptyArray() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithEmptyArray");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithEmptyArray");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -87,7 +87,7 @@
@Test
public void testNull() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithNull");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithNull");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -101,7 +101,7 @@
@Test
public void testNullable() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithNullable");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithNullable");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -115,7 +115,7 @@
@Test
public void testFilter() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithFilter");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithFilter");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -129,7 +129,7 @@
@Test
public void testTimeout() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithTimeout");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalWithTimeout");
Element[] provs = meta.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
assertNotNull("Temporal exists ", provs);
String field = provs[0].getAttribute("field");
@@ -143,7 +143,7 @@
@Test
public void testSimpleCollection() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
Element dep = getElementPerField(meta, "fs1");
String spec = dep.getAttribute("specification");
assertNotNull("Specification not null", spec);
@@ -152,7 +152,7 @@
@Test
public void testCollectionWithTimeout() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
Element dep = getElementPerField(meta, "fs2");
String spec = dep.getAttribute("specification");
assertNotNull("Specification not null", spec);
@@ -163,7 +163,7 @@
@Test
public void testCollectionWithPolicy() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
Element dep = getElementPerField(meta, "fs3");
String spec = dep.getAttribute("specification");
assertNotNull("Specification not null", spec);
@@ -174,7 +174,7 @@
@Test
public void testCollectionWithProxy() {
- Element meta = ipojoHelper.getMetadata(testedBundle, "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.temporal.TemporalCollection");
Element dep = getElementPerField(meta, "fs4");
String spec = dep.getAttribute("specification");
assertNotNull("Specification not null", spec);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestWhiteBoard.java b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestWhiteBoard.java
index 6a46c98..097ba9c 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestWhiteBoard.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestWhiteBoard.java
@@ -36,7 +36,7 @@
@Test
public void testMetadataWithOnModification() {
- Element meta = ipojoHelper.getMetadata(testedBundle, typeWI);
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), typeWI);
assertNotNull("Check meta", meta);
Element[] ext = meta.getElements("wbp", namespace);
assertEquals("Check size", 1, ext.length);
@@ -55,7 +55,7 @@
@Test
public void testMetadataWithoutOnModification() {
- Element meta = ipojoHelper.getMetadata(testedBundle, typeWO);
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), typeWO);
assertNotNull("Check meta", meta);
Element[] ext = meta.getElements("wbp", namespace);
assertEquals("Check size", 1, ext.length);
@@ -74,7 +74,7 @@
@Test
public void testWhiteboards() {
- Element meta = ipojoHelper.getMetadata(testedBundle, typeWhiteboards);
+ Element meta = ipojoHelper.getMetadata(getTestBundle(), typeWhiteboards);
assertNotNull("Check meta", meta);
Element[] ext = meta.getElements("whiteboards", namespace);
assertEquals("Check size", 1, ext.length);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index 551970a..ce43d70 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,230 +19,41 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.apache.felix.ipojo.runtime.core.components.*;
-import org.apache.felix.ipojo.runtime.core.services.CheckService;
-import org.apache.felix.ipojo.runtime.core.services.FooService;
import org.junit.After;
import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.ow2.chameleon.testing.helpers.BaseTest;
+import org.ow2.chameleon.testing.helpers.ConfigAdminHelper;
+import org.ow2.chameleon.testing.helpers.TimeUtils;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+public class Common extends BaseTest {
-import static org.ops4j.pax.exam.CoreOptions.*;
+ public static int UPDATE_WAIT_TIME = 2000;
-/**
- * Bootstrap the test from this project
- */
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+ public ConfigAdminHelper caHelper = null;
- public static long UPDATE_WAIT_TIME = 2000;
+ public ConfigurationAdmin admin;
- @Inject
- BundleContext bc;
+ public void grace() {
+ TimeUtils.grace(UPDATE_WAIT_TIME);
+ }
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
+ @Override
+ public boolean deployConfigAdmin() {
+ return true;
}
@Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- public Bundle getTestBundle() {
- return osgiHelper.getBundle("test.bundle");
+ public void initializeConfigAdmin() {
+ caHelper = new ConfigAdminHelper(bc);
+ admin = caHelper.getConfigurationAdmin();
+ caHelper.deleteAllConfigurations();
}
@After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
+ public void stoppingConfigAdmin() {
+ caHelper.deleteAllConfigurations();
+ caHelper.dispose();
}
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject());
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (Bundle bundle : bundles) {
- stability = stability && (bundle.getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- public boolean isKF() {
- return bc.getClass().toString().contains("knopflerfish");
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java
deleted file mode 100644
index 8f761cb..0000000
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.ipojo.runtime.core;
-
-import junit.framework.Assert;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationEvent;
-import org.osgi.service.cm.ConfigurationListener;
-
-public class ConfigurationMonitor implements ConfigurationListener {
-
- private String waitForEvent;
- private boolean detected;
- private ServiceRegistration reg;
-
- public synchronized void configurationEvent(ConfigurationEvent arg0) {
- System.out.println(arg0.getPid() + " reconfiguration received");
- if (waitForEvent != null) {
- if (arg0.getPid().equals(waitForEvent)) {
- this.detected = true;
- }
- }
- }
-
- public ConfigurationMonitor(BundleContext bc) {
- reg = bc.registerService(ConfigurationListener.class.getName(), this, null);
- }
-
- public void stop() {
- reg.unregister();
- reg = null;
- }
-
- public void waitForEvent(String pid, String mes) {
- waitForEvent = pid;
- detected = false;
- long begin = System.currentTimeMillis();
- long duration = 0;
- while( ! this.detected) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- // Interrupted
- }
- long end = System.currentTimeMillis();
- duration = end - begin;
- if (duration > 10000) {
- Assert.fail(mes + " -> Timeout when waiting for a reconfiguration of " + pid);
- }
- }
- System.out.println("Reconfiguration detected of " + pid);
- waitForEvent = null;
- detected = false;
- }
-
-}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java
index 72097b1..8e1e346 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java
@@ -23,60 +23,26 @@
import org.apache.felix.ipojo.PrimitiveInstanceDescription;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.runtime.core.services.FooService;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
import java.io.IOException;
import java.util.Dictionary;
import java.util.Properties;
import static junit.framework.Assert.assertEquals;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
public class TestManagedServiceFactoryTestForImmediate extends Common {
private ComponentFactory factory;
- private ConfigurationAdmin admin;
@Before
public void setUp() {
factory = (ComponentFactory) ipojoHelper.getFactory("CA-ImmConfigurableProvider");
- admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
- assertNotNull("Check configuration admin availability", admin);
- try {
- Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @After
- public void tearDown() {
- try {
- Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
- admin = null;
-
-
}
@Test
@@ -102,11 +68,7 @@
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
@@ -128,7 +90,7 @@
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -145,7 +107,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -179,11 +141,7 @@
System.out.println("PID : " + pid);
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
@@ -195,7 +153,7 @@
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -217,7 +175,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -250,11 +208,7 @@
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
@@ -262,11 +216,7 @@
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
// The instance should be created, wait for the architecture service
@@ -289,7 +239,7 @@
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -307,7 +257,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -341,22 +291,14 @@
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
factory.start();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
// The instance should be created, wait for the architecture service
@@ -369,7 +311,7 @@
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -391,7 +333,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java
index b2cb1c5..11865c8 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java
@@ -23,13 +23,10 @@
import org.apache.felix.ipojo.PrimitiveInstanceDescription;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.runtime.core.services.FooService;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
import java.io.IOException;
import java.util.Dictionary;
@@ -41,40 +38,10 @@
public class TestManagedServiceFactoryTestForServices extends Common {
private ComponentFactory factory;
- private ConfigurationAdmin admin;
@Before
public void setUp() {
factory = (ComponentFactory) ipojoHelper.getFactory("CA-ConfigurableProvider");
- admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
- assertNotNull("Check configuration admin availability", admin);
- try {
- Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
- }
-
- @After
- public void tearDown() {
- try {
- Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
- admin = null;
-
-
}
@Test
@@ -124,12 +91,7 @@
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
-
+ grace();
Dictionary p2 = configuration.getProperties();
p2.put("message", "message2");
@@ -138,7 +100,7 @@
configuration.update(p2);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -157,7 +119,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -196,17 +158,13 @@
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -228,7 +186,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -284,11 +242,7 @@
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
System.out.println("===");
@@ -296,7 +250,7 @@
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -315,7 +269,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -361,17 +315,13 @@
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -393,7 +343,7 @@
try {
configuration.delete();
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
index b130c14..f793a59 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
@@ -24,10 +24,8 @@
import org.apache.felix.ipojo.PrimitiveInstanceDescription;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.runtime.core.services.FooService;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -47,37 +45,9 @@
private ComponentFactory factImm;
- private ConfigurationAdmin admin;
-
- ConfigurationMonitor listener;
-
@Before
public void setUp() throws InterruptedException {
factImm = (ComponentFactory) ipojoHelper.getFactory(factNameImm);
- admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
- assertNotNull("Check configuration admin availability", admin);
- cleanConfigurationAdmin();
- listener = new ConfigurationMonitor(bc);
- }
-
- @After
- public void tearDown() {
- listener.stop();
- cleanConfigurationAdmin();
- admin = null;
- }
-
- private void cleanConfigurationAdmin() {
- try {
- Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
}
@Test
@@ -116,7 +86,7 @@
prc.put("message", "message2");
configuration.update(prc);
System.err.println("updated ? ");
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -134,7 +104,6 @@
assertEquals("Check count", 2, count);
instance.dispose();
- cleanConfigurationAdmin();
}
/**
@@ -146,7 +115,6 @@
public void testCreationUsingFactoryConfigurationSettingTheManagedServicePid() {
Configuration conf = null;
try {
- //TODO test multi-location:?
conf = admin.createFactoryConfiguration(factNameImm, getTestBundle().getLocation());
Dictionary props = conf.getProperties();
if (props == null) {
@@ -155,7 +123,7 @@
props.put("managed.service.pid", msp);
props.put("message", "message");
conf.update(props);
- Thread.sleep(UPDATE_WAIT_TIME); // Wait for the creation.
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -186,7 +154,7 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -212,6 +180,7 @@
try {
conf.delete();
+ grace();
} catch (IOException e) {
fail(e.getMessage());
}
@@ -232,7 +201,7 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -243,7 +212,7 @@
ComponentInstance instance = null;
try {
instance = factImm.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -272,7 +241,7 @@
}
prc.put("message", "message3");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -284,7 +253,7 @@
instance = null;
try {
instance = factImm.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME * 2);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -319,8 +288,9 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
+ e.printStackTrace();
fail(e.getMessage());
}
@@ -330,7 +300,7 @@
ComponentInstance instance = null;
try {
instance = factImm.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -356,8 +326,7 @@
}
prc.put("message", "message3");
configuration.update(prc);
- //Thread.sleep(UPDATE_WAIT_TIME);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForService.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForService.java
index 68eb29d..5b4f849 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForService.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForService.java
@@ -24,10 +24,8 @@
import org.apache.felix.ipojo.PrimitiveInstanceDescription;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.runtime.core.services.FooService;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -44,40 +42,11 @@
private String factNameSvc = "CA-ConfigurableProvider";
private String msp = "foo";
-
private ComponentFactory factSvc;
- private ConfigurationAdmin admin;
-
- ConfigurationMonitor listener;
-
@Before
public void setUp() {
factSvc = (ComponentFactory) ipojoHelper.getFactory(factNameSvc);
- admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
- assertNotNull("Check configuration admin availability", admin);
- cleanConfigurationAdmin();
- listener = new ConfigurationMonitor(bc);
- }
-
- @After
- public void tearDown() {
- listener.stop();
- cleanConfigurationAdmin();
- admin = null;
- }
-
- private void cleanConfigurationAdmin() {
- try {
- Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
}
@Test
@@ -114,7 +83,7 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -152,7 +121,7 @@
props.put("managed.service.pid", msp);
props.put("message", "message");
conf.update(props);
- Thread.sleep(UPDATE_WAIT_TIME); // Wait for the creation.
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -182,7 +151,7 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -229,7 +198,7 @@
prc.put("message", "message2");
configuration.update(prc);
//listener.waitForEvent(msp, "1");
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -240,7 +209,7 @@
ComponentInstance instance = null;
try {
instance = factSvc.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -268,7 +237,7 @@
}
prc.put("message", "message3");
configuration.update(prc);
- listener.waitForEvent(msp, "2");
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -280,7 +249,7 @@
instance = null;
try {
instance = factSvc.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -316,7 +285,7 @@
}
prc.put("message", "message2");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -327,7 +296,7 @@
ComponentInstance instance = null;
try {
instance = factSvc.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -353,7 +322,7 @@
}
prc.put("message", "message3");
configuration.update(prc);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
@@ -367,7 +336,7 @@
instance = null;
try {
instance = factSvc.createComponentInstance(props);
- Thread.sleep(UPDATE_WAIT_TIME);
+ grace();
} catch (Exception e) {
fail(e.getMessage());
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index 1025f5f..8b2ba0d 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,331 +19,27 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+public class Common extends BaseTest {
-/**
- * Bootstrap the test from this project
- */
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class Common {
+ @Override
+ public boolean deployConfigAdmin() {
+ return true;
+ }
- @Inject
- protected
- BundleContext bc;
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
- protected boolean deployTestedBundle = true;
-
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.components"
);
}
- public static void dump(BundleContext bc, File output) throws IOException {
- if (!output.exists()) {
- output.mkdirs();
- }
-
- for (Bundle bundle : bc.getBundles()) {
- if (bundle.getBundleId() == 0) {
- continue;
- }
- System.out.println("Location : " + bundle.getLocation());
- if ("local".equals(bundle.getLocation())) {
- continue; // Pax Exam, when you hug me, I feel so...
- }
- URL location = new URL(bundle.getLocation());
- FileOutputStream outputStream = null;
- if (bundle.getVersion() != null) {
- outputStream = new FileOutputStream(new File(output,
- bundle.getSymbolicName() + "-" + bundle.getVersion().toString() + ".jar"));
- } else {
- outputStream = new FileOutputStream(new File(output, bundle.getSymbolicName() + ".jar"));
- }
-
- int read = 0;
- byte[] bytes = new byte[1024];
-
- InputStream inputStream = location.openStream();
- while ((read = inputStream.read(bytes)) != -1) {
- outputStream.write(bytes, 0, read);
- }
- inputStream.close();
- outputStream.close();
- }
+ @Override
+ public boolean deployTestBundle() {
+ return false;
}
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- if (deployTestedBundle) {
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- } else {
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // Export the inherited package, components and strategies
- String export = "org.apache.felix.ipojo.runtime.core.components.inherited";
- export += ", org.apache.felix.ipojo.runtime.core.components";
- export += ", org.apache.felix.ipojo.runtime.core.components.strategies";
- // Inheritance.
- export += ", org.apache.felix.ipojo.runtime.core.components.inheritance.a";
- export += ", org.apache.felix.ipojo.runtime.core.components.inheritance.b";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (Bundle bundle : bundles) {
- stability = stability && (bundle.getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- public boolean isKF() {
- return bc.getClass().toString().contains("knopflerfish");
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComplexConfigurations.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComplexConfigurations.java
index 42e454f..9615874 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComplexConfigurations.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComplexConfigurations.java
@@ -50,7 +50,6 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
Option[] options = super.config();
// Build a service bundle
@@ -90,7 +89,7 @@
*/
@Test
public void testDynamism() throws BundleException {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
//1)
@@ -118,7 +117,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
osgiHelper.waitForService(FooService.class, null, 10000);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationInAnotherBundle.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationInAnotherBundle.java
index f59b3cd..3911bd1 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationInAnotherBundle.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationInAnotherBundle.java
@@ -44,7 +44,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -82,7 +82,7 @@
*/
@Test
public void testDynamism() throws BundleException {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
//1)
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfMyComponent.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfMyComponent.java
index 5fbed4c..bbd943b 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfMyComponent.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfMyComponent.java
@@ -43,7 +43,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -67,7 +67,7 @@
@Test
public void testConfiguration() throws IOException {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfThreeInstancesUsingMethods.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfThreeInstancesUsingMethods.java
index a0d562d..6eb7030 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfThreeInstancesUsingMethods.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfThreeInstancesUsingMethods.java
@@ -47,7 +47,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -71,7 +71,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfTwoInstances.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfTwoInstances.java
index 120e8e9..c9cd979 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfTwoInstances.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationOfTwoInstances.java
@@ -46,7 +46,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -70,7 +70,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithInheritedInstance.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithInheritedInstance.java
index ef3e646..7f26415 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithInheritedInstance.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithInheritedInstance.java
@@ -47,7 +47,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -72,7 +72,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithOverriddenInstance.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithOverriddenInstance.java
index 3d86d11..6b27139 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithOverriddenInstance.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurationWithOverriddenInstance.java
@@ -47,7 +47,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -72,7 +72,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestEmptyConfiguration.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestEmptyConfiguration.java
index 0eb70c7..7ca2d69 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestEmptyConfiguration.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestEmptyConfiguration.java
@@ -29,6 +29,7 @@
import org.ops4j.pax.exam.OptionUtils;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.TimeUtils;
import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
import java.io.IOException;
@@ -43,7 +44,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -67,7 +68,7 @@
@Test
public void testConfiguration() throws InterruptedException {
- Thread.sleep(200);
+ TimeUtils.grace(1000);
// Check configuration
Assert.assertNull(osgiHelper.getServiceReference(FooService.class));
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSeveralConfigurations.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSeveralConfigurations.java
index 693034c..3b466b4 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSeveralConfigurations.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-processor-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSeveralConfigurations.java
@@ -47,7 +47,7 @@
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
+
Option[] options = super.config();
// Build a service bundle
@@ -72,7 +72,7 @@
@Test
public void testConfiguration() {
- if (isKF()) {
+ if (isKnopflerfish()) {
return; // Test disabled on KF
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index 22c0ddf..03bdbb6 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,225 +19,43 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.apache.felix.ipojo.runtime.core.components.*;
-import org.apache.felix.ipojo.runtime.core.services.CheckService;
-import org.apache.felix.ipojo.runtime.core.services.FooService;
import org.junit.After;
import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.ow2.chameleon.testing.helpers.BaseTest;
+import org.ow2.chameleon.testing.helpers.ConfigAdminHelper;
+import org.ow2.chameleon.testing.helpers.TimeUtils;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
+ public static int UPDATE_WAIT_TIME = 2000;
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
+ public ConfigAdminHelper caHelper = null;
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
+ public ConfigurationAdmin admin;
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
+ public void grace() {
+ TimeUtils.grace(UPDATE_WAIT_TIME);
+ }
+
+ @Override
+ public boolean deployConfigAdmin() {
+ return true;
}
@Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
+ public void initializeConfigAdmin() {
+ caHelper = new ConfigAdminHelper(bc);
+ admin = caHelper.getConfigurationAdmin();
+ caHelper.deleteAllConfigurations();
}
@After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
+ public void stoppingConfigAdmin() {
+ caHelper.deleteAllConfigurations();
+ caHelper.dispose();
}
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject());
- }
-
- public Bundle getTestBundle() {
- return osgiHelper.getBundle("test.bundle");
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 1000) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 1000) {
- for (Bundle bundle : bc.getBundles()) {
- System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
- }
- System.err.println("Bundle stability isn't reached after 1000 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 1000) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(1000);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 1000) {
- System.err.println("Service stability isn't reached after 1000 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
index 9c04b4a..10fe861 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
@@ -49,8 +49,6 @@
@Before
public void setUp() {
- cleanupConfigurationAdmin();
-
String type = "CONFIG-FooProviderType-3";
Hashtable<String, String> p1 = new Hashtable<String, String>();
@@ -66,31 +64,6 @@
instance2 = ipojoHelper.createComponentInstance(type, p2);
}
- private void cleanupConfigurationAdmin() {
- ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName
- (), null);
- assertNotNull("Check configuration admin availability", admin);
- try {
- int found = 0;
- Configuration[] configurations = admin.listConfigurations(null);
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- System.out.println("Deleting configuration " + configurations[i].getPid());
- configurations[i].delete();
- found++;
- }
-
- // Wait the dispatching.
- Thread.sleep(found * 500);
-
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
@After
public void tearDown() {
instance.dispose();
@@ -126,7 +99,7 @@
configuration.update(conf);
// Asynchronous dispatching of the configuration
- Thread.sleep(1000);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -164,7 +137,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -203,7 +176,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -253,7 +226,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(1000);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -305,7 +278,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -359,7 +332,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(1000);
+ grace();
System.out.println(instance.getInstanceDescription().getDescription());
@@ -409,7 +382,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(1000);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
index fcee2a7..a2cf1e0 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
@@ -122,7 +122,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -168,7 +168,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -215,7 +215,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -269,7 +269,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -326,7 +326,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
index 17bfdc9..f58ac8c 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedService.java
@@ -73,43 +73,14 @@
*/
ComponentInstance instance3;
- private void cleanupConfigurationAdmin() {
- ConfigurationAdmin admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName
- (), null);
- assertNotNull("Check configuration admin availability", admin);
- try {
- int found = 0;
- Configuration[] configurations = admin.listConfigurations(null);
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- System.out.println("Deleting configuration " + configurations[i].getPid());
- configurations[i].delete();
- found++;
- }
-
- // Wait the dispatching.
- Thread.sleep(found * 500);
-
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
@Before
public void setUp() throws IOException {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
for (HandlerFactory handler : osgiHelper.getServiceObjects(HandlerFactory.class)) {
System.out.println("handler : " + handler.getHandlerName() + " - " + handler.getState() + " - " + handler
.getMissingHandlers());
}
- cleanupConfigurationAdmin();
-
String type = "CONFIG-FooProviderType-4Updated";
Hashtable<String, String> p = new Hashtable<String, String>();
p.put("instance.name", "instance");
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
index 9b4bd8f..986c40c 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
@@ -121,7 +121,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -165,7 +165,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -210,7 +210,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
@@ -262,7 +262,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
@@ -316,7 +316,7 @@
// Asynchronous dispatching of the configuration
configuration.update(conf);
- Thread.sleep(200);
+ grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java
index 6cfe008..bfd9e35 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java
@@ -19,220 +19,11 @@
package org.apache.felix.ipojo.runtime.externalhandlers.test;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
-
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
+public class Common extends BaseTest{
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java
index ee84a13..b7f8c90 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java
@@ -64,7 +64,7 @@
ServiceReference sr = null;
ServiceReference[] refs = null;
String filter = "("+"instance.name"+"="+name+")";
- refs =osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+ refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
if(refs != null) { sr = refs[0]; }
assertNotNull("Check the check service availability", sr);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index f03d3bc..069dc88 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,152 +19,44 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.apache.felix.ipojo.runtime.core.components.*;
-import org.apache.felix.ipojo.runtime.core.services.CheckService;
-import org.apache.felix.ipojo.runtime.core.services.FooService;
import org.junit.After;
import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.ow2.chameleon.testing.helpers.BaseTest;
+import org.ow2.chameleon.testing.helpers.ConfigAdminHelper;
+import org.ow2.chameleon.testing.helpers.TimeUtils;
import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
+ public static int UPDATE_WAIT_TIME = 2000;
+ public ConfigAdminHelper caHelper = null;
+ public ConfigurationAdmin admin;
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
+ public void grace() {
+ TimeUtils.grace(UPDATE_WAIT_TIME);
+ }
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
+ @Override
+ public boolean deployConfigAdmin() {
+ return true;
}
@Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
+ public void initializeConfigAdmin() {
+ caHelper = new ConfigAdminHelper(bc);
+ admin = caHelper.getConfigurationAdmin();
+ caHelper.deleteAllConfigurations();
}
@After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
+ public void stoppingConfigAdmin() {
+ caHelper.deleteAllConfigurations();
+ caHelper.dispose();
}
public void assertContains(String s, String[] arrays, String object) {
@@ -175,76 +67,4 @@
}
fail("Assertion failed : " + s);
}
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (Bundle bundle : bundles) {
- stability = stability && (bundle.getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
index bf61d30..1aff9c7 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
@@ -50,7 +50,7 @@
p.put("intAProp", new int[]{1, 2});
conf.update(p);
- Thread.sleep(200);
+ grace();
String pid = conf.getPid();
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
@@ -58,7 +58,7 @@
// Deletion of the configuration
conf.delete();
- Thread.sleep(200);
+ grace();
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
assertNull("Check instance deletion", ref);
@@ -80,7 +80,7 @@
p.put("intAProp", "{1,2}");
conf.update(p);
- Thread.sleep(200);
+ grace();
String pid = conf.getPid();
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
@@ -88,7 +88,7 @@
assertNotNull("Check instance creation", ref);
conf.delete();
- Thread.sleep(200);
+ grace();
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
assertNull("Check instance deletion", ref);
@@ -110,7 +110,7 @@
p.put("intAProp", new int[]{1, 2});
conf.update(p);
- Thread.sleep(200);
+ grace();
String pid = conf.getPid();
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
@@ -119,14 +119,14 @@
p.put("int", 4);
conf.update(p);
- Thread.sleep(200);
+ grace();
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
Integer test = (Integer) ref.getProperty("int");
assertEquals("Check instance modification", 4, test.intValue());
conf.delete();
- Thread.sleep(200);
+ grace();
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
assertNull("Check instance deletion", ref);
@@ -149,7 +149,7 @@
p.put("intAProp", "{1,2}");
conf.update(p);
- Thread.sleep(200);
+ grace();
String pid = conf.getPid();
@@ -157,12 +157,14 @@
assertNotNull("Check instance creation", ref);
p.put("int", new Integer("4"));
conf.update(p);
- Thread.sleep(200);
+ grace();
+
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
Integer test = (Integer) ref.getProperty("int");
assertEquals("Check instance modification", 4, test.intValue());
conf.delete();
- Thread.sleep(200);
+ grace();
+
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), pid);
assertNull("Check instance deletion", ref);
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
index 7ab84a4..5305cf2 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
@@ -39,41 +39,6 @@
public class TestReconfiguration extends Common {
- private ConfigurationAdmin admin;
-
- @Before
- public void setUp() {
- admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
- assertNotNull("Check configuration admin availability", admin);
- try {
- Configuration[] configurations = admin.listConfigurations(
- "(service.factoryPid=org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- fail(e.getMessage());
- } catch (InvalidSyntaxException e) {
- fail(e.getMessage());
- }
- }
-
- @After
- public void tearDown() {
- try {
- Configuration[] configurations = admin.listConfigurations(
- "(service.factoryPid=org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType)");
- for (int i = 0; configurations != null && i < configurations.length; i++) {
- configurations[i].delete();
- }
- } catch (IOException e) {
- fail(e.getMessage());
- } catch (InvalidSyntaxException e) {
- fail(e.getMessage());
- }
- admin = null;
- }
-
@Test
public void testRevalidationOnReconfiguration() {
ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory(
@@ -106,8 +71,6 @@
assertEquals("instance valid", ComponentInstance.VALID, ci.getState());
}
- public static long UPDATE_WAIT_TIME = 2000;
-
@Test public void testRevalidationOnReconfigurationUsingConfigAdmin() throws InvalidSyntaxException {
Configuration configuration = null;
try {
@@ -132,11 +95,7 @@
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
Assert.assertNull("No architecture", osgiHelper.getServiceReference(Architecture.class.getName(),
"(architecture.instance=" + pid + ")"));
@@ -155,11 +114,7 @@
pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
Architecture arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
@@ -222,11 +177,7 @@
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
+ grace();
// Invalid ... controller effect
Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
@@ -240,18 +191,13 @@
try {
configuration.update(props);
+ grace();
} catch (IOException e) {
fail(e.getMessage());
}
pid = configuration.getPid();
- // Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
@@ -307,19 +253,13 @@
try {
configuration.update(props);
+ grace();
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
- // Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
-
// Invalid ... controller effect
Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
Architecture arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
@@ -332,19 +272,13 @@
try {
configuration.update(props);
+ grace();
} catch (IOException e) {
fail(e.getMessage());
}
pid = configuration.getPid();
- // Wait for the processing of the first configuration.
- try {
- Thread.sleep(UPDATE_WAIT_TIME);
- } catch (InterruptedException e1) {
- fail(e1.getMessage());
- }
-
Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/Common.java
index a8c81a3..e959ee9 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/Common.java
@@ -19,71 +19,29 @@
package org.apache.felix.ipojo.tests.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.felix.ipojo.core.tests.services.MyService;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- //testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
+ @Override
+ public boolean deployTestBundle() {
+ return false;
}
public Option createServiceBundleV1() throws MalformedURLException {
@@ -130,163 +88,4 @@
}
}
-
-
-
-
-
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- public void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- for (Bundle bundle : bc.getBundles()) {
- System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
- }
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/VersionConflictTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/VersionConflictTest.java
index 26ff51e..715781a 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/VersionConflictTest.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-version-test/src/test/java/org/apache/felix/ipojo/tests/core/VersionConflictTest.java
@@ -39,6 +39,7 @@
import org.osgi.framework.*;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
+import org.ow2.chameleon.testing.helpers.Stability;
import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
import javax.inject.Inject;
@@ -179,7 +180,7 @@
Bundle b5 = context.installBundle(context.getProperty("cons"));
b5.start();
- waitForStability(bc);
+ Stability.waitForStability(bc);
Bundle[] bundles = context.getBundles();
for (Bundle bundle : bundles) {
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index b00f185..7392d25 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,309 +19,21 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.options.libraries.JUnitBundlesOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.DEBUG);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitAndMockitoBundles(),
- // No tested bundle in this project
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG")
- );
+ @Override
+ public boolean deployTestBundle() {
+ return false;
}
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repo1.maven.org/maven2").id(
- "central"),
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Mockito core does not includes Hamcrest
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import. When deployed after the hamcrest bundles, it gets
- // resolved correctly.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation. this property has no effect on the other OSGi implementation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
+ @Override
+ public boolean deployMockito() {
+ return true;
}
-
-
- /**
- * Creates a {@link org.ops4j.pax.exam.options.libraries.JUnitBundlesOption}.
- *
- * @return junit bundles option
- */
- public static CompositeOption junitBundles() {
- return new DefaultCompositeOption(
- // We need the spring source repository to get hamcrest
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- new JUnitBundlesOption(),
-
- // see config1()
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
-
-// return new DefaultCompositeOption(new JUnitBundlesOption(),
-// systemProperty("pax.exam.invoker").value("junit"),
-// bundle("mvn:org.ops4j.pax.tipi/org.ops4j.pax.tipi.hamcrest.core/1.3.0.1"),
-// bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link"));
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public static CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- public void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- for (Bundle bundle : bc.getBundles()) {
- System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
- }
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index cba09c4..0ba6a79 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,271 +19,12 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
-
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
- }
-
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
+ // No custom configuration required.
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index faf0e4e..9647dbb 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,273 +19,13 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
- }
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (Bundle bundle : bundles) {
- stability = stability && (bundle.getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
+ // No custom configuration required.
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index 56b670e..e66f328 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,275 +19,16 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- ipojoBundles(),
- junitBundles(),
- //testedBundle(), // No tested bundle to deploy
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
+ @Override
+ public boolean deployTestBundle() {
+ return false;
}
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
- }
-
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- for (Bundle bundle : bc.getBundles()) {
- System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
- }
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
index 8af2e84..6796464 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
@@ -19,191 +19,35 @@
package org.apache.felix.ipojo.runtime.core.test.dependencies;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.CompositeOption;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
+ @Override
+ protected Option[] getCustomOptions() {
+ return new Option[]{
+ eventadmin()
+ };
+ }
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.test.components.inner"
);
}
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- // Wait for stability.
- waitForStability(bc);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.out.println("Bundle stability isn't reached after 500 tries");
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the service stability");
- }
-
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- /**
- * Prints the bundle list.
- *
- * @param bc the bundle context.
- */
- public void dumpBundles(BundleContext bc) {
- System.out.println("Bundles:");
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(bundles[i].getSymbolicName() + " - " + bundles[i].getState());
- }
- }
-
-
- @After
- public void commonTearDown() {
- osgiHelper.dispose();
- ipojoHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
public CompositeOption eventadmin() {
return new DefaultCompositeOption(
mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.0"),
@@ -211,63 +55,4 @@
"1.8.0").versionAsInProject());
}
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/bundles/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // We export 'inner'
- String export = "org.apache.felix.ipojo.runtime.core.test.components.inner";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public BundleContext getContext() {
- return bc;
- }
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-policies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-policies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
index 8af2e84..ed7bf24 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-policies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-policies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
@@ -19,191 +19,35 @@
package org.apache.felix.ipojo.runtime.core.test.dependencies;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.CompositeOption;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
+ @Override
+ protected Option[] getCustomOptions() {
+ return new Option[]{
+ eventadmin()
+ };
+ }
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.test.components.inner"
);
}
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- // Wait for stability.
- waitForStability(bc);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.out.println("Bundle stability isn't reached after 500 tries");
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the service stability");
- }
-
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- /**
- * Prints the bundle list.
- *
- * @param bc the bundle context.
- */
- public void dumpBundles(BundleContext bc) {
- System.out.println("Bundles:");
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(bundles[i].getSymbolicName() + " - " + bundles[i].getState());
- }
- }
-
-
- @After
- public void commonTearDown() {
- osgiHelper.dispose();
- ipojoHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
public CompositeOption eventadmin() {
return new DefaultCompositeOption(
mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.0"),
@@ -211,63 +55,5 @@
"1.8.0").versionAsInProject());
}
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/bundles/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // We export 'inner'
- String export = "org.apache.felix.ipojo.runtime.core.test.components.inner";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public BundleContext getContext() {
- return bc;
- }
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-proxies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-proxies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
index e7b4db0..6796464 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-proxies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-proxies/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
@@ -19,192 +19,35 @@
package org.apache.felix.ipojo.runtime.core.test.dependencies;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.options.CompositeOption;
import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- protected
- BundleContext bc;
+ @Override
+ protected Option[] getCustomOptions() {
+ return new Option[]{
+ eventadmin()
+ };
+ }
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.test.components.inner"
);
}
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- // Wait for stability.
- waitForStability(bc);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.out.println("Bundle stability isn't reached after 500 tries");
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the service stability");
- }
-
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- /**
- * Prints the bundle list.
- *
- * @param bc the bundle context.
- */
- public void dumpBundles(BundleContext bc) {
- System.out.println("Bundles:");
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(bundles[i].getSymbolicName() + " - " + bundles[i].getState());
- }
- }
-
-
- @After
- public void commonTearDown() {
- osgiHelper.dispose();
- ipojoHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
public CompositeOption eventadmin() {
return new DefaultCompositeOption(
mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.0"),
@@ -212,63 +55,4 @@
"1.8.0").versionAsInProject());
}
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/bundles/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // We export 'inner'
- String export = "org.apache.felix.ipojo.runtime.core.test.components.inner";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public BundleContext getContext() {
- return bc;
- }
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata-policies.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata-policies.xml
deleted file mode 100644
index 852763f..0000000
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata-policies.xml
+++ /dev/null
@@ -1,283 +0,0 @@
-<!--
- ~ 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.
- -->
-
-<ipojo
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
- xmlns="org.apache.felix.ipojo"
->
-
- <!-- Static Dependencies -->
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticSimpleCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticVoidCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticObjectCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticRefCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticBothCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMObjectCheckServiceProvider" architecture="true">
- <requires policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMRefCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMBothCheckServiceProvider" architecture="true">
- <requires policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
-
- <!-- Static Simple & Optional Dependencies -->
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticSimpleOptionalCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" policy="static" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticVoidOptionalCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" policy="static">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticObjectOptionalCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticRefOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.CheckServiceProvider"
- name="StaticBothOptionalCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMObjectOptionalCheckServiceProvider"
- architecture="true">
- <requires optional="true" policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMRefOptionalCheckServiceProvider"
- architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true" policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodCheckServiceProvider"
- name="StaticMBothOptionalCheckServiceProvider"
- architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true" policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <!-- Static Multiple Dependencies -->
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
- name="StaticSimpleMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" policy="static" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
- name="StaticVoidMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
- name="StaticObjectMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
- name="StaticRefMultipleCheckServiceProvider" architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MultipleCheckService"
- name="StaticBothMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
- name="StaticMObjectMultipleCheckServiceProvider"
- architecture="true">
- <requires aggregate="true" policy="static">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
- name="StaticMRefMultipleCheckServiceProvider"
- architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- aggregate="true" policy="static">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.MethodMultipleCheckService"
- name="StaticMBothMultipleCheckServiceProvider"
- architecture="true">
- <requires aggregate="true" policy="static">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
-
- <!-- Dynamic-Priority -->
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.RankedFooProviderType1"
- name="RankedFooProviderType" architecture="true">
- <provides>
- <property field="m_grade" name="service.ranking"/>
- </provides>
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.DynCheckServiceProvider"
- name="DPSimpleCheckServiceProvider" architecture="true">
- <requires field="fs" policy="dynamic-priority" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.policies.DynCheckServiceProvider"
- name="DPObjectCheckServiceProvider" architecture="true">
- <requires field="fs" policy="dynamic-priority">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
-</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata.xml b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata.xml
index e42a2eb..34a23b4 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata.xml
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/main/resources/metadata.xml
@@ -222,371 +222,13 @@
</component>
<!-- Simple & Optional Dependencies -->
+ <!-- used for architecture test -->
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
name="SimpleOptionalCheckServiceProvider" architecture="true">
<requires field="fs" optional="true" id="FooService" proxy="false"/>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="SimpleOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="VoidOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="VoidOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ObjectOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ObjectOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="RefOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="RefOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="BothOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="MapOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DictOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedSimpleOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" id="FooService"/>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedVoidOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedObjectOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedRefOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedBothOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedMapOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="ProxiedDictOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="BothOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="MapOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DictOptionalNoNullableCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true" nullable="false">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="MObjectOptionalCheckServiceProvider" architecture="true">
- <requires optional="true">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="MRefOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="MBothOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="MMapOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="MDictOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
-
-
- <!-- Simple & Optional Dependencies with default-implementation -->
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DISimpleOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIVoidOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIObjectOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIRefOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIBothOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIMapOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CheckServiceProvider"
- name="DIDictOptionalCheckServiceProvider" architecture="true">
- <requires field="fs" optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="DIMObjectOptionalCheckServiceProvider" architecture="true">
- <requires optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="DIMRefOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="DIMBothOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="DIMMapOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodCheckServiceProvider"
- name="DIMDictOptionalCheckServiceProvider" architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- optional="true"
- default-implementation="org.apache.felix.ipojo.runtime.core.test.components.FooServiceDefaultImpl">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
<!-- Multiple Dependencies -->
<component
@@ -597,13 +239,6 @@
</component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedSimpleMultipleCheckServiceProvider" architecture="true">
- <requires field="fs" />
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
name="VoidMultipleCheckServiceProvider" architecture="true">
<requires field="fs" proxy="false">
<callback type="bind" method="voidBind" />
@@ -613,15 +248,6 @@
</component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedVoidMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
name="ObjectMultipleCheckServiceProvider" architecture="true">
<requires field="fs" proxy="false">
<callback type="bind" method="objectBind" />
@@ -631,15 +257,6 @@
</component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedObjectMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
name="RefMultipleCheckServiceProvider" architecture="true">
<requires field="fs" proxy="false">
<callback type="bind" method="refBind" />
@@ -647,15 +264,7 @@
</requires>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedRefMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
+
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
@@ -668,15 +277,6 @@
</component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedBothMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="bothBind" />
- <callback type="unbind" method="bothUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
name="MapMultipleCheckServiceProvider" architecture="true">
<requires field="fs" proxy="false">
<callback type="bind" method="propertiesMapBind" />
@@ -684,15 +284,7 @@
</requires>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedMapMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="propertiesMapBind" />
- <callback type="unbind" method="propertiesMapUnbind" />
- </requires>
- <provides />
- </component>
+
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
@@ -703,15 +295,6 @@
</requires>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedDictMultipleCheckServiceProvider" architecture="true">
- <requires field="fs">
- <callback type="bind" method="propertiesDictionaryBind" />
- <callback type="unbind" method="propertiesDictionaryUnbind" />
- </requires>
- <provides />
- </component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
@@ -762,6 +345,7 @@
</component>
<!-- Multiple & Optional Dependencies -->
+ <!-- Used in architecture tests -->
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
name="SimpleOptionalMultipleCheckServiceProvider"
@@ -769,97 +353,6 @@
<requires field="fs" optional="true" proxy="false"/>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="VoidOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ObjectOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="RefOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" proxy="false">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedSimpleOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true" />
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedVoidOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="voidBind" />
- <callback type="unbind" method="voidUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedObjectOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MultipleCheckService"
- name="ProxiedRefOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires field="fs" optional="true">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
-
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
- name="MObjectOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires aggregate="true" optional="true">
- <callback type="bind" method="objectBind" />
- <callback type="unbind" method="objectUnbind" />
- </requires>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.MethodMultipleCheckService"
- name="MRefOptionalMultipleCheckServiceProvider"
- architecture="true">
- <requires
- specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"
- aggregate="true" optional="true">
- <callback type="bind" method="refBind" />
- <callback type="unbind" method="refUnbind" />
- </requires>
- <provides />
- </component>
<!-- Aggregate dependency as List -->
<component
@@ -877,19 +370,6 @@
specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
- name="ProxiedSimpleListCheckServiceProvider" architecture="true">
- <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.ListCheckService"
- name="ProxiedOptionalListCheckServiceProvider"
- architecture="true">
- <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
- <provides />
- </component>
<!-- Aggregate dependency as Vector -->
<component
@@ -923,19 +403,6 @@
<requires proxy="false" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
- name="ProxiedSimpleSetCheckServiceProvider" architecture="true">
- <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.SetCheckService"
- name="ProxiedOptionalSetCheckServiceProvider"
- architecture="true">
- <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true" />
- <provides />
- </component>
<!-- Aggregate dependency as Collection -->
<component
@@ -946,12 +413,6 @@
</component>
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
- name="ProxiedSimpleCollectionCheckServiceProvider" architecture="true">
- <requires field="fs" specification="org.apache.felix.ipojo.runtime.core.test.services.FooService"/>
- <provides />
- </component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
name="OptionalCollectionCheckServiceProvider"
architecture="true">
<requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true"
@@ -959,15 +420,6 @@
/>
<provides />
</component>
- <component
- classname="org.apache.felix.ipojo.runtime.core.test.components.CollectionCheckService"
- name="ProxiedOptionalCollectionCheckServiceProvider"
- architecture="true">
- <requires specification="org.apache.felix.ipojo.runtime.core.test.services.FooService" field="fs" optional="true"
- proxy="false"
- />
- <provides />
- </component>
<!-- Modify method test -->
@@ -1040,22 +492,6 @@
<provides />
</component>
- <!-- Proxy Tests -->
- <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceDelegator">
- <provides/>
- <requires field="fs" optional="true"/>
- </component>
- <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceGetAndDelegate">
- <provides/>
- <requires field="fs" optional="true"/>
- </component>
- <component classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceNoDelegate">
- <provides/>
- <requires field="fs" optional="true"/>
- <callback transition="validate" method="start"/>
- <callback transition="invalidate" method="stop"/>
- </component>
-
<component
classname="org.apache.felix.ipojo.runtime.core.test.components.proxy.CheckServiceUsingStringService"
immediate="true">
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
index 8af2e84..46e0f65 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/Common.java
@@ -19,255 +19,21 @@
package org.apache.felix.ipojo.runtime.core.test.dependencies;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
-import static org.ops4j.pax.exam.CoreOptions.*;
-
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- BundleContext bc;
-
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws MalformedURLException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.test.components.inner"
);
}
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- // Wait for stability.
- waitForStability(bc);
- }
-
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- *
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.out.println("Bundle stability isn't reached after 500 tries");
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (!serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- dumpBundles(context);
- throw new IllegalStateException("Cannot reach the service stability");
- }
-
- }
-
- /**
- * Are bundle stables.
- *
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
- /**
- * Prints the bundle list.
- *
- * @param bc the bundle context.
- */
- public void dumpBundles(BundleContext bc) {
- System.out.println("Bundles:");
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(bundles[i].getSymbolicName() + " - " + bundles[i].getState());
- }
- }
-
-
- @After
- public void commonTearDown() {
- osgiHelper.dispose();
- ipojoHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
- }
-
- public CompositeOption eventadmin() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.eventadmin", "1.3.0"),
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.eventadmin",
- "1.8.0").versionAsInProject());
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/bundles/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // We export 'inner'
- String export = "org.apache.felix.ipojo.runtime.core.test.components.inner";
- for (File file : services) {
- if (export.length() > 0) {
- export += ", ";
- }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public BundleContext getContext() {
- return bc;
- }
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/TestSimpleDependencies.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/TestSimpleDependencies.java
index c82512a..8abd059 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/TestSimpleDependencies.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/TestSimpleDependencies.java
@@ -26,6 +26,7 @@
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.Stability;
import java.util.Properties;
@@ -38,6 +39,8 @@
@Before
public void setUp() {
+ Stability.waitForStability(getContext());
+ System.gc();
try {
Properties prov = new Properties();
prov.put("instance.name", "FooProvider");
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
index 268e0fb..5a779d2 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -19,213 +19,34 @@
package org.apache.felix.ipojo.runtime.core;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.List;
import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class Common {
+public class Common extends BaseTest {
- @Inject
- protected
- BundleContext bc;
-
- protected OSGiHelper osgiHelper;
- protected IPOJOHelper ipojoHelper;
-
- protected boolean deployTestedBundle = true;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.INFO);
-
- if (deployTestedBundle) {
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- } else {
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
+ @Override
+ public boolean deployConfigAdmin() {
+ return true;
}
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Mockito without Hamcrest and Objenesis
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
+ @Override
+ protected List<String> getExtraExports() {
+ return Arrays.asList(
+ "org.apache.felix.ipojo.runtime.core.components",
+ "org.apache.felix.ipojo.runtime.core.components.inherited",
+ "org.apache.felix.ipojo.runtime.core.components.strategies",
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.a",
+ "org.apache.felix.ipojo.runtime.core.components.inheritance.b"
);
}
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
-
- waitForStability(bc);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
-
- public CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // harmcrest-all
- //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
- // configuration admin
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
- );
- }
-
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
- if (out.exists()) {
- return bundle(out.toURI().toURL().toExternalForm());
- }
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- // Export the inherited package, components and strategies
- String export = "org.apache.felix.ipojo.runtime.core.components.inherited";
- export += ", org.apache.felix.ipojo.runtime.core.components";
- export += ", org.apache.felix.ipojo.runtime.core.components.strategies";
- // Inheritance.
- export += ", org.apache.felix.ipojo.runtime.core.components.inheritance.a";
- export += ", org.apache.felix.ipojo.runtime.core.components.inheritance.b";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.IMPORT_PACKAGE, "*")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
public void assertContains(String s, String[] arrays, String object) {
for (String suspect : arrays) {
if (object.equals(suspect)) {
@@ -235,75 +56,5 @@
fail("Assertion failed : " + s);
}
- /**
- * Waits for stability:
- * <ul>
- * <li>all bundles are activated
- * <li>service count is stable
- * </ul>
- * If the stability can't be reached after a specified time,
- * the method throws a {@link IllegalStateException}.
- * @param context the bundle context
- * @throws IllegalStateException when the stability can't be reach after a several attempts.
- */
- private void waitForStability(BundleContext context) throws IllegalStateException {
- // Wait for bundle initialization.
- boolean bundleStability = getBundleStability(context);
- int count = 0;
- while (!bundleStability && count < 500) {
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // Interrupted
- }
- count++;
- bundleStability = getBundleStability(context);
- }
-
- if (count == 500) {
- System.err.println("Bundle stability isn't reached after 500 tries");
- throw new IllegalStateException("Cannot reach the bundle stability");
- }
-
- boolean serviceStability = false;
- count = 0;
- int count1 = 0;
- int count2 = 0;
- while (! serviceStability && count < 500) {
- try {
- ServiceReference[] refs = context.getServiceReferences((String) null, null);
- count1 = refs.length;
- Thread.sleep(500);
- refs = context.getServiceReferences((String) null, null);
- count2 = refs.length;
- serviceStability = count1 == count2;
- } catch (Exception e) {
- System.err.println(e);
- serviceStability = false;
- // Nothing to do, while recheck the condition
- }
- count++;
- }
-
- if (count == 500) {
- System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
- throw new IllegalStateException("Cannot reach the service stability");
- }
- }
-
- /**
- * Are bundle stables.
- * @param bc the bundle context
- * @return <code>true</code> if every bundles are activated.
- */
- private boolean getBundleStability(BundleContext bc) {
- boolean stability = true;
- Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
- }
- return stability;
- }
-
}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestProvidedServiceArchitecture.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestProvidedServiceArchitecture.java
index 7e3f6d0..ee9aaf6 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestProvidedServiceArchitecture.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestProvidedServiceArchitecture.java
@@ -174,7 +174,6 @@
assertEquals("Check ProvidedService number", ps.length, 1);
assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 2);
assertContains("Check provided service specs - 2", ps[0].getServiceSpecifications(), FooService.class.getName());
- ;
assertContains("Check provided service specs - 2", ps[0].getServiceSpecifications(), BarService.class.getName());
assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java
index b72f011..d2524a9 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-service-providing-test/src/test/java/org/apache/felix/ipojo/runtime/core/inheritence/InheritanceTest.java
@@ -50,9 +50,13 @@
*/
public class InheritanceTest extends Common {
+ @Override
+ public boolean deployTestBundle() {
+ return false;
+ }
+
@Configuration
public Option[] config() throws IOException {
- deployTestedBundle = false;
Option[] options = super.config();
return OptionUtils.combine(
@@ -102,20 +106,16 @@
);
}
- public boolean isKF() {
- return bc.getClass().toString().contains("knopflerfish");
- }
-
@Test
public void testDeploy() {
- if (isKF()) {
+ if (isKnopflerfish()) {
System.out.println("Test disabled on knopflerfish");
return;
}
Bundle[] bundles = bc.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- Assert.assertEquals(bundles[i].getSymbolicName() + " is not active", Bundle.ACTIVE, bundles[i].getState());
+ for (Bundle bundle : bundles) {
+ Assert.assertEquals(bundle.getSymbolicName() + " is not active", Bundle.ACTIVE, bundle.getState());
}
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=c)", 10000);
@@ -132,7 +132,7 @@
@Test
public void testArchitecture() {
- if (isKF()) {
+ if (isKnopflerfish()) {
System.out.println("Test disabled on knopflerfish");
return;
}
diff --git a/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java b/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
index c3fac11..9fc2120 100644
--- a/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
+++ b/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/configuration/InstanceDSLTest.java
@@ -43,8 +43,9 @@
.with("list2").setto(list().with(1).with(2).with(3))
.with("map").setto(map().with(pair("entry", "value")))
- .with("map").setto(map()
- .with(pair("entry2", list("aaa", "bbb"))));
+ .with("map").setto(map().with(pair("entry2", list("aaa", "bbb"))))
+ .with("map").setto(map().with(pair("key", 1), pair("key2", 2)))
+ .with("map").setto(map().with(entry("key", 1), entry("key2", 2)));
}
public void testClassnameExtraction() {