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
.slc
.osgiboot
;
19 import java
.util
.Iterator
;
21 import java
.util
.TreeMap
;
23 import junit
.framework
.TestCase
;
25 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
26 import org
.osgi
.framework
.Bundle
;
27 import org
.osgi
.framework
.BundleContext
;
29 public class OsgiBootRuntimeTest
extends TestCase
{
30 protected OsgiBoot osgiBoot
= null;
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());
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());
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.");
59 fail("Bundle not started after timeout limit.");
62 protected BundleContext
startRuntime() throws Exception
{
63 String
[] args
= { "-console", "-clean" };
64 BundleContext bundleContext
= EclipseStarter
.startup(args
, null);
68 protected void stopRuntime() throws Exception
{
69 EclipseStarter
.shutdown();
72 public void setUp() throws Exception
{
73 BundleContext bundleContext
= startRuntime();
74 osgiBoot
= new OsgiBoot(bundleContext
);
77 public void tearDown() throws Exception
{