]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java
Start implementing OSGi integration tests
[gpl/argeo-slc.git] / runtime / org.argeo.slc.osgiboot / src / test / java / org / argeo / slc / osgiboot / OsgiBootRuntimeTest.java
1 package org.argeo.slc.osgiboot;
2
3 import java.util.Iterator;
4 import java.util.Map;
5 import java.util.TreeMap;
6
7 import junit.framework.TestCase;
8
9 import org.eclipse.core.runtime.adaptor.EclipseStarter;
10 import org.osgi.framework.Bundle;
11 import org.osgi.framework.BundleContext;
12
13 public class OsgiBootRuntimeTest extends TestCase {
14 protected OsgiBoot osgiBoot = null;
15
16 public void testInstallAndStart() throws Exception {
17 osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
18 OsgiBootNoRuntimeTest.BUNDLES));
19 Map map = new TreeMap(osgiBoot.getBundles());
20 for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
21 Object key = keys.next();
22 Bundle bundle = (Bundle) map.get(key);
23 System.out.println(key + " : " + bundle.getLocation());
24 }
25 assertEquals(4, map.size());
26 Iterator keys = map.keySet().iterator();
27 assertEquals("org.argeo.slc.osgiboot.test.bundle1", keys.next());
28 assertEquals("org.argeo.slc.osgiboot.test.bundle2", keys.next());
29 assertEquals("org.argeo.slc.osgiboot.test.bundle3", keys.next());
30 assertEquals("org.eclipse.osgi", keys.next());
31
32 osgiBoot.startBundles("org.argeo.slc.osgiboot.test.bundle2");
33 long begin = System.currentTimeMillis();
34 while (System.currentTimeMillis() - begin < 10000) {
35 Map mapBundles = osgiBoot.getBundles();
36 Bundle bundle = (Bundle) mapBundles
37 .get("org.argeo.slc.osgiboot.test.bundle2");
38 if (bundle.getState() == Bundle.ACTIVE) {
39 System.out.println("Bundle " + bundle + " started.");
40 return;
41 }
42 }
43 fail("Bundle not started after timeout limit.");
44 }
45
46 protected BundleContext startRuntime() throws Exception {
47 String[] args = { "-console" };
48 BundleContext bundleContext = EclipseStarter.startup(args, null);
49 return bundleContext;
50 }
51
52 protected void stopRuntime() throws Exception {
53 EclipseStarter.shutdown();
54 }
55
56 public void setUp() throws Exception{
57 BundleContext bundleContext = startRuntime();
58 osgiBoot = new OsgiBoot(bundleContext);
59 }
60
61 public void tearDown() throws Exception{
62 osgiBoot = null;
63 stopRuntime();
64 }
65
66 }