From f281ebc22e5d91262172be7e4c7cfef238804521 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 12 Mar 2009 04:03:49 +0000 Subject: Fix the DS component xml files git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@752766 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/calculator/CalculatorServiceDSImpl.java | 21 +++++++ .../calculator/test/CalculatorOSGiTestCase.java | 66 ++++++++++++++++++---- .../src/test/resources/OSGI-INF/add-component.xml | 4 +- .../resources/OSGI-INF/calculator-component.xml | 20 ++++--- .../test/resources/OSGI-INF/divide-component.xml | 4 +- .../test/resources/OSGI-INF/multiply-component.xml | 4 +- .../test/resources/OSGI-INF/subtract-component.xml | 4 +- 7 files changed, 95 insertions(+), 28 deletions(-) (limited to 'java/sca/modules/implementation-osgi/src') 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 getService(Class 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 bundles = new HashSet(); - 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); @@ -143,6 +150,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 */ 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. --> - + - + 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. --> - + - - - - + + + - + 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. --> - + - + 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. --> - + - + 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. --> - + - + -- cgit v1.2.3