org.springframework.osgi.test
Class AbstractConfigurableBundleCreatorTests
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.springframework.test.ConditionalTestCase
org.springframework.test.AbstractSpringContextTests
org.springframework.test.AbstractSingleSpringContextTests
org.springframework.test.AbstractDependencyInjectionSpringContextTests
org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
org.springframework.osgi.test.AbstractOsgiTests
org.springframework.osgi.test.AbstractConfigurableOsgiTests
org.springframework.osgi.test.AbstractSynchronizedOsgiTests
org.springframework.osgi.test.AbstractDependencyManagerTests
org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests
org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests
- All Implemented Interfaces:
- Test
public abstract class AbstractConfigurableBundleCreatorTests
- extends AbstractOnTheFlyBundleCreatorTests
Abstract JUnit base class that allows easy OSGi integration testing. It
builds on its super classes to allow full configuration of the underlying
OSGi platform implementation, of the test bundle creation (including the
manifest automatic generation).
This class follows the traditional Spring style of integration
testing in which the test simply indicates the dependencies, leaving the rest
of the work to be done by its super classes. Consider the following simple
example:
public class SimpleOsgiTest extends AbstractConfigurableBundleCreatorTests {
public void testOsgiPlatformStarts() throws Exception {
System.out.println(bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
System.out.println(bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
System.out.println(bundleContext.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
}
}
The above class can be ran just like any other JUnit test. Equinox
platform will be automatically started, the test will packed in an OSGi
bundle (with its manifest created automatically) which will be deployed
inside the OSGi platform. After running the test inside the OSGi environment,
the test results (whether they are exceptions or failures) will be reported
back to the running tool transparently. Please see the reference
documentation for more examples, customization tips and help on how to do
efficient and fast integration testing.
This class allows the test on-the-fly bundle (jar) can be configured
declaratively by indicating the locations for:
- root folder ("root.dir") - the starting point on which the
resource patterns are applied
- inclusion patterns ("include.patterns")- comma separated
strings which identify the resources that should be included into the
archive.
- manifest ("manifest")- the location of the manifest used for
testing (if automatic generation is undesired).
These settings can be configured by:
- using a properties file. By default the property name follows the
pattern "[testName]-bundle.properties", (i.e. /foo/bar/SomeTest will try to
load file /foo/bar/SomeTest-bundle.properties). If no properties file is
found, a set of defaults will be used.
- overriding the default getXXX methods and providing an alternative
implementation.
Another useful functionality inherited from
AbstractOnTheFlyBundleCreatorTests
class is the ability to create a
manifest for the test bundle on the fly, based on the classes present in the
archive.
Note: This class is the main testing framework entry point
- Author:
- Costin Leau
- See Also:
AbstractOnTheFlyBundleCreatorTests
Method Summary |
protected String[] |
getBundleContentPattern()
Returns the patterns used for identifying the resources added to the jar.
Ant-style patterns for identifying the resources added to the jar.The
patterns are considered from the root path when performing the search. |
protected Properties |
getDefaultSettings()
Returns the default settings used when creating the jar, in case no
customisations have been applied. |
protected String |
getManifestLocation()
Returns the location (in Spring resource style) of the manifest location
to be used. |
protected String |
getRootPath()
Returns the root path used for locating the resources that will be packed
in the test bundle (the root path does not become part of the jar). |
protected Properties |
getSettings()
Returns the settings used for creating this jar. |
protected String |
getSettingsLocation()
Returns the settings location (by default, the test name; i.e. |
protected void |
postProcessBundleContext(BundleContext context)
Post-processes the bundle context. |
Methods inherited from class org.springframework.osgi.test.AbstractDependencyManagerTests |
getLocator, getSpringDMVersion, getSpringVersion, getTestBundles, getTestBundlesNames, getTestFrameworkBundles, getTestFrameworkBundlesNames, getTestingFrameworkBundlesConfiguration, locateBundle, locateBundles, preProcessBundleContext |
Methods inherited from class org.springframework.test.AbstractSingleSpringContextTests |
contextKey, createBeanDefinitionReader, customizeBeanFactory, getApplicationContext, getConfigLocations, getConfigPath, getConfigPaths, getLoadCount, loadContext, loadContextLocations, onSetUp, onTearDown, prepareApplicationContext, setDirty, setUp, tearDown |
Methods inherited from class junit.framework.Assert |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame |
ROOT_DIR
protected static final String ROOT_DIR
- See Also:
- Constant Field Values
INCLUDE_PATTERNS
protected static final String INCLUDE_PATTERNS
- See Also:
- Constant Field Values
LIBS
protected static final String LIBS
- See Also:
- Constant Field Values
MANIFEST
protected static final String MANIFEST
- See Also:
- Constant Field Values
AbstractConfigurableBundleCreatorTests
public AbstractConfigurableBundleCreatorTests()
getRootPath
protected String getRootPath()
- Description copied from class:
AbstractOnTheFlyBundleCreatorTests
- Returns the root path used for locating the resources that will be packed
in the test bundle (the root path does not become part of the jar).
By default, the Maven2 test layout is used:
"file:./target/test-classes"
- Overrides:
getRootPath
in class AbstractOnTheFlyBundleCreatorTests
- Returns:
- root path given as a String
getBundleContentPattern
protected String[] getBundleContentPattern()
- Returns the patterns used for identifying the resources added to the jar.
The patterns are added to the root path when performing the search. By
default, the pattern is
**/*
.
In large test environments, performance can be improved by limiting
the resource added to the bundle by selecting only certain packages or
classes. This results in a small test bundle which is faster to create,
deploy and install.
Ant-style patterns for identifying the resources added to the jar.The
patterns are considered from the root path when performing the search.
By default, the content pattern is **/*
which
includes all sources from the root. One can configure the pattern to
include specific files by using different patterns. For example, to
include just the classes, XML and properties files one can use the
following patterns:
**/*.class
for classes
**/*.xml
for XML files
**/*.properties
for properties files
- Overrides:
getBundleContentPattern
in class AbstractOnTheFlyBundleCreatorTests
- Returns:
- array of Ant-style pattern
getManifestLocation
protected String getManifestLocation()
- Description copied from class:
AbstractOnTheFlyBundleCreatorTests
- Returns the location (in Spring resource style) of the manifest location
to be used. By default
null
is returned, indicating that
the manifest should be picked up from the bundle content (if it's
available) or be automatically created based on the test class imports.
- Overrides:
getManifestLocation
in class AbstractOnTheFlyBundleCreatorTests
- Returns:
- the manifest location
- See Also:
AbstractOnTheFlyBundleCreatorTests.getManifest()
,
AbstractOnTheFlyBundleCreatorTests.createDefaultManifest()
getSettingsLocation
protected String getSettingsLocation()
- Returns the settings location (by default, the test name; i.e.
foo.bar.SomeTest
will try to load
foo/bar/SomeTest-bundle.properties
).
- Returns:
- settings location for this test
getDefaultSettings
protected Properties getDefaultSettings()
- Returns the default settings used when creating the jar, in case no
customisations have been applied. Unless the base class is used as a
testing framework, consider using a properties file for specifying
specific properties for a test case.
- Returns:
- default settings for creating the jar
- See Also:
getSettingsLocation()
getSettings
protected Properties getSettings()
throws Exception
- Returns the settings used for creating this jar. This method tries to
locate and load the settings from the location indicated by
getSettingsLocation()
. If no file is found, the default
settings will be used.
A non-null properties object will always be returned.
- Returns:
- settings for creating the on the fly jar
- Throws:
Exception
- if loading the settings file fails
postProcessBundleContext
protected void postProcessBundleContext(BundleContext context)
throws Exception
- Description copied from class:
AbstractOsgiTests
- Post-processes the bundle context. This call back gives access to the
platform bundle context after the critical test infrastructure bundles
have been installed and started. The method is invoked after
preparing the OSGi environment for the test execution but before
any test is executed.
The given
BundleContext
belongs to the underlying OSGi
framework.
Normally, this method is called only one during the lifecycle of a
test suite.
- Overrides:
postProcessBundleContext
in class AbstractOnTheFlyBundleCreatorTests
- Parameters:
context
- the platform bundle context
- Throws:
Exception
- See Also:
AbstractOsgiTests.preProcessBundleContext(BundleContext)
Copyright © 2006-2009 Spring Framework. All Rights Reserved.