1 package org
.argeo
.slc
.osgiboot
;
3 import java
.util
.Iterator
;
5 import java
.util
.TreeMap
;
7 import junit
.framework
.TestCase
;
9 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
10 import org
.osgi
.framework
.Bundle
;
11 import org
.osgi
.framework
.BundleContext
;
13 public class OsgiBootRuntimeTest
extends TestCase
{
14 protected OsgiBoot osgiBoot
= null;
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());
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());
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.");
43 fail("Bundle not started after timeout limit.");
46 protected BundleContext
startRuntime() throws Exception
{
47 String
[] args
= { "-console" };
48 BundleContext bundleContext
= EclipseStarter
.startup(args
, null);
52 protected void stopRuntime() throws Exception
{
53 EclipseStarter
.shutdown();
56 public void setUp() throws Exception
{
57 BundleContext bundleContext
= startRuntime();
58 osgiBoot
= new OsgiBoot(bundleContext
);
61 public void tearDown() throws Exception
{