I have the following Spring route:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:topic:inbox" />
<choice>
<when>
<simple>${in.header.Value}</simple>
<log message="Cc: ${in.header.Value}" />
</when>
</choice>
<to uri="mock:result" />
</route>
</camelContext>
I have the requirement to use Spring Testing (CamelSpringJUnit4ClassRunner), although I have found easy to understand examples on how to test the condition with Java DSL. My Test Class is like this:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(locations = "file:src/main/resources/META-INF/spring/camel-context-activemq-embedded.xml")
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
public class MyTest{
private Logger LOG = LogManager.getLogger(MyTest.class.getName());
protected Exchange exchange;
protected CustomComponent customComponent= new CustomComponent();
@Produce(uri = "activemq:topic:inbox")
protected ProducerTemplate template;
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Test
public void tes1() throws InterruptedException {
String headerValue= MyComponent.Value;
EmailAddress recipients = new EmailAddress("recipient@example.com");
template.sendBodyAndHeader("activemq:topic:inbox", recipients.toString(), headerValue);
resultEndpoint.expectedBodiesReceived(headerValue);
resultEndpoint.expectedHeaderReceived("header value", headerValue);
resultEndpoint.expectedMessageCount(1);
}
I am struggling to understand how to test the actual condition dictated by the CBR, but more importantly I am doubting whether this is even the right way to test it. MyComponent.VALUEConstant is a property specified in my custom component and the above test is actually passing. However, if I instantiated the headerValue with a different property on my component and therefore the condition is supposed to fail, the test passes. Can you please help?
Thank you,
I