summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-18 17:42:47 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-18 17:42:47 +0000
commita8502d9f7c9a0531ca8fb4c53cdda8cfd5cd4228 (patch)
tree49ac06bd1c4b94d1869056ec82ef08b3066b3ffd /java
parent9b4630f63f583812f29265aed3723e137f3f8ecd (diff)
Set the client system property to control the test case to be run in client or server mode
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755671 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java119
-rw-r--r--java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/META-INF/MANIFEST.MF3
2 files changed, 68 insertions, 54 deletions
diff --git a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
index c64ee52563..86b0da3a01 100644
--- a/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
+++ b/java/sca/modules/node-impl-osgi/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
@@ -58,6 +58,7 @@ import calculator.dosgi.operations.SubtractServiceImpl;
public class CalculatorOSGiNodeTestCase {
private static EquinoxHost host;
private static BundleContext context;
+ private static Boolean client;
public static URL getCodeLocation(final Class<?> anchorClass) {
return AccessController.doPrivileged(new PrivilegedAction<URL>() {
@@ -73,6 +74,10 @@ public class CalculatorOSGiNodeTestCase {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
try {
+ String prop = System.getProperty("client");
+ if (prop != null) {
+ client = Boolean.valueOf(prop);
+ }
Set<URL> bundles = new HashSet<URL>();
File plugins = new File("target/test-classes/plugins");
@@ -82,49 +87,51 @@ public class CalculatorOSGiNodeTestCase {
}
}
-// bundles.add(getCodeLocation(OSGiImplementation.class));
-// bundles.add(getCodeLocation(OSGiBundleContributionScanner.class));
-// bundles.add(getCodeLocation(NodeImpl.class));
-
- bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar",
- "calculator/dosgi/META-INF/MANIFEST.MF",
- new String[][] {
- {"OSGI-INF/calculator-component.xml", null},
- {"calculator/dosgi/bundle.componentType",
- "OSGI-INF/sca/bundle.componentType"},
- {"calculator/dosgi/calculator.composite",
- "OSGI-INF/sca/bundle.composite"}},
- CalculatorService.class,
- // Package the interfaces so that the operations bundle can be remote
- AddService.class,
- SubtractService.class,
- MultiplyService.class,
- DivideService.class,
- CalculatorServiceImpl.class,
- CalculatorServiceDSImpl.class,
- CalculatorActivator.class));
-
- bundles.add(OSGiTestBundles
- .createBundle("target/test-classes/operations-bundle.jar",
- "calculator/dosgi/operations/META-INF/MANIFEST.MF",
- new String[][] {
- {"OSGI-INF/add-component.xml", null},
- {"OSGI-INF/subtract-component.xml", null},
- {"OSGI-INF/multiply-component.xml", null},
- {"OSGI-INF/divide-component.xml", null},
- {"calculator/dosgi/operations/bundle.componentType",
- "OSGI-INF/sca/bundle.componentType"},
- {"calculator/dosgi/operations/operations.composite",
- "OSGI-INF/sca/bundle.composite"}},
- OperationsActivator.class,
- AddService.class,
- AddServiceImpl.class,
- SubtractService.class,
- SubtractServiceImpl.class,
- MultiplyService.class,
- MultiplyServiceImpl.class,
- DivideService.class,
- DivideServiceImpl.class));
+ if (client == null || client.booleanValue()) {
+ System.out.println("Generating calculator.dosgi bundle...");
+ bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar",
+ "calculator/dosgi/META-INF/MANIFEST.MF",
+ new String[][] {
+ {"OSGI-INF/calculator-component.xml", null},
+ {"calculator/dosgi/bundle.componentType",
+ "OSGI-INF/sca/bundle.componentType"},
+ {"calculator/dosgi/calculator.composite",
+ "OSGI-INF/sca/bundle.composite"}},
+ CalculatorService.class,
+ // Package the interfaces so that the operations bundle can be remote
+ AddService.class,
+ SubtractService.class,
+ MultiplyService.class,
+ DivideService.class,
+ CalculatorServiceImpl.class,
+ CalculatorServiceDSImpl.class,
+ CalculatorActivator.class));
+ }
+
+ if (client == null || !client.booleanValue()) {
+ System.out.println("Generating calculator.dosgi.operations bundle...");
+ bundles.add(OSGiTestBundles
+ .createBundle("target/test-classes/operations-bundle.jar",
+ "calculator/dosgi/operations/META-INF/MANIFEST.MF",
+ new String[][] {
+ {"OSGI-INF/add-component.xml", null},
+ {"OSGI-INF/subtract-component.xml", null},
+ {"OSGI-INF/multiply-component.xml", null},
+ {"OSGI-INF/divide-component.xml", null},
+ {"calculator/dosgi/operations/bundle.componentType",
+ "OSGI-INF/sca/bundle.componentType"},
+ {"calculator/dosgi/operations/operations.composite",
+ "OSGI-INF/sca/bundle.composite"}},
+ OperationsActivator.class,
+ AddService.class,
+ AddServiceImpl.class,
+ SubtractService.class,
+ SubtractServiceImpl.class,
+ MultiplyService.class,
+ MultiplyServiceImpl.class,
+ DivideService.class,
+ DivideServiceImpl.class));
+ }
host = new EquinoxHost();
context = host.start();
for (URL loc : bundles) {
@@ -143,7 +150,7 @@ public class CalculatorOSGiNodeTestCase {
}
}
for (Bundle b : context.getBundles()) {
- if (b.getSymbolicName().equals("calculator.dosgi")) {
+ if (b.getSymbolicName().startsWith("calculator.dosgi")) {
b.start();
System.out.println(string(b, false));
}
@@ -181,15 +188,17 @@ public class CalculatorOSGiNodeTestCase {
@Test
public void testOSGi() {
- ServiceReference ref = context.getServiceReference(CalculatorService.class.getName());
- Assert.assertNotNull(ref);
- Object service = context.getService(ref);
- Assert.assertNotNull(service);
- CalculatorService calculator = cast(service, CalculatorService.class);
- System.out.println("2.0 + 1.0 = " + calculator.add(2.0, 1.0));
- System.out.println("2.0 - 1.0 = " + calculator.subtract(2.0, 1.0));
- System.out.println("2.0 * 1.0 = " + calculator.multiply(2.0, 1.0));
- System.out.println("2.0 / 1.0 = " + calculator.divide(2.0, 1.0));
+ if (client == null || client.booleanValue()) {
+ ServiceReference ref = context.getServiceReference(CalculatorService.class.getName());
+ Assert.assertNotNull(ref);
+ Object service = context.getService(ref);
+ Assert.assertNotNull(service);
+ CalculatorService calculator = cast(service, CalculatorService.class);
+ System.out.println("2.0 + 1.0 = " + calculator.add(2.0, 1.0));
+ System.out.println("2.0 - 1.0 = " + calculator.subtract(2.0, 1.0));
+ System.out.println("2.0 * 1.0 = " + calculator.multiply(2.0, 1.0));
+ System.out.println("2.0 / 1.0 = " + calculator.divide(2.0, 1.0));
+ }
}
/**
@@ -235,6 +244,10 @@ public class CalculatorOSGiNodeTestCase {
@AfterClass
public static void tearDownAfterClass() throws Exception {
if (host != null) {
+ if (client != null && !client.booleanValue()) {
+ System.out.println("Press Enter to stop the node...");
+ System.in.read();
+ }
host.stop();
context = null;
}
diff --git a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/META-INF/MANIFEST.MF b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/META-INF/MANIFEST.MF
index 5a4db21087..41c1264364 100644
--- a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/META-INF/MANIFEST.MF
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
-Export-Package: calculator.dosgi;version="1.0.0"
+Export-Package: calculator.dosgi;version="1.0.0",
+ calculator.dosgi.operations;version="1.0.0"
Bundle-Version: 1.0.0
Bundle-Name: calculator.dosgi
Bundle-Activator: calculator.dosgi.CalculatorActivator