Package aQute.bnd.junit
Class JUnitFramework
- java.lang.Object
-
- aQute.bnd.junit.JUnitFramework
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class JUnitFramework extends java.lang.Object implements java.lang.AutoCloseable
This class provides an OSGi framework that is configured with the current bnd workspace. A project directory is used to find the workspace. This makes all repositories in the workspace available to the framework. To be able to test JUnit code against/in this framework it is necessary that all packages on the buildpath and testpath are actually exported in the framework. This class will ensure that. Once the framework is up and running it will be possible to add bundles to it. There are a number of ways that this can be achieved:- Build a bundle – A bnd
Builder
is provided to create a bundle and install it. This makes it possible to add classes from the src or test directories or resources. Seebundle()
. - Add a bundle using a bnd spec – Using the bnd specs (e.g.
'org.apache.felix.configadmin;version=3'). See
addBundle(String)
et. al. - Add a bndrun file – A file bndrun file can be added. All properties in
this file that can be applied after a framework is started will be applied.
See
addBundles(File)
et. al.
getService(Class)
et. al. Notice that this framework starts in the same process as that the JUnit code runs. This is normally a separately started VM.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
JUnitFramework.BundleBuilder
-
Constructor Summary
Constructors Constructor Description JUnitFramework()
Start a framework assuming the current working directory is the project directory.JUnitFramework(java.io.File projectDir)
Start a framework while providing a project directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<org.osgi.framework.Bundle>
addBundle(java.lang.String spec)
void
addBundles(java.io.File bndrun)
void
addBundles(java.lang.String bndrun)
JUnitFramework.BundleBuilder
bundle()
void
close()
Close this frameworkorg.osgi.framework.BundleContext
getBundleContext()
Project
getProject()
<T> T
getService(java.lang.Class<T> class1)
<T> java.util.List<T>
getServices(java.lang.Class<T> class1)
Workspace
getWorkspace()
void
startAll(java.util.List<org.osgi.framework.Bundle> bundles)
<T> org.osgi.util.promise.Promise<T>
waitForService(java.lang.Class<T> class1, long timeoutInMs)
-
-
-
Field Detail
-
trackers
public final java.util.List<org.osgi.util.tracker.ServiceTracker<?,?>> trackers
-
bin_test
public final Jar bin_test
-
framework
public final org.osgi.framework.launch.Framework framework
-
context
public final org.osgi.framework.BundleContext context
-
projectDir
public final java.io.File projectDir
-
workspace
public Workspace workspace
-
project
public Project project
-
-
Method Detail
-
close
public void close() throws java.lang.Exception
Close this framework- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
getBundleContext
public org.osgi.framework.BundleContext getBundleContext()
-
getServices
public <T> java.util.List<T> getServices(java.lang.Class<T> class1) throws org.osgi.framework.InvalidSyntaxException
- Throws:
org.osgi.framework.InvalidSyntaxException
-
getService
public <T> T getService(java.lang.Class<T> class1) throws java.lang.Exception
- Throws:
java.lang.Exception
-
waitForService
public <T> org.osgi.util.promise.Promise<T> waitForService(java.lang.Class<T> class1, long timeoutInMs) throws java.lang.Exception
- Throws:
java.lang.Exception
-
bundle
public JUnitFramework.BundleBuilder bundle() throws java.io.IOException
- Throws:
java.io.IOException
-
addBundles
public void addBundles(java.lang.String bndrun) throws java.lang.Exception
- Throws:
java.lang.Exception
-
addBundles
public void addBundles(java.io.File bndrun) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getWorkspace
public Workspace getWorkspace() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getProject
public Project getProject() throws java.lang.Exception
- Throws:
java.lang.Exception
-
startAll
public void startAll(java.util.List<org.osgi.framework.Bundle> bundles) throws org.osgi.framework.BundleException
- Throws:
org.osgi.framework.BundleException
-
addBundle
public java.util.List<org.osgi.framework.Bundle> addBundle(java.lang.String spec) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-