You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mick Knutson <mk...@baselogic.com> on 2008/10/02 03:24:14 UTC
Re: Trying to understand how to deal with process() errors and creating an exceptionChannel for bad messages.
So I have gotten a bit further, but not all the way.
It appears that if I have a unit test that is overloaded as I can do in
TestNG, then I can seemingly re-use the same mock endpoints.
Here is a valid test that is overloaded 3 different times:
*@Test(groups = {"functional"})
@Parameters({"startEndpointUri", "successEndpointUri",
"errorEndpointUri", "messageInputBody"})
public void testCreateInvalidChangeRequest(String startEndpointUri,
String successEndpointUri,
String errorEndpointUri,
String messageInputBody
)
throws Exception {
MockEndpoint mockSuccessEndpoint =
getMockEndpoint(successEndpointUri);
MockEndpoint mockFailureEndpoint =
getMockEndpoint(errorEndpointUri);
mockFailureEndpoint.expectedBodiesReceived(messageInputBody);
mockFailureEndpoint.expectedMessageCount(1);
mockSuccessEndpoint.expectedMessageCount(0);
try {
// Create and Send message to input queue
camelContext.addRoutes(
createRoute(startEndpointUri,
changeRequestProcessor,
successEndpointUri,
errorEndpointUri
)
);
producerTemplate.sendBody(startEndpointUri, messageInputBody);
Assert.fail("Should have thrown a RuntimeCamelException");
} catch (RuntimeCamelException e) {
assertIsInstanceOf(e, RuntimeCamelException.class);
}
// this is optional.
testMocksAreValid();
MockEndpoint.assertIsSatisfied(mockFailureEndpoint,
mockSuccessEndpoint);
}
*
Now here is the kicker, when I have another test method in this class
running with the same endpoint values:
*@Test(groups = {"functional"})
@Parameters({"startEndpointUri", "successEndpointUri",
"errorEndpointUri", "messageInputBody"})
public void testCreateValidRequest(String startEndpointUri,
String successEndpointUri,
String errorEndpointUri,
String messageInputBody
)
throws Exception {
MockEndpoint mockSuccessEndpoint =
getMockEndpoint(successEndpointUri);
MockEndpoint mockFailureEndpoint =
getMockEndpoint(errorEndpointUri);
mockSuccessEndpoint.expectedMessageCount(1);
mockSuccessEndpoint.message(0).header(Constants.REQUEST_DESTINATION).isEqualTo(Constants.CHANNEL_GG_CS_COMMAND_CLUSTER);
mockFailureEndpoint.expectedMessageCount(0);
try {
// setup RouteBuilder...
// Create and Send message to input queue
camelContext.addRoutes(
createRoute(startEndpointUri,
changeRequestProcessor,
successEndpointUri,
errorEndpointUri
)
);
// Create and Send message to input queue
producerTemplate.sendBodyAndHeader(startEndpointUri,
messageInputBody, Constants.COMMAND_TYPE, Constants.PROVISION);
} catch (RuntimeCamelException e) {
Assert.fail("Should have thrown a RuntimeCamelException");
}
testMocksAreValid();
MockEndpoint.assertIsSatisfied(mockSuccessEndpoint,
mockFailureEndpoint);
}
*
*
I get the following errors:*
*<test name="InvalidChangeRequest-bad-commandType">
.....
<exception class="java.lang.AssertionError">
<message>
<![CDATA[mock:error Received message count. Expected: <1> but
was: <2>]]>
</message>
*
So the mock:error queue is not getting cleaned up and there is an extra
message.
So how on earth do I DELETE or RESET or CLEAR this mock? I have spun through
each one and ran mock.reset() but that did not help.
Re: Trying to understand how to deal with process() errors and creating an exceptionChannel for bad messages.
Posted by Mick Knutson <mk...@baselogic.com>.
As I am hacking more on this, it appears that the issue is the starting
endpoint per each test method. If I change the starting endpoint for each
test method, everything works fine.
On Wed, Oct 1, 2008 at 6:24 PM, Mick Knutson <mk...@baselogic.com> wrote:
> So I have gotten a bit further, but not all the way.
>
> It appears that if I have a unit test that is overloaded as I can do in
> TestNG, then I can seemingly re-use the same mock endpoints.
> Here is a valid test that is overloaded 3 different times:
>
> *@Test(groups = {"functional"})
> @Parameters({"startEndpointUri", "successEndpointUri",
> "errorEndpointUri", "messageInputBody"})
> public void testCreateInvalidChangeRequest(String startEndpointUri,
> String successEndpointUri,
> String errorEndpointUri,
> String messageInputBody
> )
> throws Exception {
>
> MockEndpoint mockSuccessEndpoint =
> getMockEndpoint(successEndpointUri);
> MockEndpoint mockFailureEndpoint =
> getMockEndpoint(errorEndpointUri);
>
> mockFailureEndpoint.expectedBodiesReceived(messageInputBody);
> mockFailureEndpoint.expectedMessageCount(1);
> mockSuccessEndpoint.expectedMessageCount(0);
>
> try {
> // Create and Send message to input queue
> camelContext.addRoutes(
> createRoute(startEndpointUri,
> changeRequestProcessor,
> successEndpointUri,
> errorEndpointUri
> )
> );
>
> producerTemplate.sendBody(startEndpointUri, messageInputBody);
>
> Assert.fail("Should have thrown a RuntimeCamelException");
> } catch (RuntimeCamelException e) {
> assertIsInstanceOf(e, RuntimeCamelException.class);
> }
>
> // this is optional.
> testMocksAreValid();
>
> MockEndpoint.assertIsSatisfied(mockFailureEndpoint,
> mockSuccessEndpoint);
> }
> *
>
>
>
> Now here is the kicker, when I have another test method in this class
> running with the same endpoint values:
>
>
> *@Test(groups = {"functional"})
> @Parameters({"startEndpointUri", "successEndpointUri",
> "errorEndpointUri", "messageInputBody"})
> public void testCreateValidRequest(String startEndpointUri,
> String successEndpointUri,
> String errorEndpointUri,
> String messageInputBody
> )
> throws Exception {
> MockEndpoint mockSuccessEndpoint =
> getMockEndpoint(successEndpointUri);
> MockEndpoint mockFailureEndpoint =
> getMockEndpoint(errorEndpointUri);
>
> mockSuccessEndpoint.expectedMessageCount(1);
>
> mockSuccessEndpoint.message(0).header(Constants.REQUEST_DESTINATION).isEqualTo(Constants.CHANNEL_GG_CS_COMMAND_CLUSTER);
>
> mockFailureEndpoint.expectedMessageCount(0);
>
> try {
> // setup RouteBuilder...
> // Create and Send message to input queue
> camelContext.addRoutes(
> createRoute(startEndpointUri,
> changeRequestProcessor,
> successEndpointUri,
> errorEndpointUri
> )
> );
>
> // Create and Send message to input queue
> producerTemplate.sendBodyAndHeader(startEndpointUri,
> messageInputBody, Constants.COMMAND_TYPE, Constants.PROVISION);
>
> } catch (RuntimeCamelException e) {
> Assert.fail("Should have thrown a RuntimeCamelException");
> }
>
> testMocksAreValid();
>
> MockEndpoint.assertIsSatisfied(mockSuccessEndpoint,
> mockFailureEndpoint);
> }
> *
>
> *
> I get the following errors:*
>
> *<test name="InvalidChangeRequest-bad-commandType">
> .....
> <exception class="java.lang.AssertionError">
> <message>
> <![CDATA[mock:error Received message count. Expected: <1>
> but was: <2>]]>
> </message>
> *
>
>
> So the mock:error queue is not getting cleaned up and there is an extra
> message.
>
> So how on earth do I DELETE or RESET or CLEAR this mock? I have spun
> through each one and ran mock.reset() but that did not help.
>
>
>
>
>
>
--
---
Thank You…
Mick Knutson
BASE Logic, inc.
(415) 354-4215
Website: http://baselogic.com
Blog: http://baselogic.com/blog
BLiNC Magazine: http://blincmagazine.com
Linked IN: http://linkedin.com/in/mickknutson
DJ Mick: http://djmick.com
MySpace: http://myspace.com/mickknutson
Vacation Rental: http://tahoe.baselogic.com