public class NXRuntimeTestCase extends Object implements RuntimeHarness
The runtime service itself is conveniently available as the runtime
instance variable in derived
classes.
Warning: NXRuntimeTestCase subclasses must
Modifier and Type | Field and Description |
---|---|
protected StandaloneBundleLoader |
bundleLoader |
protected Map<String,BundleFile> |
bundles |
protected List<String[]> |
deploymentStack |
protected boolean |
frameworkStarted
Whether or not the runtime components were started.
|
protected boolean |
isTestUnit
Set to true when the instance of this class is a JUnit test case.
|
protected org.jmock.Mockery |
jmcontext |
protected OSGiAdapter |
osgi |
protected boolean |
restart |
protected OSGiRuntimeService |
runtime |
protected org.osgi.framework.Bundle |
runtimeBundle |
protected TargetResourceLocator |
targetResourceLocator |
protected URL[] |
urls |
protected List<WorkingDirectoryConfigurator> |
wdConfigs |
protected File |
workingDir |
Constructor and Description |
---|
NXRuntimeTestCase()
Used when subclassing to create standalone test cases
|
NXRuntimeTestCase(Class<?> clazz)
Used by the features runner to manage the Nuxeo framework
|
Modifier and Type | Method and Description |
---|---|
void |
addWorkingDirectoryConfigurator(WorkingDirectoryConfigurator config) |
protected void |
applyInlineDeployments()
Should be called by subclasses after one or more inline deployments are made inside a test method.
|
void |
deployBundle(String name)
Deploys a whole OSGI bundle.
|
void |
deployContrib(String uri)
Deploy a contribution specified as a "bundleName:path" uri
|
void |
deployContrib(String name,
String contrib)
Deploys a contribution from a given bundle.
|
protected void |
deployContrib(URL url) |
void |
deployFolder(File folder,
ClassLoader loader) |
RuntimeContext |
deployPartial(String name,
Set<TargetExtensions> targetExtensions)
Deploys a subset of a Bundle defined per the targetExtensions parameter
|
protected void |
deployPartialComponent(RuntimeContext ctx,
Set<TargetExtensions> extensionPoints,
StreamRef component)
Read a component from his StreamRef and create a new component (suffixed with `-partial`, and the base component
name aliased) with only matching contributions of the extensionPoints parameter.
|
RuntimeContext |
deployTestContrib(String bundle,
String contrib)
Deprecated.
since 10.1, use
deployContrib(String, String) |
RuntimeContext |
deployTestContrib(String bundle,
URL contrib)
Deprecated.
since 10.1, use
deployContrib(String, String) |
void |
fireFrameworkStarted()
Fire the event
FrameworkEvent.STARTED . |
List<String> |
getClassLoaderFiles() |
RuntimeContext |
getContext()
Runtime context for deployment
|
OSGiAdapter |
getOSGiAdapter()
OSGI bridge
|
Properties |
getProperties()
Framework properties for variable injections
|
static URL |
getResource(String name) |
File |
getWorkingDir()
Gets the framework working directory.
|
protected OSGiRuntimeService |
handleNewRuntime(OSGiRuntimeService aRuntime) |
protected void |
initOsgiRuntime() |
protected void |
initUrls() |
static URL[] |
introspectClasspath(ClassLoader loader) |
boolean |
isRestart() |
boolean |
isStarted() |
protected static boolean |
isVersionSuffix(String s) |
protected Stream<URL> |
listBundleComponents(org.osgi.framework.Bundle bundle)
Listing component's urls of a bundle.
|
BundleFile |
lookupBundle(String bundleName) |
protected URL |
lookupBundleUrl(String bundle)
Resolves an URL for bundle deployment code.
|
void |
popInlineDeployments()
Remove the latest deployed components using
pushInlineDeployments(String...) . |
void |
popInlineDeployments(int index) |
protected void |
postSetUp()
Called after framework was started (at the end of setUp).
|
void |
pushInlineDeployments(String... deploymentUris)
Hot deploy the given components (identified by an URI).
|
protected String |
readSymbolicName(BundleFile bf) |
protected void |
removeInlineDeployments()
Should be called by subclasses to remove any inline deployments made in the current test method.
|
void |
restart()
Restarts the runtime and preserve homes directory.
|
protected void |
setUp()
Implementors should override this method to setup tests and not the
startRuntime() method. |
void |
start() |
void |
startRuntime() |
void |
stop() |
void |
stopRuntime() |
protected void |
tearDown()
Implementors should override this method to implement any specific test tear down and not the
stopRuntime() method |
void |
undeployContrib(String uri) |
void |
undeployContrib(String name,
String contrib)
Undeploys a contribution from a given bundle.
|
protected void |
wipeRuntime()
Makes sure there is no previous runtime hanging around.
|
protected org.jmock.Mockery jmcontext
protected OSGiRuntimeService runtime
protected File workingDir
protected StandaloneBundleLoader bundleLoader
protected Map<String,BundleFile> bundles
protected boolean restart
protected List<String[]> deploymentStack
protected boolean frameworkStarted
protected OSGiAdapter osgi
protected org.osgi.framework.Bundle runtimeBundle
protected final List<WorkingDirectoryConfigurator> wdConfigs
protected final TargetResourceLocator targetResourceLocator
protected final boolean isTestUnit
public NXRuntimeTestCase()
public NXRuntimeTestCase(Class<?> clazz)
public boolean isRestart()
isRestart
in interface RuntimeHarness
public void addWorkingDirectoryConfigurator(WorkingDirectoryConfigurator config)
addWorkingDirectoryConfigurator
in interface RuntimeHarness
public File getWorkingDir()
RuntimeHarness
getWorkingDir
in interface RuntimeHarness
public void restart() throws Exception
restart
in interface RuntimeHarness
Exception
public void start() throws Exception
start
in interface RuntimeHarness
Exception
public void startRuntime() throws Exception
Exception
protected void setUp() throws Exception
startRuntime()
method. This method
should contain all the bundle or component deployments needed by the tests. At the time this method is called the
components are not yet started. If you need to perform component/service lookups use instead the
postSetUp()
methodException
protected void tearDown() throws Exception
stopRuntime()
methodException
protected void postSetUp() throws Exception
Exception
public void fireFrameworkStarted() throws Exception
FrameworkEvent.STARTED
. This will start all the resolved Nuxeo componentsfireFrameworkStarted
in interface RuntimeHarness
Exception
OSGiRuntimeService.frameworkEvent(FrameworkEvent)
public void stopRuntime() throws Exception
Exception
public void stop() throws Exception
stop
in interface RuntimeHarness
Exception
public boolean isStarted()
isStarted
in interface RuntimeHarness
protected void initOsgiRuntime() throws Exception
Exception
protected OSGiRuntimeService handleNewRuntime(OSGiRuntimeService aRuntime)
public static URL[] introspectClasspath(ClassLoader loader)
protected void wipeRuntime() throws Exception
This happens for instance if a previous test had errors in its setUp()
, because
tearDown()
has not been called.
Exception
public static URL getResource(String name)
protected void deployContrib(URL url)
public void deployContrib(String name, String contrib) throws Exception
The path will be relative to the bundle root. Example:
deployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
For compatibility reasons the name of the bundle may be a jar name, but this use is discouraged and deprecated.
deployContrib
in interface RuntimeHarness
name
- the name of the bundle to peek the contrib incontrib
- the path to contrib in the bundle.Exception
public void deployContrib(String uri) throws Exception
Exception
@Deprecated public RuntimeContext deployTestContrib(String bundle, String contrib) throws Exception
deployContrib(String, String)
This should be used by tests wiling to deploy test contribution as part of a real bundle.
The bundle owner is important since the contribution may depend on resources deployed in that bundle.
Note that the owner bundle MUST be an already deployed bundle.
deployTestContrib
in interface RuntimeHarness
bundle
- the bundle that becomes the contribution ownercontrib
- the contribution to deploy as part of the given bundleException
@Deprecated public RuntimeContext deployTestContrib(String bundle, URL contrib) throws Exception
deployContrib(String, String)
deployTestContrib
in interface RuntimeHarness
Exception
public RuntimeContext deployPartial(String name, Set<TargetExtensions> targetExtensions) throws Exception
RuntimeHarness
deployPartial
in interface RuntimeHarness
name
- the name of the componenttargetExtensions
- Set of allowed TargetExtensions in the final contributionException
protected void deployPartialComponent(RuntimeContext ctx, Set<TargetExtensions> extensionPoints, StreamRef component) throws IOException
ctx
- RuntimeContext in which the new component will be deployedextensionPoints
- Set of white listed TargetExtensionscomponent
- Reference to the original componentIOException
protected Stream<URL> listBundleComponents(org.osgi.framework.Bundle bundle)
bundle
- Bundle to be readpublic void undeployContrib(String name, String contrib) throws Exception
The path will be relative to the bundle root. Example:
undeployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
undeployContrib
in interface RuntimeHarness
name
- the bundlecontrib
- the contributionException
public void undeployContrib(String uri) throws Exception
Exception
protected static boolean isVersionSuffix(String s)
protected URL lookupBundleUrl(String bundle)
TODO: Implementation could be finer...
public void deployBundle(String name) throws Exception
The lookup is first done on symbolic name, as set in MANIFEST.MF
and then falls back to the bundle
url (e.g., nuxeo-platform-search-api
) for backwards compatibility.
deployBundle
in interface RuntimeHarness
name
- the symbolic nameException
protected String readSymbolicName(BundleFile bf)
public BundleFile lookupBundle(String bundleName) throws Exception
Exception
public void deployFolder(File folder, ClassLoader loader) throws Exception
deployFolder
in interface RuntimeHarness
Exception
public Properties getProperties()
RuntimeHarness
getProperties
in interface RuntimeHarness
public RuntimeContext getContext()
RuntimeHarness
getContext
in interface RuntimeHarness
public OSGiAdapter getOSGiAdapter()
RuntimeHarness
getOSGiAdapter
in interface RuntimeHarness
public List<String> getClassLoaderFiles() throws URISyntaxException
getClassLoaderFiles
in interface RuntimeHarness
URISyntaxException
protected void applyInlineDeployments() throws Exception
postSetUp()
for convenience.Exception
protected void removeInlineDeployments() throws Exception
postSetUp()
for convenience.Exception
public void pushInlineDeployments(String... deploymentUris) throws Exception
popInlineDeployments()
A component URI is of the form: bundleSymbolicName:pathToComponentXmlInBundle
Exception
public void popInlineDeployments() throws Exception
pushInlineDeployments(String...)
.Exception
public void popInlineDeployments(int index) throws Exception
Exception
Copyright © 2018 Nuxeo. All rights reserved.