Class AbstractConfigurableBundleCreatorTests

  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.springframework.test.ConditionalTestCase
              extended by org.springframework.test.AbstractSpringContextTests
                  extended by org.springframework.test.AbstractSingleSpringContextTests
                      extended by org.springframework.test.AbstractDependencyInjectionSpringContextTests
                          extended by org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
                              extended by org.springframework.osgi.test.AbstractOsgiTests
                                  extended by org.springframework.osgi.test.AbstractConfigurableOsgiTests
                                      extended by org.springframework.osgi.test.AbstractSynchronizedOsgiTests
                                          extended by org.springframework.osgi.test.AbstractDependencyManagerTests
                                              extended by org.springframework.osgi.test.AbstractOnTheFlyBundleCreatorTests
                                                  extended by org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests
All Implemented Interfaces:

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 {

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:

These settings can be configured by:

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

Costin Leau
See Also:

Field Summary
protected static String INCLUDE_PATTERNS
protected static String LIBS
protected static String MANIFEST
protected static String ROOT_DIR
Fields inherited from class org.springframework.osgi.test.AbstractSynchronizedOsgiTests
Fields inherited from class org.springframework.osgi.test.AbstractConfigurableOsgiTests
Fields inherited from class org.springframework.osgi.test.AbstractOsgiTests
Fields inherited from class org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
Fields inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
Fields inherited from class org.springframework.test.ConditionalTestCase
Constructor Summary
Method Summary
protected  String[] getBundleContentPattern()
          Returns the patterns used for identifying the resources added to the jar.
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.AbstractOnTheFlyBundleCreatorTests
createDefaultManifest, createManifestOnlyFromTestClass, getManifest
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.osgi.test.AbstractSynchronizedOsgiTests
getDefaultWaitTime, isSpringDMManaged, shouldWaitForSpringBundlesContextCreation, waitOnContextCreation, waitOnContextCreation, waitOnContextCreation
Methods inherited from class org.springframework.osgi.test.AbstractConfigurableOsgiTests
createPlatform, getBootDelegationPackages, getPlatformName
Methods inherited from class org.springframework.osgi.test.AbstractOsgiTests
run, runBare
Methods inherited from class org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
createApplicationContext, isContextKeyEmpty
Methods inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
getAutowireMode, injectDependencies, isDependencyCheck, isPopulateProtectedVariables, prepareTestInstance, setAutowireMode, setDependencyCheck, setPopulateProtectedVariables
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 org.springframework.test.AbstractSpringContextTests
addContext, contextKeyString, getContext, hasCachedContext, setDirty
Methods inherited from class org.springframework.test.ConditionalTestCase
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runTest, setName, toString
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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


protected static final String ROOT_DIR
See Also:
Constant Field Values


protected static final String INCLUDE_PATTERNS
See Also:
Constant Field Values


protected static final String LIBS
See Also:
Constant Field Values


protected static final String MANIFEST
See Also:
Constant Field Values
Constructor Detail


public AbstractConfigurableBundleCreatorTests()
Method Detail


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"

getRootPath in class AbstractOnTheFlyBundleCreatorTests
root path given as a String


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:

  1. **/*.class for classes
  2. **/*.xml for XML files
  3. **/*.properties for properties files

getBundleContentPattern in class AbstractOnTheFlyBundleCreatorTests
array of Ant-style pattern


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.

getManifestLocation in class AbstractOnTheFlyBundleCreatorTests
the manifest location
See Also:
AbstractOnTheFlyBundleCreatorTests.getManifest(), AbstractOnTheFlyBundleCreatorTests.createDefaultManifest()


protected String getSettingsLocation()
Returns the settings location (by default, the test name; i.e. will try to load foo/bar/

settings location for this test


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.

default settings for creating the jar
See Also:


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.

settings for creating the on the fly jar
Exception - if loading the settings file fails


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.

postProcessBundleContext in class AbstractOnTheFlyBundleCreatorTests
context - the platform bundle context
See Also:

Copyright © 2006-2011 Spring Framework. All Rights Reserved.