Package org.apache.camel.component.mock
Class MockEndpoint
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultEndpoint
-
- org.apache.camel.component.mock.MockEndpoint
-
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.CamelContextAware,org.apache.camel.Endpoint,org.apache.camel.IsSingleton,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.BrowsableEndpoint,org.apache.camel.spi.HasId,org.apache.camel.spi.NotifyBuilderMatcher,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
@UriEndpoint(firstVersion="1.0.0", scheme="mock", title="Mock", syntax="mock:name", producerOnly=true, category={CORE,TESTING}, lenientProperties=true) public class MockEndpoint extends org.apache.camel.support.DefaultEndpoint implements org.apache.camel.spi.BrowsableEndpoint, org.apache.camel.spi.NotifyBuilderMatcherTest routes and mediation rules using mocks. A Mock endpoint which provides a literate, fluent API for testing routes using a JMock style API. The mock endpoint have two set of methods- expectedXXX or expectsXXX - To set pre conditions, before the test is executed
- assertXXX - To assert assertions, after the test has been executed
setExpectedMessageCount(int)with 0, then take extra care, as 0 matches when the tests starts, so you need to set a assert period time to let the test run for a while to make sure there are still no messages arrived; for that usesetAssertPeriod(long). An alternative is to use NotifyBuilder, and use the notifier to know when Camel is done routing some messages, before you call theassertIsSatisfied()method on the mocks. This allows you to not use a fixed assert period, to speedup testing times. Important: If usingexpectedMessageCount(int)and alsoexpectedBodiesReceived(java.util.List)orexpectedHeaderReceived(String, Object)then the latter overrides the number of expected message based on the number of values provided in the bodies/headers.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.camel.Processorreporter
-
Constructor Summary
Constructors Constructor Description MockEndpoint()MockEndpoint(String endpointUri, org.apache.camel.Component component)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddReceivedExchange(org.apache.camel.Exchange copy)Adds the received exchange.AssertionClauseallMessages()Adds an assertion to all the received messagesprotected voidassertEquals(String message, Object expectedValue, Object actualValue)org.apache.camel.ExchangeassertExchangeReceived(int index)Asserts that the given index of message is received (starting at zero)protected voidassertFalse(String message, boolean predicate)Asserts that the givenpredicateisfalse, if not anAssertionErroris raised with the give message.voidassertIsNotSatisfied()Validates that the assertions fail on this endpointvoidassertIsNotSatisfied(long timeoutForEmptyEndpoints)Validates that the assertions fail on this endpointvoidassertIsSatisfied()Validates that all the available expectations on this endpoint are satisfied; or throw an exceptionvoidassertIsSatisfied(long timeoutForEmptyEndpoints)Validates that all the available expectations on this endpoint are satisfied; or throw an exceptionstatic voidassertIsSatisfied(long timeout, TimeUnit unit, MockEndpoint... endpoints)static voidassertIsSatisfied(org.apache.camel.CamelContext context)Asserts that all the expectations on anyMockEndpointinstances registered in the given context are validstatic voidassertIsSatisfied(org.apache.camel.CamelContext context, long timeout, TimeUnit unit)Asserts that all the expectations on anyMockEndpointinstances registered in the given context are validstatic voidassertIsSatisfied(MockEndpoint... endpoints)voidassertMessagesAscending(org.apache.camel.Expression expression)Asserts that the messages have ascending values of the given expressionvoidassertMessagesDescending(org.apache.camel.Expression expression)Asserts that the messages have descending values of the given expressionprotected voidassertMessagesSorted(org.apache.camel.Expression expression, boolean ascending)protected voidassertMessagesSorted(org.apache.camel.Expression expression, boolean ascending, int index)voidassertNoDuplicates(org.apache.camel.Expression expression)Asserts among all the current received exchanges that there are no duplicate messageprotected voidassertTrue(String message, boolean predicate)Asserts that the givenpredicateistrue, if not anAssertionErroris raised with the give message.static voidassertWait(long timeout, TimeUnit unit, MockEndpoint... endpoints)voidawait()booleanawait(long timeout, TimeUnit unit)org.apache.camel.ConsumercreateConsumer(org.apache.camel.Processor processor)org.apache.camel.ProducercreateProducer()protected voiddoAssertIsSatisfied(long timeoutForEmptyEndpoints)voidexpectedBodiesReceived(Object... bodies)Sets an expectation that the given body values are received by this endpointvoidexpectedBodiesReceived(List<?> bodies)Adds an expectation that the given body values are received by this endpoint in the specified ordervoidexpectedBodiesReceivedInAnyOrder(Object... bodies)Adds an expectation that the given body values are received by this endpoint in any ordervoidexpectedBodiesReceivedInAnyOrder(List<?> bodies)Adds an expectation that the given body values are received by this endpoint in any orderAssertionClauseexpectedBodyReceived()Adds an expectation that the given body value are received by this endpointvoidexpectedExchangePattern(org.apache.camel.ExchangePattern exchangePattern)Adds an expectation that messages received should have the given exchange patternvoidexpectedFileExists(String name)Adds an expectation that a file exists with the given namevoidexpectedFileExists(String name, String content)Adds an expectation that a file exists with the given namevoidexpectedFileExists(Path name)Adds an expectation that a file exists with the given namevoidexpectedFileExists(Path name, String content)Adds an expectation that a file exists with the given namevoidexpectedHeaderReceived(String name, Object value)Sets an expectation that the given header name & value are received by this endpointvoidexpectedHeaderValuesReceivedInAnyOrder(String name, Object... values)Adds an expectation that the given header values are received by this endpoint in any ordervoidexpectedHeaderValuesReceivedInAnyOrder(String name, List<?> values)Adds an expectation that the given header values are received by this endpoint in any order.voidexpectedMessageCount(int expectedCount)Specifies the expected number of message exchanges that should be received by this endpoint If you want to assert that exactly n messages arrives to this mock endpoint, then see also thesetAssertPeriod(long)method for further details.voidexpectedMessagesMatches(org.apache.camel.Predicate... predicates)Sets an expectation that the given predicates matches the received messages by this endpointvoidexpectedMinimumMessageCount(int expectedCount)Specifies the minimum number of expected message exchanges that should be received by this endpointvoidexpectedNoHeaderReceived()Sets an expectation that the messages received by this endpoint have no headervoidexpectedPropertyReceived(String name, Object value)Sets an expectation that the given property name & value are received by this endpointvoidexpectedPropertyValuesReceivedInAnyOrder(String name, Object... values)Adds an expectation that the given property values are received by this endpoint in any ordervoidexpectedPropertyValuesReceivedInAnyOrder(String name, List<?> values)Adds an expectation that the given property values are received by this endpoint in any order.voidexpects(Runnable runnable)Adds the expectation which will be invoked when enough messages are receivedAssertionClauseexpectsAscending()Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter valuevoidexpectsAscending(org.apache.camel.Expression expression)Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter valueAssertionClauseexpectsDescending()Adds an expectation that messages received should have descending values of the given expression such as a user generated counter valuevoidexpectsDescending(org.apache.camel.Expression expression)Adds an expectation that messages received should have descending values of the given expression such as a user generated counter valuestatic voidexpectsMessageCount(int count, MockEndpoint... endpoints)AssertionClauseexpectsNoDuplicates()Adds an expectation that no duplicate messages should be received using the expression to determine the message IDvoidexpectsNoDuplicates(org.apache.camel.Expression expression)Adds an expectation that no duplicate messages should be received using the expression to determine the message IDprotected voidfail(Object message)longgetAssertPeriod()MockComponentgetComponent()List<org.apache.camel.Exchange>getExchanges()intgetExpectedCount()intgetExpectedMinimumCount()List<Throwable>getFailures()StringgetName()intgetReceivedCounter()List<org.apache.camel.Exchange>getReceivedExchanges()org.apache.camel.ProcessorgetReporter()intgetReportGroup()longgetResultMinimumWaitTime()longgetResultWaitTime()intgetRetainFirst()intgetRetainLast()longgetSleepForEmptyTest()voidhandle(org.apache.camel.Exchange exchange)Handles the incoming exchange.booleanisCopyOnExchange()booleanisFailFast()booleanisLenientProperties()booleanisLog()AssertionClausemessage(int messageIndex)Adds an assertion to the given message indexbooleannotifyBuilderMatches()voidnotifyBuilderOnExchange(org.apache.camel.Exchange exchange)voidnotifyBuilderReset()protected voidonExchange(org.apache.camel.Exchange exchange)protected voidperformAssertions(org.apache.camel.Exchange exchange, org.apache.camel.Exchange copy)Performs the assertions on the incoming exchange.voidreset()static voidresetMocks(org.apache.camel.CamelContext context)Reset all mock endpointsstatic MockEndpointresolve(org.apache.camel.CamelContext context, String uri)A helper method to resolve the mock endpoint of the given URI on the given contextvoidreturnReplyBody(org.apache.camel.Expression expression)Set the expression which value will be set to the message bodyvoidreturnReplyHeader(String headerName, org.apache.camel.Expression expression)Set the expression which value will be set to the message headervoidsetAssertPeriod(long period)Sets a grace period after which the mock endpoint will re-assert to ensure the preliminary assertion is still valid.static voidsetAssertPeriod(org.apache.camel.CamelContext context, long period)Sets the assert period on all the expectations on anyMockEndpointinstances registered in the given context.voidsetCopyOnExchange(boolean copyOnExchange)Sets whether to make a deep copy of the incomingExchangewhen received at this mock endpoint.voidsetExpectedCount(int expectedCount)Specifies the expected number of message exchanges that should be received by this endpoint.voidsetExpectedMessageCount(int expectedCount)voidsetFailFast(boolean failFast)Sets whetherassertIsSatisfied()should fail fast at the first detected failed expectation while it may otherwise wait for all expected messages to arrive before performing expectations verifications.voidsetLog(boolean log)To turn on logging when the mock receives an incoming message.voidsetMinimumExpectedMessageCount(int expectedCount)Specifies the minimum number of expected message exchanges that should be received by this endpointvoidsetName(String name)voidsetReporter(org.apache.camel.Processor reporter)Allows a processor to added to the endpoint to report on progress of the testvoidsetReportGroup(int reportGroup)A number that is used to turn on throughput logging based on groups of the size.voidsetResultMinimumWaitTime(long resultMinimumWaitTime)Sets the minimum expected amount of time (in millis) theassertIsSatisfied()will wait on a latch until it is satisfiedvoidsetResultWaitTime(long resultWaitTime)Sets the maximum amount of time (in millis) theassertIsSatisfied()will wait on a latch until it is satisfiedvoidsetRetainFirst(int retainFirst)Specifies to only retain the first n'th number of receivedExchanges.voidsetRetainLast(int retainLast)Specifies to only retain the last n'th number of receivedExchanges.voidsetSleepForEmptyTest(long sleepForEmptyTest)Allows a sleep to be specified to wait to check that this endpoint really is empty whenexpectedMessageCount(int)is called with zeroprotected voidwaitForCompleteLatch()protected voidwaitForCompleteLatch(long timeout)voidwhenAnyExchangeReceived(org.apache.camel.Processor processor)Set the processor that will be invoked when the some message is received.voidwhenExchangeReceived(int index, org.apache.camel.Processor processor)Set the processor that will be invoked when the index message is received.-
Methods inherited from class org.apache.camel.support.DefaultEndpoint
configureConsumer, configureExchange, configurePollingConsumer, configureProperties, createAsyncProducer, createEndpointUri, createExchange, createExchange, createPollingConsumer, doInit, doStart, doStop, equals, getCamelContext, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.camel.Endpoint
configureExchange, configureProperties, createAsyncProducer, createExchange, createExchange, createPollingConsumer, getCamelContext, getEndpointBaseUri, getEndpointKey, getEndpointUri, getExchangePattern, isSingletonProducer, setCamelContext
-
-
-
-
Constructor Detail
-
MockEndpoint
public MockEndpoint()
-
MockEndpoint
public MockEndpoint(String endpointUri, org.apache.camel.Component component)
-
-
Method Detail
-
resolve
public static MockEndpoint resolve(org.apache.camel.CamelContext context, String uri)
A helper method to resolve the mock endpoint of the given URI on the given context- Parameters:
context- the camel context to try resolve the mock endpoint fromuri- the uri of the endpoint to resolve- Returns:
- the endpoint
-
assertWait
public static void assertWait(long timeout, TimeUnit unit, MockEndpoint... endpoints) throws InterruptedException- Throws:
InterruptedException
-
assertIsSatisfied
public static void assertIsSatisfied(long timeout, TimeUnit unit, MockEndpoint... endpoints) throws InterruptedException- Throws:
InterruptedException
-
assertIsSatisfied
public static void assertIsSatisfied(MockEndpoint... endpoints) throws InterruptedException
- Throws:
InterruptedException
-
assertIsSatisfied
public static void assertIsSatisfied(org.apache.camel.CamelContext context) throws InterruptedExceptionAsserts that all the expectations on anyMockEndpointinstances registered in the given context are valid- Parameters:
context- the camel context used to find all the available endpoints to be asserted- Throws:
InterruptedException
-
assertIsSatisfied
public static void assertIsSatisfied(org.apache.camel.CamelContext context, long timeout, TimeUnit unit) throws InterruptedExceptionAsserts that all the expectations on anyMockEndpointinstances registered in the given context are valid- Parameters:
context- the camel context used to find all the available endpoints to be assertedtimeout- timeoutunit- time unit- Throws:
InterruptedException
-
setAssertPeriod
public static void setAssertPeriod(org.apache.camel.CamelContext context, long period)Sets the assert period on all the expectations on anyMockEndpointinstances registered in the given context.- Parameters:
context- the camel context used to find all the available endpointsperiod- the period in millis
-
resetMocks
public static void resetMocks(org.apache.camel.CamelContext context)
Reset all mock endpoints- Parameters:
context- the camel context used to find all the available endpoints to reset
-
expectsMessageCount
public static void expectsMessageCount(int count, MockEndpoint... endpoints)
-
getExchanges
public List<org.apache.camel.Exchange> getExchanges()
- Specified by:
getExchangesin interfaceorg.apache.camel.spi.BrowsableEndpoint
-
createConsumer
public org.apache.camel.Consumer createConsumer(org.apache.camel.Processor processor) throws Exception- Specified by:
createConsumerin interfaceorg.apache.camel.Endpoint- Throws:
Exception
-
createProducer
public org.apache.camel.Producer createProducer() throws Exception- Specified by:
createProducerin interfaceorg.apache.camel.Endpoint- Throws:
Exception
-
reset
public void reset()
-
handle
@Handler public void handle(org.apache.camel.Exchange exchange) throws ExceptionHandles the incoming exchange. This method turns this mock endpoint into a bean which you can use in the Camel routes, which allows you to inject MockEndpoint as beans in your routes and use the features of the mock to control the bean.- Parameters:
exchange- the exchange- Throws:
Exception- can be thrown
-
whenExchangeReceived
public void whenExchangeReceived(int index, org.apache.camel.Processor processor)Set the processor that will be invoked when the index message is received.
-
whenAnyExchangeReceived
public void whenAnyExchangeReceived(org.apache.camel.Processor processor)
Set the processor that will be invoked when the some message is received. This processor could be overwritten bywhenExchangeReceived(int, Processor)method.
-
returnReplyBody
public void returnReplyBody(org.apache.camel.Expression expression)
Set the expression which value will be set to the message body- Parameters:
expression- which is use to set the message body
-
returnReplyHeader
public void returnReplyHeader(String headerName, org.apache.camel.Expression expression)
Set the expression which value will be set to the message header- Parameters:
headerName- that will be set valueexpression- which is use to set the message header
-
assertIsSatisfied
public void assertIsSatisfied() throws InterruptedExceptionValidates that all the available expectations on this endpoint are satisfied; or throw an exception- Throws:
InterruptedException
-
assertIsSatisfied
public void assertIsSatisfied(long timeoutForEmptyEndpoints) throws InterruptedExceptionValidates that all the available expectations on this endpoint are satisfied; or throw an exception- Parameters:
timeoutForEmptyEndpoints- the timeout in milliseconds that we should wait for the test to be true- Throws:
InterruptedException
-
doAssertIsSatisfied
protected void doAssertIsSatisfied(long timeoutForEmptyEndpoints) throws InterruptedException- Throws:
InterruptedException
-
assertIsNotSatisfied
public void assertIsNotSatisfied() throws InterruptedExceptionValidates that the assertions fail on this endpoint- Throws:
InterruptedException
-
assertIsNotSatisfied
public void assertIsNotSatisfied(long timeoutForEmptyEndpoints) throws InterruptedExceptionValidates that the assertions fail on this endpoint- Parameters:
timeoutForEmptyEndpoints- the timeout in milliseconds that we should wait for the test to be true- Throws:
InterruptedException
-
expectedMessageCount
public void expectedMessageCount(int expectedCount)
Specifies the expected number of message exchanges that should be received by this endpoint If you want to assert that exactly n messages arrives to this mock endpoint, then see also thesetAssertPeriod(long)method for further details.- Parameters:
expectedCount- the number of message exchanges that should be expected by this endpoint- See Also:
setAssertPeriod(long)
-
getAssertPeriod
public long getAssertPeriod()
-
setAssertPeriod
public void setAssertPeriod(long period)
Sets a grace period after which the mock endpoint will re-assert to ensure the preliminary assertion is still valid. This is used for example to assert that exactly a number of messages arrives. For example if expected count was set to 5, then the assertion is satisfied when 5 or more message arrives. To ensure that exactly 5 messages arrives, then you would need to wait a little period to ensure no further message arrives. This is what you can use this method for. By default this period is disabled.- Parameters:
period- grace period in millis
-
expectedMinimumMessageCount
public void expectedMinimumMessageCount(int expectedCount)
Specifies the minimum number of expected message exchanges that should be received by this endpoint- Parameters:
expectedCount- the number of message exchanges that should be expected by this endpoint
-
expectedHeaderReceived
public void expectedHeaderReceived(String name, Object value)
Sets an expectation that the given header name & value are received by this endpoint You can set multiple expectations for different header names. If you set a value of null that means we accept either the header is absent, or its value is null
-
expectedNoHeaderReceived
public void expectedNoHeaderReceived()
Sets an expectation that the messages received by this endpoint have no header
-
expectedHeaderValuesReceivedInAnyOrder
public void expectedHeaderValuesReceivedInAnyOrder(String name, List<?> values)
Adds an expectation that the given header values are received by this endpoint in any order. Important: The number of values must match the expected number of messages, so if you expect 3 messages, then there must be 3 values. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedHeaderValuesReceivedInAnyOrder
public void expectedHeaderValuesReceivedInAnyOrder(String name, Object... values)
Adds an expectation that the given header values are received by this endpoint in any order Important: The number of values must match the expected number of messages, so if you expect 3 messages, then there must be 3 values. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedPropertyReceived
public void expectedPropertyReceived(String name, Object value)
Sets an expectation that the given property name & value are received by this endpoint You can set multiple expectations for different property names. If you set a value of null that means we accept either the property is absent, or its value is null
-
expectedPropertyValuesReceivedInAnyOrder
public void expectedPropertyValuesReceivedInAnyOrder(String name, List<?> values)
Adds an expectation that the given property values are received by this endpoint in any order. Important: The number of values must match the expected number of messages, so if you expect 3 messages, then there must be 3 values. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedPropertyValuesReceivedInAnyOrder
public void expectedPropertyValuesReceivedInAnyOrder(String name, Object... values)
Adds an expectation that the given property values are received by this endpoint in any order Important: The number of values must match the expected number of messages, so if you expect 3 messages, then there must be 3 values. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedBodiesReceived
public void expectedBodiesReceived(List<?> bodies)
Adds an expectation that the given body values are received by this endpoint in the specified order Important: The number of values must match the expected number of messages, so if you expect 3 messages, then there must be 3 values. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedMessagesMatches
public void expectedMessagesMatches(org.apache.camel.Predicate... predicates)
Sets an expectation that the given predicates matches the received messages by this endpoint
-
expectedBodiesReceived
public void expectedBodiesReceived(Object... bodies)
Sets an expectation that the given body values are received by this endpoint Important: The number of bodies must match the expected number of messages, so if you expect 3 messages, then there must be 3 bodies. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedBodyReceived
public AssertionClause expectedBodyReceived()
Adds an expectation that the given body value are received by this endpoint
-
expectedBodiesReceivedInAnyOrder
public void expectedBodiesReceivedInAnyOrder(List<?> bodies)
Adds an expectation that the given body values are received by this endpoint in any order Important: The number of bodies must match the expected number of messages, so if you expect 3 messages, then there must be 3 bodies. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedBodiesReceivedInAnyOrder
public void expectedBodiesReceivedInAnyOrder(Object... bodies)
Adds an expectation that the given body values are received by this endpoint in any order Important: The number of bodies must match the expected number of messages, so if you expect 3 messages, then there must be 3 bodies. Important: This overrides any previous set value usingexpectedMessageCount(int)
-
expectedFileExists
public void expectedFileExists(Path name)
Adds an expectation that a file exists with the given name- Parameters:
name- name of file, will cater for / and \ on different OS platforms
-
expectedFileExists
public void expectedFileExists(String name)
Adds an expectation that a file exists with the given name- Parameters:
name- name of file, will cater for / and \ on different OS platforms
-
expectedFileExists
public void expectedFileExists(Path name, String content)
Adds an expectation that a file exists with the given name Will wait at most 5 seconds while checking for the existence of the file.- Parameters:
name- name of file, will cater for / and \ on different OS platformscontent- content of file to compare, can be null to not compare content
-
expectedFileExists
public void expectedFileExists(String name, String content)
Adds an expectation that a file exists with the given name Will wait at most 5 seconds while checking for the existence of the file.- Parameters:
name- name of file, will cater for / and \ on different OS platformscontent- content of file to compare, can be null to not compare content
-
expectedExchangePattern
public void expectedExchangePattern(org.apache.camel.ExchangePattern exchangePattern)
Adds an expectation that messages received should have the given exchange pattern
-
expectsAscending
public void expectsAscending(org.apache.camel.Expression expression)
Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter value
-
expectsAscending
public AssertionClause expectsAscending()
Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter value
-
expectsDescending
public void expectsDescending(org.apache.camel.Expression expression)
Adds an expectation that messages received should have descending values of the given expression such as a user generated counter value
-
expectsDescending
public AssertionClause expectsDescending()
Adds an expectation that messages received should have descending values of the given expression such as a user generated counter value
-
expectsNoDuplicates
public void expectsNoDuplicates(org.apache.camel.Expression expression)
Adds an expectation that no duplicate messages should be received using the expression to determine the message ID- Parameters:
expression- the expression used to create a unique message ID for message comparison (which could just be the message payload if the payload can be tested for uniqueness usingObject.equals(Object)andObject.hashCode()
-
expectsNoDuplicates
public AssertionClause expectsNoDuplicates()
Adds an expectation that no duplicate messages should be received using the expression to determine the message ID
-
assertMessagesAscending
public void assertMessagesAscending(org.apache.camel.Expression expression)
Asserts that the messages have ascending values of the given expression
-
assertMessagesDescending
public void assertMessagesDescending(org.apache.camel.Expression expression)
Asserts that the messages have descending values of the given expression
-
assertMessagesSorted
protected void assertMessagesSorted(org.apache.camel.Expression expression, boolean ascending)
-
assertMessagesSorted
protected void assertMessagesSorted(org.apache.camel.Expression expression, boolean ascending, int index)
-
assertNoDuplicates
public void assertNoDuplicates(org.apache.camel.Expression expression)
Asserts among all the current received exchanges that there are no duplicate message- Parameters:
expression- the expression to use for duplication check
-
expects
public void expects(Runnable runnable)
Adds the expectation which will be invoked when enough messages are received
-
message
public AssertionClause message(int messageIndex)
Adds an assertion to the given message index- Parameters:
messageIndex- the number of the message- Returns:
- the assertion clause
-
allMessages
public AssertionClause allMessages()
Adds an assertion to all the received messages- Returns:
- the assertion clause
-
assertExchangeReceived
public org.apache.camel.Exchange assertExchangeReceived(int index)
Asserts that the given index of message is received (starting at zero)
-
notifyBuilderOnExchange
public void notifyBuilderOnExchange(org.apache.camel.Exchange exchange)
- Specified by:
notifyBuilderOnExchangein interfaceorg.apache.camel.spi.NotifyBuilderMatcher
-
notifyBuilderReset
public void notifyBuilderReset()
- Specified by:
notifyBuilderResetin interfaceorg.apache.camel.spi.NotifyBuilderMatcher
-
notifyBuilderMatches
public boolean notifyBuilderMatches()
- Specified by:
notifyBuilderMatchesin interfaceorg.apache.camel.spi.NotifyBuilderMatcher
-
getName
public String getName()
-
setName
public void setName(String name)
-
getReceivedCounter
public int getReceivedCounter()
-
getReceivedExchanges
public List<org.apache.camel.Exchange> getReceivedExchanges()
-
getExpectedCount
public int getExpectedCount()
-
getSleepForEmptyTest
public long getSleepForEmptyTest()
-
setSleepForEmptyTest
public void setSleepForEmptyTest(long sleepForEmptyTest)
Allows a sleep to be specified to wait to check that this endpoint really is empty whenexpectedMessageCount(int)is called with zero- Parameters:
sleepForEmptyTest- the milliseconds to sleep for to determine that this endpoint really is empty
-
getResultWaitTime
public long getResultWaitTime()
-
setResultWaitTime
public void setResultWaitTime(long resultWaitTime)
Sets the maximum amount of time (in millis) theassertIsSatisfied()will wait on a latch until it is satisfied
-
getResultMinimumWaitTime
public long getResultMinimumWaitTime()
-
setResultMinimumWaitTime
public void setResultMinimumWaitTime(long resultMinimumWaitTime)
Sets the minimum expected amount of time (in millis) theassertIsSatisfied()will wait on a latch until it is satisfied
-
setExpectedCount
public void setExpectedCount(int expectedCount)
Specifies the expected number of message exchanges that should be received by this endpoint. Beware: If you want to expect that 0 messages, then take extra care, as 0 matches when the tests starts, so you need to set a assert period time to let the test run for a while to make sure there are still no messages arrived; for that usesetAssertPeriod(long). An alternative is to use NotifyBuilder, and use the notifier to know when Camel is done routing some messages, before you call theassertIsSatisfied()method on the mocks. This allows you to not use a fixed assert period, to speedup testing times. If you want to assert that exactly n'th message arrives to this mock endpoint, then see also thesetAssertPeriod(long)method for further details.- Parameters:
expectedCount- the number of message exchanges that should be expected by this endpoint- See Also:
setAssertPeriod(long)
-
setExpectedMessageCount
public void setExpectedMessageCount(int expectedCount)
- See Also:
setExpectedCount(int)
-
setMinimumExpectedMessageCount
public void setMinimumExpectedMessageCount(int expectedCount)
Specifies the minimum number of expected message exchanges that should be received by this endpoint- Parameters:
expectedCount- the number of message exchanges that should be expected by this endpoint
-
getReporter
public org.apache.camel.Processor getReporter()
-
setReporter
public void setReporter(org.apache.camel.Processor reporter)
Allows a processor to added to the endpoint to report on progress of the test
-
getRetainFirst
public int getRetainFirst()
-
setRetainFirst
public void setRetainFirst(int retainFirst)
Specifies to only retain the first n'th number of receivedExchanges. This is used when testing with big data, to reduce memory consumption by not storing copies of everyExchangethis mock endpoint receives. Important: When using this limitation, then thegetReceivedCounter()will still return the actual number of receivedExchanges. For example if we have received 5000Exchanges, and have configured to only retain the first 10Exchanges, then thegetReceivedCounter()will still return 5000 but there is only the first 10Exchanges in thegetExchanges()andgetReceivedExchanges()methods. When using this method, then some of the other expectation methods is not supported, for example theexpectedBodiesReceived(Object...)sets a expectation on the first number of bodies received. You can configure bothsetRetainFirst(int)andsetRetainLast(int)methods, to limit both the first and last received.- Parameters:
retainFirst- to limit and only keep the first n'th receivedExchanges, use 0 to not retain any messages, or -1 to retain all.- See Also:
setRetainLast(int)
-
getRetainLast
public int getRetainLast()
-
setRetainLast
public void setRetainLast(int retainLast)
Specifies to only retain the last n'th number of receivedExchanges. This is used when testing with big data, to reduce memory consumption by not storing copies of everyExchangethis mock endpoint receives. Important: When using this limitation, then thegetReceivedCounter()will still return the actual number of receivedExchanges. For example if we have received 5000Exchanges, and have configured to only retain the last 20Exchanges, then thegetReceivedCounter()will still return 5000 but there is only the last 20Exchanges in thegetExchanges()andgetReceivedExchanges()methods. When using this method, then some of the other expectation methods is not supported, for example theexpectedBodiesReceived(Object...)sets a expectation on the first number of bodies received. You can configure bothsetRetainFirst(int)andsetRetainLast(int)methods, to limit both the first and last received.- Parameters:
retainLast- to limit and only keep the last n'th receivedExchanges, use 0 to not retain any messages, or -1 to retain all.- See Also:
setRetainFirst(int)
-
getReportGroup
public int getReportGroup()
-
setReportGroup
public void setReportGroup(int reportGroup)
A number that is used to turn on throughput logging based on groups of the size.
-
isLog
public boolean isLog()
-
setLog
public void setLog(boolean log)
To turn on logging when the mock receives an incoming message. This will log only one time at INFO level for the incoming message. For more detailed logging then set the logger to DEBUG level for the org.apache.camel.component.mock.MockEndpoint class.
-
isCopyOnExchange
public boolean isCopyOnExchange()
-
setCopyOnExchange
public void setCopyOnExchange(boolean copyOnExchange)
Sets whether to make a deep copy of the incomingExchangewhen received at this mock endpoint. Is by default true.
-
isFailFast
public boolean isFailFast()
-
setFailFast
public void setFailFast(boolean failFast)
Sets whetherassertIsSatisfied()should fail fast at the first detected failed expectation while it may otherwise wait for all expected messages to arrive before performing expectations verifications. Is by default true. Set to false to use behavior as in Camel 2.x.
-
getComponent
public MockComponent getComponent()
- Overrides:
getComponentin classorg.apache.camel.support.DefaultEndpoint
-
onExchange
protected void onExchange(org.apache.camel.Exchange exchange)
-
performAssertions
protected void performAssertions(org.apache.camel.Exchange exchange, org.apache.camel.Exchange copy) throws ExceptionPerforms the assertions on the incoming exchange.- Parameters:
exchange- the actual exchangecopy- a copy of the exchange (only store this)- Throws:
Exception- can be thrown if something went wrong
-
addReceivedExchange
protected void addReceivedExchange(org.apache.camel.Exchange copy)
Adds the received exchange.- Parameters:
copy- a copy of the received exchange
-
waitForCompleteLatch
protected void waitForCompleteLatch() throws InterruptedException- Throws:
InterruptedException
-
waitForCompleteLatch
protected void waitForCompleteLatch(long timeout) throws InterruptedException- Throws:
InterruptedException
-
assertTrue
protected void assertTrue(String message, boolean predicate)
Asserts that the givenpredicateistrue, if not anAssertionErroris raised with the give message.- Parameters:
message- the message to use in case of a failure.predicate- the predicate allowing to determinate if it is a failure or not.
-
assertFalse
protected void assertFalse(String message, boolean predicate)
Asserts that the givenpredicateisfalse, if not anAssertionErroris raised with the give message.- Parameters:
message- the message to use in case of a failure.predicate- the predicate allowing to determinate if it is a failure or not.
-
fail
protected void fail(Object message)
-
getExpectedMinimumCount
public int getExpectedMinimumCount()
-
await
public void await() throws InterruptedException- Throws:
InterruptedException
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedException- Throws:
InterruptedException
-
isLenientProperties
public boolean isLenientProperties()
- Specified by:
isLenientPropertiesin interfaceorg.apache.camel.Endpoint- Overrides:
isLenientPropertiesin classorg.apache.camel.support.DefaultEndpoint
-
-