2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.osgi
.boot
;
19 import java
.util
.Iterator
;
21 import java
.util
.TreeMap
;
23 import junit
.framework
.TestCase
;
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
;
30 /** Starts an Equinox runtime and provision it with OSGi boot. */
31 public class OsgiBootRuntimeTest
extends TestCase
{
32 protected OsgiBoot osgiBoot
= null;
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());
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());
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.");
61 fail("Bundle not started after timeout limit.");
64 protected BundleContext
startRuntime() throws Exception
{
65 String
[] args
= { "-console", "-clean" };
66 BundleContext bundleContext
= EclipseStarter
.startup(args
, null);
70 protected void stopRuntime() throws Exception
{
71 EclipseStarter
.shutdown();
74 public void setUp() throws Exception
{
75 BundleContext bundleContext
= startRuntime();
76 osgiBoot
= new OsgiBoot(bundleContext
);
79 public void tearDown() throws Exception
{