cchacin / jee-testcontainers

testcontainers.org for Jakarta EE application servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JEE Testcontainers

download

Simply start and stop Jakarta EE containers and deploy applications for your integration tests. This is an extension to Testcontainers for Jakarta EE application servers, so Docker is used under the hood, but you don’t need to write, e.g., a Dockerfile.

Prototypical Example:

@Testcontainers
public class MyAppIT {
    @Container static JeeContainer CONTAINER = JeeContainer.create()
        .withDeployment("target/my-app.war");

    @Test void shouldGetStatusResponse() {
        String body = CONTAINER.target().request(APPLICATION_JSON_TYPE).get(String.class);

        then(body).isEqualTo("{\"status\":\"okay\"}");
    }
}

Or if you have an implementation of Microprofile Rest Client on your test classpath:

@Testcontainers
public class MyAppIT {
    @Container static JeeContainer CONTAINER = JeeContainer.create()
        .withDeployment("target/my-app.war");

    @Data public static class Status {
        String condition;
    }

    public interface StatusApi {
        @GET Status getStatus();
    }

    @Test void shouldGetStatusResponse() {
        StatusApi body = CONTAINER.restClient(StatusApi.class);

        Status status = body.getStatus();

        then(status.getCondition()).isEqualTo("okay");
    }
}

The console output of the container is piped to the test’s output, STDOUT in green and STDERR in blue.

Deployments

As seen in the prototypical example above, you can install an application by calling .withDeployment(<file>).

Instead of a local file, you can also install from an URL. Or you can use a maven URN like urn:mvn:org.jolokia:jolokia-war-unsecured:1.6.3:war.

Configuration

Set the system property jee-testcontainer to one of the following keys to select the corresponding container. Ideally you shouldn’t have to care about what server your application runs on, or you may even want to test it in multiple containers. Then you can run your test suite in your CI pipeline with different system properties.

You can append a tag to the jee-testcontainer separated by a colon :. This is often simply the version of the container; e.g. wildfly:18.0.1.Final.

Key Container Docker Image Notes

wildfly

WildFly

jboss/wildfly

default container, not an 'official' image

open-liberty

Open Liberty

open-liberty

tomee

TomEE

tomee

Official image but currently outdated

payara

Payara

payara

not an 'official' image

Set the system property testcontainer-reuse to true to let the container run as long as the config doesn’t change. This feature is in beta of testcontainers.org (see PR-1781).

Limitations

You can’t currently configure your application, e.g. by adding data sources. I will add that when I need it, which may be very soon ;-)

About

testcontainers.org for Jakarta EE application servers

License:Apache License 2.0


Languages

Language:Java 100.0%