You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by BERTRAND Antoine AWL-IT <an...@atos.net> on 2011/08/24 10:56:08 UTC

InOut endoint unit test

Hi,

I've a camel route like this:

public class DummyRoute extends RouteBuilder {
  private String inputOutput;
  private boolean tracing;

  @Override
  public void configure() throws Exception {
    this.getContext().setTracing(tracing);
    from(inputOutput)
      [... All the rest of the route ...]
    ;
  }
  [...]
}

I want to write a unit test for this route.

Generaly I'm writing test like that:

@ContextConfiguration(locations={"/test-context.xml"})
public class DummyRouteTest extends AbstractJUnit4SpringContextTests {
  @Autowired
  protected CamelContext camelContext;

  @EndpointInject(uri = "mock:output")
  protected MockEndpoint output;

  @Produce(uri = "direct:input")
  protected ProducerTemplate input;

  @Test
  public void testMocksAreValid() throws Exception {
    MockEndpoint.assertIsSatisfied(this.camelContext);
  }

  [... all the test cases ...]
}

But How can I test my dummy route?
Can I produce message with mock endpoint or expect any assert for a producer template?

Ps: I'm using camel 2.6

Regards,
Antoine


Atos Worldline SA/NV - Chaussee de Haecht 1442 Haachtsesteenweg
- 1130 Brussels - Belgium
RPM-RPR Bruxelles-Brussel - TVA-BTW BE 0418.547.872
Bankrekening-Compte Bancaire-Bank Account 310-0269424-44
BIC BBRUBEBB - IBAN BE55 3100 2694 2444

"The information contained in this e-mail and any attachment thereto is confidential and may contain information which is protected by intellectual property rights.
This information is intended for the exclusive use of the recipient(s) named above.
This e-mail does not constitute any binding relationship or offer toward any of the addressees.
If you are not one of the addressees , one of their employees or a proxy holder entitled to hand over this message to the addressee(s), any use of the information contained herein (e.g. reproduction, divulgation, communication or distribution,...) is prohibited.
If you have received this message in error, please notify the sender and destroy it immediately after.
The integrity and security of this message cannot be guaranteed and it may be subject to data corruption, interception and unauthorized amendment, for which we accept no liability."


Re: InOut endoint unit test

Posted by boday <be...@initekconsulting.com>.
If you have an InOut route, then all you need to do is to assert that the
result from the producer template call is as expected.  Also, mock is used
to validate exchanges are received (generally at the end of a route).  Just
add ".to("mock:output")" to the end of your dummy route, then call... 

//set the expected mock results
mock.setMinimumExpectedMessageCount(<expected count>);
mock.expectedBodiesReceived(<expected message>);

//send test message and assert the response
Object response = input.requestBody(<yourTestMessage>);
assertTrue("response should be X", <expected-response>, response);

//assert mock
mock.assertIsSatisfied();

here is a simple unit test to use as an example...

https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PipelineMEPTest.java


BERTRAND Antoine     AWL-IT-2 wrote:
> 
> Hi,
> 
> I've a camel route like this:
> 
> public class DummyRoute extends RouteBuilder {
>   private String inputOutput;
>   private boolean tracing;
> 
>   @Override
>   public void configure() throws Exception {
>     this.getContext().setTracing(tracing);
>     from(inputOutput)
>       [... All the rest of the route ...]
>     ;
>   }
>   [...]
> }
> 
> I want to write a unit test for this route.
> 
> Generaly I'm writing test like that:
> 
> @ContextConfiguration(locations={"/test-context.xml"})
> public class DummyRouteTest extends AbstractJUnit4SpringContextTests {
>   @Autowired
>   protected CamelContext camelContext;
> 
>   @EndpointInject(uri = "mock:output")
>   protected MockEndpoint output;
> 
>   @Produce(uri = "direct:input")
>   protected ProducerTemplate input;
> 
>   @Test
>   public void testMocksAreValid() throws Exception {
>     MockEndpoint.assertIsSatisfied(this.camelContext);
>   }
> 
>   [... all the test cases ...]
> }
> 
> But How can I test my dummy route?
> Can I produce message with mock endpoint or expect any assert for a
> producer template?
> 
> Ps: I'm using camel 2.6
> 
> Regards,
> Antoine
> 
> 
> Atos Worldline SA/NV - Chaussee de Haecht 1442 Haachtsesteenweg
> - 1130 Brussels - Belgium
> RPM-RPR Bruxelles-Brussel - TVA-BTW BE 0418.547.872
> Bankrekening-Compte Bancaire-Bank Account 310-0269424-44
> BIC BBRUBEBB - IBAN BE55 3100 2694 2444
> 
> "The information contained in this e-mail and any attachment thereto is
> confidential and may contain information which is protected by
> intellectual property rights.
> This information is intended for the exclusive use of the recipient(s)
> named above.
> This e-mail does not constitute any binding relationship or offer toward
> any of the addressees.
> If you are not one of the addressees , one of their employees or a proxy
> holder entitled to hand over this message to the addressee(s), any use of
> the information contained herein (e.g. reproduction, divulgation,
> communication or distribution,...) is prohibited.
> If you have received this message in error, please notify the sender and
> destroy it immediately after.
> The integrity and security of this message cannot be guaranteed and it may
> be subject to data corruption, interception and unauthorized amendment,
> for which we accept no liability."
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/InOut-endoint-unit-test-tp4729750p4760134.html
Sent from the Camel - Users mailing list archive at Nabble.com.