]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTest.java
Start implementing OSGi integration tests
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.equinox / src / test / java / org / argeo / slc / osgi / test / AbstractOsgiRuntimeTest.java
1 package org.argeo.slc.osgi.test;
2
3 import junit.framework.TestCase;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.slc.osgiboot.OsgiBoot;
8 import org.osgi.framework.Bundle;
9 import org.osgi.framework.BundleContext;
10 import org.springframework.osgi.test.platform.EquinoxPlatform;
11 import org.springframework.osgi.test.platform.OsgiPlatform;
12 import org.springframework.osgi.util.OsgiStringUtils;
13
14 public abstract class AbstractOsgiRuntimeTest extends TestCase {
15 private final static Log log = LogFactory
16 .getLog(AbstractOsgiRuntimeTest.class);
17
18 protected OsgiBoot osgiBoot = null;
19 protected OsgiPlatform osgiPlatform = null;
20
21 protected OsgiPlatform createOsgiPlatform() {
22 return new EquinoxPlatform();
23 }
24
25 protected void postStart() throws Exception {
26
27 }
28
29 public void setUp() throws Exception {
30 // To avoid xerces from the classpath being detected as the provider
31 System
32 .setProperty("javax.xml.parsers.DocumentBuilderFactory",
33 "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
34 System.setProperty("javax.xml.parsers.SAXParserFactory",
35 "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
36
37 osgiPlatform = createOsgiPlatform();
38 osgiPlatform.start();
39 osgiBoot = new OsgiBoot(osgiPlatform.getBundleContext());
40 log.info("OSGi platform " + osgiPlatform + " started.");
41 postStart();
42 }
43
44 public void tearDown() throws Exception {
45 osgiBoot = null;
46 osgiPlatform.stop();
47 osgiPlatform = null;
48 log.info("OSGi platform " + osgiPlatform + " stopped.");
49 }
50
51 protected void listInstalledBundles() {
52 BundleContext bundleContext = osgiPlatform.getBundleContext();
53 Bundle[] bundles = bundleContext.getBundles();
54 for (int i = 0; i < bundles.length; i++) {
55 System.out
56 .println(OsgiStringUtils.nullSafeSymbolicName(bundles[i]));
57 }
58
59 }
60 }