1

I am trying to follow the guide here to learn to run integration tests which is exactly what we need functionality wise. https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices

In our org the way things are setup is that we produce a jar file instead of a war file at this phase of the project. Then another unrelated devops project which we do not control over builds the war file from this jar file with various env specific properties and deploys it.

https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices/pom.xml

    <groupId>io.openliberty.guides</groupId>
    <artifactId>backendServices</artifactId>
    **<packaging>jar</packaging>**
    <version>1.0-SNAPSHOT</version>

The question is how do we tell openliberty ideally programmatically to turn the jar file into a war file to deploy the binary and then use it for integration testing ? for e.g. run the below test https://github.com/OpenLiberty/guide-jpa-intro/blob/prod/finish/backendServices/src/test/java/it/io/openliberty/guides/event/EventEntityIT.java

Javadee
  • 139
  • 10
  • Open Liberty doesn't have any functionality to transform the packaging of applications from .jar to .war. You'd likely need to build this into your maven build lifecycle at the `package` step. – KyleAure Jul 10 '23 at 13:47

1 Answers1

2

You could use a separate test WAR module which uses your JAR module as a dependency.

This WAR module could include:

  • Liberty config for your integration test server (src/main/liberty/config/server.xml)
  • The integration test Java files (**IT.java)
  • The liberty-maven-plugin config to assist in installing the Liberty test server and deploying your application during IT
  • The failsafe plugin config for integration testing

This shouldn't prevent you from separately building another WAR (e.g. production) through some other DevOps process which ignores this test WAR.

ALTERNATIVE

It would also be possible to use the separate test WAR module while keeping the integration test source **IT.java within the JAR module, if you feel that is a better organization of your overall project. You would want then to configure the failsafe plugin to run IT against the test WAR module deploying the app to the test Liberty server and NOT configure the failsafe plugin to run IT in the context of the JAR module build.

I think it might be better though to include the integration test source within the WAR module since it's using endpoints (e.g. host/port) which are tightly-coupled to the Liberty server. You could use a single "multi-module" Maven project to allow all of the code to be grouped into a single source repository (Git), possibly using Maven "profiles" to control whether to build and execute the IT logic or just to build the JAR dependency (for use by your other DevOps process).

Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
  • Thanks for the answer. I have set it up in a new module. How would you run some independent java process's before the openliberty is launched in dev mode for integration testing? for e.g. we want to start a "mock" external rest service and an external DB(launched from java code) before openliberty is actually started up. – Javadee Aug 08 '23 at 13:23
  • 1
    You could use pre-integration-test and the exec-maven-plugin. If you have containerized it you could use pre-integration-test and the docker-maven-plugin, or you could use an approach with Testcontainers. If you want to discuss you might want to post a new question, or try out Gitter chat room: https://app.gitter.im/#/room/#OpenLiberty_developer-experience:gitter.im – Scott Kurz Aug 08 '23 at 13:57