Search in sources :

Example 1 with HelloBean

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");
    }
}
Also used : InitialContext(javax.naming.InitialContext) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Context(javax.naming.Context) CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) NameNotFoundException(javax.naming.NameNotFoundException) HelloBean(org.wildfly.camel.test.common.types.HelloBean) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException)

Aggregations

Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 HelloBean (org.wildfly.camel.test.common.types.HelloBean)1 WildFlyCamelContext (org.wildfly.extension.camel.WildFlyCamelContext)1