CDI and ApplicationComposer: finally easy to test deltaspike with AppComposer


OpenEJB/TomEE ApplicationComposer design is to describe a test application with an in memory model close to the xml EE one (Beans for beans.xml, EjbJar for ejb-jar.xml…).

But when it comes to CDI and since it was mainly designed for small apps it is hard to say “I have a CDI dependency/library”.

The more obvious use case is DeltaSpike!

To make it easier we added @Jars recently.

Idea is to list dependencies to include in the test.

Here a sample:

import org.apache.openejb.itest.failover.ejb.Calculator;
import org.apache.openejb.jee.WebApp;
import org.apache.openejb.junit.ApplicationComposer;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ejb.EJB;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@RunWith(ApplicationComposer.class)
public class AppComposerJarsTest {
    @Module
    @Jars("deltaspike-")
    public WebApp war() {
        return new WebApp();
    }

    @EJB
    private Calculator calculator;

    @Test
    public void externalBeanFound() {
        assertNotNull(calculator);
        assertEquals(3, calculator.sum(1, 2));
    }
}

This will add as dependency of the app all deltaspike-* jars.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s