org.springframework.osgi.test
Class AbstractOnTheFlyBundleCreatorTests

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
All Implemented Interfaces:
Test
Direct Known Subclasses:
AbstractConfigurableBundleCreatorTests

public abstract class AbstractOnTheFlyBundleCreatorTests
extends AbstractDependencyManagerTests

Enhanced subclass of AbstractDependencyManagerTests that facilitates OSGi testing by creating at runtime, on the fly, a jar using the indicated manifest and resource patterns (by default all files found under the root path).

The test class can automatically determine the imports required by the test, create the OSGi bundle manifest and pack the test and its resources in a jar that can be installed inside an OSGi platform.

Additionally, a valid OSGi manifest is automatically created for the resulting test if the user does not provide one. The classes present in the archive are analyzed and based on their byte-code, the required Import-Package entries (for packages not found in the bundle) are created. Please see the reference documentation for an in-depth explanation and usage examples.

Note that in more complex scenarios, dedicated packaging tools (such as ant scripts or maven2) should be used.

It is recommend to extend AbstractConfigurableBundleCreatorTests rather then this class as the former offers sensible defaults.

Author:
Costin Leau

Field Summary
 
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
AbstractOnTheFlyBundleCreatorTests()
           
AbstractOnTheFlyBundleCreatorTests(String testName)
           
 
Method Summary
protected  Manifest createDefaultManifest()
          Creates the default manifest in case none if found on the disk.
protected  boolean createManifestOnlyFromTestClass()
          Indicates if the automatic manifest creation should consider only the test class (true) or all classes included in the test bundle(false).
protected  String[] getBundleContentPattern()
          Returns the patterns used for identifying the resources added to the jar.
protected  Manifest getManifest()
          Returns the current test bundle manifest.
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  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.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
 

Constructor Detail

AbstractOnTheFlyBundleCreatorTests

public AbstractOnTheFlyBundleCreatorTests()

AbstractOnTheFlyBundleCreatorTests

public AbstractOnTheFlyBundleCreatorTests(String testName)
Method Detail

getRootPath

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).

By default, the Maven2 test layout is used: "file:./target/test-classes"

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.

Returns:
the patterns identifying the resources added to the jar

getManifestLocation

protected String getManifestLocation()
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.

Returns:
the manifest location
See Also:
getManifest(), createDefaultManifest()

getManifest

protected Manifest getManifest()
Returns the current test bundle manifest. The method tries to read the manifest from the given location; in case the location is null (default), it will search for META-INF/MANIFEST.MF file in jar content (as specified through the patterns) and, if it cannot find the file, automatically create a Manifest object containing default entries.

Subclasses can override this method to enhance the returned Manifest.

Returns:
Manifest used for this test suite.
See Also:
createDefaultManifest()

createManifestOnlyFromTestClass

protected boolean createManifestOnlyFromTestClass()
Indicates if the automatic manifest creation should consider only the test class (true) or all classes included in the test bundle(false). The latter should be used when the test bundle contains additional classes that help with the test case.

By default, this method returns true, meaning that only the test class will be searched for dependencies.

Returns:
true if only the test hierarchy is searched for dependencies or false if all classes discovered in the test archive need to be parsed.

createDefaultManifest

protected Manifest createDefaultManifest()
Creates the default manifest in case none if found on the disk. By default, the imports are synthetised based on the test class bytecode.

Returns:
default manifest for the jar created on the fly

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 AbstractSynchronizedOsgiTests
Parameters:
context - the platform bundle context
Throws:
Exception
See Also:
AbstractOsgiTests.preProcessBundleContext(BundleContext)


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