You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sylvester <sy...@gmail.com> on 2008/11/28 06:43:53 UTC
problem with the intercept pattern
Hi,
I am running a JUnit test and doing the following:
template.sendBodyAndHeader("direct:a", "answer", "recipientListHeader",
"mock:x,mock:y");
intercept(header("recipientListHeader").matchesRegex("mock:[xe],mock:[gy]")).to("mock:z");
from("direct:a").recipientList(header("recipientListHeader").tokenize(","));
Doubt #1:
When the messages are actually sent, will the either have:
a. one of the headers (mock:x or mock:y) OR
b. both the headers (mock:x and mock:y) ?
Doubt #2:
According to me (just an educated guess) the right answer is 'a'.
Assuming this is the answer no messages should be intercepted and mock:z
should not get anything. However, when I run the test:
MockEndpoint x = getMockEndpoint("mock:x");
MockEndpoint y = getMockEndpoint("mock:y");
MockEndpoint z = getMockEndpoint("mock:z");
x.expectedBodiesReceived("answer");
y.expectedBodiesReceived("answer");
z.expectedBodiesReceived("answer");
z.expectedMinimumMessageCount(100);
sendBody();
assertMockEndpointsSatisifed();
it is still shows all tests as successful. How is this happening? The
exact output is:
org.apache.camel.impl.DefaultCamelContext <init>
INFO: JMX enabled. Using InstrumentationLifecycleStrategy.
org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
INFO: Asserting: Endpoint[mock:z] is satisfied
org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
INFO: Asserting: Endpoint[mock:y] is satisfied
org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
INFO: Asserting: Endpoint[mock:x] is satisfied
Now, even if I'm wrong and 'a' is not the answer to doubt#1, and
messages do reach mock:z, how can it get 100 messages?
Thanks,
Sylvester
Re: problem with the intercept pattern
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
After running the test and dig the code, the
MockEndpont.expectedMinimumMessageCount() is not right.
Actually, the mock:z only get one message here.
I will do a quick fix for the expectedMinimumMessageCount()[1].
Here is log about the route
[Route[[From[direct:a]] -> [Intercept[[Choice[[When[{not
header(recipientListHeader).matches(mock:[xe],mock:[gy])} ->
[org.apache.camel.model.ProceedType@c21495]]] Otherwise[[To[mock:z],
org.apache.camel.model.ProceedType@c21495]]]]]]]] routes: []
Now I don't know why there is no recipientList type output
[Route[[From[direct:a]] ->
[RecipientList[{tokenize(header(recipientListHeader), ,)}]]]] routes: []
[1]https://issues.apache.org/activemq/browse/CAMEL-1125
Willem
Sylvester wrote:
> Hi,
> I am running a JUnit test and doing the following:
>
> template.sendBodyAndHeader("direct:a", "answer", "recipientListHeader",
> "mock:x,mock:y");
> intercept(header("recipientListHeader").matchesRegex("mock:[xe],mock:[gy]")).to("mock:z");
>
>
> from("direct:a").recipientList(header("recipientListHeader").tokenize(","));
>
>
> Doubt #1:
>
> When the messages are actually sent, will the either have:
>
> a. one of the headers (mock:x or mock:y) OR
> b. both the headers (mock:x and mock:y) ?
>
> Doubt #2:
>
> According to me (just an educated guess) the right answer is 'a'.
> Assuming this is the answer no messages should be intercepted and mock:z
> should not get anything. However, when I run the test:
>
> MockEndpoint x = getMockEndpoint("mock:x");
> MockEndpoint y = getMockEndpoint("mock:y");
> MockEndpoint z = getMockEndpoint("mock:z");
> x.expectedBodiesReceived("answer");
> y.expectedBodiesReceived("answer");
> z.expectedBodiesReceived("answer");
> z.100);
>
> sendBody();
> assertMockEndpointsSatisifed();
>
> it is still shows all tests as successful. How is this happening? The
> exact output is:
>
> org.apache.camel.impl.DefaultCamelContext <init>
> INFO: JMX enabled. Using InstrumentationLifecycleStrategy.
> org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
> INFO: Asserting: Endpoint[mock:z] is satisfied
> org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
> INFO: Asserting: Endpoint[mock:y] is satisfied
> org.apache.camel.component.mock.MockEndpoint assertIsSatisfied
> INFO: Asserting: Endpoint[mock:x] is satisfied
>
> Now, even if I'm wrong and 'a' is not the answer to doubt#1, and
> messages do reach mock:z, how can it get 100 messages?
>
> Thanks,
> Sylvester
>