|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.camel.impl.DefaultEndpoint
org.apache.camel.component.mock.MockEndpoint
public class MockEndpoint
A Mock endpoint which provides a literate, fluent API for testing routes using a JMock style API.
Constructor Summary | |
---|---|
MockEndpoint()
|
|
MockEndpoint(String endpointUri)
|
|
MockEndpoint(String endpointUri,
Component component)
|
Method Summary | |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
|
AssertionClause |
allMessages()
Adds an assertion to all the received messages |
protected void |
assertEquals(String message,
Object expectedValue,
Object actualValue)
|
Exchange |
assertExchangeReceived(int index)
Asserts that the given index of message is received (starting at zero) |
void |
assertIsNotSatisfied()
Validates that the assertions fail on this endpoint |
void |
assertIsNotSatisfied(long timeoutForEmptyEndpoints)
Validates that the assertions fail on this endpoint |
void |
assertIsSatisfied()
Validates that all the available expectations on this endpoint are satisfied; or throw an exception |
static void |
assertIsSatisfied(CamelContext context)
Asserts that all the expectations on any MockEndpoint instances registered
in the given context are valid |
void |
assertIsSatisfied(long timeoutForEmptyEndpoints)
Validates that all the available expectations on this endpoint are satisfied; or throw an exception |
static void |
assertIsSatisfied(long timeout,
TimeUnit unit,
MockEndpoint... endpoints)
|
static void |
assertIsSatisfied(MockEndpoint... endpoints)
|
void |
assertMessagesAscending(Expression expression)
Asserts that the messages have ascending values of the given expression |
void |
assertMessagesDescending(Expression expression)
Asserts that the messages have descending values of the given expression |
protected void |
assertMessagesSorted(Expression expression,
boolean ascending)
|
void |
assertNoDuplicates(Expression expression)
|
protected void |
assertTrue(String message,
boolean predicate)
|
static void |
assertWait(long timeout,
TimeUnit unit,
MockEndpoint... endpoints)
|
void |
await()
|
boolean |
await(long timeout,
TimeUnit unit)
|
Consumer |
createConsumer(Processor processor)
Creates a new Event Driven Consumer which consumes messages from the endpoint using the given processor |
Producer |
createProducer()
Creates a new producer which is used send messages into the endpoint |
void |
expectedBodiesReceived(List bodies)
Adds an expectation that the given body values are received by this endpoint in the specified order |
void |
expectedBodiesReceived(Object... bodies)
Adds an expectation that the given body values are received by this endpoint |
void |
expectedBodiesReceivedInAnyOrder(List bodies)
Adds an expectation that the given body values are received by this endpoint in any order |
void |
expectedBodiesReceivedInAnyOrder(Object... bodies)
Adds an expectation that the given body values are received by this endpoint in any order |
ExpressionClause |
expectedBodyReceived()
Adds an expectation that the given body value are received by this endpoint |
void |
expectedFileExists(String name)
Adds an expection that a file exists with the given name |
void |
expectedFileExists(String name,
String content)
Adds an expection that a file exists with the given name Will wait at most 5 seconds while checking for the existence of the file. |
void |
expectedHeaderReceived(String name,
Object value)
Adds an expectation that the given header name & value are received by this endpoint |
void |
expectedMessageCount(int expectedCount)
Specifies the expected number of message exchanges that should be received by this endpoint |
void |
expectedMinimumMessageCount(int expectedCount)
Specifies the minimum number of expected message exchanges that should be received by this endpoint |
void |
expectedPropertyReceived(String name,
Object value)
Adds an expectation that the given property name & value are received by this endpoint |
void |
expects(Runnable runnable)
Adds the expectation which will be invoked when enough messages are received |
ExpressionClause |
expectsAscending()
Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter value |
void |
expectsAscending(Expression expression)
Adds an expectation that messages received should have ascending values of the given expression such as a user generated counter value |
ExpressionClause |
expectsDescending()
Adds an expectation that messages received should have descending values of the given expression such as a user generated counter value |
void |
expectsDescending(Expression expression)
Adds an expectation that messages received should have descending values of the given expression such as a user generated counter value |
static void |
expectsMessageCount(int count,
MockEndpoint... endpoints)
|
ExpressionClause |
expectsNoDuplicates()
Adds an expectation that no duplicate messages should be received using the expression to determine the message ID |
void |
expectsNoDuplicates(Expression expression)
Adds an expectation that no duplicate messages should be received using the expression to determine the message ID |
protected void |
fail(Object message)
|
List<Exchange> |
getExchanges()
Return the exchanges available on this endpoint |
int |
getExpectedCount()
|
int |
getExpectedMinimumCount()
|
List<Throwable> |
getFailures()
|
int |
getReceivedCounter()
|
List<Exchange> |
getReceivedExchanges()
|
Processor |
getReporter()
|
long |
getResultWaitTime()
|
long |
getSleepForEmptyTest()
|
boolean |
isSingleton()
Wheter this class supports being singleton or not. |
AssertionClause |
message(int messageIndex)
Adds an assertion to the given message index |
protected void |
onExchange(Exchange exchange)
|
protected void |
performAssertions(Exchange exchange)
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
|
void |
reset()
|
static MockEndpoint |
resolve(CamelContext context,
String uri)
A helper method to resolve the mock endpoint of the given URI on the given context |
void |
setExpectedMessageCount(int expectedCount)
Specifies the expected number of message exchanges that should be received by this endpoint |
void |
setMinimumExpectedMessageCount(int expectedCount)
Specifies the minimum number of expected message exchanges that should be received by this endpoint |
void |
setMinimumResultWaitTime(long resultMinimumWaitTime)
Sets the minimum expected amount of time (in millis) the assertIsSatisfied() will
wait on a latch until it is satisfied |
void |
setReporter(Processor reporter)
Allows a processor to added to the endpoint to report on progress of the test |
void |
setResultWaitTime(long resultWaitTime)
Sets the maximum amount of time (in millis) the assertIsSatisfied() will
wait on a latch until it is satisfied |
void |
setSleepForEmptyTest(long sleepForEmptyTest)
Allows a sleep to be specified to wait to check that this endpoint really is empty when expectedMessageCount(int) is called with zero |
protected void |
waitForCompleteLatch()
|
void |
whenAnyExchangeReceived(Processor processor)
Set the processor that will be invoked when the some message is received. |
void |
whenExchangeReceived(int index,
Processor processor)
Set the processor that will be invoked when the index message is received. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.camel.Endpoint |
---|
configureProperties, createExchange, createExchange, createExchange, createPollingConsumer, getCamelContext, getEndpointKey, getEndpointUri, isLenientProperties, setCamelContext |
Constructor Detail |
---|
public MockEndpoint(String endpointUri, Component component)
public MockEndpoint(String endpointUri)
public MockEndpoint()
Method Detail |
---|
public static MockEndpoint resolve(CamelContext context, String uri)
context
- the camel context to try resolve the mock endpoint fromuri
- the uri of the endpoint to resolve
public static void assertWait(long timeout, TimeUnit unit, MockEndpoint... endpoints) throws InterruptedException
InterruptedException
public static void assertIsSatisfied(long timeout, TimeUnit unit, MockEndpoint... endpoints) throws InterruptedException
InterruptedException
public static void assertIsSatisfied(MockEndpoint... endpoints) throws InterruptedException
InterruptedException
public static void assertIsSatisfied(CamelContext context) throws InterruptedException
MockEndpoint
instances registered
in the given context are valid
context
- the camel context used to find all the available endpoints to be asserted
InterruptedException
public static void expectsMessageCount(int count, MockEndpoint... endpoints) throws InterruptedException
InterruptedException
public List<Exchange> getExchanges()
BrowsableEndpoint
getExchanges
in interface BrowsableEndpoint
public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
public Consumer createConsumer(Processor processor) throws Exception
Endpoint
createConsumer
in interface Endpoint
processor
- the given processor
Exception
- can be thrownpublic Producer createProducer() throws Exception
Endpoint
createProducer
in interface Endpoint
Exception
- can be thrownpublic void reset()
public void whenExchangeReceived(int index, Processor processor)
public void whenAnyExchangeReceived(Processor processor)
whenExchangeReceived(int, Processor)
method.
public void assertIsSatisfied() throws InterruptedException
InterruptedException
public void assertIsSatisfied(long timeoutForEmptyEndpoints) throws InterruptedException
timeoutForEmptyEndpoints
- the timeout in milliseconds that we
should wait for the test to be true
InterruptedException
public void assertIsNotSatisfied() throws InterruptedException
InterruptedException
public void assertIsNotSatisfied(long timeoutForEmptyEndpoints) throws InterruptedException
timeoutForEmptyEndpoints
- the timeout in milliseconds that we
should wait for the test to be true
InterruptedException
public void expectedMessageCount(int expectedCount)
expectedCount
- the number of message exchanges that should be
expected by this endpointpublic void expectedMinimumMessageCount(int expectedCount)
expectedCount
- the number of message exchanges that should be
expected by this endpointpublic void expectedHeaderReceived(String name, Object value)
public void expectedPropertyReceived(String name, Object value)
public void expectedBodiesReceived(List bodies)
public void expectedBodiesReceived(Object... bodies)
public ExpressionClause expectedBodyReceived()
public void expectedBodiesReceivedInAnyOrder(List bodies)
public void expectedBodiesReceivedInAnyOrder(Object... bodies)
public void expectedFileExists(String name)
name
- name of file, will cater for / and \ on different OS platformspublic void expectedFileExists(String name, String content)
name
- name of file, will cater for / and \ on different OS platformscontent
- content of file to compare, can be null to not compare contentpublic void expectsAscending(Expression expression)
public ExpressionClause expectsAscending()
public void expectsDescending(Expression expression)
public ExpressionClause expectsDescending()
public void expectsNoDuplicates(Expression expression)
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 using
Object.equals(Object)
and
Object.hashCode()
public ExpressionClause expectsNoDuplicates()
public void assertMessagesAscending(Expression expression)
public void assertMessagesDescending(Expression expression)
protected void assertMessagesSorted(Expression expression, boolean ascending)
public void assertNoDuplicates(Expression expression)
public void expects(Runnable runnable)
public AssertionClause message(int messageIndex)
messageIndex
- the number of the message
public AssertionClause allMessages()
public Exchange assertExchangeReceived(int index)
public List<Throwable> getFailures()
public int getReceivedCounter()
public List<Exchange> getReceivedExchanges()
public int getExpectedCount()
public long getSleepForEmptyTest()
public void setSleepForEmptyTest(long sleepForEmptyTest)
expectedMessageCount(int)
is called with zero
sleepForEmptyTest
- the milliseconds to sleep for to determine that
this endpoint really is emptypublic long getResultWaitTime()
public void setResultWaitTime(long resultWaitTime)
assertIsSatisfied()
will
wait on a latch until it is satisfied
public void setMinimumResultWaitTime(long resultMinimumWaitTime)
assertIsSatisfied()
will
wait on a latch until it is satisfied
public void setExpectedMessageCount(int expectedCount)
expectedCount
- the number of message exchanges that should be
expected by this endpointpublic void setMinimumExpectedMessageCount(int expectedCount)
expectedCount
- the number of message exchanges that should be
expected by this endpointpublic Processor getReporter()
public void setReporter(Processor reporter)
protected void onExchange(Exchange exchange)
protected void performAssertions(Exchange exchange) throws Exception
Exception
protected void waitForCompleteLatch() throws InterruptedException
InterruptedException
protected void assertEquals(String message, Object expectedValue, Object actualValue)
protected void assertTrue(String message, boolean predicate)
protected void fail(Object message)
public int getExpectedMinimumCount()
public void await() throws InterruptedException
InterruptedException
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
public boolean isSingleton()
IsSingleton
isSingleton
in interface IsSingleton
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |