Skip to content

Instantly share code, notes, and snippets.

@mzimecki
Last active May 27, 2017 19:25
Show Gist options
  • Save mzimecki/4ea8487c1f21bebd017d7abdd0176b95 to your computer and use it in GitHub Desktop.
Save mzimecki/4ea8487c1f21bebd017d7abdd0176b95 to your computer and use it in GitHub Desktop.
Unit tests
private Exchange createExchange(final int redeliveryCount) {
final Exchange exchange = ExchangeBuilder.anExchange(context()).build();
exchange.getIn().setHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, redeliveryCount);
return exchange;
}
@Test
public void should_increment_redelivery_count_and_send_to_jms_endpoint() throws Exception {
configureMockEndpoint();
final Exchange requestExchange = createExchange(0);
final Exchange resultExchange = template.send("direct:deadLetterQueueMock", requestExchange);
final int redeliveryCountResult = resultExchange.getIn().getHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, Integer.class).intValue();
assertEquals(1, redeliveryCountResult);
assertEquals(TEST_BODY_PAYLOAD, resultExchange.getIn().getBody(String.class));
}
@Test
public void should_not_increment_redelivery_count_and_not_reach_jms_enpoint() throws Exception {
configureMockEndpoint();
final Exchange requestExchange = createExchange(6);
final Exchange resultExchange = template.send("direct:deadLetterQueueMock", requestExchange);
final int redeliveryCountResult = resultExchange.getIn().getHeader(ServiceConstants.REDELIVERY_COUNT_HEADER_NAME, Integer.class).intValue();
assertEquals(6, redeliveryCountResult);
assertNull(resultExchange.getIn().getBody(String.class));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment