Package org.apache.camel.test.spring
Class CamelSpringTestContextLoader
- java.lang.Object
-
- org.springframework.test.context.support.AbstractContextLoader
-
- org.apache.camel.test.spring.CamelSpringTestContextLoader
-
- All Implemented Interfaces:
org.springframework.test.context.ContextLoader
,org.springframework.test.context.SmartContextLoader
public class CamelSpringTestContextLoader extends org.springframework.test.context.support.AbstractContextLoader
Replacement for the defaultGenericXmlContextLoader
that provides hooks for processing some class level Camel related test annotations.
-
-
Constructor Summary
Constructors Constructor Description CamelSpringTestContextLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cleanup(Class<?> testClass)
Cleanup/restore global state to defaults / pre-test values after the test setup is complete.protected org.springframework.context.support.GenericApplicationContext
createContext(Class<?> testClass, org.springframework.test.context.MergedContextConfiguration mergedConfig)
Creates and starts the Spring context while optionally starting any loaded Camel contexts.String
getResourceSuffix()
Returns "-context.xml
".protected Class<?>
getTestClass()
Returns the class under test in order to enable inspection of annotations while the Spring context is being created.protected Method
getTestMethod()
Returns the test method under test.protected void
handleCamelContextStartup(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles starting of Camel contexts based onUseAdviceWith
and other state in the JVM.protected void
handleDisableJmx(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles disabling of JMX on Camel contexts based onDisableJmx
.protected void
handleMockEndpoints(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles auto-intercepting of endpoints with mocks based onMockEndpoints
.protected void
handleMockEndpointsAndSkip(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles auto-intercepting of endpoints with mocks based onMockEndpointsAndSkip
and skipping the original endpoint.protected void
handleProvidesBreakpoint(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles the processing of theProvidesBreakpoint
annotation on a test class.protected void
handleShutdownTimeout(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles updating shutdown timeouts on Camel contexts based onShutdownTimeout
.protected void
handleUseOverridePropertiesWithPropertiesComponent(org.springframework.context.ConfigurableApplicationContext context, Class<?> testClass)
Sets property overrides for the CamelPropertiesComponent
.protected void
loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, String... locations)
protected void
loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, org.springframework.test.context.MergedContextConfiguration mergedConfig)
org.springframework.context.ApplicationContext
loadContext(String... locations)
Modeled after the Spring implementation inAbstractGenericContextLoader
, this method creates and refreshes the application context while providing for processing of additional Camel specific post-refresh actions.protected org.springframework.context.ApplicationContext
loadContext(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Performs the bulk of the Spring application context loading/customization.org.springframework.context.ApplicationContext
loadContext(org.springframework.test.context.MergedContextConfiguration mergedConfig)
Modeled after the Spring implementation inAbstractGenericContextLoader
, this method creates and refreshes the application context while providing for processing of additional Camel specific post-refresh actions.
-
-
-
Method Detail
-
loadContext
public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration mergedConfig) throws Exception
Modeled after the Spring implementation inAbstractGenericContextLoader
, this method creates and refreshes the application context while providing for processing of additional Camel specific post-refresh actions. We do not provide the pre-post hooks for customization seen inAbstractGenericContextLoader
because they probably are unnecessary for 90+% of users. For some functionality, we cannot useTestExecutionListener
because we need to both produce the desired outcome during application context loading, and also cleanup after ourselves even if the test class never executes. Thus the listeners, which only run if the application context is successfully initialized are insufficient to provide the behavior described above.- Throws:
Exception
-
loadContext
public org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
Modeled after the Spring implementation inAbstractGenericContextLoader
, this method creates and refreshes the application context while providing for processing of additional Camel specific post-refresh actions. We do not provide the pre-post hooks for customization seen inAbstractGenericContextLoader
because they probably are unnecessary for 90+% of users. For some functionality, we cannot useTestExecutionListener
because we need to both produce the desired outcome during application context loading, and also cleanup after ourselves even if the test class never executes. Thus the listeners, which only run if the application context is successfully initialized are insufficient to provide the behavior described above.- Throws:
Exception
-
getResourceSuffix
public String getResourceSuffix()
Returns "-context.xml
".- Specified by:
getResourceSuffix
in classorg.springframework.test.context.support.AbstractContextLoader
-
loadContext
protected org.springframework.context.ApplicationContext loadContext(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Performs the bulk of the Spring application context loading/customization.- Parameters:
context
- the partially configured context. The context should have the bean definitions loaded, but nothing else.testClass
- the test class being executed- Returns:
- the initialized (refreshed) Spring application context
- Throws:
Exception
- if there is an error during initialization/customization
-
cleanup
protected void cleanup(Class<?> testClass)
Cleanup/restore global state to defaults / pre-test values after the test setup is complete.- Parameters:
testClass
- the test class being executed
-
loadBeanDefinitions
protected void loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, org.springframework.test.context.MergedContextConfiguration mergedConfig)
-
loadBeanDefinitions
protected void loadBeanDefinitions(org.springframework.context.support.GenericApplicationContext context, String... locations)
-
createContext
protected org.springframework.context.support.GenericApplicationContext createContext(Class<?> testClass, org.springframework.test.context.MergedContextConfiguration mergedConfig)
Creates and starts the Spring context while optionally starting any loaded Camel contexts.- Parameters:
testClass
- the test class that is being executed- Returns:
- the loaded Spring context
-
handleDisableJmx
protected void handleDisableJmx(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass)
Handles disabling of JMX on Camel contexts based onDisableJmx
.- Parameters:
context
- the initialized Spring contexttestClass
- the test class being executed
-
handleProvidesBreakpoint
protected void handleProvidesBreakpoint(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Handles the processing of theProvidesBreakpoint
annotation on a test class. Exists here as it is needed in- Parameters:
context
- the initialized Spring context containing the Camel context(s) to insert breakpoints intotestClass
- the test class being processed- Throws:
Exception
- if there is an error processing the class
-
handleShutdownTimeout
protected void handleShutdownTimeout(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Handles updating shutdown timeouts on Camel contexts based onShutdownTimeout
.- Parameters:
context
- the initialized Spring contexttestClass
- the test class being executed- Throws:
Exception
-
handleMockEndpoints
protected void handleMockEndpoints(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Handles auto-intercepting of endpoints with mocks based onMockEndpoints
.- Parameters:
context
- the initialized Spring contexttestClass
- the test class being executed- Throws:
Exception
-
handleMockEndpointsAndSkip
protected void handleMockEndpointsAndSkip(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Handles auto-intercepting of endpoints with mocks based onMockEndpointsAndSkip
and skipping the original endpoint.- Parameters:
context
- the initialized Spring contexttestClass
- the test class being executed- Throws:
Exception
-
handleUseOverridePropertiesWithPropertiesComponent
protected void handleUseOverridePropertiesWithPropertiesComponent(org.springframework.context.ConfigurableApplicationContext context, Class<?> testClass) throws Exception
Sets property overrides for the CamelPropertiesComponent
.- Parameters:
context
- the pre-refresh Spring contexttestClass
- the test class being executed- Throws:
Exception
-
handleCamelContextStartup
protected void handleCamelContextStartup(org.springframework.context.support.GenericApplicationContext context, Class<?> testClass) throws Exception
Handles starting of Camel contexts based onUseAdviceWith
and other state in the JVM.- Parameters:
context
- the initialized Spring contexttestClass
- the test class being executed- Throws:
Exception
-
getTestClass
protected Class<?> getTestClass()
Returns the class under test in order to enable inspection of annotations while the Spring context is being created.- Returns:
- the test class that is being executed
- See Also:
CamelSpringTestHelper
-
getTestMethod
protected Method getTestMethod()
Returns the test method under test.- Returns:
- the method that is being executed
- See Also:
CamelSpringTestHelper
-
-