]> git.argeo.org Git - lgpl/argeo-commons.git/blob - osgi/runtime/org.argeo.osgi.boot/src/test/java/org/argeo/osgi/boot/OsgiBootRuntimeTest.java
Ignore generated MANIFEST
[lgpl/argeo-commons.git] / osgi / runtime / org.argeo.osgi.boot / src / test / java / org / argeo / osgi / boot / 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.osgi.boot;
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.argeo.osgi.boot.OsgiBoot;
26 import org.eclipse.core.runtime.adaptor.EclipseStarter;
27 import org.osgi.framework.Bundle;
28 import org.osgi.framework.BundleContext;
29
30 /** Starts an Equinox runtime and provision it with OSGi boot. */
31 public class OsgiBootRuntimeTest extends TestCase {
32 protected OsgiBoot osgiBoot = null;
33
34 public void testInstallAndStart() throws Exception {
35 osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
36 OsgiBootNoRuntimeTest.BUNDLES));
37 Map map = new TreeMap(osgiBoot.getBundles());
38 for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
39 Object key = keys.next();
40 Bundle bundle = (Bundle) map.get(key);
41 System.out.println(key + " : " + bundle.getLocation());
42 }
43 assertEquals(4, map.size());
44 Iterator keys = map.keySet().iterator();
45 assertEquals("org.argeo.osgi.boot.test.bundle1", keys.next());
46 assertEquals("org.argeo.osgi.boot.test.bundle2", keys.next());
47 assertEquals("org.argeo.osgi.boot.test.bundle3", keys.next());
48 assertEquals("org.eclipse.osgi", keys.next());
49
50 osgiBoot.startBundles("org.argeo.osgi.boot.test.bundle2");
51 long begin = System.currentTimeMillis();
52 while (System.currentTimeMillis() - begin < 10000) {
53 Map mapBundles = osgiBoot.getBundles();
54 Bundle bundle = (Bundle) mapBundles
55 .get("org.argeo.osgi.boot.test.bundle2");
56 if (bundle.getState() == Bundle.ACTIVE) {
57 System.out.println("Bundle " + bundle + " started.");
58 return;
59 }
60 }
61 fail("Bundle not started after timeout limit.");
62 }
63
64 protected BundleContext startRuntime() throws Exception {
65 String[] args = { "-console", "-clean" };
66 BundleContext bundleContext = EclipseStarter.startup(args, null);
67 return bundleContext;
68 }
69
70 protected void stopRuntime() throws Exception {
71 EclipseStarter.shutdown();
72 }
73
74 public void setUp() throws Exception {
75 BundleContext bundleContext = startRuntime();
76 osgiBoot = new OsgiBoot(bundleContext);
77 }
78
79 public void tearDown() throws Exception {
80 osgiBoot = null;
81 stopRuntime();
82 }
83
84 }