Class CamelMainTestSupport

java.lang.Object
org.apache.camel.test.junit5.AbstractTestSupport
org.apache.camel.test.junit5.CamelTestSupport
org.apache.camel.test.main.junit5.CamelMainTestSupport
All Implemented Interfaces:
org.apache.camel.test.junit5.CommonTestSupport, org.apache.camel.test.junit5.ConfigurableContext, org.apache.camel.test.junit5.ConfigurableTest, org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.Extension

public abstract class CamelMainTestSupport extends org.apache.camel.test.junit5.CamelTestSupport
The base class of all the test classes that are meant to test a Camel Main application.
  • Field Summary

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

    camelTestSupportExtension, contextManagerExtension, testLoggerExtension

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

    camelContextConfiguration, consumer, context, fluentTemplate, template, testConfigurationBuilder
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    bindToRegistryAfterInjections(org.apache.camel.spi.Registry registry)
    Deprecated.
    protected void
    configure(org.apache.camel.main.MainConfigurationProperties configuration)
    Override this method to be able to configure the Camel for the test like a Camel Main application.
    protected org.apache.camel.CamelContext
     
    protected Class<?>
    Allows specifying the main class of the application to test if needed to simulate the same behavior as with Main(Class).
    protected String
    Gives the file name of the property placeholder to use for the test.
    protected String
    Gives a comma separated list of the property placeholder locations to use for the test.

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

    afterTestExecution, applyCamelPostProcessor, assertExpression, assertPredicate, assertResolveLanguage, assertValidContext, beforeTestExecution, bindToRegistry, configureContext, configureTest, createCamelRegistry, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, doPostSetup, doPostTearDown, doPreSetup, doQuarkusCheck, doSetUp, doSpringBootCheck, expression, getCurrentTestName, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getShutdownTimeout, hasClassAnnotation, postProcessTest, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setUp, startCamelContext, stopCamelContext, tearDown, timeTaken, unsupportedCheck

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

    camelContextConfiguration, camelContextService, cleanupResources, consumer, context, disableJMX, enableJMX, fluentTemplate, getCamelContextService, getDumpRoute, getRouteFilterExcludePattern, getRouteFilterIncludePattern, ignoreMissingLocationWithPropertiesComponent, isAutoStartupExcludePatterns, isCreateCamelContextPerClass, isDumpRouteCoverage, isMockEndpoints, isMockEndpointsAndSkip, isRouteCoverageEnabled, isStubEndpoints, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, replaceRouteFromWith, setCamelContextService, setContext, setupResources, setUseRouteBuilder, template, testConfiguration, useJmx, useOverridePropertiesWithPropertiesComponent

    Methods inherited from class java.lang.Object

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

    • CamelMainTestSupport

      public CamelMainTestSupport()
  • Method Details

    • configure

      protected void configure(org.apache.camel.main.MainConfigurationProperties configuration)
      Override this method to be able to configure the Camel for the test like a Camel Main application.
      Parameters:
      configuration - the Global configuration for Camel Main.
    • bindToRegistryAfterInjections

      @Deprecated protected void bindToRegistryAfterInjections(org.apache.camel.spi.Registry registry) throws Exception
      Deprecated.
      Override this method to bind custom beans to the Camel Registry like the method CamelTestSupport.bindToRegistry(Registry) but after all possible injections and automatic binding have been done which for example allows to create the custom beans based on injected objects like properties but also allows to replace a bean automatically created and bound by Camel.

      In the next example, an instance of a custom bean of type CustomGreetings could be created from the value of property name and is used to replace the bean of type Greetings automatically bound by Camel with the name myGreetings.

       
      
       class ReplaceBeanTest extends CamelMainTestSupport {
      
           @PropertyInject("name")
           String name;
      
           @Override
           protected void bindToRegistryAfterInjections(Registry registry) throws Exception {
               registry.bind("myGreetings", Greetings.class, new CustomGreetings(name));
           }
      
           // Rest of the test class
       }
       
       
      Parameters:
      registry - the registry in which the custom beans are bound.
      Throws:
      Exception - if an error occurs while binding a custom bean.
    • getPropertyPlaceholderLocations

      protected String getPropertyPlaceholderLocations()
      Gives a comma separated list of the property placeholder locations to use for the test. In case a property is defined at several property placeholder locations, the value of this property in the first property placeholder location according to the order in the list is used. In other words, the value of the properties defined in the first location of the property placeholder in the list takes precedence over the value of the properties of the following location of the property placeholder and so on.

      By default, it tries to get the inferred locations from the method getPropertyPlaceholderFileName() in case it returns a non null value otherwise it uses the default property placeholder location corresponding to the file application.properties available from the default package.

      Returns:
      the property placeholder locations to use for the test.
    • getPropertyPlaceholderFileName

      protected String getPropertyPlaceholderFileName()
      Gives the file name of the property placeholder to use for the test. This method assumes that the file is located either in the package of the test class or directly in the default package. In other words, if the test class is com.company.SomeTest and this method has been overridden to return some-app.properties, then it assumes that the actual possible locations of the property placeholder are classpath:com/company/some-app.properties;optional=true,classpath:some-app.properties;optional=true which means that for each property to find, it tries to get it first from the properties file of the same package if it exists and if it cannot be found, it tries to get it from the properties file with the same name but in the default package if it exists.

      Note: Since the properties files are declared as optional, no exception is raised if they are both absent.

      Returns:
      the file name of the property placeholder located in the same package as the test class or directly in the default package. null by default.
    • getMainClass

      protected Class<?> getMainClass()
      Allows specifying the main class of the application to test if needed to simulate the same behavior as with Main(Class).
      Returns:
      the main class of the application to test if any. null by default indicating that there is no specific main class.
    • createCamelContext

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