]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.osgiboot/src/test/java/org/argeo/slc/osgiboot/OsgiBootRuntimeTest.java
remove empty packages
[gpl/argeo-slc.git] / runtime / org.argeo.slc.osgiboot / src / test / java / org / argeo / slc / osgiboot / OsgiBootRuntimeTest.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.osgiboot;
18
19 import java.util.Iterator;
20 import java.util.Map;
21 import java.util.TreeMap;
22
23 import junit.framework.TestCase;
24
25 import org.eclipse.core.runtime.adaptor.EclipseStarter;
26 import org.osgi.framework.Bundle;
27 import org.osgi.framework.BundleContext;
28
29 public class OsgiBootRuntimeTest extends TestCase {
30 protected OsgiBoot osgiBoot = null;
31
32 public void testInstallAndStart() throws Exception {
33 osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
34 OsgiBootNoRuntimeTest.BUNDLES));
35 Map map = new TreeMap(osgiBoot.getBundles());
36 for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
37 Object key = keys.next();
38 Bundle bundle = (Bundle) map.get(key);
39 System.out.println(key + " : " + bundle.getLocation());
40 }
41 assertEquals(4, map.size());
42 Iterator keys = map.keySet().iterator();
43 assertEquals("org.argeo.slc.osgiboot.test.bundle1", keys.next());
44 assertEquals("org.argeo.slc.osgiboot.test.bundle2", keys.next());
45 assertEquals("org.argeo.slc.osgiboot.test.bundle3", keys.next());
46 assertEquals("org.eclipse.osgi", keys.next());
47
48 osgiBoot.startBundles("org.argeo.slc.osgiboot.test.bundle2");
49 long begin = System.currentTimeMillis();
50 while (System.currentTimeMillis() - begin < 10000) {
51 Map mapBundles = osgiBoot.getBundles();
52 Bundle bundle = (Bundle) mapBundles
53 .get("org.argeo.slc.osgiboot.test.bundle2");
54 if (bundle.getState() == Bundle.ACTIVE) {
55 System.out.println("Bundle " + bundle + " started.");
56 return;
57 }
58 }
59 fail("Bundle not started after timeout limit.");
60 }
61
62 protected BundleContext startRuntime() throws Exception {
63 String[] args = { "-console", "-clean" };
64 BundleContext bundleContext = EclipseStarter.startup(args, null);
65 return bundleContext;
66 }
67
68 protected void stopRuntime() throws Exception {
69 EclipseStarter.shutdown();
70 }
71
72 public void setUp() throws Exception {
73 BundleContext bundleContext = startRuntime();
74 osgiBoot = new OsgiBoot(bundleContext);
75 }
76
77 public void tearDown() throws Exception {
78 osgiBoot = null;
79 stopRuntime();
80 }
81
82 }