I just found out that the problem was that the error message did mislead me. 
When I’m trying to get Strings through the route, expectedBodiesReceived works 
perfectly fine. If I do send List<Object> across the routes, then I’m 
struggling with the expectedBodiesReceived() method. 


On 20 Feb 2015, at 21:38, Christian Weichselbaum <c.weichselb...@cortical.io> 
wrote:

> Hello, 
> 
> I’m having troubles with testing a camel route. Now I reduced the test and 
> the route to almost nothing and was able to pinpoint the problem but am still 
> struggling with finding a solution.
> 
> The first snippet here does fail with following assertion problem: 
> java.lang.AssertionError: mock://result Received message count. Expected: <1> 
> but was: <0>
> ---
> mock.expectedMessageCount(1);
> mock.expectedBodiesReceived(posTypesExpected);
> template.sendBody("apple");
> mock.assertIsSatisfied();
> ---
> if I comment the 2nd line and omit the “expectedBodiesReceived” then <1> is 
> expected and <1> is received as message count. Why do the first 4 lines fail 
> and why does omitting the expectedBodies method  solve the problem?
> ---
> mock.expectedMessageCount(1);
> //mock.expectedBodiesReceived(posTypesExpected);
> template.sendBody("apple");
> mock.assertIsSatisfied();
> ---
> 
> 
> Thank you very much for any help.
> 
> Here is the JUnit Test:
> 
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
> @MockEndpoints("mock:result")
> @ContextConfiguration("classpath:META-INF/spring/TestCamel.xml")
> public class TestCamel extends CamelTestSupport {
>     
>     @EndpointInject(uri = "mock:result")
>     protected MockEndpoint mock;
>  
>     @Produce(uri = "vm:retrievePOS_Start")
>     protected ProducerTemplate template;
>  
>     /**
>      * 
>      * @throws java.lang.Exception
>      */
>     @Before
>     public void setUp() throws Exception {
>     }
>     
>     /**
>      * 
>      * @throws java.lang.Exception
>      */
>     @After
>     public void tearDown() throws Exception {
>     }
>     
>     @Test
>     public final void test() throws InterruptedException {
>         List<WiktionaryPosType> posTypesExpected = new 
> ArrayList<WiktionaryPosType>();
>         posTypesExpected.add(WiktionaryPosType.NOUN);
>         mock.expectedMessageCount(1);
>         mock.expectedBodiesReceived(posTypesExpected);
>         template.sendBody("apple");
>         mock.assertIsSatisfied();
>     }
> 
> And that’s how the spring xml looks like:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <beans xmlns="http://www.springframework.org/schema/beans";
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>     xsi:schemaLocation="http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans.xsd
>         http://camel.apache.org/schema/spring 
> http://camel.apache.org/schema/spring/camel-spring.xsd";>
> 
> 
>     <camelContext id="testCamel"
>         xmlns="http://camel.apache.org/schema/spring";>
> 
>         <route>
>             <from uri="vm:retrievePOS_Start" />
> 
>             <to uri="mock:result" />
>         </route>
> 
>     </camelContext>
> 
> </beans>
> 
> Mit freundlichen Grüßen,
> With kind regards,
> 
> Christian Weichselbaum
> Senior Programmer & Data Scientist
> 
> cortical.io
> Mariahilferstrasse 4, 1070 Vienna, Austria
> +43 676 725 1954
> c.weichselb...@cortical.io
> http://cortical.io
> 
> 
> 
> <facebook_32.png><linkedin_32.png><twitter_32.png><google_32.png>
> 

Reply via email to