From ec8926ed8309011d585a40ae66fc7a3489696d59 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Fri, 8 Sep 2023 15:45:22 -0400 Subject: [PATCH 01/11] Add Open Liberty profile --- README.md | 25 ++++ pom.xml | 67 +++++++++ src/main/liberty/config/bootstrap.properties | 6 + src/main/liberty/config/server.xml | 142 +++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 src/main/liberty/config/bootstrap.properties create mode 100644 src/main/liberty/config/server.xml diff --git a/README.md b/README.md index 0b3bfa92..3f3a390d 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,31 @@ To set up in Visual Studio Code, follow these steps: * Open the directory that contains the code in Visual Studio Code. Visual Studio Code will do the rest for you, it will automatically configure a Maven project. Proceed with clean/building the application. * After the project is built (which will take a while the very first time as Maven downloads dependencies), simply run the generated `cargo-tracker.war` file under the `target` directory using Payara Tools. +## Getting Started with Open Liberty + +To set up the project with Open Liberty and Maven: + +* Ensure you are running Java SE 11, or Java SE 17 (IBM Semeru recommended with Open Liberty: https://developer.ibm.com/languages/java/semeru-runtimes/downloads/ -> select from the version dropdown menu. +* Make sure `JAVA_HOME` is set. +* Navigate to the cargotracker directory and develop the application with Liberty Maven Plugin: `mvn -P openliberty liberty:dev`. + +You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as these dont affect the application functionality. + +* The application should start without any additional errors and you can view it at http://localhost:8080/cargo-tracker. + +To set up the project with Open Liberty and Eclipse IDE: + +* Ensure that you have either Eclipse version 2022-06 or later. +* Follow the instructions in the Github repository to install Liberty Tools for Eclipse. https://github.com/OpenLiberty/liberty-tools-eclipse/blob/main/docs/installation.md +* Import the Cargo Tracker project via `File` -> `Import` -> `Existing Maven Projects` and follow the rest of the steps in the configuration wizard. +* Find the application on the Liberty dashboard through Liberty Tools. +* Right click the project name and start the application with parameters (the second start option): +* Specify the Liberty profile by using `-P openliberty` and then starting the application by selecting OK. +* The application should start without any further issues beside the cosmetic warnings related to DB setup and message endpoint initialization. +* You can view the app at http://localhost:8080/cargo-tracker. + +NOTE: On Mac OS, if the `mvn` command is not found by Eclipse, users must start Eclipse through a folder by navigating to their Eclipse version (for example, eclipse/jee-2022-06), right-clicking the Eclipse icon, then selecting `Show Package Contents`. Then, navigate to `Contents` -> `MacOS` and start Eclipse using the executable file found there. The Maven path should be resolved. + ## Exploring the Application After the application runs, it will be available at: diff --git a/pom.xml b/pom.xml index a6f83883..d1819442 100644 --- a/pom.xml +++ b/pom.xml @@ -296,5 +296,72 @@ + + openliberty + + false + + + UTF-8 + UTF-8 + org.hsqldb.jdbc.JDBCDriver + jdbc:hsqldb:file:./cargo-tracker-data/cargo-tracker-database;create=true + + + + + org.eclipse.microprofile + microprofile + 6.0 + pom + provided + + + jakarta.platform + jakarta.jakartaee-api + 10.0.0 + provided + + + org.hsqldb + hsqldb + 2.7.2 + provided + + + org.glassfish.jersey.core + jersey-server + 3.1.2 + provided + + + + + + + + io.openliberty.tools + liberty-maven-plugin + 3.8.2 + + + + ${project.build.directory}/liberty/wlp/usr/shared/resources + + org.hsqldb + hsqldb + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0 + + + + \ No newline at end of file diff --git a/src/main/liberty/config/bootstrap.properties b/src/main/liberty/config/bootstrap.properties new file mode 100644 index 00000000..95fb375e --- /dev/null +++ b/src/main/liberty/config/bootstrap.properties @@ -0,0 +1,6 @@ +org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true +com.ibm.ws.logging.max.file.size=100 +com.ibm.ws.logging.max.files=3 +default.http.port=8080 +default.https.port=8081 +# com.ibm.ws.logging.trace.specification=*=info=enabled:logservice=all:com.ibm.ws.jaxrs*=all:com.ibm.websphere.jaxrs*=all:org.apache.cxf.*=all:EJBContainer=all:Injection=all diff --git a/src/main/liberty/config/server.xml b/src/main/liberty/config/server.xml new file mode 100644 index 00000000..1dd8ff4e --- /dev/null +++ b/src/main/liberty/config/server.xml @@ -0,0 +1,142 @@ + + + + + batch-2.1 + beanValidation-3.0 + cdi-4.0 + enterpriseBeansLite-4.0 + enterpriseBeansPersistentTimer-4.0 + faces-4.0 + jdbc-4.3 + jndi-1.0 + jsonb-3.0 + mdb-4.0 + messaging-3.1 + messagingClient-3.0 + messagingServer-3.0 + persistence-3.1 + restfulWS-3.1 + xmlBinding-4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ff2572a01dfb6ea699f620934dead5bc590d7a41 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Tue, 12 Sep 2023 14:11:15 -0400 Subject: [PATCH 02/11] temporarily remove instructions for Eclipse IDE --- README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/README.md b/README.md index 3f3a390d..eaedb823 100644 --- a/README.md +++ b/README.md @@ -51,18 +51,6 @@ You can safely ignore the shrinkwrap features warning, message-driven bean warni * The application should start without any additional errors and you can view it at http://localhost:8080/cargo-tracker. -To set up the project with Open Liberty and Eclipse IDE: - -* Ensure that you have either Eclipse version 2022-06 or later. -* Follow the instructions in the Github repository to install Liberty Tools for Eclipse. https://github.com/OpenLiberty/liberty-tools-eclipse/blob/main/docs/installation.md -* Import the Cargo Tracker project via `File` -> `Import` -> `Existing Maven Projects` and follow the rest of the steps in the configuration wizard. -* Find the application on the Liberty dashboard through Liberty Tools. -* Right click the project name and start the application with parameters (the second start option): -* Specify the Liberty profile by using `-P openliberty` and then starting the application by selecting OK. -* The application should start without any further issues beside the cosmetic warnings related to DB setup and message endpoint initialization. -* You can view the app at http://localhost:8080/cargo-tracker. - -NOTE: On Mac OS, if the `mvn` command is not found by Eclipse, users must start Eclipse through a folder by navigating to their Eclipse version (for example, eclipse/jee-2022-06), right-clicking the Eclipse icon, then selecting `Show Package Contents`. Then, navigate to `Contents` -> `MacOS` and start Eclipse using the executable file found there. The Maven path should be resolved. ## Exploring the Application From 21fba0dca788434327a573adb2de0895efb4b90b Mon Sep 17 00:00:00 2001 From: David Mueller <48686014+dmuelle@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:04:52 -0400 Subject: [PATCH 03/11] Update Open Liberty section of README.md (#2) * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * add VS Code instructions * Update Open Liberty section of README.md --------- Co-authored-by: Gilbert Kwan --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index eaedb823..8d60f274 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,29 @@ To set up in Visual Studio Code, follow these steps: To set up the project with Open Liberty and Maven: -* Ensure you are running Java SE 11, or Java SE 17 (IBM Semeru recommended with Open Liberty: https://developer.ibm.com/languages/java/semeru-runtimes/downloads/ -> select from the version dropdown menu. -* Make sure `JAVA_HOME` is set. -* Navigate to the cargotracker directory and develop the application with Liberty Maven Plugin: `mvn -P openliberty liberty:dev`. - -You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as these dont affect the application functionality. - -* The application should start without any additional errors and you can view it at http://localhost:8080/cargo-tracker. +* Ensure you are running Java SE 11, or Java SE 17. IBM Semeru is the recommended Java SDK for Open Liberty. Go to [IBM Semeru Runtimes Downloads](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) and select Java 11 or Java 17 from the version dropdown menu. +* Make sure the `JAVA_HOME`environment variable is set on your system. +* Navigate to the `cargotracker` directory and develop the application with the [Liberty Maven Plugin](https://github.com/OpenLiberty/ci.maven#cimaven--): `mvn -P openliberty liberty:dev`. +* You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as they don't affect the application functionality. +* The application starts without any additional errors and you can visit it at the http://localhost:8080/cargo-tracker URL. + +To set up the project with Open Liberty in Visual Studio Code: + +* Ensure you are running [Visual Studio Code](https://code.visualstudio.com/download) with Java 17. +* Install [Liberty Tools for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=Open-Liberty.liberty-dev-vscode-ext). +* Open the Cargo Tracker project by selecting **Explorer** > **Open Folder**. Select the `cargotracker` directory. +* The `cargo-tracker` project appears under the `LIBERTY DASHBOARD` extension in the Explorer sidebar. +* Right-click the `cargo-tracker` project and select `Start...` to start the application. Type `-P openliberty` in the pop-up entry field and then press the Enter/return key. +* A terminal window in the IDE opens and the Liberty Maven Plugin starts the application. Liberty is running in dev mode. +* You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as they don't affect the application functionality. +* You can visit the application at http://localhost:8080/cargo-tracker when you see the following message at the terminal: +``` +************************************************************************ +[INFO] * Liberty is running in dev mode. +... +[INFO] Source compilation was successful. +[INFO] Tests compilation was successful. +``` ## Exploring the Application From 080987b6cef7524de3a8db9905b5a97ed81f9523 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Tue, 19 Sep 2023 17:59:34 -0400 Subject: [PATCH 04/11] add integration tests for the rest apis --- pom.xml | 33 +++++++------ .../rest/GraphTraversalServiceIT.java | 44 +++++++++++++++++ .../rest/HandlingReportServiceIT.java | 40 ++++++++++++++++ .../rest/RealtimeCargoTrackingServiceIT.java | 48 +++++++++++++++++++ 4 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java create mode 100644 src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java create mode 100644 src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java diff --git a/pom.xml b/pom.xml index 7c9e9b10..78262535 100644 --- a/pom.xml +++ b/pom.xml @@ -435,19 +435,6 @@ - - org.eclipse.microprofile - microprofile - 6.0 - pom - provided - - - jakarta.platform - jakarta.jakartaee-api - 10.0.0 - provided - org.hsqldb hsqldb @@ -460,6 +447,19 @@ 3.1.2 provided + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.2.5.Final + test + + + org.glassfish.jersey.media + jersey-media-sse + 3.1.3 + test + @@ -484,7 +484,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.1.2 + + + org/**/BookingServiceTest.java + + diff --git a/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java new file mode 100644 index 00000000..b21388be --- /dev/null +++ b/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java @@ -0,0 +1,44 @@ +package org.eclipse.cargotracker.rest; + +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.List; +import org.eclipse.pathfinder.api.TransitEdge; +import org.eclipse.pathfinder.api.TransitPath; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class GraphTraversalServiceIT { + + @Test + public void testShortestPath() { + + SimpleDateFormat f = new SimpleDateFormat("MMddyyyy"); + Calendar nextYear = Calendar.getInstance(); + nextYear.add(Calendar.YEAR, 1); + String deadline = f.format(nextYear.getTime()); + + Client client = ClientBuilder.newClient(); + WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/graph-traversal/shortest-path"); + WebTarget shortPathTarget = webTarget.queryParam("origin", new Object[] { "USNYC" }).queryParam("destination", new Object[] { "CNHKG" }).queryParam("deadline", new Object[] { deadline }); + Response response = shortPathTarget.request(new String[] { "application/json" }).get(); + Assertions.assertEquals(200, response.getStatus(), "Unexpected response code"); + + String responseStr = (String)response.readEntity(String.class); + Jsonb jsonb = JsonbBuilder.create(); + TransitPath[] transitPaths = (TransitPath[]) jsonb.fromJson(responseStr, TransitPath[].class); + Assertions.assertTrue((transitPaths.length > 0), "Expected at least 1 transit path."); + for (TransitPath p : transitPaths) { + List edges = p.getTransitEdges(); + Assertions.assertTrue((edges.size() > 0), "Expected at least 1 transit edge."); + } + } + +} + diff --git a/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java new file mode 100644 index 00000000..7cf4addf --- /dev/null +++ b/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java @@ -0,0 +1,40 @@ +package org.eclipse.cargotracker.rest; + +import jakarta.json.bind.JsonbBuilder; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Response; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Properties; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class HandlingReportServiceIT { + + @Test + public void testHandlingRreports() { + + SimpleDateFormat f = new SimpleDateFormat("M/dd/yyyy"); + Calendar nextYear = Calendar.getInstance(); + nextYear.add(Calendar.YEAR, 1); + String completionDate = f.format(nextYear.getTime()); + + Properties p = new Properties(); + p.put("completionTime", completionDate + " 3:3 a.m."); + p.put("trackingId", "ABC123"); + p.put("eventType", "LOAD"); + p.put("unLocode", "CNHGH"); + p.put("voyageNumber", "0100S"); + String jsonParms = JsonbBuilder.create().toJson(p); + + Client client = ClientBuilder.newClient(); + WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/handling/reports"); + Response response = webTarget.request().post(Entity.entity(jsonParms, "application/json")); + Assertions.assertEquals(204, response.getStatus(), "Unexpected response code"); + } + +} + diff --git a/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java new file mode 100644 index 00000000..c920947f --- /dev/null +++ b/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java @@ -0,0 +1,48 @@ +package org.eclipse.cargotracker.rest; + +import java.util.ArrayList; +import java.util.Map; + +import org.glassfish.jersey.media.sse.EventInput; +import org.glassfish.jersey.media.sse.InboundEvent; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; + +public class RealtimeCargoTrackingServiceIT { + + @Test + public void testGetCargo() { + Client client = ClientBuilder.newClient(); + WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/cargo"); + + EventInput eventInput = (EventInput)webTarget.request().get(EventInput.class); + Jsonb jsonb = JsonbBuilder.create(); + ArrayList trackingIDs = new ArrayList(); + int i = 0; + while ((!eventInput.isClosed()) && (i < 4)) { + InboundEvent inboundEvent = (InboundEvent)eventInput.read(); + if (inboundEvent == null) { + break; + } + String eventStr = (String)inboundEvent.readData(String.class); + Map cargoRoute = (Map) jsonb.fromJson(eventStr, Map.class); + trackingIDs.add(cargoRoute.get("trackingId").toString()); + i++; + } + eventInput.close(); + Assertions.assertEquals(4, trackingIDs.size(), "Expected at least 4 cargo routes"); + Assertions.assertTrue( + (trackingIDs.contains("ABC123")) || + (trackingIDs.contains("JKL567")) || + (trackingIDs.contains("DEF789")) || + (trackingIDs.contains("MNO456")), + "Expected either one of the tracking IDs"); + } + +} \ No newline at end of file From 21ece40f3e866e43494c2e56d0f6f68146d70850 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Wed, 20 Sep 2023 08:44:32 -0400 Subject: [PATCH 05/11] remove integration tests --- .../rest/GraphTraversalServiceIT.java | 44 ----------------- .../rest/HandlingReportServiceIT.java | 40 ---------------- .../rest/RealtimeCargoTrackingServiceIT.java | 48 ------------------- 3 files changed, 132 deletions(-) delete mode 100644 src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java delete mode 100644 src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java delete mode 100644 src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java diff --git a/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java deleted file mode 100644 index b21388be..00000000 --- a/src/test/java/org/eclipse/cargotracker/rest/GraphTraversalServiceIT.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.eclipse.cargotracker.rest; - -import jakarta.json.bind.Jsonb; -import jakarta.json.bind.JsonbBuilder; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.Response; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.List; -import org.eclipse.pathfinder.api.TransitEdge; -import org.eclipse.pathfinder.api.TransitPath; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class GraphTraversalServiceIT { - - @Test - public void testShortestPath() { - - SimpleDateFormat f = new SimpleDateFormat("MMddyyyy"); - Calendar nextYear = Calendar.getInstance(); - nextYear.add(Calendar.YEAR, 1); - String deadline = f.format(nextYear.getTime()); - - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/graph-traversal/shortest-path"); - WebTarget shortPathTarget = webTarget.queryParam("origin", new Object[] { "USNYC" }).queryParam("destination", new Object[] { "CNHKG" }).queryParam("deadline", new Object[] { deadline }); - Response response = shortPathTarget.request(new String[] { "application/json" }).get(); - Assertions.assertEquals(200, response.getStatus(), "Unexpected response code"); - - String responseStr = (String)response.readEntity(String.class); - Jsonb jsonb = JsonbBuilder.create(); - TransitPath[] transitPaths = (TransitPath[]) jsonb.fromJson(responseStr, TransitPath[].class); - Assertions.assertTrue((transitPaths.length > 0), "Expected at least 1 transit path."); - for (TransitPath p : transitPaths) { - List edges = p.getTransitEdges(); - Assertions.assertTrue((edges.size() > 0), "Expected at least 1 transit edge."); - } - } - -} - diff --git a/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java deleted file mode 100644 index 7cf4addf..00000000 --- a/src/test/java/org/eclipse/cargotracker/rest/HandlingReportServiceIT.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.eclipse.cargotracker.rest; - -import jakarta.json.bind.JsonbBuilder; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.Response; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Properties; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class HandlingReportServiceIT { - - @Test - public void testHandlingRreports() { - - SimpleDateFormat f = new SimpleDateFormat("M/dd/yyyy"); - Calendar nextYear = Calendar.getInstance(); - nextYear.add(Calendar.YEAR, 1); - String completionDate = f.format(nextYear.getTime()); - - Properties p = new Properties(); - p.put("completionTime", completionDate + " 3:3 a.m."); - p.put("trackingId", "ABC123"); - p.put("eventType", "LOAD"); - p.put("unLocode", "CNHGH"); - p.put("voyageNumber", "0100S"); - String jsonParms = JsonbBuilder.create().toJson(p); - - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/handling/reports"); - Response response = webTarget.request().post(Entity.entity(jsonParms, "application/json")); - Assertions.assertEquals(204, response.getStatus(), "Unexpected response code"); - } - -} - diff --git a/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java b/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java deleted file mode 100644 index c920947f..00000000 --- a/src/test/java/org/eclipse/cargotracker/rest/RealtimeCargoTrackingServiceIT.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.eclipse.cargotracker.rest; - -import java.util.ArrayList; -import java.util.Map; - -import org.glassfish.jersey.media.sse.EventInput; -import org.glassfish.jersey.media.sse.InboundEvent; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import jakarta.json.bind.Jsonb; -import jakarta.json.bind.JsonbBuilder; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.WebTarget; - -public class RealtimeCargoTrackingServiceIT { - - @Test - public void testGetCargo() { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/cargo"); - - EventInput eventInput = (EventInput)webTarget.request().get(EventInput.class); - Jsonb jsonb = JsonbBuilder.create(); - ArrayList trackingIDs = new ArrayList(); - int i = 0; - while ((!eventInput.isClosed()) && (i < 4)) { - InboundEvent inboundEvent = (InboundEvent)eventInput.read(); - if (inboundEvent == null) { - break; - } - String eventStr = (String)inboundEvent.readData(String.class); - Map cargoRoute = (Map) jsonb.fromJson(eventStr, Map.class); - trackingIDs.add(cargoRoute.get("trackingId").toString()); - i++; - } - eventInput.close(); - Assertions.assertEquals(4, trackingIDs.size(), "Expected at least 4 cargo routes"); - Assertions.assertTrue( - (trackingIDs.contains("ABC123")) || - (trackingIDs.contains("JKL567")) || - (trackingIDs.contains("DEF789")) || - (trackingIDs.contains("MNO456")), - "Expected either one of the tracking IDs"); - } - -} \ No newline at end of file From 5366b749ac481c60cba4676cddf3e6ea5742b715 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Wed, 20 Sep 2023 17:34:48 -0400 Subject: [PATCH 06/11] enable BookingServiceTest to run with Open Liberty --- pom.xml | 20 +++++++------------ src/main/liberty/config/server.xml | 1 + .../application/BookingServiceTest.java | 16 ++++++++++++--- src/test/resources/arquillian.xml | 10 ++++++++++ src/test/resources/test-beans.xml | 6 ++++++ src/test/resources/test-liberty-web.xml | 17 ++++++++++++++++ 6 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/test/resources/test-beans.xml create mode 100644 src/test/resources/test-liberty-web.xml diff --git a/pom.xml b/pom.xml index 78262535..d2f9822e 100644 --- a/pom.xml +++ b/pom.xml @@ -447,17 +447,11 @@ 3.1.2 provided - - org.jboss.resteasy - resteasy-json-binding-provider - 6.2.5.Final - test - - - org.glassfish.jersey.media - jersey-media-sse - 3.1.3 + io.openliberty.arquillian + arquillian-liberty-managed-jakarta-junit5 + 2.1.4 + pom test @@ -486,9 +480,9 @@ maven-surefire-plugin 3.1.2 - - org/**/BookingServiceTest.java - + + openliberty + diff --git a/src/main/liberty/config/server.xml b/src/main/liberty/config/server.xml index 1dd8ff4e..1fdefc28 100644 --- a/src/main/liberty/config/server.xml +++ b/src/main/liberty/config/server.xml @@ -11,6 +11,7 @@ jdbc-4.3 jndi-1.0 jsonb-3.0 + localConnector-1.0 mdb-4.0 messaging-3.1 messagingClient-3.0 diff --git a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java index f96fe4db..fe21f53f 100644 --- a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java +++ b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java @@ -69,6 +69,7 @@ import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; + /** * Application layer integration test covering a number of otherwise fairly trivial components that * largely do not warrant their own tests. @@ -86,6 +87,13 @@ public class BookingServiceTest { @Deployment public static WebArchive createDeployment() { + + String launch = System.getProperty("arquillian.launch", "payara"); + String webXml = launch.equals("openliberty") ? "test-liberty-web.xml" : "test-web.xml"; + String[] dependencies = launch.equals("openliberty") ? + new String[] { "org.apache.commons:commons-lang3" } : + new String[] { "org.apache.commons:commons-lang3", "com.h2database:h2"}; + return ShrinkWrap.create(WebArchive.class, "cargo-tracker-test.war") // Application layer component directly under test. .addClass(BookingService.class) @@ -147,16 +155,18 @@ public static WebArchive createDeployment() { // Persistence unit descriptor .addAsResource("test-persistence.xml", "META-INF/persistence.xml") // Web application descriptor - .addAsWebInfResource("test-web.xml", "web.xml") + .addAsWebInfResource(webXml, "web.xml") + // Bean archive descriptor + .addAsWebInfResource("test-beans.xml", "beans.xml") // Library dependencies .addAsLibraries( Maven.resolver() .loadPomFromFile("pom.xml") - .resolve("org.apache.commons:commons-lang3", "com.h2database:h2") + .resolve(dependencies) .withTransitivity() .asFile()); } - + @Test @Order(1) public void testRegisterNew() { diff --git a/src/test/resources/arquillian.xml b/src/test/resources/arquillian.xml index 3b17308f..89b2e908 100644 --- a/src/test/resources/arquillian.xml +++ b/src/test/resources/arquillian.xml @@ -23,4 +23,14 @@ true + + + true + target/liberty/wlp + defaultServer + 8080 + xml + dbLib + + \ No newline at end of file diff --git a/src/test/resources/test-beans.xml b/src/test/resources/test-beans.xml new file mode 100644 index 00000000..44819c2f --- /dev/null +++ b/src/test/resources/test-beans.xml @@ -0,0 +1,6 @@ + + + diff --git a/src/test/resources/test-liberty-web.xml b/src/test/resources/test-liberty-web.xml new file mode 100644 index 00000000..7763229e --- /dev/null +++ b/src/test/resources/test-liberty-web.xml @@ -0,0 +1,17 @@ + + + + java:app/configuration/GraphTraversalUrl + java.lang.String + http://localhost:8080/cargo-tracker-test/rest/graph-traversal/shortest-path + + + java:app/jdbc/CargoTrackerDatabase + org.hsqldb.jdbc.JDBCDriver + jdbc:hsqldb:mem:CargoTrackerDB + usr + pwd + + From 62c699eaafddf223170e43612dafc9b31cde9f3f Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Wed, 20 Sep 2023 17:36:12 -0400 Subject: [PATCH 07/11] enable BookingServiceTest to run with Open Liberty --- .../org/eclipse/cargotracker/application/BookingServiceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java index fe21f53f..80b540e8 100644 --- a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java +++ b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java @@ -69,7 +69,6 @@ import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.extension.ExtendWith; - /** * Application layer integration test covering a number of otherwise fairly trivial components that * largely do not warrant their own tests. From 26c76c4e88df78e06bb86809e3d4e0a071136912 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Wed, 20 Sep 2023 17:37:33 -0400 Subject: [PATCH 08/11] enable BookingServiceTest to run with Open Liberty --- .../eclipse/cargotracker/application/BookingServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java index 80b540e8..2fd563ee 100644 --- a/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java +++ b/src/test/java/org/eclipse/cargotracker/application/BookingServiceTest.java @@ -86,11 +86,11 @@ public class BookingServiceTest { @Deployment public static WebArchive createDeployment() { - + String launch = System.getProperty("arquillian.launch", "payara"); String webXml = launch.equals("openliberty") ? "test-liberty-web.xml" : "test-web.xml"; String[] dependencies = launch.equals("openliberty") ? - new String[] { "org.apache.commons:commons-lang3" } : + new String[] { "org.apache.commons:commons-lang3" } : new String[] { "org.apache.commons:commons-lang3", "com.h2database:h2"}; return ShrinkWrap.create(WebArchive.class, "cargo-tracker-test.war") From c8ec7aa0773955e187d5fc0c073c5ce973eb9b36 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Fri, 22 Sep 2023 17:33:32 -0400 Subject: [PATCH 09/11] enable package goal to install Liberty --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 1aed882e..aabfc694 100644 --- a/pom.xml +++ b/pom.xml @@ -475,6 +475,16 @@ + + + install liberty + compile + + create + install-feature + + + org.apache.maven.plugins From 379d72e3e0a50456ebb46a38d056516317b93952 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Fri, 22 Sep 2023 17:34:53 -0400 Subject: [PATCH 10/11] enable package goal to install Liberty --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aabfc694..78c1942d 100644 --- a/pom.xml +++ b/pom.xml @@ -477,7 +477,7 @@ - install liberty + install Liberty compile create From fd250a96c87571efc9f76ea02a8712ebdbe0c7d2 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Fri, 22 Sep 2023 17:35:36 -0400 Subject: [PATCH 11/11] enable package goal to install Liberty --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78c1942d..01311dcd 100644 --- a/pom.xml +++ b/pom.xml @@ -477,7 +477,7 @@ - install Liberty + install-liberty compile create