Class CamelBlueprintTestSupport


  • public abstract class CamelBlueprintTestSupport
    extends org.apache.camel.test.junit4.CamelTestSupport
    Base class for OSGi Blueprint unit tests with Camel
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String SPROP_CAMEL_CONTEXT_CREATION_TIMEOUT
      Name of a system property that sets camel context creation timeout.
      • Fields inherited from class org.apache.camel.test.junit4.CamelTestSupport

        CAMEL_TEAR_DOWN_RULE, camelContextService, consumer, context, extra, fluentTemplate, ROUTE_COVERAGE_ENABLED, template
      • Fields inherited from class org.apache.camel.test.junit4.TestSupport

        log, LS
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void addServicesOnStartup​(List<org.apache.camel.util.KeyValueHolder<String,​org.apache.camel.util.KeyValueHolder<Object,​Dictionary>>> services)
      Override this method to add services to be registered on startup.
      protected void addServicesOnStartup​(Map<String,​org.apache.camel.util.KeyValueHolder<Object,​Dictionary>> services)
      Override this method to add services to be registered on startup.
      protected org.apache.camel.util.KeyValueHolder<String,​org.apache.camel.util.KeyValueHolder<Object,​Dictionary>> asKeyValueService​(String name, Object service, Dictionary dict)
      Creates a holder for the given service, which make it easier to use addServicesOnStartup(java.util.List)
      protected org.apache.camel.util.KeyValueHolder<Object,​Dictionary> asService​(Object service, String key, String value)
      Creates a holder for the given service, which make it easier to use addServicesOnStartup(java.util.Map)
      protected org.apache.camel.util.KeyValueHolder<Object,​Dictionary> asService​(Object service, Dictionary dict)
      Creates a holder for the given service, which make it easier to use addServicesOnStartup(java.util.Map)
      void cleanupResources()  
      protected org.osgi.framework.BundleContext createBundleContext()  
      protected org.apache.camel.CamelContext createCamelContext()  
      protected boolean expectBlueprintContainerReloadOnConfigAdminUpdate()
      This method may be overriden to instruct BP test support that BP container will reloaded when Config Admin configuration is updated.
      protected String getBlueprintDescriptor()
      Gets the bundle descriptor from the classpath.
      protected org.osgi.framework.BundleContext getBundleContext()
      Return the system bundle context
      protected String getBundleDirectives()
      Gets the bundle directives.
      protected String getBundleFilter()
      Gets filter expression of bundle descriptors.
      protected String getBundleVersion()
      Gets test bundle version.
      protected Long getCamelContextCreationTimeout()
      Returns how long to wait for Camel Context to be created.
      protected String getCamelContextFilter()
      Gets filter expression for the Camel context you want to test.
      protected <T> T getOsgiService​(Class<T> type)  
      protected <T> T getOsgiService​(Class<T> type, long timeout)  
      protected <T> T getOsgiService​(Class<T> type, String filter)  
      protected <T> T getOsgiService​(Class<T> type, String filter, long timeout)  
      protected boolean includeTestBundle()
      Override this method if you don't want CamelBlueprintTestSupport create the test bundle
      boolean isCreateCamelContextPerClass()
      Deprecated.
      protected String[] loadConfigAdminConfigurationFile()
      Override this method and provide the name of the .cfg configuration file to use for ConfigAdmin service.
      protected String setConfigAdminInitialConfiguration​(Properties props)
      Override this method as an alternative to loadConfigAdminConfigurationFile() if there's a need to set initial ConfigAdmin configuration without using files.
      void setUp()  
      void tearDown()  
      protected boolean useAsynchronousBlueprintStartup()
      Override this method if you want to start Blueprint containers asynchronously using the thread that starts the bundles itself.
      protected String useOverridePropertiesWithConfigAdmin​(Dictionary<String,​String> props)
      Override this method to override config admin properties.
      • Methods inherited from class org.apache.camel.test.junit4.CamelTestSupport

        applyCamelPostProcessor, assertExpression, assertMockEndpointsSatisfied, assertMockEndpointsSatisfied, assertPredicate, assertResolveLanguage, assertValidContext, bindToRegistry, camelContextService, consumer, context, createCamelRegistry, createExchangeWithBody, createRouteBuilder, createRouteBuilders, debugAfter, debugBefore, disableJMX, doPostSetup, doPostTearDown, doPreSetup, doSpringBootCheck, enableJMX, fluentTemplate, getCamelContextService, getCamelTestWatcher, getMandatoryEndpoint, getMandatoryEndpoint, getMockEndpoint, getMockEndpoint, getRouteFilterExcludePattern, getRouteFilterIncludePattern, getShutdownTimeout, hasClassAnnotation, ignoreMissingLocationWithPropertiesComponent, isDumpRouteCoverage, isLazyLoadingTypeConverter, isMockEndpoints, isMockEndpointsAndSkip, isUseAdviceWith, isUseDebugger, isUseRouteBuilder, postProcessTest, replaceRouteFromWith, resetMocks, resolveMandatoryEndpoint, resolveMandatoryEndpoint, sendBodies, sendBody, sendBody, setCamelContextService, setupResources, setUseRouteBuilder, startCamelContext, stopCamelContext, template, useJmx, useOverridePropertiesWithPropertiesComponent
      • Methods inherited from class org.apache.camel.test.junit4.TestSupport

        assertCollectionSize, assertCollectionSize, assertDirectoryEquals, assertDirectoryEquals, assertDirectoryExists, assertEndpointUri, assertExpression, assertFileExists, assertFileNotExists, assertInMessageBodyEquals, assertInMessageHeader, assertIsInstanceOf, assertListSize, assertListSize, assertMessageHeader, assertOneElement, assertOutMessageBodyEquals, assertOutMessageHeader, assertPredicate, assertPredicateDoesNotMatch, assertPredicateMatches, assertStringContains, body, bodyAs, createDirectory, createExchangeWithBody, deleteDirectory, deleteDirectory, exchangeProperty, getJavaMajorVersion, getRouteList, getTestMethodName, getTestName, header, isJava15, isJava16, isJava17, isJava18, isJava19, isJavaVendor, isPlatform, property, resolveMandatoryEndpoint, resolveMandatoryEndpoint, systemProperty, systemProperty
      • Methods inherited from class org.junit.Assert

        assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
    • Field Detail

      • SPROP_CAMEL_CONTEXT_CREATION_TIMEOUT

        public static final String SPROP_CAMEL_CONTEXT_CREATION_TIMEOUT
        Name of a system property that sets camel context creation timeout.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CamelBlueprintTestSupport

        public CamelBlueprintTestSupport()
    • Method Detail

      • includeTestBundle

        protected boolean includeTestBundle()
        Override this method if you don't want CamelBlueprintTestSupport create the test bundle
        Returns:
        includeTestBundle If the return value is true CamelBlueprintTestSupport creates the test bundle which includes blueprint configuration files If the return value is false CamelBlueprintTestSupport won't create the test bundle
      • useAsynchronousBlueprintStartup

        protected boolean useAsynchronousBlueprintStartup()

        Override this method if you want to start Blueprint containers asynchronously using the thread that starts the bundles itself. By default this method returns true which means Blueprint Extender will use thread pool (threads named "Blueprint Extender: N") to startup Blueprint containers.

        Karaf and Fuse OSGi containers use synchronous startup.

        Asynchronous startup is more in the spirit of OSGi and usually means that if everything works fine asynchronously, it'll work synchronously as well. This isn't always true otherwise.

        Returns:
        true when blueprint containers are to be started asynchronously, otherwise false.
      • createBundleContext

        protected org.osgi.framework.BundleContext createBundleContext()
                                                                throws Exception
        Throws:
        Exception
      • isCreateCamelContextPerClass

        @Deprecated
        public boolean isCreateCamelContextPerClass()
        Deprecated.
        This option is not supported / in-use for blueprint
        Overrides:
        isCreateCamelContextPerClass in class org.apache.camel.test.junit4.CamelTestSupport
      • setUp

        public void setUp()
                   throws Exception
        Overrides:
        setUp in class org.apache.camel.test.junit4.CamelTestSupport
        Throws:
        Exception
      • expectBlueprintContainerReloadOnConfigAdminUpdate

        protected boolean expectBlueprintContainerReloadOnConfigAdminUpdate()
        This method may be overriden to instruct BP test support that BP container will reloaded when Config Admin configuration is updated. By default, this is expected, when blueprint XML definition contains <cm:property-placeholder persistent-id="PID" update-strategy="reload">
      • addServicesOnStartup

        protected void addServicesOnStartup​(List<org.apache.camel.util.KeyValueHolder<String,​org.apache.camel.util.KeyValueHolder<Object,​Dictionary>>> services)
        Override this method to add services to be registered on startup.

        You can use the builder methods asKeyValueService(String, Object, Dictionary) to make it easy to add the services to the List.

      • useOverridePropertiesWithConfigAdmin

        protected String useOverridePropertiesWithConfigAdmin​(Dictionary<String,​String> props)
                                                       throws Exception

        Override this method to override config admin properties. Overriden properties will be passed to Configuration.update(Dictionary) and may or may not lead to reload of Blueprint container - this depends on update-strategy="reload|none" in <cm:property-placeholder>

        This method should be used to simulate configuration update after Blueprint container is already initialized and started. Don't use this method to initialized ConfigAdmin configuration.

        Parameters:
        props - properties where you add the properties to override
        Returns:
        the PID of the OSGi ConfigurationAdmin which are defined in the Blueprint XML file.
        Throws:
        Exception
      • loadConfigAdminConfigurationFile

        protected String[] loadConfigAdminConfigurationFile()
        Override this method and provide the name of the .cfg configuration file to use for ConfigAdmin service. Provided file will be used to initialize ConfigAdmin configuration before Blueprint container is loaded.
        Returns:
        the name of the path for the .cfg file to load, and the persistence-id of the property placeholder.
      • setConfigAdminInitialConfiguration

        protected String setConfigAdminInitialConfiguration​(Properties props)
        Override this method as an alternative to loadConfigAdminConfigurationFile() if there's a need to set initial ConfigAdmin configuration without using files.
        Parameters:
        props - always non-null. Tests may initialize ConfigAdmin configuration by returning PID.
        Returns:
        persistence-id of the property placeholder. If non-null, props will be used as initial ConfigAdmin configuration
      • tearDown

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

        public void cleanupResources()
                              throws Exception
        Overrides:
        cleanupResources in class org.apache.camel.test.junit4.CamelTestSupport
        Throws:
        Exception
      • getBundleContext

        protected org.osgi.framework.BundleContext getBundleContext()
        Return the system bundle context
      • getBlueprintDescriptor

        protected String getBlueprintDescriptor()
        Gets the bundle descriptor from the classpath.

        Return the location(s) of the bundle descriptors from the classpath. Separate multiple locations by comma, or return a single location.

        Only one CamelContext is supported per blueprint bundle, so if you have multiple XML files then only one of them should have <camelContext>.

        For example override this method and return OSGI-INF/blueprint/camel-context.xml

        Returns:
        the location of the bundle descriptor file.
      • getBundleFilter

        protected String getBundleFilter()
        Gets filter expression of bundle descriptors. Modify this method if you wish to change default behavior.
        Returns:
        filter expression for OSGi bundles.
      • getBundleVersion

        protected String getBundleVersion()
        Gets test bundle version. Modify this method if you wish to change default behavior.
        Returns:
        test bundle version
      • getBundleDirectives

        protected String getBundleDirectives()
        Gets the bundle directives.

        Modify this method if you wish to add some directives.

      • getCamelContextCreationTimeout

        protected Long getCamelContextCreationTimeout()
        Returns how long to wait for Camel Context to be created.
        Returns:
        timeout in milliseconds.
      • getCamelContextFilter

        protected String getCamelContextFilter()
        Gets filter expression for the Camel context you want to test. Modify this if you have multiple contexts in the OSGi registry and want to test a specific one.
        Returns:
        filter expression for Camel context.
      • createCamelContext

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

        protected <T> T getOsgiService​(Class<T> type)
      • getOsgiService

        protected <T> T getOsgiService​(Class<T> type,
                                       long timeout)
      • getOsgiService

        protected <T> T getOsgiService​(Class<T> type,
                                       String filter)
      • getOsgiService

        protected <T> T getOsgiService​(Class<T> type,
                                       String filter,
                                       long timeout)