camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Camel newbie, endpoint configuration?
Date Fri, 30 Apr 2010 08:18:20 GMT
Hi

Take a look at some examples from the source code how to use mocks for testing
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SimpleMockTest.java

And you can read about it as well
http://camel.apache.org/testing

And chapter 6 in the Camel in Action book covers testing throughly.
It also explains you how testing with mock works so you will
understand it much better.



On Thu, Apr 29, 2010 at 7:06 PM, Mattias Severson <matsev@gmail.com> wrote:
>
> Hmm, no there is still something missing
>
> I updated the setUp() method to
>
>  @Before
>    public void setUp() throws Exception {
>        camelContext = new DefaultCamelContext();
>        outputHandler = new OutputHandlerImpl(camelContext);
>        mockEndpoint = new MockEndpoint(RECIEVER_URL);
>        camelContext.addEndpoint(RECIEVER_URL, mockEndpoint);
>        camelContext.addComponent("fileformat",
> camelContext.getComponent("mock"));
>    }
>
> But the Exchange does not seem to reach the mockEndpoint. The call to
> Exchange exchange = mockEndpoint.getExchanges().get(0); results in an
> ArrayIndexOutOfBoundsException because the getExchanges() returns an empty
> list.
>
>
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> You need to add the mock component with the scheme fileformat
>>
>> // for example as follows
>> context.addComponent"fileformat", context.getComponent("mock"));
>>
>>
>>
>> On Thu, Apr 29, 2010 at 5:54 PM, Mattias Severson <matsev@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> I have a system that has a handle(long id) interface that I must
>>> implement.
>>> My plan is to use this method as a Producer in the camel context:
>>>
>>> public class SystemApiImpl {
>>>
>>>    public static final String RECIEVER_URL = "some:receiver";
>>>
>>>    private final ProducerTemplate producerTemplate;
>>>
>>>    public SystemApiImpl(CamelContext camelContext) {
>>>        producerTemplate = camelContext.createProducerTemplate();
>>>    }
>>>
>>>    public void handle(long someId) {
>>>        producerTemplate.sendBody(RECIEVER_URL, someId);
>>>    }
>>> }
>>>
>>>
>>> Now, I would like to create a unit test that verifies that the
>>> RECEIVER_URL
>>> gets the id:
>>>
>>> public class SystemApiImplTest {
>>>
>>>    private static final long SOME_ID = 42;
>>>    private OutputHandler outputHandler;
>>>    private DefaultCamelContext camelContext;
>>>    private MockEndpoint mockEndpoint;
>>>
>>>    @Before
>>>    public void setUp() throws Exception {
>>>        camelContext = new DefaultCamelContext();
>>>        outputHandler = new OutputHandlerImpl(camelContext);
>>>        mockEndpoint = new MockEndpoint(RECIEVER_URL);
>>>        camelContext.addEndpoint(RECIEVER_URL, mockEndpoint);
>>>    }
>>>
>>>    @Test
>>>    public void testHandle() {
>>>        outputHandler.handle(SOME_ID);
>>>        Exchange exchange = mockEndpoint.getExchanges().get(0);
>>>        Message in = exchange.getIn();
>>>        Long value = in.getBody(Long.class);
>>>        assertEquals(SOME_ID, value.longValue());
>>>    }
>>> }
>>>
>>>
>>> However, it seems that I have missed something fundamental, because the
>>> sendBody() method throws an exception:
>>> org.apache.camel.ResolveEndpointFailedException: Failed to resolve
>>> endpoint:
>>> fileformat://router due to: No component found with scheme: fileformat
>>>
>>>
>>> Please advise,
>>>
>>> Mattias
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Camel-newbie%2C-endpoint-configuration--tp28402433p28402433.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Camel-newbie%2C-endpoint-configuration--tp28402433p28403300.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message