You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mattias Severson <ma...@gmail.com> on 2010/04/29 17:54:54 UTC
Camel newbie, endpoint configuration?
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.
Re: Camel newbie, endpoint configuration?
Posted by Mattias Severson <ma...@gmail.com>.
Hi,
I updated test to:
public class SystemApiImplTest {
private static final long SOME_ID = 42;
private SystemApiImpl outputHandler;
private DefaultCamelContext camelContext;
private MockEndpoint mockEndpoint;
@Before
public void setUp() throws Exception {
camelContext = new DefaultCamelContext();
outputHandler = new SystemApiImpl(camelContext);
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").to("mock:result");
}});
camelContext.start();
}
@After
public void tearDown() throws Exception{
camelContext.stop();
}
@Test
public void testHandle() throws Exception {
mockEndpoint =
(MockEndpoint)camelContext.getEndpoint("mock:result");
mockEndpoint.expectedBodiesReceived(SOME_ID);
outputHandler.handle(SOME_ID);
mockEndpoint.assertIsSatisfied();
}
}
and now it works like a charm. :-)
Thanks, Mattias
Claus Ibsen-2 wrote:
>
> 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 <ma...@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 <ma...@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
>
>
--
View this message in context: http://old.nabble.com/Camel-newbie%2C-endpoint-configuration--tp28402433p28412200.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel newbie, endpoint configuration?
Posted by Claus Ibsen <cl...@gmail.com>.
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 <ma...@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 <ma...@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
Re: Camel newbie, endpoint configuration?
Posted by Mattias Severson <ma...@gmail.com>.
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 <ma...@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.
Re: Camel newbie, endpoint configuration?
Posted by Claus Ibsen <cl...@gmail.com>.
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 <ma...@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