Add session to junit4osgi:
- services are automatically unget
- instances created with the iPOJO helper are automatically disposed
Add a log service implementation to the junit4osgi plugin to collected logged messages during test execution (as well as messages printed on System.out ans System.err).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@720011 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/examples/junit4osgi/junit4osgi/metadata.xml b/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
index 74c7f08..9fd4d99 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
+++ b/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
@@ -10,6 +10,8 @@
onArrival="onBundleArrival" onDeparture="onBundleDeparture" />
<callback transition="invalidate" method="stopping" />
<callback transition="validate" method="starting" />
+ <requires field="m_log" optional="true"
+ default-implementation="org.apache.felix.ipojo.junit4osgi.impl.LogServiceImpl"/>
<provides />
</component>
<instance
diff --git a/ipojo/examples/junit4osgi/junit4osgi/pom.xml b/ipojo/examples/junit4osgi/junit4osgi/pom.xml
index ff61e05..2737035 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/pom.xml
+++ b/ipojo/examples/junit4osgi/junit4osgi/pom.xml
@@ -78,7 +78,6 @@
org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestCase,
org.apache.felix.ipojo.junit4osgi.test.TestTestSuite,
org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestSuite,
- org.apache.felix.ipojo.junit4osgi.test.MyTestCase
</Test-Suite> -->
</instructions>
</configuration>
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
index 4ae4309..6a860ad 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
@@ -18,14 +18,15 @@
*/
package org.apache.felix.ipojo.junit4osgi;
+import java.util.ArrayList;
+import java.util.List;
+
import junit.framework.TestCase;
-import org.apache.felix.ipojo.Factory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedServiceFactory;
/**
* OSGi Test Case. Allow the injection of the bundle context.
@@ -35,6 +36,23 @@
public class OSGiTestCase extends TestCase {
protected BundleContext context;
+
+
+ private List references = new ArrayList();
+
+ /**
+ * Extends runBare to release (unget) services after the teardown.
+ * @throws Throwable when an error occurs.
+ * @see junit.framework.TestCase#runBare()
+ */
+ public void runBare() throws Throwable {
+ super.runBare();
+ // Unget services
+ for (int i = 0; i < references.size(); i++) {
+ context.ungetService((ServiceReference) references.get(i));
+ }
+ references.clear();
+ }
public void setBundleContext(BundleContext bc) {
context = bc;
@@ -180,8 +198,6 @@
return false;
}
-
-
private static String formatEqualsMessage(String message, Object expected,
Object actual) {
String formatted = "";
@@ -311,18 +327,6 @@
ServiceReference ref = getServiceReference(itf, null);
return ref != null;
}
-
- /**
- * Checks if the service is available.
- * @param itf the service interface
- * @param the service provider name
- * @return <code>true</code> if the service is available,
- * <code>false</code> otherwise.
- */
- public boolean isServiceAvailableByName(String itf, String name) {
- ServiceReference ref = getServiceReferenceByName(itf, name);
- return ref != null;
- }
/**
* Checks if the service is available.
@@ -371,33 +375,6 @@
/**
- * Returns the service reference of a service provided by the specified
- * bundle, offering the specified interface and having the given name.
- *
- * @param bundle
- * the bundle in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param name
- * the name of the searched service.
- * @return a service provided by the specified bundle, offering the
- * specified interface and having the given name.
- */
- public static ServiceReference getServiceReferenceByName(Bundle bundle,
- String itf, String name) {
- String filter = null;
- if (itf.equals(Factory.class.getName())
- || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- return getServiceReference(bundle, itf, filter);
- }
-
-
-
- /**
* Returns the service reference of all the services provided in the
* specified bundle, offering the specified interface and matching the given
* filter.
@@ -443,8 +420,32 @@
* specified interface and matching the given filter.
*/
public Object getServiceObject(String itf, String filter) {
- return getServiceObject(context.getBundle(), itf, filter);
+ ServiceReference ref = getServiceReference(itf, filter);
+ if (ref != null) {
+ references.add(ref);
+ return context.getService(ref);
+ } else {
+ return null;
+ }
}
+
+
+ /**
+ * Returns the service object associated with this service
+ * reference.
+ *
+ * @param ref
+ * service reference
+ * @return the service object.
+ */
+ public Object getServiceObject(ServiceReference ref) {
+ if (ref != null) {
+ references.add(ref);
+ return context.getService(ref);
+ } else {
+ return null;
+ }
+ }
/**
* Returns the service objects of the services provided by the local
@@ -458,8 +459,18 @@
* the specified interface and matching the given filter.
*/
public Object[] getServiceObjects(String itf, String filter) {
- return getServiceObjects(context.getBundle(), itf, filter);
- }
+ ServiceReference[] refs = getServiceReferences(itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ references.add(refs[i]);
+ list[i] = context.getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
/**
* Returns the service reference of a service provided by the local
@@ -476,6 +487,20 @@
public ServiceReference getServiceReference(String itf, String filter) {
return getServiceReference(context.getBundle(), itf, filter);
}
+
+ /**
+ * Returns the service reference of a service provided
+ * offering the specified interface.
+ *
+ * @param itf
+ * the interface provided by the searched service.
+ * @return a service reference provided by the local bundle, offering
+ * the specified interface and matching the given filter. If no
+ * service is found, {@code null} is returned.
+ */
+ public ServiceReference getServiceReference(String itf) {
+ return getServiceReference(context.getBundle(), itf, null);
+ }
/**
* Returns the service reference of the service provided by the local
@@ -494,21 +519,6 @@
}
/**
- * Returns the service reference of a service provided by the local
- * bundle, offering the specified interface and having the given name.
- *
- * @param itf
- * the interface provided by the searched service.
- * @param name
- * the name of the searched service.
- * @return a service provided by the specified bundle, offering the
- * specified interface and having the given name.
- */
- public ServiceReference getServiceReferenceByName(String itf, String name) {
- return getServiceReferenceByName(context.getBundle(), itf, name);
- }
-
- /**
* Returns the service reference of all the services provided in the
* local bundle, offering the specified interface and matching the given
* filter.
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
index 0218926..697a4c2 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
@@ -18,7 +18,9 @@
*/
package org.apache.felix.ipojo.junit4osgi.helpers;
+import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.List;
import java.util.Properties;
import org.apache.felix.ipojo.ComponentInstance;
@@ -26,6 +28,7 @@
import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.HandlerFactory;
import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManifestMetadataParser;
@@ -41,9 +44,29 @@
private BundleContext context;
private OSGiTestCase testcase;
+
+ private List instances;
+
public IPOJOHelper(OSGiTestCase tc) {
testcase = tc;
context = testcase.getBundleContext();
+ instances = new ArrayList();
+ }
+
+ public void dispose() {
+ for (int i = 0; i < instances.size(); i++) {
+ ((ComponentInstance) instances.get(i)).dispose();
+ }
+ instances.clear();
+ }
+
+ public ComponentInstance getInstanceByName(String name) {
+ for (int i = 0; i < instances.size(); i++) {
+ if (((ComponentInstance) instances.get(i)).getInstanceName().equals(name)) {
+ return (ComponentInstance) instances.get(i);
+ }
+ }
+ return null;
}
/**
@@ -232,8 +255,10 @@
*/
public ComponentInstance createComponentInstance(String factoryName,
String instanceName) {
- return createComponentInstance(context.getBundle(), factoryName,
+ ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
instanceName);
+ instances.add(ci);
+ return ci;
}
/**
@@ -248,8 +273,25 @@
*/
public ComponentInstance createComponentInstance(String factoryName,
Dictionary configuration) {
- return createComponentInstance(context.getBundle(), factoryName,
+ ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
configuration);
+ instances.add(ci);
+ return ci;
+ }
+
+ /**
+ * Creates a new component instance with no configuration, from the
+ * factory specified in the local bundle.
+ *
+ * @param factoryName
+ * the name of the component factory, in the local bundle.
+ * @return the newly created component instance.
+ */
+ public ComponentInstance createComponentInstance(String factoryName) {
+ ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
+ (Dictionary) null);
+ instances.add(ci);
+ return ci;
}
/**
@@ -269,8 +311,10 @@
*/
public ComponentInstance createComponentInstance(String factoryName,
String instanceName, Dictionary configuration) {
- return createComponentInstance(context.getBundle(), factoryName,
+ ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
instanceName, configuration);
+ instances.add(ci);
+ return ci;
}
/**
@@ -614,6 +658,8 @@
if (itf.equals(Factory.class.getName())
|| itf.equals(ManagedServiceFactory.class.getName())) {
filter = "(" + "factory.name" + "=" + name + ")";
+ } else if (itf.equals(Architecture.class.getName())) {
+ filter = "(" + "architecture.instance" + "=" + name + ")";
} else {
filter = "(" + "instance.name" + "=" + name + ")";
}
@@ -659,5 +705,59 @@
return ref != null;
}
+ /**
+ * Returns the service reference of a service provided by the specified
+ * bundle, offering the specified interface and having the given name.
+ *
+ * @param bundle
+ * the bundle in which the service is searched.
+ * @param itf
+ * the interface provided by the searched service.
+ * @param name
+ * the name of the searched service.
+ * @return a service provided by the specified bundle, offering the
+ * specified interface and having the given name.
+ */
+ public static ServiceReference getServiceReferenceByName(Bundle bundle,
+ String itf, String name) {
+ String filter = null;
+ if (itf.equals(Factory.class.getName())
+ || itf.equals(ManagedServiceFactory.class.getName())) {
+ filter = "(" + "factory.name" + "=" + name + ")";
+ } else if (itf.equals(Architecture.class.getName())) {
+ filter = "(" + "architecture.instance" + "=" + name + ")";
+ } else {
+ filter = "(" + "instance.name" + "=" + name + ")";
+ }
+ return OSGiTestCase.getServiceReference(bundle, itf, filter);
+ }
+
+ /**
+ * Returns the service reference of a service provided by the local
+ * bundle, offering the specified interface and having the given name.
+ *
+ * @param itf
+ * the interface provided by the searched service.
+ * @param name
+ * the name of the searched service.
+ * @return a service provided by the specified bundle, offering the
+ * specified interface and having the given name.
+ */
+ public ServiceReference getServiceReferenceByName(String itf, String name) {
+ return getServiceReferenceByName(context.getBundle(), itf, name);
+ }
+
+ /**
+ * Checks if the service is available.
+ * @param itf the service interface
+ * @param the service provider name
+ * @return <code>true</code> if the service is available,
+ * <code>false</code> otherwise.
+ */
+ public boolean isServiceAvailableByName(String itf, String name) {
+ ServiceReference ref = getServiceReferenceByName(itf, name);
+ return ref != null;
+ }
+
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
index c79541d..39ee95f 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
@@ -40,6 +40,7 @@
import org.apache.felix.ipojo.parser.ParseUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
/**
* Detect test suite from installed bundles.
@@ -52,18 +53,20 @@
private Map/*<Bundle, List<Class>>*/ m_suites = new HashMap/*<Bundle, List<Class>>*/();
private ResultPrinter m_printer = new ResultPrinter(System.out);
+
+ private LogService m_log;
void onBundleArrival(Bundle bundle, String header) {
String[] tss = ParseUtils.split(header, ",");
for (int i = 0; i < tss.length; i++) {
try {
if (tss[i].length() != 0) {
- System.out.println("Loading " + tss[i]);
+ m_log.log(LogService.LOG_INFO, "Loading " + tss[i]);
Class/*<? extends Test>*/ clazz = bundle.loadClass(tss[i].trim());
addTestSuite(bundle, clazz);
}
} catch (ClassNotFoundException e) {
- System.err.println("The test suite " + tss[i] + " is not in the bundle " + bundle.getBundleId() + " : " + e.getMessage());
+ m_log.log(LogService.LOG_ERROR, "The test suite " + tss[i] + " is not in the bundle " + bundle.getBundleId() + " : " + e.getMessage());
}
}
}
@@ -81,7 +84,7 @@
private synchronized void removeTestSuites(Bundle bundle) {
List list = (List) m_suites.remove(bundle);
- System.out.println("Unload test suites " + list);
+ m_log.log(LogService.LOG_INFO, "Unload test suites " + list);
}
void onBundleDeparture(Bundle bundle) {
@@ -147,7 +150,7 @@
}
if (!Modifier.isStatic(suiteMethod.getModifiers())) {
- System.err.println("Suite() method must be static");
+ m_log.log(LogService.LOG_ERROR, "Suite() method must be static");
return null;
}
Test test = null;
@@ -158,10 +161,10 @@
test = (Test) suiteMethod.invoke(null, (Object[]) new Class[0]); // static method
}
} catch (InvocationTargetException e) {
- System.err.println("Failed to invoke suite():" + e.getTargetException().toString());
+ m_log.log(LogService.LOG_ERROR, "Failed to invoke suite():" + e.getTargetException().toString());
return null;
} catch (IllegalAccessException e) {
- System.err.println("Failed to invoke suite():" + e.toString());
+ m_log.log(LogService.LOG_ERROR, "Failed to invoke suite():" + e.toString());
return null;
}
@@ -225,12 +228,12 @@
}
public synchronized void stopping() {
- System.out.println("Cleaning test suites ...");
+ m_log.log(LogService.LOG_INFO, "Cleaning test suites ...");
m_suites.clear();
}
public void starting() {
- System.out.println("Junit Extender starting ...");
+ m_log.log(LogService.LOG_INFO, "Junit Extender starting ...");
}
private BundleContext getBundleContext(Bundle bundle) {
@@ -264,13 +267,13 @@
try {
return (BundleContext) meth.invoke(bundle, new Object[0]);
} catch (IllegalArgumentException e) {
- err("Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
return null;
} catch (IllegalAccessException e) {
- err("Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
return null;
} catch (InvocationTargetException e) {
- err("Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
return null;
}
}
@@ -285,20 +288,16 @@
try {
return (BundleContext) fields[i].get(bundle);
} catch (IllegalArgumentException e) {
- err("Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
return null;
} catch (IllegalAccessException e) {
- err("Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
return null;
}
}
}
- err("Cannot find the BundleContext for " + bundle.getSymbolicName(), null);
+ m_log.log(LogService.LOG_ERROR, "Cannot find the BundleContext for " + bundle.getSymbolicName(), null);
return null;
}
- private void err(String s, Throwable e) {
- System.err.println(s + " : " + e.getMessage());
- }
-
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java
new file mode 100644
index 0000000..1da168a
--- /dev/null
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java
@@ -0,0 +1,48 @@
+package org.apache.felix.ipojo.junit4osgi.impl;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+public class LogServiceImpl implements LogService {
+
+ private String computeLogMessage(int level, String msg, Throwable exception) {
+ String message = null;
+ switch (level) {
+ case LogService.LOG_DEBUG:
+ message = "[DEBUG] " + msg;
+ break;
+ case LogService.LOG_ERROR:
+ message = "[ERROR] " + msg;
+ break;
+ case LogService.LOG_INFO:
+ message = "[INFO] " + msg;
+ break;
+ case LogService.LOG_WARNING:
+ message = "[WARNING] " + msg;
+ break;
+ }
+
+ if (exception != null) {
+ message = message + " : " + exception.getMessage();
+ }
+
+ return message;
+ }
+
+ public void log(int arg0, String arg1) {
+ System.err.println(computeLogMessage(arg0, arg1, null));
+ }
+
+ public void log(int arg0, String arg1, Throwable arg2) {
+ System.err.println(computeLogMessage(arg0, arg1, arg2));
+ }
+
+ public void log(ServiceReference arg0, int arg1, String arg2) {
+ System.err.println(computeLogMessage(arg1, arg2, null));
+ }
+
+ public void log(ServiceReference arg0, int arg1, String arg2, Throwable arg3) {
+ System.err.println(computeLogMessage(arg1, arg2, arg3));
+ }
+
+}
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
index dafd5e5..a1798d6 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
@@ -23,7 +23,7 @@
<artifactId>maven-junit4osgi-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1.0-SNAPSHOT</version>
- <name>maven-junit4osgi-plugin Maven Mojo</name>
+ <name>Junit4OSGi Maven Plugin</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
@@ -35,7 +35,6 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -66,7 +65,6 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo</artifactId>
<version>1.1.0-SNAPSHOT</version>
- <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
diff --git a/ipojo/examples/junit4osgi/pom.xml b/ipojo/examples/junit4osgi/pom.xml
index c0c0a4e..1dede45 100644
--- a/ipojo/examples/junit4osgi/pom.xml
+++ b/ipojo/examples/junit4osgi/pom.xml
@@ -27,6 +27,7 @@
<modules>
<module>junit4osgi</module>
<module>felix-command</module>
+ <module>maven-junit4osgi-plugin</module>
</modules>
<profiles>
diff --git a/ipojo/examples/junit4osgi/swing-runner/pom.xml b/ipojo/examples/junit4osgi/swing-runner/pom.xml
index 5369b6a..fe9b18e 100644
--- a/ipojo/examples/junit4osgi/swing-runner/pom.xml
+++ b/ipojo/examples/junit4osgi/swing-runner/pom.xml
@@ -66,6 +66,7 @@
<Private-Package>
org.apache.felix.ipojo.junit4osgi.command
</Private-Package>
+ <Import-Package>org.osgi.framework;version=1.3,*</Import-Package>
</instructions>
</configuration>
</plugin>
diff --git a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
index 54cbbe7..7cbc1ae 100644
--- a/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
+++ b/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/jmx/JMXSimple.java
@@ -1,12 +1,11 @@
package org.apache.felix.ipojo.test.scenarios.component.jmx;
import org.apache.felix.ipojo.annotations.Component;
-import org.apache.felix.ipojo.handlers.jmx.Config;
import org.apache.felix.ipojo.handlers.jmx.Method;
import org.apache.felix.ipojo.handlers.jmx.Property;
@Component
-@Config(domain="my-domain", usesMOSGi=false)
+@org.apache.felix.ipojo.handlers.jmx.Config(domain="my-domain", usesMOSGi=false)
public class JMXSimple {
@Property(name="prop", notification=true, rights="w")
diff --git a/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/ComparatorTestCase.java b/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/ComparatorTestCase.java
index c58acf3..f5ca73a 100644
--- a/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/ComparatorTestCase.java
+++ b/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/ComparatorTestCase.java
@@ -26,18 +26,17 @@
}
public void tearDown() {
- dynInstance.dispose();
- dpInstance.dispose();
+ helper.dispose();
}
public void testDynamic() {
- ComponentInstance grade1 = createGrade(1);
+ createGrade(1);
ComponentInstance grade2 = createGrade(2);
- ServiceReference ref = getServiceReferenceByName(CheckService.class.getName(), dynInstance.getInstanceName());
+ ServiceReference ref = helper.getServiceReferenceByName(CheckService.class.getName(), dynInstance.getInstanceName());
assertNotNull("CS availability", ref);
- CheckService cs = (CheckService) context.getService(ref);
+ CheckService cs = (CheckService) getServiceObject(ref);
Properties result = cs.getProps();
int fsGrade = ((Integer) result.get("fs")).intValue();
int fs2Grade = ((Integer) result.get("fs2")).intValue();
@@ -51,7 +50,7 @@
assertEquals("fss grade[0] -1", 2, fssGrades[0]);
assertEquals("fss grade[1] -1", 1, fssGrades[1]);
- ComponentInstance grade3 = createGrade(3);
+ createGrade(3);
result = cs.getProps();
fsGrade = ((Integer) result.get("fs")).intValue();
fs2Grade = ((Integer) result.get("fs2")).intValue();
@@ -76,21 +75,16 @@
assertEquals("fss grade size -3", 2, fssGrades.length);
assertEquals("fss grade[0] -3", 1, fssGrades[0]);
assertEquals("fss grade[1] -3", 3, fssGrades[1]);
-
- context.ungetService(ref);
- grade1.dispose();
- grade2.dispose();
- grade3.dispose();
}
public void testDynamicPriority() {
- ComponentInstance grade1 = createGrade(1);
+ createGrade(1);
ComponentInstance grade2 = createGrade(2);
- ServiceReference ref = getServiceReferenceByName(CheckService.class.getName(), dpInstance.getInstanceName());
+ ServiceReference ref = helper.getServiceReferenceByName(CheckService.class.getName(), dpInstance.getInstanceName());
assertNotNull("CS availability", ref);
- CheckService cs = (CheckService) context.getService(ref);
+ CheckService cs = (CheckService) getServiceObject(ref);
Properties result = cs.getProps();
int fsGrade = ((Integer) result.get("fs")).intValue();
int fs2Grade = ((Integer) result.get("fs2")).intValue();
@@ -102,7 +96,7 @@
assertEquals("fss grade[0] -1", 2, fssGrades[0]);
assertEquals("fss grade[1] -1", 1, fssGrades[1]);
- ComponentInstance grade3 = createGrade(3);
+ createGrade(3);
result = cs.getProps();
fsGrade = ((Integer) result.get("fs")).intValue();
fs2Grade = ((Integer) result.get("fs2")).intValue();
@@ -127,11 +121,6 @@
assertEquals("fss grade size -3", 2, fssGrades.length);
assertEquals("fss grade[0] -3", 3, fssGrades[0]);
assertEquals("fss grade[1] -3", 1, fssGrades[1]);
-
- context.ungetService(ref);
- grade1.dispose();
- grade2.dispose();
- grade3.dispose();
}
private ComponentInstance createGrade(int grade) {
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicProps.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicProps.java
index 3929cc6..fd351b9 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicProps.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicProps.java
@@ -20,25 +20,19 @@
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class DynamicProps extends OSGiTestCase {
- ComponentInstance fooProvider1;
- ComponentInstance fooProvider2;
- ComponentInstance fooProvider3;
- ComponentInstance fooProvider4;
+ IPOJOHelper helper;
public void setUp() {
+ helper = new IPOJOHelper(this);
String type = "PS-FooProviderType-Dyn";
-
- Properties p1 = new Properties();
- p1.put("instance.name","FooProvider-1");
- fooProvider1 = Utils.getComponentInstance(context, type, p1);
+ helper.createComponentInstance(type, "FooProvider-1");
Properties p2 = new Properties();
p2.put("instance.name","FooProvider-2");
@@ -47,7 +41,7 @@
p2.put("string", new String("bar"));
p2.put("strAProp", new String[] {"bar", "foo"});
p2.put("intAProp", new int[] {1, 2, 3});
- fooProvider2 = Utils.getComponentInstance(context, type, p2);
+ helper.createComponentInstance(type, p2);
String type2 = "PS-FooProviderType-Dyn2";
Properties p3 = new Properties();
@@ -57,27 +51,20 @@
p3.put("string", new String(""));
p3.put("strAProp", new String[0]);
p3.put("intAProp", new int[0]);
- fooProvider3 = Utils.getComponentInstance(context, type2, p3);
+ helper.createComponentInstance(type2, p3);
Properties p4 = new Properties();
p4.put("instance.name","FooProvider-4");
- fooProvider4 = Utils.getComponentInstance(context, type2, p4);
+ helper.createComponentInstance(type2, p4);
}
public void tearDown() {
- fooProvider1.dispose();
- fooProvider1 = null;
- fooProvider2.dispose();
- fooProvider2 = null;
- fooProvider3.dispose();
- fooProvider3 = null;
- fooProvider4.dispose();
- fooProvider4 = null;
+ helper.dispose();
}
public void testProperties1() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -102,7 +89,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -127,11 +114,10 @@
}
fs = null;
- context.ungetService(sr);
}
public void testProperties2() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -156,7 +142,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -181,11 +167,10 @@
}
fs = null;
- context.ungetService(sr);
}
public void testProperties3() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -210,7 +195,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -231,12 +216,10 @@
assertNull("Check intAProp hidding (no value)", intAProp);
fs = null;
- context.ungetService(sr);
-
}
public void testProperties4() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-4");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -258,7 +241,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -278,9 +261,7 @@
}
assertNull("Check intAProp hidding (no value)", intAProp);
- fs = null;
- context.ungetService(sr);
-
+ fs = null;
}
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicPropsReconfiguration.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicPropsReconfiguration.java
index c162147..680d4d2 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicPropsReconfiguration.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicPropsReconfiguration.java
@@ -23,8 +23,8 @@
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
@@ -32,7 +32,10 @@
public class DynamicPropsReconfiguration extends OSGiTestCase {
ComponentInstance fooProvider3, fooProvider4;
- public void setUp() {
+ IPOJOHelper helper;
+
+ public void setUp() {
+ helper = new IPOJOHelper(this);
String type2 = "PS-FooProviderType-Dyn2";
Properties p3 = new Properties();
p3.put("instance.name","FooProvider-3");
@@ -41,22 +44,17 @@
p3.put("string", new String(""));
p3.put("strAProp", new String[0]);
p3.put("intAProp", new int[0]);
- fooProvider3 = Utils.getComponentInstance(context, type2, p3);
+ fooProvider3 = helper.createComponentInstance(type2, p3);
- Properties p4 = new Properties();
- p4.put("instance.name","FooProvider-4");
- fooProvider4 = Utils.getComponentInstance(context, type2, p4);
+ fooProvider4 = helper.createComponentInstance(type2, "FooProvider-4");
}
public void tearDown() {
- fooProvider3.dispose();
- fooProvider3 = null;
- fooProvider4.dispose();
- fooProvider4 = null;
+ helper.dispose();
}
public void testFactoryReconf() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -81,8 +79,8 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- Factory fact = (Factory) context.getService(fact_ref);
+ ServiceReference fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ Factory fact = (Factory) getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("instance.name","FooProvider-3");
p3.put("int", new Integer(1));
@@ -96,7 +94,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -121,7 +119,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -142,8 +140,8 @@
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- fact = (Factory) context.getService(fact_ref);
+ fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ fact = (Factory) getServiceObject(fact_ref);
p3 = new Properties();
p3.put("instance.name","FooProvider-3");
p3.put("int", new Integer(1));
@@ -157,7 +155,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -182,13 +180,11 @@
}
fact = null;
- context.ungetService(fact_ref);
fs = null;
- context.ungetService(sr);
}
public void testFactoryReconfString() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -213,8 +209,8 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- Factory fact = (Factory) context.getService(fact_ref);
+ ServiceReference fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ Factory fact = (Factory) getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("instance.name","FooProvider-3");
p3.put("int", "1");
@@ -228,7 +224,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -253,7 +249,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -274,8 +270,8 @@
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- fact = (Factory) context.getService(fact_ref);
+ fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ fact = (Factory) getServiceObject(fact_ref);
p3 = new Properties();
p3.put("instance.name","FooProvider-3");
p3.put("int", "1");
@@ -289,7 +285,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -314,13 +310,11 @@
}
fact = null;
- context.ungetService(fact_ref);
fs = null;
- context.ungetService(sr);
}
public void testMSFReconf() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -345,8 +339,8 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
- ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ ServiceReference fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("int", new Integer(1));
p3.put("boolean", new Boolean(true));
@@ -359,7 +353,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -384,7 +378,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -405,8 +399,8 @@
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
- fact = (ManagedServiceFactory) context.getService(fact_ref);
+ fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) getServiceObject(fact_ref);
p3 = new Properties();
p3.put("int", new Integer(1));
p3.put("boolean", new Boolean(true));
@@ -419,7 +413,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -444,13 +438,11 @@
}
fact = null;
- context.ungetService(fact_ref);
fs = null;
- context.ungetService(sr);
}
public void testMSFReconfString() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -475,8 +467,8 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
- ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ ServiceReference fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
+ ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("int", "1");
p3.put("boolean", "true");
@@ -489,7 +481,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -514,7 +506,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -535,8 +527,8 @@
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
- fact = (ManagedServiceFactory) context.getService(fact_ref);
+ fact_ref = helper.getServiceReferenceByName(ManagedServiceFactory.class.getName() , "PS-FooProviderType-Dyn2");
+ fact = (ManagedServiceFactory) getServiceObject(fact_ref);
p3 = new Properties();
p3.put("int", "1");
p3.put("boolean", "true");
@@ -549,7 +541,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -574,13 +566,11 @@
}
fact = null;
- context.ungetService(fact_ref);
fs = null;
- context.ungetService(sr);
}
public void testFactoryReconfNoValue() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-4");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -602,8 +592,8 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- Factory fact = (Factory) context.getService(fact_ref);
+ ServiceReference fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ Factory fact = (Factory) getServiceObject(fact_ref);
Properties p3 = new Properties();
p3.put("instance.name","FooProvider-4");
p3.put("int", new Integer(1));
@@ -617,7 +607,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-4");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -642,7 +632,7 @@
}
// Invoke
- FooService fs = (FooService) context.getService(sr);
+ FooService fs = (FooService) getServiceObject(sr);
assertTrue("invoke fs", fs.foo());
// Re-check the property (change)
@@ -663,8 +653,8 @@
assertNull("Check intAProp hidding (no value)", intAProp);
// Reconfiguration
- fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName() , "PS-FooProviderType-Dyn2");
- fact = (Factory) context.getService(fact_ref);
+ fact_ref = helper.getServiceReferenceByName(Factory.class.getName() , "PS-FooProviderType-Dyn2");
+ fact = (Factory) getServiceObject(fact_ref);
p3 = new Properties();
p3.put("instance.name","FooProvider-3");
p3.put("int", new Integer(1));
@@ -678,7 +668,7 @@
fail("Unable to reconfigure the instance with : " + p3);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+ sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -703,9 +693,7 @@
}
fact = null;
- context.ungetService(fact_ref);
fs = null;
- context.ungetService(sr);
}
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/Exposition.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/Exposition.java
index 6228d4c..d888e61 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/Exposition.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/Exposition.java
@@ -18,13 +18,11 @@
*/
package org.apache.felix.ipojo.test.scenarios.ps;
-import java.util.Properties;
-
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.BarService;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class Exposition extends OSGiTestCase {
@@ -35,26 +33,19 @@
private ComponentInstance fooBarProvider2;
private ComponentInstance fooBarProvider3;
+ private IPOJOHelper helper;
+
public void setUp(){
- Properties p1 = new Properties();
- p1.put("instance.name","fooProviderSimple");
- fooProviderSimple = Utils.getComponentInstance(context, "PS-FooProviderType-1", p1);
+ helper = new IPOJOHelper(this);
+ fooProviderSimple = helper.createComponentInstance("PS-FooProviderType-1", "fooProviderSimple");
- Properties p2 = new Properties();
- p2.put("instance.name","fooProviderItf");
- fooProviderItf = Utils.getComponentInstance(context, "PS-FooProviderType-itf", p2);
+ fooProviderItf = helper.createComponentInstance("PS-FooProviderType-itf", "fooProviderItf");
- Properties p3 = new Properties();
- p3.put("instance.name","fooProviderItfs");
- fooBarProvider = Utils.getComponentInstance(context, "PS-FooBarProviderType-1", p3);
+ fooBarProvider = helper.createComponentInstance("PS-FooBarProviderType-1", "fooProviderItfs");
- Properties p4 = new Properties();
- p4.put("instance.name","fooProviderItfs2");
- fooBarProvider2 = Utils.getComponentInstance(context, "PS-FooBarProviderType-2", p4);
+ fooBarProvider2 = helper.createComponentInstance("PS-FooBarProviderType-2", "fooProviderItfs2");
- Properties p5 = new Properties();
- p5.put("instance.name","fooProviderItfs3");
- fooBarProvider3 = Utils.getComponentInstance(context, "PS-FooBarProviderType-3", p5);
+ fooBarProvider3 = helper.createComponentInstance("PS-FooBarProviderType-3", "fooProviderItfs3");
assertNotNull("Check the instance creation of fooProviderSimple", fooProviderSimple);
assertNotNull("Check the instance creation of fooProviderItf", fooProviderItf);
@@ -65,113 +56,96 @@
}
public void tearDown() {
- fooProviderSimple.dispose();
- fooProviderItf.dispose();
- fooBarProvider.dispose();
- fooBarProvider2.dispose();
- fooBarProvider3.dispose();
- fooProviderSimple = null;
- fooProviderItf = null;
- fooBarProvider = null;
- fooBarProvider2 = null;
- fooBarProvider3 = null;
+ helper.dispose();
}
public void testSimpleExposition() {
- ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), fooProviderSimple.getInstanceName());
assertNotNull("Check the availability of the FS from "+fooProviderSimple.getInstanceName(), ref);
- FooService fs = (FooService) context.getService(ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check fs invocation", fs.foo());
fs = null;
- context.ungetService(ref);
fooProviderSimple.stop();
- ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderSimple.getInstanceName());
+ ref = helper.getServiceReferenceByName(FooService.class.getName(), fooProviderSimple.getInstanceName());
assertNull("Check the absence of the FS from "+fooProviderSimple.getInstanceName(), ref);
}
public void testItfExposition() {
- ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), fooProviderItf.getInstanceName());
assertNotNull("Check the availability of the FS from "+fooProviderItf.getInstanceName(), ref);
- FooService fs = (FooService) context.getService(ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check fs invocation", fs.foo());
fs = null;
- context.ungetService(ref);
fooProviderItf.stop();
- ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProviderItf.getInstanceName());
+ ref = helper.getServiceReferenceByName(FooService.class.getName(), fooProviderItf.getInstanceName());
assertNull("Check the absence of the FS from "+fooProviderItf.getInstanceName(), ref);
}
public void testItfsExposition() {
- ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
+ ServiceReference refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider.getInstanceName());
assertNotNull("Check the availability of the FS from "+fooBarProvider.getInstanceName(), refFoo);
- ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ ServiceReference refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider.getInstanceName());
assertNotNull("Check the availability of the BS from "+fooBarProvider.getInstanceName(), refBar);
assertSame("Check service reference equality", refFoo, refBar);
- FooService fs = (FooService) context.getService(refFoo);
+ FooService fs = (FooService) getServiceObject(refFoo);
assertTrue("Check fs invocation", fs.foo());
fs = null;
- context.ungetService(refFoo);
- BarService bs = (BarService) context.getService(refBar);
+ BarService bs = (BarService) getServiceObject(refBar);
assertTrue("Check bs invocation", bs.bar());
bs = null;
- context.ungetService(refBar);
fooBarProvider.stop();
- refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider.getInstanceName());
- refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider.getInstanceName());
+ refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider.getInstanceName());
+ refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider.getInstanceName());
assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
}
public void testItfsExposition2() {
- ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
+ ServiceReference refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider2.getInstanceName());
assertNotNull("Check the availability of the FS from "+fooBarProvider2.getInstanceName(), refFoo);
- ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ ServiceReference refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider2.getInstanceName());
assertNotNull("Check the availability of the BS from "+fooBarProvider2.getInstanceName(), refBar);
assertSame("Check service reference equality", refFoo, refBar);
- FooService fs = (FooService) context.getService(refFoo);
+ FooService fs = (FooService) getServiceObject(refFoo);
assertTrue("Check fs invocation", fs.foo());
fs = null;
- context.ungetService(refFoo);
- BarService bs = (BarService) context.getService(refBar);
+ BarService bs = (BarService) getServiceObject(refBar);
assertTrue("Check bs invocation", bs.bar());
bs = null;
- context.ungetService(refBar);
fooBarProvider2.stop();
- refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider2.getInstanceName());
- refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider2.getInstanceName());
+ refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider2.getInstanceName());
+ refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider2.getInstanceName());
assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
}
public void testItfsExposition3() {
- ServiceReference refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
+ ServiceReference refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider3.getInstanceName());
assertNotNull("Check the availability of the FS from "+fooBarProvider3.getInstanceName(), refFoo);
- ServiceReference refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ ServiceReference refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider3.getInstanceName());
assertNotNull("Check the availability of the BS from "+fooBarProvider3.getInstanceName(), refBar);
assertNotSame("Check service reference inequality", refFoo, refBar);
- FooService fs = (FooService) context.getService(refFoo);
+ FooService fs = (FooService) getServiceObject(refFoo);
assertTrue("Check fs invocation", fs.foo());
fs = null;
- context.ungetService(refFoo);
- BarService bs = (BarService) context.getService(refBar);
+ BarService bs = (BarService) getServiceObject(refBar);
assertTrue("Check bs invocation", bs.bar());
bs = null;
- context.ungetService(refBar);
// Check properties
String baz1 = (String) refFoo.getProperty("baz");
@@ -182,8 +156,8 @@
fooBarProvider3.stop();
- refFoo = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooBarProvider3.getInstanceName());
- refBar = Utils.getServiceReferenceByName(context, BarService.class.getName(), fooBarProvider3.getInstanceName());
+ refFoo = helper.getServiceReferenceByName(FooService.class.getName(), fooBarProvider3.getInstanceName());
+ refBar = helper.getServiceReferenceByName(BarService.class.getName(), fooBarProvider3.getInstanceName());
assertNull("Check the absence of the FS from "+fooBarProvider.getInstanceName(), refFoo);
assertNull("Check the absence of the BS from "+fooBarProvider.getInstanceName(), refBar);
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/InheritedTest.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/InheritedTest.java
index 0653496..41777ea 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/InheritedTest.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/InheritedTest.java
@@ -21,27 +21,34 @@
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.ChildInterface;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
import org.apache.felix.ipojo.test.scenarios.ps.service.ParentInterface1;
import org.apache.felix.ipojo.test.scenarios.ps.service.ParentInterface2;
import org.apache.felix.ipojo.test.scenarios.ps.service.ParentParentInterface;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class InheritedTest extends OSGiTestCase {
private Factory pi1, pi11, pi12, pi2, pi21, pi3;
+ private IPOJOHelper helper;
+
public void setUp() {
- pi1 = Utils.getFactoryByName(context, "PS-PI1");
- pi11 = Utils.getFactoryByName(context, "PS-PI1-1");
- pi12 = Utils.getFactoryByName(context, "PS-PI1-2");
+ helper = new IPOJOHelper(this);
+ pi1 = helper.getFactory("PS-PI1");
+ pi11 = helper.getFactory("PS-PI1-1");
+ pi12 = helper.getFactory("PS-PI1-2");
- pi2 = Utils.getFactoryByName(context, "PS-PI2");
- pi21 = Utils.getFactoryByName(context, "PS-PI2-1");
+ pi2 = helper.getFactory("PS-PI2");
+ pi21 = helper.getFactory("PS-PI2-1");
- pi3 = Utils.getFactoryByName(context, "PS-PI3");
+ pi3 = helper.getFactory("PS-PI3");
+ }
+
+ public void tearDown() {
+ helper.dispose();
}
private boolean contains(String[] arr, String txt) {
@@ -101,87 +108,87 @@
}
public void testIP1() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi1.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi1.getName(), "ci");
- ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ ServiceReference ref1 = helper.getServiceReferenceByName( ChildInterface.class.getName(), "ci");
assertNotNull("Check Child", ref1);
- ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ ServiceReference ref2 = helper.getServiceReferenceByName( ParentInterface1.class.getName(), "ci");
assertNotNull("Check Parent1", ref2);
- ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ ServiceReference ref3 = helper.getServiceReferenceByName( ParentInterface2.class.getName(), "ci");
assertNotNull("Check Parent2", ref3);
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
ci.dispose();
}
public void testIP11() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi11.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi11.getName(), "ci");
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
ci.dispose();
}
public void testIP12() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi12.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi12.getName(), "ci");
- ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ ServiceReference ref3 = helper.getServiceReferenceByName( ParentInterface2.class.getName(), "ci");
assertNotNull("Check Parent2", ref3);
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
ci.dispose();
}
public void testIP2() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi2.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi2.getName(), "ci");
- ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ ServiceReference ref1 = helper.getServiceReferenceByName( ChildInterface.class.getName(), "ci");
assertNotNull("Check Child", ref1);
- ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ ServiceReference ref2 = helper.getServiceReferenceByName( ParentInterface1.class.getName(), "ci");
assertNotNull("Check Parent1", ref2);
- ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ ServiceReference ref3 = helper.getServiceReferenceByName( ParentInterface2.class.getName(), "ci");
assertNotNull("Check Parent2", ref3);
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
ci.dispose();
}
public void testIP21() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi21.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi21.getName(), "ci");
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
ci.dispose();
}
public void testIP3() {
- ComponentInstance ci = Utils.getComponentInstanceByName(context, pi3.getName(), "ci");
+ ComponentInstance ci = helper.createComponentInstance( pi3.getName(), "ci");
- ServiceReference ref1 = Utils.getServiceReferenceByName(context, ChildInterface.class.getName(), "ci");
+ ServiceReference ref1 = helper.getServiceReferenceByName( ChildInterface.class.getName(), "ci");
assertNotNull("Check Child", ref1);
- ServiceReference ref2 = Utils.getServiceReferenceByName(context, ParentInterface1.class.getName(), "ci");
+ ServiceReference ref2 = helper.getServiceReferenceByName( ParentInterface1.class.getName(), "ci");
assertNotNull("Check Parent1", ref2);
- ServiceReference ref3 = Utils.getServiceReferenceByName(context, ParentInterface2.class.getName(), "ci");
+ ServiceReference ref3 = helper.getServiceReferenceByName( ParentInterface2.class.getName(), "ci");
assertNotNull("Check Parent2", ref3);
- ServiceReference ref4 = Utils.getServiceReferenceByName(context, ParentParentInterface.class.getName(), "ci");
+ ServiceReference ref4 = helper.getServiceReferenceByName( ParentParentInterface.class.getName(), "ci");
assertNotNull("Check PP", ref4);
- ServiceReference ref5 = Utils.getServiceReferenceByName(context, FooService.class.getName(), "ci");
+ ServiceReference ref5 = helper.getServiceReferenceByName( FooService.class.getName(), "ci");
assertNotNull("Check FS", ref5);
ci.dispose();
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceArchitectureTest.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceArchitectureTest.java
index e9ed400..15ac19d 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceArchitectureTest.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceArchitectureTest.java
@@ -20,7 +20,6 @@
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.architecture.HandlerDescription;
@@ -28,35 +27,37 @@
import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription;
import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.BarService;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class ProvidedServiceArchitectureTest extends OSGiTestCase {
+ private IPOJOHelper helper;
+
+ public void setUp() {
+ helper = new IPOJOHelper(this);
+ }
+
+ public void tearDown() {
+ helper.dispose();
+ }
public void testExposition() {
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory( factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
-
- Properties props = new Properties();
- props.put("instance.name",compName);
- ComponentInstance ci = null;
- try {
- ci = fact.createComponentInstance(props);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), "FooProvider-1");
+ helper.createComponentInstance(factName, compName);
+
+ ServiceReference arch_ref = helper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
- Architecture arch = (Architecture) context.getService(arch_ref);
+ Architecture arch = (Architecture) getServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
@@ -85,8 +86,6 @@
assertEquals("Check service properties number", prop.size(), 2);
assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
-
- ci.dispose();
}
public void testProps() {
@@ -94,7 +93,7 @@
String compName = "FooProvider";
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory( factName);
assertNotNull("Cannot find the factory FooProvider", fact);
Properties props = new Properties();
@@ -102,15 +101,12 @@
props.put("foo", "foo");
props.put("bar", "2");
props.put("baz", "baz");
- ComponentInstance ci = null;
- try {
- ci = fact.createComponentInstance(props);
- } catch (Exception e) { fail(e.getMessage()); }
+ helper.createComponentInstance(factName, props);
- ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), compName);
+ ServiceReference arch_ref = helper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
- Architecture arch = (Architecture) context.getService(arch_ref);
+ Architecture arch = (Architecture) getServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
@@ -144,7 +140,6 @@
assertEquals("Check bar property", prop.getProperty("bar"), "2");
assertEquals("Check baz property", prop.getProperty("baz"), "baz");
- ci.dispose();
}
public void testDoubleProviding() {
@@ -152,22 +147,15 @@
String compName = "FooProvider";
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory( factName);
assertNotNull("Cannot find the factory FooProvider", fact);
- Properties props = new Properties();
- props.put("instance.name",compName);
- ComponentInstance ci = null;
- try {
- ci = fact.createComponentInstance(props);
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ helper.createComponentInstance(factName, compName);
- ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), compName);
+ ServiceReference arch_ref = helper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
- Architecture arch = (Architecture) context.getService(arch_ref);
+ Architecture arch = (Architecture) getServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
@@ -193,7 +181,6 @@
assertContains("Check provided service specs - 2", ps[0].getServiceSpecification(), BarService.class.getName());
assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
- ci.dispose();
}
public void testPropsNoValue() {
@@ -201,20 +188,15 @@
String compName = "FooProvider";
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory( factName);
assertNotNull("Cannot find the factory FooProvider", fact);
-
- Properties props = new Properties();
- props.put("instance.name",compName);
- ComponentInstance ci = null;
- try {
- ci = fact.createComponentInstance(props);
- } catch (Exception e) { fail(e.getMessage()); }
+
+ helper.createComponentInstance(factName, compName);
- ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), compName);
+ ServiceReference arch_ref = helper.getServiceReferenceByName(Architecture.class.getName(), compName);
assertNotNull("Architecture not available", arch_ref);
- Architecture arch = (Architecture) context.getService(arch_ref);
+ Architecture arch = (Architecture) getServiceObject(arch_ref);
InstanceDescription id = arch.getInstanceDescription();
assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
@@ -245,8 +227,6 @@
assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
-
- ci.dispose();
}
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
index 8d9ba33..24ba6af 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/SimplePS.java
@@ -18,63 +18,50 @@
*/
package org.apache.felix.ipojo.test.scenarios.ps;
-import java.util.Properties;
-
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
public class SimplePS extends OSGiTestCase {
public void testPS() {
+ IPOJOHelper helper = new IPOJOHelper(this);
+
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
- ServiceReference[] refs = null;
+ ServiceReference ref = null;
// Check that no Foo Service are available
- try {
- refs = context.getServiceReferences(FooService.class.getName(), null);
- } catch (InvalidSyntaxException e) { fail("Service query failed : " + e); }
+ ref = getServiceReference(FooService.class.getName());
- assertNull("FS already available", refs);
+ assertNull("FS already available", ref);
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
- Properties props = new Properties();
- props.put("instance.name",compName);
- ComponentInstance ci = null;
- try {
- ci = fact.createComponentInstance(props);
- } catch (Exception e1) { fail(e1.getMessage()); }
+ helper.createComponentInstance(factName, compName);
// Get a FooService provider
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
- } catch (InvalidSyntaxException e) { fail("Service query failed (2) " + e); }
-
- assertNotNull("FS not available", refs);
+ ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
+
+ assertNotNull("FS not available", ref);
// Test foo invocation
- FooService fs = (FooService) context.getService(refs[0]);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
- // Unget the service
- context.ungetService(refs[0]);
-
- ci.dispose();
+ helper.dispose();
+
// Check that there is no more FooService
- try {
- refs = context.getServiceReferences(FooService.class.getName(), null);
- } catch (InvalidSyntaxException e) { fail("Service query failed (3) : " + e.getMessage()); }
+ ref = getServiceReference(FooService.class.getName(), null);
- assertNull("FS available, but component instance stopped", refs);
+
+ assertNull("FS available, but component instance stopped", ref);
+
}
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticProps.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticProps.java
index 484bacb..f40bbe6 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticProps.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticProps.java
@@ -20,23 +20,20 @@
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class StaticProps extends OSGiTestCase {
-
- ComponentInstance fooProvider1;
- ComponentInstance fooProvider2;
+
+ IPOJOHelper helper;
public void setUp() {
+ helper = new IPOJOHelper(this);
String type = "PS-FooProviderType-2";
-
- Properties p1 = new Properties();
- p1.put("instance.name","FooProvider-1");
- fooProvider1 = Utils.getComponentInstance(context, type, p1);
+
+ helper.createComponentInstance(type, "FooProvider-1");
Properties p2 = new Properties();
p2.put("instance.name","FooProvider-2");
@@ -45,19 +42,16 @@
p2.put("string", new String("bar"));
p2.put("strAProp", new String[] {"bar", "foo"});
p2.put("intAProp", new int[] {1, 2, 3});
- fooProvider2 = Utils.getComponentInstance(context, type, p2);
+ helper.createComponentInstance(type, p2);
}
public void tearDown() {
- fooProvider1.dispose();
- fooProvider1 = null;
- fooProvider2.dispose();
- fooProvider2 = null;
+ helper.dispose();
}
public void testProperties1() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -84,7 +78,7 @@
}
public void testProperties2() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticPropsReconfiguration.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticPropsReconfiguration.java
index 203d4a3..8d944d4 100644
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticPropsReconfiguration.java
+++ b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/StaticPropsReconfiguration.java
@@ -21,26 +21,23 @@
import java.util.Dictionary;
import java.util.Properties;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.ps.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
public class StaticPropsReconfiguration extends OSGiTestCase {
- ComponentInstance fooProvider1;
- ComponentInstance fooProvider2;
-
- public void setUp() {
+ IPOJOHelper helper;
+
+ public void setUp() {
+ helper = new IPOJOHelper(this);
+
String type = "PS-FooProviderType-2";
-
- Properties p1 = new Properties();
- p1.put("instance.name","FooProvider-1");
- fooProvider1 = Utils.getComponentInstance(context, type, p1);
+ helper.createComponentInstance(type, "FooProvider-1");
Properties p2 = new Properties();
p2.put("instance.name","FooProvider-2");
@@ -49,19 +46,15 @@
p2.put("string", new String("bar"));
p2.put("strAProp", new String[] {"bar", "foo"});
p2.put("intAProp", new int[] {1, 2, 3});
- fooProvider2 = Utils.getComponentInstance(context, type, p2);
-
+ helper.createComponentInstance(type, p2);
}
public void tearDown() {
- fooProvider1.dispose();
- fooProvider1 = null;
- fooProvider2.dispose();
- fooProvider2 = null;
+ helper.dispose();
}
public void testReconfFactory1() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ ServiceReference sr = helper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -86,7 +79,7 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "PS-FooProviderType-2");
+ ServiceReference fact_ref = helper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-2");
Dictionary reconf = new Properties();
reconf.put("instance.name","FooProvider-1");
reconf.put("int", new Integer(5));
@@ -94,14 +87,14 @@
reconf.put("string", new String("toto"));
reconf.put("strAProp", new String[] {"foo", "baz"});
reconf.put("intAProp", new int[] {3, 2, 1});
- Factory fact = (Factory) context.getService(fact_ref);
+ Factory fact = (Factory) getServiceObject(fact_ref);
try {
fact.reconfigure(reconf);
} catch(Exception e) {
fail("Configuration non acceptable : " + reconf);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ sr = helper.getServiceReferenceByName( FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties after the reconfiguration
@@ -125,13 +118,12 @@
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
}
- context.ungetService(fact_ref);
fact = null;
}
public void testReconfFactory2() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ ServiceReference sr = helper.getServiceReferenceByName( FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -157,7 +149,7 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, Factory.class.getName(), "PS-FooProviderType-2");
+ ServiceReference fact_ref = helper.getServiceReferenceByName( Factory.class.getName(), "PS-FooProviderType-2");
Dictionary reconf = new Properties();
reconf.put("instance.name","FooProvider-2");
reconf.put("int", new Integer(5));
@@ -165,7 +157,7 @@
reconf.put("string", new String("toto"));
reconf.put("strAProp", new String[] {"foo", "baz"});
reconf.put("intAProp", new int[] {3, 2, 1});
- Factory fact = (Factory) context.getService(fact_ref);
+ Factory fact = (Factory) getServiceObject(fact_ref);
try {
fact.reconfigure(reconf);
} catch(Exception e) {
@@ -192,13 +184,11 @@
for (int i = 0; i < intAProp.length; i++) {
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
}
-
- context.ungetService(fact_ref);
fact = null;
}
public void testMSFFactory1() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ ServiceReference sr = helper.getServiceReferenceByName( FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -223,21 +213,21 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
+ ServiceReference fact_ref = helper.getServiceReferenceByName( ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
Dictionary reconf = new Properties();
reconf.put("int", new Integer(5));
reconf.put("long", new Long(43));
reconf.put("string", new String("toto"));
reconf.put("strAProp", new String[] {"foo", "baz"});
reconf.put("intAProp", new int[] {3, 2, 1});
- ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
try {
fact.updated("FooProvider-1", reconf);
} catch (ConfigurationException e) {
fail("Configuration non acceptable : " + reconf);
}
- sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-1");
+ sr = helper.getServiceReferenceByName( FooService.class.getName(), "FooProvider-1");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties after the reconfiguration
@@ -261,13 +251,12 @@
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
}
- context.ungetService(fact_ref);
fact = null;
}
public void testReconfMSF2() {
- ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+ ServiceReference sr = helper.getServiceReferenceByName( FooService.class.getName(), "FooProvider-2");
assertNotNull("Check the availability of the FS service", sr);
// Check service properties
@@ -293,14 +282,14 @@
}
// Reconfiguration
- ServiceReference fact_ref = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
+ ServiceReference fact_ref = helper.getServiceReferenceByName( ManagedServiceFactory.class.getName(), "PS-FooProviderType-2");
Dictionary reconf = new Properties();
reconf.put("int", new Integer(5));
reconf.put("long", new Long(43));
reconf.put("string", new String("toto"));
reconf.put("strAProp", new String[] {"foo", "baz"});
reconf.put("intAProp", new int[] {3, 2, 1});
- ManagedServiceFactory fact = (ManagedServiceFactory) context.getService(fact_ref);
+ ManagedServiceFactory fact = (ManagedServiceFactory) getServiceObject(fact_ref);
try {
fact.updated("FooProvider-2", reconf);
} catch (ConfigurationException e) {
@@ -328,7 +317,6 @@
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
}
- context.ungetService(fact_ref);
fact = null;
}
diff --git a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
deleted file mode 100644
index bcec3d5..0000000
--- a/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
+++ /dev/null
@@ -1,329 +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.test.scenarios.util;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
-import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.HandlerManagerFactory;
-import org.apache.felix.ipojo.ServiceContext;
-import org.apache.felix.ipojo.architecture.Architecture;
-//import org.apache.felix.ipojo.composite.CompositeManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedServiceFactory;
-
-public class Utils {
-
- public static Factory getFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static HandlerManagerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return (HandlerManagerFactory) bc.getService(refs[0]);
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- // if(fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- return null;
- }
- // }
- // else {
- // System.err.println("Configuration not accepted by : " + factoryName);
- // return null;
- // }
- }
-
- public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- try {
- Properties props = new Properties();
- props.put("instance.name",name);
- return fact.createComponentInstance(props);
- } catch (Exception e) {
- System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- e.printStackTrace();
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else if (itf.equals(Architecture.class.getName())) {
- filter = "(" + "architecture.instance" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
- ServiceReference[] refs = null;
- String filter = "(" + "service.pid" + "=" + pid + ")";
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else if (refs.length == 1) {
- return refs[0];
- } else {
- Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
- return null;
- }
- }
-
- public static Object getServiceObject(BundleContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
-// public static ServiceContext getServiceContext(ComponentInstance ci) {
-// if (ci instanceof CompositeManager) {
-// return ((CompositeManager) ci).getServiceContext();
-// } else {
-// throw new RuntimeException("Cannot get the service context form an non composite instance");
-// }
-// }
-
- public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) { return null; }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) { return null; }
-
- if (fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return null;
- }
- } else {
- System.err.println("Configuration not accepted by : " + factoryName);
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
- public static boolean contains(String string, String[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] != null && array[i].equals(string)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean contains(int value, int[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] == value) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
index 8ce4af5..78e92e9 100644
--- a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
+++ b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/POJOCreation.java
@@ -21,19 +21,19 @@
import java.util.Properties;
import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.component.FooProviderType1;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
/**
* Check the different method to create POJO object.
*/
public class POJOCreation extends OSGiTestCase {
+
+ private IPOJOHelper helper;
private ComponentInstance ci_lazzy;
private ComponentInstance ci_immediate;
@@ -43,90 +43,59 @@
private Architecture immeArch;
private Architecture immeArchSing;
- private ServiceReference lazzyRef;
- private ServiceReference immRef;
- private ServiceReference immRefSing;
+
private ComponentInstance ci_lazzy_sing;
private ComponentInstance ci_lazzy_sev;
- private ServiceReference lazzyRefSing;
- private ServiceReference lazzyRefSev;
+
private Architecture lazzyArchSing;
private Architecture lazzyArchSev;
private ComponentInstance ci_lazzy_singM;
private ComponentInstance ci_lazzy_sevM;
- private ServiceReference lazzyRefSingM;
- private ServiceReference lazzyRefSevM;
+
private Architecture lazzyArchSingM;
private Architecture lazzyArchSevM;
public void setUp() {
+ helper = new IPOJOHelper(this);
+
String factName = "ManipulationCreation-FooProviderType-1";
String compName = "FooProvider-1";
- Properties p = new Properties();
- p.put("instance.name",compName);
- ci_lazzy = Utils.getComponentInstance(context, factName ,p);
+ ci_lazzy = helper.createComponentInstance(factName ,compName);
String factName2 = "ManipulationCreation-ImmediateFooProviderType";
String compName2 = "FooProvider-2";
- Properties p2 = new Properties();
- p2.put("instance.name",compName2);
- ci_immediate = Utils.getComponentInstance(context, factName2, p2);
+ ci_immediate = helper.createComponentInstance(factName2, compName2);
String factName3 = "ManipulationCreation-ImmediateFooProviderTypeSingleton";
String compName3 = "FooProvider-3";
- Properties p3 = new Properties();
- p3.put("instance.name",compName3);
- ci_immediate_singleton = Utils.getComponentInstance(context, factName3, p3);
+ ci_immediate_singleton = helper.createComponentInstance(factName3, compName3);
String factName4 = "ManipulationCreation-FooProviderType-1-Sing";
String compName4 = "FooProvider-1-Sing";
- Properties p4 = new Properties();
- p4.put("instance.name",compName4);
- ci_lazzy_sing = Utils.getComponentInstance(context, factName4 ,p4);
+ ci_lazzy_sing = helper.createComponentInstance(factName4, compName4);
String factName5 = "ManipulationCreation-FooProviderType-1-Sev";
String compName5 = "FooProvider-1-Sev";
- Properties p5 = new Properties();
- p5.put("instance.name",compName5);
- ci_lazzy_sev = Utils.getComponentInstance(context, factName5 ,p5);
+ ci_lazzy_sev = helper.createComponentInstance(factName5, compName5);
String factName6 = "ManipulationCreation-FooProviderType-1-SingM";
String compName6 = "FooProvider-1-SingM";
- Properties p6 = new Properties();
- p6.put("instance.name",compName6);
- ci_lazzy_singM = Utils.getComponentInstance(context, factName6 ,p6);
+ ci_lazzy_singM = helper.createComponentInstance(factName6, compName6);
String factName7 = "ManipulationCreation-FooProviderType-1-SevM";
String compName7 = "FooProvider-1-SevM";
- Properties p7 = new Properties();
- p7.put("instance.name",compName7);
- ci_lazzy_sevM = Utils.getComponentInstance(context, factName7 ,p7);
+ ci_lazzy_sevM = helper.createComponentInstance(factName7, compName7);
- lazzyRef = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName+")");
- immRef = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName2+")");
- immRefSing = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName3+")");
- lazzyRefSing = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName4+")");
- lazzyRefSev = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName5+")");
- lazzyRefSingM = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName6+")");
- lazzyRefSevM = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName7+")");
-
- lazzyArch = (Architecture) context.getService(lazzyRef);
- immeArch = (Architecture) context.getService(immRef);
- immeArchSing = (Architecture) context.getService(immRefSing);
- lazzyArchSing = (Architecture) context.getService(lazzyRefSing);
- lazzyArchSev = (Architecture) context.getService(lazzyRefSev);
- lazzyArchSingM = (Architecture) context.getService(lazzyRefSingM);
- lazzyArchSevM = (Architecture) context.getService(lazzyRefSevM);
+ lazzyArch = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName+")");
+ immeArch = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName2+")");
+ immeArchSing = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName3+")");
+ lazzyArchSing = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName4+")");
+ lazzyArchSev = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName5+")");
+ lazzyArchSingM = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName6+")");
+ lazzyArchSevM = (Architecture) getServiceObject(Architecture.class.getName(), "(architecture.instance="+compName7+")");
}
public void tearDown() {
- context.ungetService(lazzyRef);
- context.ungetService(immRef);
- context.ungetService(immRefSing);
- context.ungetService(lazzyRefSing);
- context.ungetService(lazzyRefSev);
- context.ungetService(lazzyRefSingM);
- context.ungetService(lazzyRefSevM);
lazzyArch = null;
immeArch = null;
immeArchSing = null;
@@ -134,13 +103,7 @@
lazzyArchSev = null;
lazzyArchSingM = null;
lazzyArchSevM = null;
- ci_lazzy.dispose();
- ci_immediate.dispose();
- ci_immediate_singleton.dispose();
- ci_lazzy_sing.dispose();
- ci_lazzy_sev.dispose();
- ci_lazzy_singM.dispose();
- ci_lazzy_sevM.dispose();
+ helper.dispose();
}
/**
@@ -148,15 +111,11 @@
*/
public void testLazyCreation() {
assertEquals("Check that no objects are created ", 0, lazzyArch.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object",1, lazzyArch.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -164,15 +123,11 @@
*/
public void testLazyCreationSingleton() {
assertEquals("Check that no objects are created ", 0, lazzyArchSing.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sing.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy_sing.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sing.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy_sing.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object",1, lazzyArchSing.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -180,17 +135,13 @@
*/
public void testLazyCreationSeveral() {
assertEquals("Check that no objects are created ", 0, lazzyArchSev.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sev.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy_sev.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
- FooService fs2 = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sev.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy_sev.getInstanceName() + " is available", ref);
+ FooService fs = (FooService) getServiceObject(ref);
+ FooService fs2 = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertTrue("Check the FooService invocation-2", fs2.foo());
assertEquals("Check the creation of 1 object",1, lazzyArchSev.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -198,31 +149,23 @@
*/
public void testImmediateCreation() {
assertEquals("Check that one object is created ", 1, immeArch.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_immediate.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_immediate.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_immediate.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_immediate.getInstanceName() + " is available", ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, immeArch.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
* Check bundle context injection.
*/
public void testBundleContext() {
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
Properties p = fs.fooProps();
assertNotNull("Check the bundle context", p.get("context"));
assertEquals("Check the creation of 1 object",1, lazzyArch.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -230,15 +173,11 @@
*/
public void testImmediateSingletonCreation() {
assertEquals("Check that one object is created ", 1, immeArchSing.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_immediate_singleton.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_immediate_singleton.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_immediate_singleton.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_immediate_singleton.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object", 1, immeArchSing.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -247,17 +186,13 @@
*/
public void testLazyCreationSingletonM() {
assertEquals("Check that no objects are created ", 0, lazzyArchSingM.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_singM.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy_singM.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
- FooService fs2 = (FooService) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_singM.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy_singM.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
+ FooService fs2 = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertTrue("Check the FooService invocation", fs2.foo());
assertEquals("Check the creation of 1 object",1, lazzyArchSingM.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -266,19 +201,15 @@
*/
public void testLazyCreationSeveralM() {
assertEquals("Check that no objects are created ", 0, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy_sevM.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy_sevM.getInstanceName() + " is available",refs);
- FooService fs = (FooService) context.getService(refs[0]);
+ ServiceReference ref= helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sevM.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy_sevM.getInstanceName() + " is available",ref);
+ FooService fs = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation", fs.foo());
assertEquals("Check the creation of 1 object",1, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
- FooService fs2 = (FooService) context.getService(refs[0]);
+ FooService fs2 = (FooService) getServiceObject(ref);
assertTrue("Check the FooService invocation-2", fs2.foo());
// Only one object as the getService method is called only once (service factory) despite the policy="method".
assertEquals("Check the creation of 1 object",1, lazzyArchSevM.getInstanceDescription().getCreatedObjects().length);
- context.ungetService(refs[0]);
}
/**
@@ -295,9 +226,7 @@
public void testSuperCall() {
try {
- Factory fact = Utils.getFactoryByName(context, "org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructor");
- ComponentInstance ci = fact.createComponentInstance(null);
- ci.dispose();
+ helper.createComponentInstance("org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructor");
} catch (Throwable e) {
fail(e.getMessage());
}
@@ -305,9 +234,7 @@
public void testSuperCallWithBC() {
try {
- Factory fact = Utils.getFactoryByName(context, "org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithBC");
- ComponentInstance ci = fact.createComponentInstance(null);
- ci.dispose();
+ helper.createComponentInstance("org.apache.felix.ipojo.test.scenarios.component.CallSuperConstructorWithBC");
} catch (Throwable e) {
fail(e.getMessage());
}
diff --git a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
deleted file mode 100644
index bcec3d5..0000000
--- a/ipojo/tests/manipulator/creation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
+++ /dev/null
@@ -1,329 +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.test.scenarios.util;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
-import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.HandlerManagerFactory;
-import org.apache.felix.ipojo.ServiceContext;
-import org.apache.felix.ipojo.architecture.Architecture;
-//import org.apache.felix.ipojo.composite.CompositeManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedServiceFactory;
-
-public class Utils {
-
- public static Factory getFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static HandlerManagerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return (HandlerManagerFactory) bc.getService(refs[0]);
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- // if(fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- return null;
- }
- // }
- // else {
- // System.err.println("Configuration not accepted by : " + factoryName);
- // return null;
- // }
- }
-
- public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- try {
- Properties props = new Properties();
- props.put("instance.name",name);
- return fact.createComponentInstance(props);
- } catch (Exception e) {
- System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- e.printStackTrace();
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else if (itf.equals(Architecture.class.getName())) {
- filter = "(" + "architecture.instance" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
- ServiceReference[] refs = null;
- String filter = "(" + "service.pid" + "=" + pid + ")";
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else if (refs.length == 1) {
- return refs[0];
- } else {
- Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
- return null;
- }
- }
-
- public static Object getServiceObject(BundleContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
-// public static ServiceContext getServiceContext(ComponentInstance ci) {
-// if (ci instanceof CompositeManager) {
-// return ((CompositeManager) ci).getServiceContext();
-// } else {
-// throw new RuntimeException("Cannot get the service context form an non composite instance");
-// }
-// }
-
- public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) { return null; }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) { return null; }
-
- if (fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return null;
- }
- } else {
- System.err.println("Configuration not accepted by : " + factoryName);
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
- public static boolean contains(String string, String[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] != null && array[i].equals(string)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean contains(int value, int[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] == value) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java
index 085f357..737edbe 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ExceptionTest.java
@@ -18,54 +18,46 @@
*/
package org.apache.felix.ipojo.test.scenarios.manipulation;
-import java.util.Properties;
-
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.component.FooProviderType1;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
/**
- * Test execption handling. POJO exception must be propagated.
+ * Test exception handling. POJO exception must be propagated.
*/
public class ExceptionTest extends OSGiTestCase {
private ComponentInstance ci_lazzy;
- private ComponentInstance ci_immediate;
private ServiceReference lazzyRef;
private ServiceReference immRef;
+
+ IPOJOHelper helper;
public void setUp() {
+ helper = new IPOJOHelper(this);
+
String factName = "Manipulation-FooProviderType-1";
String compName = "FooProvider-1";
-
- Properties p = new Properties();
- p.put("instance.name",compName);
- ci_lazzy = Utils.getComponentInstance(context, factName, p);
+ ci_lazzy = helper.createComponentInstance(factName, compName);
String factName2 = "Manipulation-ImmediateFooProviderType";
String compName2 = "FooProvider-2";
+ helper.createComponentInstance(factName2, compName2);
- Properties p2 = new Properties();
- p2.put("instance.name",compName2);
- ci_immediate = Utils.getComponentInstance(context, factName2, p2);
+ lazzyRef = getServiceReference(Architecture.class.getName(), "(architecture.instance="+compName+")");
+ immRef = getServiceReference(Architecture.class.getName(), "(architecture.instance="+compName2+")");
- lazzyRef = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName+")");
- immRef = Utils.getServiceReference(context, Architecture.class.getName(), "(architecture.instance="+compName2+")");
assertNotNull("LazzyRef", lazzyRef);
assertNotNull("ImmRef", immRef);
}
public void tearDown() {
- context.ungetService(lazzyRef);
- context.ungetService(immRef);
- ci_lazzy.dispose();
- ci_immediate.dispose();
+ helper.dispose();
}
@@ -73,18 +65,14 @@
* Check that the exception is correctly propagated.
*/
public void testException() {
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
- FooProviderType1 fs = (FooProviderType1) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",ref);
+ FooProviderType1 fs = (FooProviderType1) getServiceObject(ref);
try {
fs.testException();
- context.ungetService(refs[0]);
fail("The method must returns an exception");
} catch(Exception e) {
- context.ungetService(refs[0]);
+ // OK
}
}
@@ -92,17 +80,12 @@
* Check that the exception is correctly catch by the POJO.
*/
public void testTry() {
- ServiceReference[] refs = null;
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name="+ci_lazzy.getInstanceName()+")");
- } catch (InvalidSyntaxException e) { e.printStackTrace(); }
- assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",refs);
- FooProviderType1 fs = (FooProviderType1) context.getService(refs[0]);
+ ServiceReference ref = helper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
+ assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available",ref);
+ FooProviderType1 fs = (FooProviderType1) context.getService(ref);
try {
fs.testTry();
- context.ungetService(refs[0]);
} catch(Exception e) {
- context.ungetService(refs[0]);
fail("The method has returned an exception");
}
}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java
index 2554cb0..1789a47 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/GetComponentInstanceTest.java
@@ -25,9 +25,8 @@
import org.apache.felix.ipojo.Pojo;
import org.apache.felix.ipojo.architecture.InstanceDescription;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.FooService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
/**
@@ -35,6 +34,16 @@
*/
public class GetComponentInstanceTest extends OSGiTestCase {
+ IPOJOHelper helper;
+
+ public void setUp() {
+ helper = new IPOJOHelper(this);
+ }
+
+ public void tearDown() {
+ helper.dispose();
+ }
+
/**
* Check if a pojo can correctly be cast in POJO.
* Check the getComponentInstance method.
@@ -42,10 +51,10 @@
public void testGetComponentInstance() {
String factName = "Manipulation-FooProviderType-1";
String compName = "FooProvider-1";
- ServiceReference[] refs = null;
+ ServiceReference ref = null;
// Get the factory to create a component instance
- Factory fact = Utils.getFactoryByName(context, factName);
+ Factory fact = helper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
Properties props = new Properties();
@@ -58,14 +67,12 @@
assertEquals("Check instance name", compName, ci.getInstanceName());
// Get a FooService provider
- try {
- refs = context.getServiceReferences(FooService.class.getName(), "(instance.name=" + compName + ")");
- } catch (InvalidSyntaxException e) { fail("Service query failed (2) " + e); }
+ ref = helper.getServiceReferenceByName(FooService.class.getName(), compName);
- assertNotNull("FS not available", refs);
+ assertNotNull("FS not available", ref);
// Get foo object
- FooService fs = (FooService) context.getService(refs[0]);
+ FooService fs = (FooService) getServiceObject(ref);
// Cast to POJO
Pojo pojo = (Pojo) fs;
@@ -81,16 +88,13 @@
assertEquals("Check instance description name", id.getName(), compName);
// Unget the service
- context.ungetService(refs[0]);
+ context.ungetService(ref);
ci.dispose();
// Check that there is no more FooService
- try {
- refs = context.getServiceReferences(FooService.class.getName(), null);
- } catch (InvalidSyntaxException e) { fail("Service query failed (3) : " + e.getMessage()); }
-
- assertNull("FS available, but component instance stopped", refs);
+ ref = getServiceReference(FooService.class.getName());
+ assertNull("FS available, but component instance stopped", ref);
}
}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
index cd60777..e076b6a 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
@@ -4,12 +4,11 @@
import java.util.Properties;
import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.component.InnerClasses;
import org.apache.felix.ipojo.test.scenarios.component.InnerClasses.PublicNested;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.CheckService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class NestedClassesTests extends OSGiTestCase {
@@ -17,8 +16,11 @@
private ComponentInstance instance;
private CheckService service;
+ IPOJOHelper helper;
+
+
public void setUp() {
- Factory factory = Utils.getFactoryByName(context, "inners");
+ helper = new IPOJOHelper(this);
Properties map = new Properties();
map.put("publicObject", "publicObject");
map.put("publicInt", new Integer(0));
@@ -30,20 +32,15 @@
map.put("privateInt", new Integer(3));
map.put("nonObject", "nonObject");
map.put("nonInt", new Integer(4));
- try {
- instance = factory.createComponentInstance(map);
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ instance = helper.createComponentInstance("inners", map);
- ServiceReference ref =Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());
+ ServiceReference ref = helper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Check service availability", ref);
- service = (CheckService) context.getService(ref);
+ service = (CheckService) getServiceObject(ref);
}
public void tearDown() {
- instance.dispose();
- instance = null;
+ helper.dispose();
service = null;
}
@@ -177,7 +174,5 @@
assertEquals("Check non-managed int", new Integer(5), data.get("nonInt"));
}
-
-
}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
deleted file mode 100644
index bcec3d5..0000000
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
+++ /dev/null
@@ -1,329 +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.test.scenarios.util;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
-import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.HandlerManagerFactory;
-import org.apache.felix.ipojo.ServiceContext;
-import org.apache.felix.ipojo.architecture.Architecture;
-//import org.apache.felix.ipojo.composite.CompositeManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedServiceFactory;
-
-public class Utils {
-
- public static Factory getFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static HandlerManagerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return (HandlerManagerFactory) bc.getService(refs[0]);
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- // if(fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- return null;
- }
- // }
- // else {
- // System.err.println("Configuration not accepted by : " + factoryName);
- // return null;
- // }
- }
-
- public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- try {
- Properties props = new Properties();
- props.put("instance.name",name);
- return fact.createComponentInstance(props);
- } catch (Exception e) {
- System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- e.printStackTrace();
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else if (itf.equals(Architecture.class.getName())) {
- filter = "(" + "architecture.instance" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
- ServiceReference[] refs = null;
- String filter = "(" + "service.pid" + "=" + pid + ")";
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else if (refs.length == 1) {
- return refs[0];
- } else {
- Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
- return null;
- }
- }
-
- public static Object getServiceObject(BundleContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
-// public static ServiceContext getServiceContext(ComponentInstance ci) {
-// if (ci instanceof CompositeManager) {
-// return ((CompositeManager) ci).getServiceContext();
-// } else {
-// throw new RuntimeException("Cannot get the service context form an non composite instance");
-// }
-// }
-
- public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) { return null; }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) { return null; }
-
- if (fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return null;
- }
- } else {
- System.err.println("Configuration not accepted by : " + factoryName);
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
- public static boolean contains(String string, String[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] != null && array[i].equals(string)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean contains(int value, int[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] == value) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Boxing.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Boxing.java
index 2a800c1..871356a 100644
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Boxing.java
+++ b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/Boxing.java
@@ -4,8 +4,8 @@
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.PrimitiveManipulationTestService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class Boxing extends OSGiTestCase {
@@ -15,22 +15,23 @@
PrimitiveManipulationTestService prim;
ServiceReference prim_ref;
+
+ IPOJOHelper helper;
public void setUp() {
+ helper = new IPOJOHelper(this);
Properties p1 = new Properties();
p1.put("instance.name","primitives");
- instance = Utils.getComponentInstance(context, "ManipulationPrimitives5-PrimitiveManipulationTester", p1);
+ instance = helper.createComponentInstance("ManipulationPrimitives5-PrimitiveManipulationTester", p1);
assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
- prim_ref = Utils.getServiceReferenceByName(context, PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
+ prim_ref = helper.getServiceReferenceByName(PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
assertNotNull("Check prim availability", prim_ref);
- prim = (PrimitiveManipulationTestService) context.getService(prim_ref);
+ prim = (PrimitiveManipulationTestService) getServiceObject(prim_ref);
}
public void tearDown() {
- context.ungetService(prim_ref);
+ helper.dispose();
prim = null;
- instance.dispose();
- instance = null;
}
public void testLongFromObject() {
diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
index 439135c..aefa7cf 100644
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
+++ b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
@@ -1,22 +1,21 @@
package org.apache.felix.ipojo.test.scenarios.manipulation;
-import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.Plop;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
public class DuplicateMethod extends OSGiTestCase {
public void testDuplicateMethod() {
- ComponentInstance instance = Utils.getComponentInstanceByName(context, "plopimpl", "plop");
- ServiceReference ref = Utils.getServiceReferenceByName(context, Plop.class.getName(), "plop");
+ IPOJOHelper helper = new IPOJOHelper(this);
+ helper.createComponentInstance("plopimpl", "plop");
+ ServiceReference ref = helper.getServiceReferenceByName(Plop.class.getName(), "plop");
assertNotNull("Check plop", ref);
- Plop plop = (Plop) context.getService(ref);
+ Plop plop = (Plop) getServiceObject(ref);
Object o = plop.getPlop();
assertEquals("Check result", "plop", o);
- context.ungetService(ref);
- instance.dispose();
+ helper.dispose();
}
}
diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/TypedList.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/TypedList.java
index b515a9e..72395c9 100644
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/TypedList.java
+++ b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/TypedList.java
@@ -26,14 +26,12 @@
}
public void tearDown() {
- foo1.dispose();
- foo2.dispose();
- checker.dispose();
+ helper.dispose();
}
public void testTypedList() {
- ServiceReference ref = getServiceReferenceByName(CheckService.class.getName(), checker.getInstanceName());
- CheckService check = (CheckService) context.getService(ref);
+ ServiceReference ref = helper.getServiceReferenceByName(CheckService.class.getName(), checker.getInstanceName());
+ CheckService check = (CheckService) getServiceObject(ref);
assertNotNull("Checker availability", check);
// Check without providers
assertFalse("Empty list", check.check());
@@ -58,10 +56,6 @@
props = check.getProps();
list = (List<FooService>) props.get("list");
assertEquals("Check size - 3", 1, list.size());
-
- context.ungetService(ref);
}
-
-
}
diff --git a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
deleted file mode 100644
index bcec3d5..0000000
--- a/ipojo/tests/manipulator/manipulator-java5/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
+++ /dev/null
@@ -1,329 +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.test.scenarios.util;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import junit.framework.Assert;
-
-import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Factory;
-import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.HandlerManagerFactory;
-import org.apache.felix.ipojo.ServiceContext;
-import org.apache.felix.ipojo.architecture.Architecture;
-//import org.apache.felix.ipojo.composite.CompositeManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ManagedServiceFactory;
-
-public class Utils {
-
- public static Factory getFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static HandlerManagerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");
- if (refs == null) {
- System.err.println("Cannot get the factory " + factoryName);
- return null;
- }
- return (HandlerManagerFactory) bc.getService(refs[0]);
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- // if(fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- return null;
- }
- // }
- // else {
- // System.err.println("Configuration not accepted by : " + factoryName);
- // return null;
- // }
- }
-
- public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) {
- System.err.println("Factory " + factoryName + " not found");
- return null;
- }
-
- try {
- Properties props = new Properties();
- props.put("instance.name",name);
- return fact.createComponentInstance(props);
- } catch (Exception e) {
- System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());
- e.printStackTrace();
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else if (itf.equals(Architecture.class.getName())) {
- filter = "(" + "architecture.instance" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {
- ServiceReference[] refs = null;
- String filter = "(" + "service.pid" + "=" + pid + ")";
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else if (refs.length == 1) {
- return refs[0];
- } else {
- Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);
- return null;
- }
- }
-
- public static Object getServiceObject(BundleContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
-// public static ServiceContext getServiceContext(ComponentInstance ci) {
-// if (ci instanceof CompositeManager) {
-// return ((CompositeManager) ci).getServiceContext();
-// } else {
-// throw new RuntimeException("Cannot get the service context form an non composite instance");
-// }
-// }
-
- public static Factory getFactoryByName(ServiceContext bc, String factoryName) {
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");
- if (refs == null) { return null; }
- return ((Factory) bc.getService(refs[0]));
- } catch (InvalidSyntaxException e) {
- System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());
- return null;
- }
- }
-
- public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {
- Factory fact = getFactoryByName(bc, factoryName);
-
- if (fact == null) { return null; }
-
- if (fact.isAcceptable(configuration)) {
- try {
- return fact.createComponentInstance(configuration);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return null;
- }
- } else {
- System.err.println("Configuration not accepted by : " + factoryName);
- return null;
- }
- }
-
- public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
- public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {
- ServiceReference[] refs = null;
- String filter = null;
- if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {
- filter = "(" + "factory.name" + "=" + name + ")";
- } else {
- filter = "(" + "instance.name" + "=" + name + ")";
- }
- try {
- refs = bc.getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- System.err.println("Invalid Filter : " + filter);
- }
- if (refs == null) {
- return null;
- } else {
- return refs[0];
- }
- }
-
- public static Object getServiceObject(ServiceContext bc, String itf, String filter) {
- ServiceReference ref = getServiceReference(bc, itf, filter);
- if (ref != null) {
- return bc.getService(ref);
- } else {
- return null;
- }
- }
-
- public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bc, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bc.getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
-
- public static boolean contains(String string, String[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] != null && array[i].equals(string)) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean contains(int value, int[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] == value) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java b/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java
index 493d418..c6907cd 100644
--- a/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java
+++ b/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest.java
@@ -18,38 +18,31 @@
*/
package org.apache.felix.ipojo.test.scenarios.manipulation;
-import java.util.Properties;
-
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.PrimitiveManipulationTestService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
-import org.osgi.framework.ServiceReference;
/**
* Check the manipulation of primitive type (boxed and unboxed).
*/
public class PrimitiveTypeTest extends OSGiTestCase {
- ComponentInstance instance; // Instance under test
PrimitiveManipulationTestService prim;
- ServiceReference prim_ref;
+
+ IPOJOHelper helper;
public void setUp() {
- Properties p1 = new Properties();
- p1.put("instance.name","primitives");
- instance = Utils.getComponentInstance(context, "ManipulationPrimitives-PrimitiveManipulationTester", p1);
+ helper = new IPOJOHelper(this);
+ ComponentInstance instance = helper.createComponentInstance("ManipulationPrimitives-PrimitiveManipulationTester");
assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
- prim_ref = Utils.getServiceReferenceByName(context, PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
- assertNotNull("Check prim availability", prim_ref);
- prim = (PrimitiveManipulationTestService) context.getService(prim_ref);
+ prim = (PrimitiveManipulationTestService) getServiceObject(PrimitiveManipulationTestService.class.getName(), "(instance.name=" + instance.getInstanceName() + ")");
+ assertNotNull("Check prim availability", prim);
}
public void tearDown() {
- context.ungetService(prim_ref);
+ helper.dispose();
prim = null;
- instance.dispose();
- instance = null;
}
public void testByte() {
diff --git a/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java b/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java
index 2ef112b..81b99a7 100644
--- a/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java
+++ b/ipojo/tests/manipulator/primitives/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/PrimitiveTypeTest2.java
@@ -18,12 +18,10 @@
*/
package org.apache.felix.ipojo.test.scenarios.manipulation;
-import java.util.Properties;
-
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.PrimitiveManipulationTestService;
-import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
/**
@@ -32,27 +30,21 @@
*/
public class PrimitiveTypeTest2 extends OSGiTestCase {
- ComponentInstance instance; // Instance under test
-
PrimitiveManipulationTestService prim;
-
- ServiceReference prim_ref;
-
+ IPOJOHelper helper;
+
public void setUp() {
- Properties p1 = new Properties();
- p1.put("instance.name","primitives");
- instance = Utils.getComponentInstance(context, "ManipulationPrimitives-PrimitiveManipulationTesterA", p1);
+ helper = new IPOJOHelper(this);
+ ComponentInstance instance = helper.createComponentInstance("ManipulationPrimitives-PrimitiveManipulationTesterA");
assertTrue("check instance state", instance.getState() == ComponentInstance.VALID);
- prim_ref = Utils.getServiceReferenceByName(context, PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
- assertNotNull("Check prim availability", prim_ref);
- prim = (PrimitiveManipulationTestService) context.getService(prim_ref);
+ ServiceReference ref = helper.getServiceReferenceByName(PrimitiveManipulationTestService.class.getName(), instance.getInstanceName());
+ assertNotNull("Check prim availability", ref);
+ prim = (PrimitiveManipulationTestService) getServiceObject(ref);
}
public void tearDown() {
- context.ungetService(prim_ref);
prim = null;
- instance.dispose();
- instance = null;
+ helper.dispose();
}
public void testByte() {