Hi All,

I am looking to set up some mock test using Apache camel and I see
contradictory behaviours.
Please advice.

I am not sure if the mock is doing what is should (Verify if the headers are
set properly).


<route>
<from uri="direct:dataToParse"/>
<log message="Received xml from MocB ${body}"/>
<choice>
        <when>
                <simple>${in.header.messageId} == 1</simple>
                <log message="processing TAP file"/>
                <setHeader 
headerName="contentType"><constant>TAP</constant></setHeader>
                <to uri="direct:parsedData"/>
                <to uri="mock:mockParsedData" />
        </when>
        <when>
                <simple>${in.header.messageId} == 2</simple>
                <log message="processing TDR file"/>
                <setHeader 
headerName="contentType"><constant>TDR</constant></setHeader>
                <to uri="direct:parsedData"/>
                <to uri="mock:mockParsedData" />
        </when>
</choice>
</route>

*Correct flow:* I am passing the messageId =2 which goes into the "TDR" flow
and sets the Header "contentType". This is happening correctly (log snippet
below).

>From Log:
2012-05-18 14:41:02,039 INFO  [Camel (camel-1) thread #0 - file:///tdr/in]
route2            - processing TDR file

*Issue: *The below test result is PASS which should actually be FAIL as the
contentType set is TDR.

        @Test
        public void testMockC() throws Exception{
            context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() {
                @Override
                public void configure() throws Exception {
                    mockEndpoints("mockParsedData");
                }
            });
        
getMockEndpoint("mock:mockParsedData").expectedHeaderReceived("contentType",
"TAP");
                
getMockEndpoint("mock:mockParsedData").expectedHeaderReceived("messageId",
2);
                
getMockEndpoint("mock:mockParsedData").expectedHeaderReceived("batchSize",
2000);
                
                assertMockEndpointsSatisfied();
                assertNotNull(context.hasEndpoint("mock:mockParsedData"));
        }

2nd Issue:

<choice>
        <when>
                <simple> ${header.batchSize} == 2000 </simple>
                <log message="processing batch of size == 2000 ---
[${in.header.contentType}]"/>
                <choice>
                        <when><simple> ${in.header.contentType} contains 'TAP' 
</simple>
                                <log message="persisting TAP file 
${in.header.CamelFileNameOnly}"/>

The log shows contradictory flow. Same thread but the log shows the cheader
"contentType" is set to 'TDR' where as the wrong choice block is executed.

2012-05-18 14:41:02,039 INFO  [Camel (camel-1) thread #0 - file:///tdr/in]
route3            - processing batch of size == 2000 --- [TDR]
2012-05-18 14:41:02,039 INFO  [Camel (camel-1) thread #0 - file:///tdr/in]
route3            - persisting TAP file
ID-WNY46231LBITDBO-3571-1337366460383-0-2

Thanks & regards,
Ebe

--
View this message in context: 
http://camel.465427.n5.nabble.com/Mock-Testing-tp5712080.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to