org.springframework.osgi.test
Class AbstractConfigurableBundleCreatorTests

java.lang.Object
  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:
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:

These settings can be configured by:

Note: This class is the main testing framework entry point

Author:
Costin Leau

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
DEFAULT_WAIT_TIME
 
Fields inherited from class org.springframework.osgi.test.AbstractConfigurableOsgiTests
OSGI_FRAMEWORK_SELECTOR
 
Fields inherited from class org.springframework.osgi.test.AbstractOsgiTests
resourceLoader
 
Fields inherited from class org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
bundleContext
 
Fields inherited from class org.springframework.test.AbstractDependencyInjectionSpringContextTests
AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_NO
 
Fields inherited from class org.springframework.test.AbstractSingleSpringContextTests
applicationContext
 
Fields inherited from class org.springframework.test.ConditionalTestCase
logger
 
Constructor Summary
AbstractConfigurableBundleCreatorTests()
           
 
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, 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, 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, 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

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
Constructor Detail

AbstractConfigurableBundleCreatorTests

public AbstractConfigurableBundleCreatorTests()
Method Detail

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:

  1. **/*.class for classes
  2. **/*.xml for XML files
  3. **/*.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-2008 Spring Framework. All Rights Reserved.