Class CamelBlueprintTestSupport
- java.lang.Object
-
- org.junit.Assert
-
- org.apache.camel.test.junit4.TestSupport
-
- org.apache.camel.test.junit4.CamelTestSupport
-
- org.apache.camel.test.blueprint.CamelBlueprintTestSupport
-
public abstract class CamelBlueprintTestSupport extends org.apache.camel.test.junit4.CamelTestSupportBase class for OSGi Blueprint unit tests with Camel
-
-
Field Summary
Fields Modifier and Type Field Description static StringSPROP_CAMEL_CONTEXT_CREATION_TIMEOUTName of a system property that sets camel context creation timeout.
-
Constructor Summary
Constructors Constructor Description CamelBlueprintTestSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddServicesOnStartup(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 voidaddServicesOnStartup(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 useaddServicesOnStartup(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 useaddServicesOnStartup(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 useaddServicesOnStartup(java.util.Map)voidcleanupResources()protected org.osgi.framework.BundleContextcreateBundleContext()protected org.apache.camel.CamelContextcreateCamelContext()protected booleanexpectBlueprintContainerReloadOnConfigAdminUpdate()This method may be overriden to instruct BP test support that BP container will reloaded when Config Admin configuration is updated.protected StringgetBlueprintDescriptor()Gets the bundle descriptor from the classpath.protected org.osgi.framework.BundleContextgetBundleContext()Return the system bundle contextprotected StringgetBundleDirectives()Gets the bundle directives.protected StringgetBundleFilter()Gets filter expression of bundle descriptors.protected StringgetBundleVersion()Gets test bundle version.protected LonggetCamelContextCreationTimeout()Returns how long to wait for Camel Context to be created.protected StringgetCamelContextFilter()Gets filter expression for the Camel context you want to test.protected <T> TgetOsgiService(Class<T> type)protected <T> TgetOsgiService(Class<T> type, long timeout)protected <T> TgetOsgiService(Class<T> type, String filter)protected <T> TgetOsgiService(Class<T> type, String filter, long timeout)protected booleanincludeTestBundle()Override this method if you don't want CamelBlueprintTestSupport create the test bundlebooleanisCreateCamelContextPerClass()Deprecated.protected String[]loadConfigAdminConfigurationFile()Override this method and provide the name of the .cfg configuration file to use for ConfigAdmin service.protected StringsetConfigAdminInitialConfiguration(Properties props)Override this method as an alternative toloadConfigAdminConfigurationFile()if there's a need to set initial ConfigAdmin configuration without using files.voidsetUp()voidtearDown()protected booleanuseAsynchronousBlueprintStartup()Override this method if you want to start Blueprint containers asynchronously using the thread that starts the bundles itself.protected StringuseOverridePropertiesWithConfigAdmin(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
-
-
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
truewhich 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:
truewhen blueprint containers are to be started asynchronously, otherwisefalse.
-
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:
isCreateCamelContextPerClassin classorg.apache.camel.test.junit4.CamelTestSupport
-
setUp
public void setUp() throws Exception- Overrides:
setUpin classorg.apache.camel.test.junit4.CamelTestSupport- Throws:
Exception
-
addServicesOnStartup
protected void addServicesOnStartup(Map<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 methodsasService(Object, java.util.Dictionary),asService(Object, String, String)to make it easy to add the services to the map.
-
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 methodsasKeyValueService(String, Object, Dictionary)to make it easy to add the services to the List.
-
asService
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 useaddServicesOnStartup(java.util.Map)
-
asKeyValueService
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 useaddServicesOnStartup(java.util.List)
-
asService
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 useaddServicesOnStartup(java.util.Map)
-
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 onupdate-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
ConfigurationAdminwhich 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 toloadConfigAdminConfigurationFile()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,
propswill be used as initial ConfigAdmin configuration
-
tearDown
public void tearDown() throws Exception- Overrides:
tearDownin classorg.apache.camel.test.junit4.CamelTestSupport- Throws:
Exception
-
cleanupResources
public void cleanupResources() throws Exception- Overrides:
cleanupResourcesin classorg.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:
createCamelContextin classorg.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)
-
-