org.springframework.osgi.test
Class AbstractSynchronizedOsgiTests

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
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractDependencyManagerTests

public abstract class AbstractSynchronizedOsgiTests
extends AbstractConfigurableOsgiTests

JUnit superclass which offers synchronization for application context initialization. The class automatically determines Spring powered bundles that are installed by the testing framework and (by default), will wait for their application context to fully start. Only after all the application contexts have been fully refreshed, the actual test execution will commence.

The class also provides utility waiting methods for discovering Spring application context (published as OSGi services) in case programmatic waiting is required (for example, when installing bundles manually).

As the rest of the other classes, the behaviour of this class can be customized by extending its methods.

Author:
Costin Leau, Adrian Colyer

Field Summary
protected static long 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
AbstractSynchronizedOsgiTests()
          Default constructor.
AbstractSynchronizedOsgiTests(String name)
          Constructs a new AbstractSynchronizedOsgiTests instance.
 
Method Summary
protected  long getDefaultWaitTime()
          Returns the test default waiting time (in seconds).
protected  void postProcessBundleContext(BundleContext platformBundleContext)
          Post-processes the bundle context.
protected  boolean shouldWaitForSpringBundlesContextCreation()
          Indicates whether the test class should wait or not for the context creation of Spring/OSGi bundles before executing the tests.
protected  void waitOnContextCreation(BundleContext context, String forBundleWithSymbolicName, long timeout)
          Waits for a Spring powered bundle, given by its symbolic name, to be fully started.
protected  void waitOnContextCreation(String forBundleWithSymbolicName)
          Waits for a Spring powered bundle, given by its symbolic name, to be fully started.
protected  void waitOnContextCreation(String forBundleWithSymbolicName, long timeout)
          Waits for a Spring powered bundle, given by its symbolic name to be fully started.
 
Methods inherited from class org.springframework.osgi.test.AbstractConfigurableOsgiTests
createPlatform, getBootDelegationPackages, getPlatformName
 
Methods inherited from class org.springframework.osgi.test.AbstractOsgiTests
getTestBundles, getTestFrameworkBundles, preProcessBundleContext, 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

DEFAULT_WAIT_TIME

protected static final long DEFAULT_WAIT_TIME
See Also:
Constant Field Values
Constructor Detail

AbstractSynchronizedOsgiTests

public AbstractSynchronizedOsgiTests()
Default constructor. Constructs a new AbstractSynchronizedOsgiTests instance.


AbstractSynchronizedOsgiTests

public AbstractSynchronizedOsgiTests(String name)
Constructs a new AbstractSynchronizedOsgiTests instance.

Parameters:
name - test name
Method Detail

waitOnContextCreation

protected void waitOnContextCreation(String forBundleWithSymbolicName,
                                     long timeout)
Waits for a Spring powered bundle, given by its symbolic name to be fully started.

Forces the current (test) thread to wait for the a Spring application context to be published under the given symbolic name. This method allows waiting for full initialization of Spring OSGi bundles before starting the actual test execution. This method will use the test bundle context for service lookup.

Parameters:
forBundleWithSymbolicName - bundle symbolic name
timeout - maximum time to wait (in seconds) for the application context to be published

waitOnContextCreation

protected void waitOnContextCreation(BundleContext context,
                                     String forBundleWithSymbolicName,
                                     long timeout)
Waits for a Spring powered bundle, given by its symbolic name, to be fully started.

Forces the current (test) thread to wait for the a Spring application context to be published under the given symbolic name. This method allows waiting for full initialization of Spring OSGi bundles before starting the actual test execution.

Parameters:
context - bundle context to use for service lookup
forBundleWithSymbolicName - bundle symbolic name
timeout - maximum time to wait (in seconds) for the application context to be published

waitOnContextCreation

protected void waitOnContextCreation(String forBundleWithSymbolicName)
Waits for a Spring powered bundle, given by its symbolic name, to be fully started.

This method uses the default wait time and test bundle context and is identical to #waitOnContextCreation(bundleContext, forBundleWithSymbolicName, getDefaultWaitTime()).

This method is used by the testing framework at startup before executing the actual tests.

Parameters:
forBundleWithSymbolicName - bundle symbolic name
See Also:
getDefaultWaitTime(), waitOnContextCreation(BundleContext, String, long)

getDefaultWaitTime

protected long getDefaultWaitTime()
Returns the test default waiting time (in seconds). Subclasses should override this method if the DEFAULT_WAIT_TIME is not enough. For more customization, consider setting shouldWaitForSpringBundlesContextCreation() to false and using waitOnContextCreation(BundleContext, String, long).

Returns:
the default wait time (in seconds) for each spring bundle context to be published as an OSGi service

shouldWaitForSpringBundlesContextCreation

protected boolean shouldWaitForSpringBundlesContextCreation()
Indicates whether the test class should wait or not for the context creation of Spring/OSGi bundles before executing the tests. Default is true.

Returns:
true (the default) if the test will wait for spring bundle context creation or false otherwise

postProcessBundleContext

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


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