org.springframework.osgi.test
Class AbstractOsgiTests

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
All Implemented Interfaces:
Test, org.springframework.osgi.internal.test.OsgiJUnitTest
Direct Known Subclasses:
AbstractConfigurableOsgiTests

public abstract class AbstractOsgiTests
extends AbstractOptionalDependencyInjectionTests
implements org.springframework.osgi.internal.test.OsgiJUnitTest

Base test for OSGi environments. Takes care of starting the OSGi platform, installing the given bundles and delegating the test execution to a copy which runs inside OSGi.

Author:
Costin Leau

Field Summary
protected  BundleContext bundleContext
           
protected  ResourceLoader resourceLoader
           
 
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
 
Fields inherited from interface org.springframework.osgi.internal.test.OsgiJUnitTest
FOR_OSGI, FROM_OSGI, OSGI_TEST, OSGI_TEST_BUNDLE_ID
 
Constructor Summary
AbstractOsgiTests()
           
AbstractOsgiTests(String name)
           
 
Method Summary
protected abstract  OsgiPlatform createPlatform()
          Create (and configure) the OSGi platform.
protected  BundleContext getBundleContext()
          Deprecated. use the bundleContext field directly
protected  String[] getBundleLocations()
          Deprecated. use
protected  String[] getBundles()
          Deprecated. use #getTestBundlesNames()
protected abstract  String[] getMandatoryBundles()
          Deprecated. use getTestFrameworkBundles()
protected  ResourceLoader getResourceLoader()
          Deprecated. use the resourceLoader field directly
protected abstract  Resource[] getTestBundles()
          Bundles required for the the test execution.
protected abstract  Resource[] getTestFrameworkBundles()
          Test framework bundles (part of the test setup).
 void injectBundleContext(BundleContext bundleContext)
          Set the bundle context to be used by this test.
 void injectOsgiJUnitTest(org.springframework.osgi.internal.test.OsgiJUnitTest test)
          Set the underlying OsgiJUnitTest used for the test delegation.
 void osgiRunTest()
          Actual test execution (delegates to the superclass implementation).
 void osgiSetUp()
          the setUp version for the OSGi environment.
 void osgiTearDown()
           
protected  void postProcessBundleContext(BundleContext platformBundleContext)
          Callback for processing the platform bundle context after the critical test infrastructure bundles have been installed and started.
protected  void preProcessBundleContext(BundleContext platformBundleContext)
          Callback for processing the platform bundle context before any bundles have been installed.
 void run(TestResult result)
          Replacement run method.
 void runBare()
           
 void setName(String name)
           
 
Methods inherited from class org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests
createApplicationContext
 
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, 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, 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

bundleContext

protected BundleContext bundleContext

resourceLoader

protected ResourceLoader resourceLoader
Constructor Detail

AbstractOsgiTests

public AbstractOsgiTests()

AbstractOsgiTests

public AbstractOsgiTests(String name)
Method Detail

getBundleLocations

protected String[] getBundleLocations()
Deprecated. use

Legacy method - will be removed in future SVN revisions.

Returns:

getResourceLoader

protected ResourceLoader getResourceLoader()
Deprecated. use the resourceLoader field directly

Return the resource loader used by this test.

Returns:
an OsgiBundleResourceLoader if the bundleContext was set or null otherwise.

getBundleContext

protected BundleContext getBundleContext()
Deprecated. use the bundleContext field directly

Return the bundleContext for the bundle in which this test is running.

Specified by:
getBundleContext in class AbstractOptionalDependencyInjectionTests
Returns:

getBundles

protected String[] getBundles()
Deprecated. use #getTestBundlesNames()

Bundles that should be installed before the test execution.

Returns:
the array of bundles to install

getMandatoryBundles

protected abstract String[] getMandatoryBundles()
Deprecated. use getTestFrameworkBundles()

Mandatory bundles (part of the test setup). Used by the test infrastructure. Override this method only if you want to change the jars used by default, by the testing infrastructure. User subclasses should use getBundles() instead.

Returns:
the array of mandatory bundle names.

getTestFrameworkBundles

protected abstract Resource[] getTestFrameworkBundles()
Test framework bundles (part of the test setup). Used by the test infrastructure. Override this method only if you want to change the jars used by default, by the testing infrastructure. User subclasses should use getBundles() instead.

Returns:
the array of test framework bundle resources

getTestBundles

protected abstract Resource[] getTestBundles()
Bundles required for the the test execution.

Returns:
the array of bundles to install

createPlatform

protected abstract OsgiPlatform createPlatform()
                                        throws Exception
Create (and configure) the OSGi platform.

Returns:
OSGi platform.
Throws:
Exception

preProcessBundleContext

protected void preProcessBundleContext(BundleContext platformBundleContext)
                                throws Exception
Callback for processing the platform bundle context before any bundles have been installed. The method is invoked after starting the OSGi environment but before any bundles are installed in the OSGi framework. Normally, this method is called only one during the lifecycle of a test suite.

Parameters:
platformBundleContext -
Throws:
Exception
See Also:
postProcessBundleContext(BundleContext)

postProcessBundleContext

protected void postProcessBundleContext(BundleContext platformBundleContext)
                                 throws Exception
Callback for processing 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.

Note that at this point, getBundleContext() returns null since the OSGi test execution hasn't started yet - the only BundleContext available is that of the OSGi framework.

Parameters:
platformBundleContext -
Throws:
Exception
See Also:
preProcessBundleContext(BundleContext)

run

public final void run(TestResult result)
Replacement run method. Get a hold of the TestRunner used for running this test so it can populate it with the results retrieved from OSGi.

Specified by:
run in interface Test
Overrides:
run in class TestCase

runBare

public void runBare()
             throws Throwable
Overrides:
runBare in class ConditionalTestCase
Throws:
Throwable

osgiSetUp

public final void osgiSetUp()
                     throws Exception
the setUp version for the OSGi environment.

Specified by:
osgiSetUp in interface org.springframework.osgi.internal.test.OsgiJUnitTest
Throws:
Exception

osgiTearDown

public final void osgiTearDown()
                        throws Exception
Specified by:
osgiTearDown in interface org.springframework.osgi.internal.test.OsgiJUnitTest
Throws:
Exception

osgiRunTest

public final void osgiRunTest()
                       throws Throwable
Actual test execution (delegates to the superclass implementation).

Specified by:
osgiRunTest in interface org.springframework.osgi.internal.test.OsgiJUnitTest
Throws:
Throwable

injectBundleContext

public final void injectBundleContext(BundleContext bundleContext)
Set the bundle context to be used by this test.

This method is called automatically by the test infrastructure after the OSGi platform is being setup.

Specified by:
injectBundleContext in interface org.springframework.osgi.internal.test.OsgiJUnitTest

setName

public void setName(String name)
Specified by:
setName in interface org.springframework.osgi.internal.test.OsgiJUnitTest
Overrides:
setName in class TestCase

injectOsgiJUnitTest

public final void injectOsgiJUnitTest(org.springframework.osgi.internal.test.OsgiJUnitTest test)
Set the underlying OsgiJUnitTest used for the test delegation.

This method is called automatically by the test infrastructure after the OSGi platform is being setup.

Parameters:
test -


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