org.apache.camel.component.mock
Class MockEndpoint

java.lang.Object
  extended by org.apache.camel.impl.DefaultEndpoint<Exchange>
      extended by org.apache.camel.component.mock.MockEndpoint
All Implemented Interfaces:
Endpoint<Exchange>

public class MockEndpoint
extends DefaultEndpoint<Exchange>

A Mock endpoint which provides a literate, fluent API for testing routes using a JMock style API.

Version:
$Revision: 1.1 $

Constructor Summary
MockEndpoint(String endpointUri, Component component)
           
 
Method Summary
 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 assertIsSatisfied()
          Validates that all the available expectations on this endpoint are satisfied; or throw an exception
 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)
           
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<Exchange> createConsumer(Processor processor)
          Creates a new Event Driven Consumer which consumes messages from the endpoint using the given processor
 Exchange createExchange()
          Create a new exchange for communicating with this endpoint
 Producer<Exchange> 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
 void expectedBodiesReceived(Object... bodies)
          Adds an expectation that the given body values 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 expects(Runnable runnable)
          Adds the expection which will be invoked when enough messages are received
static void expectsMessageCount(int count, MockEndpoint... endpoints)
           
protected  void fail(Object message)
           
 int getExpectedCount()
           
 int getExpectedMinimumCount()
           
 List<Throwable> getFailures()
           
 int getReceivedCounter()
           
 List<Exchange> getReceivedExchanges()
           
 long getSleepForEmptyTest()
           
 boolean isSingleton()
          Returns if the endpoint should be a CamelContext singleton.
 AssertionClause message(int messageIndex)
          Adds an assertion to the given message index
protected  void onExchange(Exchange exchange)
           
 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
 
Methods inherited from class org.apache.camel.impl.DefaultEndpoint
convertTo, createExchange, createExecutorService, createPollingConsumer, equals, getComponent, getContext, getEndpointUri, getExchangeType, getExecutorService, hashCode, setExecutorService, toExchangeType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockEndpoint

public MockEndpoint(String endpointUri,
                    Component component)
Method Detail

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

expectsMessageCount

public static void expectsMessageCount(int count,
                                       MockEndpoint... endpoints)
                                throws InterruptedException
Throws:
InterruptedException

createExchange

public Exchange createExchange()
Description copied from interface: Endpoint
Create a new exchange for communicating with this endpoint


createConsumer

public Consumer<Exchange> createConsumer(Processor processor)
                                  throws Exception
Description copied from interface: Endpoint
Creates a new Event Driven Consumer which consumes messages from the endpoint using the given processor

Returns:
a newly created consumer
Throws:
Exception

createProducer

public Producer<Exchange> createProducer()
                                  throws Exception
Description copied from interface: Endpoint
Creates a new producer which is used send messages into the endpoint

Returns:
a newly created producer
Throws:
Exception

assertIsSatisfied

public void assertIsSatisfied()
                       throws InterruptedException
Validates that all the available expectations on this endpoint are satisfied; or throw an exception

Throws:
InterruptedException

assertIsSatisfied

public void assertIsSatisfied(long timeoutForEmptyEndpoints)
                       throws InterruptedException
Validates that all the available expectations on this endpoint are satisfied; or throw an exception

Throws:
InterruptedException

expectedMessageCount

public void expectedMessageCount(int expectedCount)
Specifies the expected number of message exchanges that should be received by this endpoint

Parameters:
expectedCount - the number of message exchanges that should be expected by this endpoint

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

expectedBodiesReceived

public void expectedBodiesReceived(List bodies)
Adds an expectation that the given body values are received by this endpoint


expectedBodiesReceived

public void expectedBodiesReceived(Object... bodies)
Adds an expectation that the given body values are received by this endpoint


expects

public void expects(Runnable runnable)
Adds the expection 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 Exchange assertExchangeReceived(int index)
Asserts that the given index of message is received (starting at zero)


getFailures

public List<Throwable> getFailures()

getReceivedCounter

public int getReceivedCounter()

getReceivedExchanges

public List<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 when expectedMessageCount(int) is called with zero

Parameters:
sleepForEmptyTest - the milliseconds to sleep for to determine that this endpoint really is empty

onExchange

protected void onExchange(Exchange exchange)

assertEquals

protected void assertEquals(String message,
                            Object expectedValue,
                            Object actualValue)

assertTrue

protected void assertTrue(String message,
                          boolean predicate)

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

isSingleton

public boolean isSingleton()
Description copied from interface: Endpoint
Returns if the endpoint should be a CamelContext singleton. If the endpoint is a Singleton, then a single Endpoint instance will be shared by all routes with the same URI. Because the endpoint is shared, it should be treated as an immutable.



Copyright © 2007 Apache Software Foundation. All Rights Reserved.