summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-12 04:03:49 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-12 04:03:49 +0000
commitf281ebc22e5d91262172be7e4c7cfef238804521 (patch)
tree6e6211dc99202f98049b534c0f3d4a0c3f3f3561
parent046fad4e373bd83f64d580857cedb53aea9e5f49 (diff)
Fix the DS component xml files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@752766 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceDSImpl.java21
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java66
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/add-component.xml4
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml20
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/divide-component.xml4
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/multiply-component.xml4
-rw-r--r--java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/subtract-component.xml4
7 files changed, 95 insertions, 28 deletions
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceDSImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceDSImpl.java
index a4eb881792..7f9fa6803c 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceDSImpl.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceDSImpl.java
@@ -36,6 +36,7 @@ public class CalculatorServiceDSImpl implements CalculatorService {
public CalculatorServiceDSImpl() {
super();
+ System.out.println("CalculatorServiceDSImpl()");
}
protected void activate(ComponentContext context) {
@@ -50,6 +51,7 @@ public class CalculatorServiceDSImpl implements CalculatorService {
* The following setters can be used for DS injection
*/
public void setAddService(AddService addService) {
+ System.out.println("setAddService()");
this.addService = addService;
}
@@ -65,6 +67,25 @@ public class CalculatorServiceDSImpl implements CalculatorService {
this.multiplyService = multiplyService;
}
+ /*
+ * The following setters can be used for DS injection
+ */
+ public void unsetAddService(AddService addService) {
+ System.out.println("unsetAddService()");
+ this.addService = null;
+ }
+
+ public void unsetSubtractService(SubtractService subtractService) {
+ this.subtractService = null;
+ }
+
+ public void unsetDivideService(DivideService divideService) {
+ this.divideService = null;
+ }
+
+ public void unsetMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = null;
+ }
private <T> T getService(Class<T> cls) {
for (Object s : new Object[] {addService, subtractService, multiplyService, divideService}) {
if (cls.isInstance(s)) {
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java
index 47bc927181..3477732c5f 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java
@@ -19,6 +19,7 @@
package calculator.test;
+import java.io.File;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -37,6 +38,7 @@ import org.osgi.framework.ServiceReference;
import calculator.CalculatorActivator;
import calculator.CalculatorService;
+import calculator.CalculatorServiceDSImpl;
import calculator.CalculatorServiceImpl;
import calculator.operations.AddService;
import calculator.operations.AddServiceImpl;
@@ -61,15 +63,11 @@ public class CalculatorOSGiTestCase {
public static void setUpBeforeClass() throws Exception {
Set<URL> bundles = new HashSet<URL>();
- URL url =
- CalculatorOSGiTestCase.class.getClassLoader()
- .getResource("org/osgi/service/component/ComponentContext.class");
- if (url != null) {
- String path = url.getPath();
- int index = path.lastIndexOf('!');
- path = path.substring(0, index);
- url = new URL(path);
- bundles.add(url);
+ File plugins = new File("target/test-classes/plugins");
+ for (File f : plugins.listFiles()) {
+ if (f.isFile()) {
+ bundles.add(f.toURI().toURL());
+ }
}
bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar",
@@ -77,6 +75,7 @@ public class CalculatorOSGiTestCase {
new String[] {"OSGI-INF/calculator-component.xml"},
CalculatorService.class,
CalculatorServiceImpl.class,
+ CalculatorServiceDSImpl.class,
CalculatorActivator.class));
bundles.add(OSGiTestBundles.createBundle("target/test-classes/operations-bundle.jar",
@@ -98,8 +97,16 @@ public class CalculatorOSGiTestCase {
host = new EquinoxHost(bundles);
BundleContext context = host.start();
for (Bundle b : context.getBundles()) {
- System.out.println(b.getSymbolicName());
- b.start();
+ if (b.getSymbolicName().equals("org.eclipse.equinox.ds")) {
+ b.start();
+ System.out.println(string(b, false));
+ }
+ }
+ for (Bundle b : context.getBundles()) {
+ if (b.getSymbolicName().startsWith("calculator")) {
+ b.start();
+ System.out.println(string(b, false));
+ }
}
ServiceReference ref = context.getServiceReference(CalculatorService.class.getName());
CalculatorService calculator = cast(context.getService(ref), CalculatorService.class);
@@ -144,6 +151,43 @@ public class CalculatorOSGiTestCase {
}
/**
+ * Returns a string representation of the given bundle.
+ *
+ * @param b
+ * @param verbose
+ * @return
+ */
+ static String string(Bundle bundle, boolean verbose) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(bundle.getBundleId()).append(" ").append(bundle.getSymbolicName());
+ int s = bundle.getState();
+ if ((s & Bundle.UNINSTALLED) != 0) {
+ sb.append(" UNINSTALLED");
+ }
+ if ((s & Bundle.INSTALLED) != 0) {
+ sb.append(" INSTALLED");
+ }
+ if ((s & Bundle.RESOLVED) != 0) {
+ sb.append(" RESOLVED");
+ }
+ if ((s & Bundle.STARTING) != 0) {
+ sb.append(" STARTING");
+ }
+ if ((s & Bundle.STOPPING) != 0) {
+ sb.append(" STOPPING");
+ }
+ if ((s & Bundle.ACTIVE) != 0) {
+ sb.append(" ACTIVE");
+ }
+
+ if (verbose) {
+ sb.append(" ").append(bundle.getLocation());
+ sb.append(" ").append(bundle.getHeaders());
+ }
+ return sb.toString();
+ }
+
+ /**
* @throws java.lang.Exception
*/
@AfterClass
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/add-component.xml b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/add-component.xml
index fd1f907999..f1ed05111a 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/add-component.xml
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/add-component.xml
@@ -17,9 +17,9 @@
* specific language governing permissions and limitations
* under the License.
-->
-<component name="AddComponent" xmlns="http://www.osgi.org/xmlns/scr/v1.0.0">
+<scr:component name="AddComponent" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<implementation class="calculator.operations.AddServiceImpl" />
<service>
<provide interface="calculator.operations.AddService" />
</service>
-</component>
+</scr:component>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
index f02f2503d9..a78433e002 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
@@ -17,19 +17,21 @@
* specific language governing permissions and limitations
* under the License.
-->
-<component name="CalculatorComponent" xmlns="http://www.osgi.org/xmlns/scr/v1.0.0">
+<scr:component name="CalculatorComponent"
+ immediate="true"
+ xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<implementation class="calculator.CalculatorServiceDSImpl" />
<service>
<provide interface="calculator.CalculatorService" />
</service>
- <reference name="addService" interface="calculator.AddService" bind="setAddService" unbind="setAddService"
- policy="dynamic" />
- <reference name="subtractService" interface="calculator.SubtractService" bind="setSubtractService" unbind="setSubtractService"
- policy="dynamic" />
- <reference name="multiplyService" interface="calculator.MultiplyService" bind="setMultiplyService" unbind="setMultiplyService"
- policy="dynamic" />
- <reference name="divideService" interface="calculator.DivideService" bind="setDivideService" unbind="setDivideService"
+ <reference name="addService" interface="calculator.operations.AddService" bind="setAddService" unbind="unsetAddService"
policy="dynamic" />
+ <reference name="subtractService" interface="calculator.operations.SubtractService" bind="setSubtractService"
+ unbind="unsetSubtractService" policy="dynamic" />
+ <reference name="multiplyService" interface="calculator.operations.MultiplyService" bind="setMultiplyService"
+ unbind="unsetMultiplyService" policy="dynamic" />
+ <reference name="divideService" interface="calculator.operations.DivideService" bind="setDivideService"
+ unbind="unsetDivideService" policy="dynamic" />
-</component>
+</scr:component>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/divide-component.xml b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/divide-component.xml
index 8351554a16..60a6cef4e1 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/divide-component.xml
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/divide-component.xml
@@ -17,9 +17,9 @@
* specific language governing permissions and limitations
* under the License.
-->
-<component name="DivideComponent" xmlns="http://www.osgi.org/xmlns/scr/v1.0.0">
+<scr:component name="DivideComponent" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<implementation class="calculator.operations.DivideServiceImpl" />
<service>
<provide interface="calculator.operations.DivideService" />
</service>
-</component>
+</scr:component>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/multiply-component.xml b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/multiply-component.xml
index 8033916595..2fd843b272 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/multiply-component.xml
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/multiply-component.xml
@@ -17,9 +17,9 @@
* specific language governing permissions and limitations
* under the License.
-->
-<component name="MultiplyComponent" xmlns="http://www.osgi.org/xmlns/scr/v1.0.0">
+<scr:component name="MultiplyComponent" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<implementation class="calculator.operations.MultiplyServiceImpl" />
<service>
<provide interface="calculator.operations.MultiplyService" />
</service>
-</component>
+</scr:component>
diff --git a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/subtract-component.xml b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/subtract-component.xml
index a4e5711786..ceb0a5d821 100644
--- a/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/subtract-component.xml
+++ b/java/sca/modules/implementation-osgi/src/test/resources/OSGI-INF/subtract-component.xml
@@ -17,9 +17,9 @@
* specific language governing permissions and limitations
* under the License.
-->
-<component name="SubtractComponent" xmlns="http://www.osgi.org/xmlns/scr/v1.0.0">
+<scr:component name="SubtractComponent" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<implementation class="calculator.operations.SubtractServiceImpl" />
<service>
<provide interface="calculator.operations.SubtractService" />
</service>
-</component>
+</scr:component>