use of org.wildfly.camel.test.common.types.HelloBean in project wildfly-camel by wildfly-extras.
the class JNDIIntegrationTest method assertBeanBinding.
private void assertBeanBinding(WildFlyCamelContext camelctx) throws NamingException, Exception {
InitialContext inicxt = new InitialContext();
String bindingName = CamelConstants.CAMEL_CONTEXT_BINDING_NAME + "/" + camelctx.getName();
Context jndictx = camelctx.getNamingContext();
jndictx.bind("helloBean", new HelloBean());
try {
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").bean("helloBean");
}
});
camelctx.start();
try {
// Assert that the context is bound into JNDI after start
CamelContext lookup = (CamelContext) inicxt.lookup(bindingName);
Assert.assertSame(camelctx, lookup);
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", "Kermit", String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
camelctx.stop();
}
// Assert that the context is unbound from JNDI after stop
try {
// Removing an msc service is asynchronous
Thread.sleep(200);
inicxt.lookup(bindingName);
Assert.fail("NameNotFoundException expected");
} catch (NameNotFoundException ex) {
// expected
}
} finally {
jndictx.unbind("helloBean");
}
}
Aggregations