Class CamelSpringTestSupport

java.lang.Object
org.apache.camel.test.junit5.CamelTestSupport
org.apache.camel.test.spring.junit5.CamelSpringTestSupport
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.Extension

public abstract class CamelSpringTestSupport extends org.apache.camel.test.junit5.CamelTestSupport
Base test-class for classic Spring application such as standalone, web applications. Do not use this class for Spring Boot testing, instead use @CamelSpringBootTest.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.springframework.context.support.AbstractApplicationContext
     
    protected static final Object
     
    static final String
     
    static final String
     
    static final String
     
    protected static final ThreadLocal<org.springframework.context.support.AbstractApplicationContext>
     

    Fields inherited from class org.apache.camel.test.junit5.CamelTestSupport

    camelContextService, camelTestSupportExtension, consumer, context, extra, fluentTemplate, ROUTE_COVERAGE_ENABLED, template
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String[]
    Which active profiles should be used.
    protected abstract org.springframework.context.support.AbstractApplicationContext
     
    protected org.apache.camel.CamelContext
     
    void
     
    void
     
    protected Class<?>
    Template method used to exclude a Route from the test camel context
    protected Class<?>[]
    Template method used to exclude Route from the test time context route scanning
    <T> T
    getMandatoryBean(Class<T> type, String name)
    Looks up the mandatory spring bean of the given name and type, failing if it is not present or the correct type
    protected org.springframework.context.ApplicationContext
    Create a parent context that initializes a PackageScanClassResolver to exclude a set of given classes from being resolved.
    protected Map<String,String>
     
    org.springframework.context.support.AbstractXmlApplicationContext
    newAppContext(String configLocation)
     
    org.springframework.context.support.AbstractXmlApplicationContext
    newAppContext(String... configLocations)
     
    newAppContext(String[] configLocations, Class<?> clazz, Map<String,String> props)
     
    static org.springframework.context.support.AbstractXmlApplicationContext
    newAppContext(String configLocation, Class<?> clazz)
     
    newAppContext(String configLocation, Class<?> clazz, Map<String,String> props)
     
    void
     
    void
     

    Methods inherited from class org.apache.camel.test.junit5.CamelTestSupport

    afterAll, afterEach, afterTestExecution, applyCamelPostProcessor, assertExpression, assertPredicate, assertResolveLanguage, assertValidContext, beforeAll, beforeEach, beforeTestExecution, bindToRegistry, camelContextService, cleanupResources, consumer, context, createCamelRegistry, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, disableJMX, doPostSetup, doQuarkusCheck, doSetUp, doSpringBootCheck, doStopCamelContext, enableJMX, fluentTemplate, getCamelContextService, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getRouteFilterExcludePattern, getRouteFilterIncludePattern, getShutdownTimeout, hasClassAnnotation, ignoreMissingLocationWithPropertiesComponent, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setCamelContextService, setUp, setupResources, setUseRouteBuilder, startCamelContext, stopCamelContext, template, timeTaken, useJmx, useOverridePropertiesWithPropertiesComponent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEST_CLASS_NAME_PROPERTY

      public static final String TEST_CLASS_NAME_PROPERTY
      See Also:
    • TEST_CLASS_SIMPLE_NAME_PROPERTY

      public static final String TEST_CLASS_SIMPLE_NAME_PROPERTY
      See Also:
    • TEST_DIRECTORY_PROPERTY

      public static final String TEST_DIRECTORY_PROPERTY
      See Also:
    • THREAD_APP_CONTEXT

      protected static final ThreadLocal<org.springframework.context.support.AbstractApplicationContext> THREAD_APP_CONTEXT
    • LOCK

      protected static final Object LOCK
    • applicationContext

      protected org.springframework.context.support.AbstractApplicationContext applicationContext
  • Constructor Details

    • CamelSpringTestSupport

      public CamelSpringTestSupport()
  • Method Details

    • createApplicationContext

      protected abstract org.springframework.context.support.AbstractApplicationContext createApplicationContext()
    • postProcessTest

      public void postProcessTest() throws Exception
      Overrides:
      postProcessTest in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • doPreSetup

      public void doPreSetup() throws Exception
      Overrides:
      doPreSetup in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • tearDown

      @AfterEach public void tearDown() throws Exception
      Overrides:
      tearDown in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • doPostTearDown

      public void doPostTearDown() throws Exception
      Overrides:
      doPostTearDown in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • getRouteExcludingApplicationContext

      protected org.springframework.context.ApplicationContext getRouteExcludingApplicationContext()
      Create a parent context that initializes a PackageScanClassResolver to exclude a set of given classes from being resolved. Typically this is used at test time to exclude certain routes, which might otherwise be just noisy, from being discovered and initialized.

      To use this filtering mechanism it is necessary to provide the ApplicationContext returned from here as the parent context to your test context e.g.

       protected AbstractXmlApplicationContext createApplicationContext() {
           return new ClassPathXmlApplicationContext(
                   new String[] { "test-context.xml" }, getRouteExcludingApplicationContext());
       }
       
      This will, in turn, call the template methods excludedRoutes and excludedRoute to determine the classes to be excluded from scanning.
      Returns:
      ApplicationContext a parent ApplicationContext configured to exclude certain classes from package scanning
    • excludeRoutes

      protected Class<?>[] excludeRoutes()
      Template method used to exclude Route from the test time context route scanning
      Returns:
      Class[] the classes to be excluded from test time context route scanning
    • excludeRoute

      protected Class<?> excludeRoute()
      Template method used to exclude a Route from the test camel context
    • getMandatoryBean

      public <T> T getMandatoryBean(Class<T> type, String name)
      Looks up the mandatory spring bean of the given name and type, failing if it is not present or the correct type
    • activeProfiles

      protected String[] activeProfiles()
      Which active profiles should be used.

      Important: When using active profiles, then the code in createApplicationContext() should create the Spring AbstractApplicationContext without refreshing. For example creating an ClassPathXmlApplicationContext you would need to pass in false in the refresh parameter, in the constructor. Camel will thrown an IllegalStateException if this is not correct stating this problem. The reason is that we cannot active profiles after a Spring application context has already been refreshed, and is active.

      Returns:
      an array of active profiles to use, use null to not use any active profiles.
    • createCamelContext

      protected org.apache.camel.CamelContext createCamelContext() throws Exception
      Overrides:
      createCamelContext in class org.apache.camel.test.junit5.CamelTestSupport
      Throws:
      Exception
    • newAppContext

      public org.springframework.context.support.AbstractXmlApplicationContext newAppContext(String configLocation) throws org.springframework.beans.BeansException
      Throws:
      org.springframework.beans.BeansException
    • newAppContext

      public org.springframework.context.support.AbstractXmlApplicationContext newAppContext(String... configLocations) throws org.springframework.beans.BeansException
      Throws:
      org.springframework.beans.BeansException
    • getTranslationProperties

      protected Map<String,String> getTranslationProperties()
    • newAppContext

      public static org.springframework.context.support.AbstractXmlApplicationContext newAppContext(String configLocation, Class<?> clazz)
    • newAppContext

      public static CamelSpringTestSupport.MyXmlApplicationContext newAppContext(String configLocation, Class<?> clazz, Map<String,String> props)
    • newAppContext

      public static CamelSpringTestSupport.MyXmlApplicationContext newAppContext(String[] configLocations, Class<?> clazz, Map<String,String> props)