|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.testng.Assert
org.apache.camel.testng.TestSupport
org.apache.camel.testng.CamelTestSupport
public abstract class CamelTestSupport
A useful base class which creates a CamelContext with some routes
along with a ProducerTemplate for use in the test case
| Field Summary | |
|---|---|
protected static Service |
camelContextService
|
protected static ConsumerTemplate |
consumer
|
protected static CamelContext |
context
|
protected static ProducerTemplate |
template
|
| Fields inherited from class org.apache.camel.testng.TestSupport |
|---|
log |
| Constructor Summary | |
|---|---|
CamelTestSupport()
|
|
| Method Summary | ||
|---|---|---|
protected void |
assertExpression(Exchange exchange,
String languageName,
String expressionText,
Object expectedValue)
Asserts that the given language name and expression evaluates to the given value on a specific exchange |
|
protected void |
assertMockEndpointsSatisfied()
Asserts that all the expectations of the Mock endpoints are valid |
|
protected void |
assertMockEndpointsSatisfied(long timeout,
TimeUnit unit)
Asserts that all the expectations of the Mock endpoints are valid |
|
protected void |
assertPredicate(String languageName,
String expressionText,
Exchange exchange,
boolean expected)
Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange |
|
protected Language |
assertResolveLanguage(String languageName)
Asserts that the language name can be resolved |
|
protected void |
assertValidContext(CamelContext context)
|
|
Service |
camelContextService()
|
|
ConsumerTemplate |
consumer()
|
|
CamelContext |
context()
|
|
protected CamelContext |
createCamelContext()
|
|
protected Exchange |
createExchangeWithBody(Object body)
Creates an exchange with the given body |
|
protected Context |
createJndiContext()
|
|
protected JndiRegistry |
createRegistry()
|
|
protected RouteBuilder |
createRouteBuilder()
Factory method which derived classes can use to create a RouteBuilder
to define the routes for testing |
|
protected RouteBuilder[] |
createRouteBuilders()
Factory method which derived classes can use to create an array of RouteBuilders to define the routes for testing |
|
protected void |
debugAfter(Exchange exchange,
Processor processor,
ProcessorDefinition definition,
String id,
String label,
long timeTaken)
Single step debugs and Camel invokes this method after processing the given processor |
|
protected void |
debugBefore(Exchange exchange,
Processor processor,
ProcessorDefinition definition,
String id,
String label)
Single step debugs and Camel invokes this method before entering the given processor |
|
protected void |
disableJMX()
Disables the JMX agent. |
|
protected void |
doSetUp()
|
|
protected void |
enableJMX()
Enables the JMX agent. |
|
Service |
getCamelContextService()
|
|
protected Endpoint |
getMandatoryEndpoint(String uri)
|
|
protected
|
getMandatoryEndpoint(String uri,
Class<T> type)
|
|
protected MockEndpoint |
getMockEndpoint(String uri)
Resolves the mandatory Mock endpoint using a URI of the form mock:someName |
|
protected int |
getShutdownTimeout()
Returns the timeout to use when shutting down (unit in seconds). |
|
boolean |
isCreateCamelContextPerClass()
Override to control whether CamelContext should be setup per test or per class. |
|
protected boolean |
isLazyLoadingTypeConverter()
Whether or not type converters should be lazy loaded (notice core converters is always loaded) We enabled lazy by default as it would speedup unit testing. |
|
String |
isMockEndpoints()
Override to enable auto mocking endpoints based on the pattern. |
|
boolean |
isUseRouteBuilder()
Use the RouteBuilder or not |
|
protected void |
postProcessTest()
Lets post process this test instance to process any Camel annotations. |
|
protected void |
resetMocks()
Reset all Mock endpoints. |
|
protected Endpoint |
resolveMandatoryEndpoint(String uri)
Resolves a mandatory endpoint for the given URI or an exception is thrown |
|
protected
|
resolveMandatoryEndpoint(String uri,
Class<T> endpointType)
Resolves a mandatory endpoint for the given URI and expected type or an exception is thrown |
|
protected void |
sendBodies(String endpointUri,
Object... bodies)
Sends messages to the given endpoint for each of the specified bodies |
|
protected void |
sendBody(String endpointUri,
Object body)
Sends a message to the given endpoint URI with the body value |
|
protected void |
sendBody(String endpointUri,
Object body,
Map<String,Object> headers)
Sends a message to the given endpoint URI with the body value and specified headers |
|
void |
setCamelContextService(Service service)
Allows a service to be registered a separate lifecycle service to start and stop the context; such as for Spring when the ApplicationContext is started and stopped, rather than directly stopping the CamelContext |
|
void |
setUp()
|
|
void |
setUseRouteBuilder(boolean useRouteBuilder)
|
|
protected void |
startCamelContext()
|
|
protected void |
stopCamelContext()
|
|
void |
tearDown()
|
|
static void |
tearDownAfterClass()
|
|
ProducerTemplate |
template()
|
|
protected boolean |
useJmx()
Whether or not JMX should be used during testing. |
|
| Methods inherited from class org.testng.Assert |
|---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEqualsNoOrder, assertEqualsNoOrder, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, fail |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static volatile CamelContext context
protected static volatile ProducerTemplate template
protected static volatile ConsumerTemplate consumer
protected static volatile Service camelContextService
| Constructor Detail |
|---|
public CamelTestSupport()
| Method Detail |
|---|
public boolean isUseRouteBuilder()
CamelContext will be auto started,
false then CamelContext will not be auto started (you will have to start it manually)public void setUseRouteBuilder(boolean useRouteBuilder)
public boolean isCreateCamelContextPerClass()
CamelContext should be setup per test or per class.
By default it will be setup/teardown per test (per test method). If you want to re-use
CamelContext between test methods you can override this method and return true
Important: Use this with care as the CamelContext will carry over state
from previous tests, such as endpoints, components etc. So you cannot use this in all your tests.
public String isMockEndpoints()
EndpointHelper.matchEndpoint(String, String)public Service getCamelContextService()
public void setCamelContextService(Service service)
public void setUp()
throws Exception
Exception
protected void doSetUp()
throws Exception
Exception
public void tearDown()
throws Exception
Exception
public static void tearDownAfterClass()
throws Exception
Exceptionprotected int getShutdownTimeout()
protected boolean useJmx()
protected boolean isLazyLoadingTypeConverter()
protected void postProcessTest()
throws Exception
Exception
protected void stopCamelContext()
throws Exception
Exceptionpublic Service camelContextService()
public CamelContext context()
public ProducerTemplate template()
public ConsumerTemplate consumer()
protected void startCamelContext()
throws Exception
Exception
protected CamelContext createCamelContext()
throws Exception
Exception
protected JndiRegistry createRegistry()
throws Exception
Exception
protected Context createJndiContext()
throws Exception
Exception
protected RouteBuilder createRouteBuilder()
throws Exception
RouteBuilder
to define the routes for testing
Exception
protected RouteBuilder[] createRouteBuilders()
throws Exception
RouteBuilders to define the routes for testing
ExceptioncreateRouteBuilder()protected Endpoint resolveMandatoryEndpoint(String uri)
uri - the Camel URI to use to create or resolve an endpoint
protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri,
Class<T> endpointType)
uri - the Camel URI to use to create or resolve an endpoint
protected MockEndpoint getMockEndpoint(String uri)
mock:someName
uri - the URI which typically starts with "mock:" and has some name
protected void sendBody(String endpointUri,
Object body)
endpointUri - the URI of the endpoint to send tobody - the body for the message
protected void sendBody(String endpointUri,
Object body,
Map<String,Object> headers)
endpointUri - the URI of the endpoint to send tobody - the body for the messageheaders - any headers to set on the message
protected void sendBodies(String endpointUri,
Object... bodies)
endpointUri - the endpoint URI to send tobodies - the bodies to send, one per messageprotected Exchange createExchangeWithBody(Object body)
protected void assertExpression(Exchange exchange,
String languageName,
String expressionText,
Object expectedValue)
protected void assertPredicate(String languageName,
String expressionText,
Exchange exchange,
boolean expected)
protected Language assertResolveLanguage(String languageName)
protected void assertMockEndpointsSatisfied()
throws InterruptedException
InterruptedException
protected void assertMockEndpointsSatisfied(long timeout,
TimeUnit unit)
throws InterruptedException
InterruptedExceptionprotected void resetMocks()
protected void assertValidContext(CamelContext context)
protected <T extends Endpoint> T getMandatoryEndpoint(String uri,
Class<T> type)
protected Endpoint getMandatoryEndpoint(String uri)
protected void disableJMX()
setUp() method.
protected void enableJMX()
setUp() method.
protected void debugBefore(Exchange exchange,
Processor processor,
ProcessorDefinition definition,
String id,
String label)
protected void debugAfter(Exchange exchange,
Processor processor,
ProcessorDefinition definition,
String id,
String label,
long timeTaken)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||