简体   繁体   中英

How can i use CDI with CamelTestSupport

I have a main test with Camel.

@RunWith(EJBContainerRunner.class)
public class TestIntegrationBeanCtrlContrat extends CamelTestSupport {

@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;

@Produce(uri = "direct:start")
protected ProducerTemplate template;

@Override
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        @Override
        public void configure() {

            this.from("direct:start")
                    .bean(MappingCB2ABean.class, "mapToObj")
                    .bean(BeanCalculChampsSpecif.class, "beanChampsSpecif")
                    .bean(BeanAlimContrat.class, "beanAlimentationValContrat")
                    .bean(BeanInitDateForce.class, "initialisation")
                    .bean(CtrlContratBean.class, "ctrlContrat")
                    .to("mock:result");

        }
    };
}

@Test
public void test_ControleBean_Integration() throws Exception {

    // Important : pensez à changer le nom du fichier ou répertoire où se trouve le fichier test

    this.context.getShutdownStrategy().setTimeout(3000000L);
    this.template.sendBody("direct:start", new File(
            "C:/Files/spool_in/R2-CB2A-EM22055.REMCB2A.D20140505.H103059.FORCEDT20141210"));

}

 }

Each bean works fine, but when i add a bean which use a CDI component, it doesn't work.

The bean is CtrlContratBean.

public class CtrlContratBean {

@Inject
DateBusinessManager dateBusinessManager;

/**
 * Bean Ctrl Contrat
 * 
 * @param exchange
 * @return
 */
public List<ContratControllable> ctrlContrat(final Exchange exchange) {
    this.dateBusinessManager.getFirstDayOfMonth(
    Integer.valueOf(TypeCalendar.CALENDAIRE.getValueCalendar()), valueForceDt);}

The value of dateBusinessManager Still NULL. The dateBusinnesManager comes from another projet which connect to a BDD to recover Data.

I don't know why it doesn't work , further i add @RunWith(EJBContainerRunner.class) to the Test Class to Run the Ejb Container.

Any ideas ? Thxs

I think you may need to extends the CdiTestSupport instead of CamelTestSupport. The key point is find the right CdiContainer to use, as I didn't see the code of EJBContainerRunner, you may need to the work there if the CdiTestSupport doesn't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM