From 71249711e4eb153ca4c8737e12f7f36e0b4f310c Mon Sep 17 00:00:00 2001 From: alex-butcher <21243172+abutch3r@users.noreply.github.com> Date: Fri, 16 Sep 2022 16:09:00 +0100 Subject: [PATCH] Add Integration test for Microprofile/Liberty for Jee9 package Tidy-up pom files and filepaths Signed-off-by: alex-butcher <21243172+abutch3r@users.noreply.github.com> --- examples/pom.xml | 2 +- .../README.md | 2 +- .../pom.xml | 4 +- .../microprofile/CloudEventsApplication.java | 0 .../microprofile/CloudEventsJaxrsService.java | 0 .../src/main/liberty/config/server.xml | 0 .../pom.xml | 5 +- .../restful-ws-jakarta-common/pom.xml | 7 +- .../restful-ws-jersey/pom.xml | 8 +- .../com/github/hanleyt/JerseyExtension.java | 4 +- .../restful-ws-liberty/pom.xml | 164 ++++++++++++++++++ .../cloudevents/restful/mp/test/MpCEApp.java | 9 + .../restful/mp/test/TestResource.java | 60 +++++++ .../src/main/liberty/config/server.xml | 18 ++ .../microprofile/TestMicroprofile.java | 123 +++++++++++++ .../restful-ws-microprofile/pom.xml | 16 -- .../restful-ws-resteasy/pom.xml | 5 +- http/restful-ws-jakarta/pom.xml | 15 +- pom.xml | 2 +- 19 files changed, 405 insertions(+), 39 deletions(-) rename examples/{restful-ws-microprofile-ee9 => restful-ws-microprofile-liberty}/README.md (98%) rename examples/{restful-ws-microprofile-ee9 => restful-ws-microprofile-liberty}/pom.xml (98%) rename examples/{restful-ws-microprofile-ee9 => restful-ws-microprofile-liberty}/src/main/java/io/cloudevents/examples/microprofile/CloudEventsApplication.java (100%) rename examples/{restful-ws-microprofile-ee9 => restful-ws-microprofile-liberty}/src/main/java/io/cloudevents/examples/microprofile/CloudEventsJaxrsService.java (100%) rename examples/{restful-ws-microprofile-ee9 => restful-ws-microprofile-liberty}/src/main/liberty/config/server.xml (100%) rename http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/{main => test}/java/com/github/hanleyt/JerseyExtension.java (97%) create mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml create mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/MpCEApp.java create mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/TestResource.java create mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/liberty/config/server.xml create mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/test/java/io/cloudevents/http/restful/ws/jakarta/microprofile/TestMicroprofile.java delete mode 100644 http/restful-ws-jakarta-integration-tests/restful-ws-microprofile/pom.xml diff --git a/examples/pom.xml b/examples/pom.xml index 9ffa6486d..fe13f0540 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -21,7 +21,7 @@ kafka restful-ws-quarkus - restful-ws-microprofile-ee9 + restful-ws-microprofile-liberty vertx basic-http restful-ws-spring-boot diff --git a/examples/restful-ws-microprofile-ee9/README.md b/examples/restful-ws-microprofile-liberty/README.md similarity index 98% rename from examples/restful-ws-microprofile-ee9/README.md rename to examples/restful-ws-microprofile-liberty/README.md index 6e6db680e..a5a320222 100644 --- a/examples/restful-ws-microprofile-ee9/README.md +++ b/examples/restful-ws-microprofile-liberty/README.md @@ -4,7 +4,7 @@ This project uses Microprofile 5.0 with OpenLiberty If you would like to know more about Microprofile go to https://microprofile.io -This Example uses Jakarta EE9 features as such the top level namespace of the `ws-api` packages has changed from `javax` to `jakarta` and uses the `cloudevents-http-restful-ws-ee9` artifact. +This Example uses Jakarta EE9 features as such the top level namespace of the `ws-api` packages has changed from `javax` to `jakarta` and uses the `cloudevents-http-restful-ws-jakarta` artifact. ## Build and Execution diff --git a/examples/restful-ws-microprofile-ee9/pom.xml b/examples/restful-ws-microprofile-liberty/pom.xml similarity index 98% rename from examples/restful-ws-microprofile-ee9/pom.xml rename to examples/restful-ws-microprofile-liberty/pom.xml index 9fb4cabe5..8a4338cd1 100644 --- a/examples/restful-ws-microprofile-ee9/pom.xml +++ b/examples/restful-ws-microprofile-liberty/pom.xml @@ -7,7 +7,7 @@ ../ 4.0.0 - cloudevents-restful-ws-microprofile-example + cloudevents-restful-ws-microprofile-liberty-example war @@ -44,7 +44,7 @@ io.cloudevents - cloudevents-http-restful-ws-ee9 + cloudevents-http-restful-ws-jakarta ${project.parent.version} diff --git a/examples/restful-ws-microprofile-ee9/src/main/java/io/cloudevents/examples/microprofile/CloudEventsApplication.java b/examples/restful-ws-microprofile-liberty/src/main/java/io/cloudevents/examples/microprofile/CloudEventsApplication.java similarity index 100% rename from examples/restful-ws-microprofile-ee9/src/main/java/io/cloudevents/examples/microprofile/CloudEventsApplication.java rename to examples/restful-ws-microprofile-liberty/src/main/java/io/cloudevents/examples/microprofile/CloudEventsApplication.java diff --git a/examples/restful-ws-microprofile-ee9/src/main/java/io/cloudevents/examples/microprofile/CloudEventsJaxrsService.java b/examples/restful-ws-microprofile-liberty/src/main/java/io/cloudevents/examples/microprofile/CloudEventsJaxrsService.java similarity index 100% rename from examples/restful-ws-microprofile-ee9/src/main/java/io/cloudevents/examples/microprofile/CloudEventsJaxrsService.java rename to examples/restful-ws-microprofile-liberty/src/main/java/io/cloudevents/examples/microprofile/CloudEventsJaxrsService.java diff --git a/examples/restful-ws-microprofile-ee9/src/main/liberty/config/server.xml b/examples/restful-ws-microprofile-liberty/src/main/liberty/config/server.xml similarity index 100% rename from examples/restful-ws-microprofile-ee9/src/main/liberty/config/server.xml rename to examples/restful-ws-microprofile-liberty/src/main/liberty/config/server.xml diff --git a/http/restful-ws-jakarta-integration-tests/pom.xml b/http/restful-ws-jakarta-integration-tests/pom.xml index 5347893db..4d813060e 100644 --- a/http/restful-ws-jakarta-integration-tests/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/pom.xml @@ -10,7 +10,8 @@ 4.0.0 - restful-ws-jakarta-integration-tests + cloudevents-http-restful-ws-jakarta-integration-tests + CloudEvents - JAX-RS Jakarta EE9+ Web Http Binding Integration Tests pom @@ -20,9 +21,9 @@ restful-ws-jakarta-common - restful-ws-microprofile restful-ws-resteasy restful-ws-jersey + restful-ws-liberty diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml index 16f4f04b9..0845b89a2 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-jakarta-common/pom.xml @@ -1,20 +1,20 @@ - restful-ws-jakarta-integration-tests + cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 2.4.0-SNAPSHOT ../ 4.0.0 cloudevents-http-restful-ws-jakarta-integration-tests-common - CloudEvents - JAX-RS Jakarta Integration Tests - Common + CloudEvents - JAX-RS Jakarta EE9+ Integration Tests - Common jar io.cloudevents - cloudevents-http-restful-ws-ee9 + cloudevents-http-restful-ws-jakarta ${project.parent.version} @@ -24,7 +24,6 @@ test-jar ${project.version} - org.assertj assertj-core diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml index 2da17db2d..5480c4ae9 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/pom.xml @@ -20,7 +20,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - restful-ws-jakarta-integration-tests + cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 2.4.0-SNAPSHOT ../ @@ -28,7 +28,7 @@ 4.0.0 cloudevents-http-restful-ws-jakarta-integration-tests-jersey - CloudEvents - JAX-RS Integration Tests - Jersey + CloudEvents - JAX-RS Jakarta EE9+ Integration Tests - Jersey jar @@ -48,21 +48,25 @@ jakarta.ws.rs jakarta.ws.rs-api ${jakarta-ee.version} + test org.glassfish.jersey.test-framework.providers jersey-test-framework-provider-jetty ${jersey.version} + test org.glassfish.jersey.inject jersey-hk2 ${jersey.version} + test org.junit.jupiter junit-jupiter-api ${junit-jupiter.version} + test diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/main/java/com/github/hanleyt/JerseyExtension.java b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/test/java/com/github/hanleyt/JerseyExtension.java similarity index 97% rename from http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/main/java/com/github/hanleyt/JerseyExtension.java rename to http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/test/java/com/github/hanleyt/JerseyExtension.java index b1453c87e..066535c05 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/main/java/com/github/hanleyt/JerseyExtension.java +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-jersey/src/test/java/com/github/hanleyt/JerseyExtension.java @@ -1,5 +1,7 @@ /* - * Ported from https://github.com/hanleyt/jersey-junit as no version support Jesery versions >=3.0.0 + * Ported from https://github.com/hanleyt/jersey-junit as no version supports Jesery versions >=3.0.0 + * + * Only update is the replacement of the ws-rs package namespace from javax. to jakarta. */ package com.github.hanleyt; diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml new file mode 100644 index 000000000..81d1098fa --- /dev/null +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/pom.xml @@ -0,0 +1,164 @@ + + + + cloudevents-http-restful-ws-jakarta-integration-tests + io.cloudevents + 2.4.0-SNAPSHOT + ../ + + 4.0.0 + + cloudevents-http-restful-ws-jakarta-integration-tests-microprofile + CloudEvents - JAX-RS Jakarta EE9+ Integration Tests - Microprofile and Liberty + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + 9080 + 9443 + + microprofile-test + + + + + + org.jboss.arquillian + arquillian-bom + 1.6.0.Final + pom + import + + + + + + + + jakarta.platform + jakarta.jakartaee-api + 9.1.0 + provided + + + org.eclipse.microprofile + microprofile + 5.0 + pom + provided + + + io.cloudevents + cloudevents-http-restful-ws-jakarta + ${project.version} + + + io.cloudevents + cloudevents-core + tests + test-jar + ${project.version} + + + org.jboss.resteasy + resteasy-client + 6.0.0.Final + test + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.0.0.Final + test + + + org.glassfish + jakarta.json + 2.0.1 + test + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + javax.activation + activation + 1.1.1 + + + io.openliberty.arquillian + arquillian-liberty-managed-jakarta-junit + 2.0.2 + pom + test + + + org.jboss.shrinkwrap + shrinkwrap-api + test + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + pom.xml + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.2 + + + ${arquillian.war.name}.war + + + + + test + + integration-test + + + + + + io.openliberty.tools + liberty-maven-plugin + 3.5.1 + + + + -Dsystem.context.root=/${arquillian.war.name} + + + + + + arquillian-configuration + generate-test-resources + + create + install-feature + configure-arquillian + + + + + + + diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/MpCEApp.java b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/MpCEApp.java new file mode 100644 index 000000000..279cdb3e4 --- /dev/null +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/MpCEApp.java @@ -0,0 +1,9 @@ +package io.cloudevents.restful.mp.test; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("/") +public class MpCEApp extends Application { + +} diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/TestResource.java b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/TestResource.java new file mode 100644 index 000000000..5a73efeb6 --- /dev/null +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/java/io/cloudevents/restful/mp/test/TestResource.java @@ -0,0 +1,60 @@ +package io.cloudevents.restful.mp.test; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.mock.CSVFormat; +import io.cloudevents.core.provider.EventFormatProvider; +import io.cloudevents.core.test.Data; +import io.cloudevents.http.restful.ws.StructuredEncoding; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.RequestScoped; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Response; + +@RequestScoped +@Path("/") +public class TestResource{ + + @PostConstruct + void init() { + EventFormatProvider.getInstance().registerFormat(CSVFormat.INSTANCE); + } + + @GET + @Path("getMinEvent") + public CloudEvent getMinEvent() { + return Data.V1_MIN; + } + + @GET + @Path("getStructuredEvent") + @StructuredEncoding("application/cloudevents+csv") + public CloudEvent getStructuredEvent() { + return Data.V1_MIN; + } + + @GET + @Path("getEvent") + public CloudEvent getEvent() { + return Data.V1_WITH_JSON_DATA_WITH_EXT_STRING; + } + + @POST + @Path("postEventWithoutBody") + public Response postEventWithoutBody(CloudEvent inputEvent) { + if (inputEvent.equals(Data.V1_MIN)) { + return Response.ok().build(); + } + return Response.serverError().build(); + } + + @POST + @Path("postEvent") + public Response postEvent(CloudEvent inputEvent) { + if (inputEvent.equals(Data.V1_WITH_JSON_DATA_WITH_EXT_STRING)) { + return Response.ok().build(); + } + return Response.serverError().build(); + } +} diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/liberty/config/server.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/liberty/config/server.xml new file mode 100644 index 000000000..9725cb9c8 --- /dev/null +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/main/liberty/config/server.xml @@ -0,0 +1,18 @@ + + + + microProfile-5.0 + + localConnector-1.0 + servlet-5.0 + + + + + + + + + + diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/test/java/io/cloudevents/http/restful/ws/jakarta/microprofile/TestMicroprofile.java b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/test/java/io/cloudevents/http/restful/ws/jakarta/microprofile/TestMicroprofile.java new file mode 100644 index 000000000..184fa2c8d --- /dev/null +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-liberty/src/test/java/io/cloudevents/http/restful/ws/jakarta/microprofile/TestMicroprofile.java @@ -0,0 +1,123 @@ +package io.cloudevents.http.restful.ws.jakarta.microprofile; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.mock.CSVFormat; +import io.cloudevents.core.test.Data; +import io.cloudevents.http.restful.ws.CloudEventsProvider; +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.HttpHeaders; +import jakarta.ws.rs.core.Response; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; + + +/** + * Arquilian does not support assertj, so test cases have been ported to Junit to work with arquilian + */ +@RunWith(Arquillian.class) +public class TestMicroprofile { + + private static final String WARNAME = "microprofile-test.war"; + private Client client = ClientBuilder.newClient(); + + @Deployment(testable = true) + public static WebArchive createDeployment() { + System.out.println(WARNAME); + WebArchive archive = ShrinkWrap.create(WebArchive.class, WARNAME).addPackages(true,"io.cloudevents"); + return archive; + } + + @ArquillianResource + private URL baseURL; + + private WebTarget webTarget; + + public WebTarget getWebTarget() { + if(webTarget == null){ + webTarget = client.target(baseURL.toString()); + webTarget.register(CloudEventsProvider.class); + } + return webTarget; + } + + @Test + @RunAsClient + public void getMinEvent() { + Response res = getWebTarget().path("getMinEvent").request().buildGet().invoke(); + + Assert.assertEquals("1.0",res.getHeaderString("ce-specversion")); + Assert.assertEquals(Data.V1_MIN,res.readEntity(CloudEvent.class)); + + res.close(); + } + + @Test + @RunAsClient + public void getStructuredEvent() { + Response res = getWebTarget().path("getStructuredEvent").request().buildGet().invoke(); + + Assert.assertEquals(Data.V1_MIN,res.readEntity(CloudEvent.class)); + Assert.assertEquals(CSVFormat.INSTANCE.serializedContentType(),res.getHeaderString(HttpHeaders.CONTENT_TYPE)); + + res.close(); + } + + @Test + @RunAsClient + public void testGetEvent() throws Exception { + Response response = getWebTarget().path("getEvent").request().buildGet().invoke(); + + Assert.assertEquals("Valid response code", 200, response.getStatus()); + Assert.assertEquals("should match", Data.V1_WITH_JSON_DATA_WITH_EXT_STRING, response.readEntity(CloudEvent.class)); + + response.close(); + } + + @Test + @RunAsClient + public void postEventWithoutBody() { + Response res = getWebTarget() + .path("postEventWithoutBody") + .request() + .buildPost(Entity.entity(Data.V1_MIN, CloudEventsProvider.CLOUDEVENT_TYPE)) + .invoke(); + + Assert.assertEquals(200,res.getStatus()); + } + + @Test + @RunAsClient + public void postEventStructured() { + Response res = getWebTarget() + .path("postEventWithoutBody") + .request() + .buildPost(Entity.entity(Data.V1_MIN, "application/cloudevents+csv")) + .invoke(); + + Assert.assertEquals(200,res.getStatus()); + } + + @Test + @RunAsClient + public void postEvent() { + Response res = getWebTarget() + .path("postEvent") + .request() + .buildPost(Entity.entity(Data.V1_WITH_JSON_DATA_WITH_EXT_STRING, CloudEventsProvider.CLOUDEVENT_TYPE)) + .invoke(); + + Assert.assertEquals(200,res.getStatus()); + } +} diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-microprofile/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-microprofile/pom.xml deleted file mode 100644 index 595e1e3a5..000000000 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-microprofile/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - restful-ws-jakarta-integration-tests - io.cloudevents - 2.4.0-SNAPSHOT - ../ - - 4.0.0 - - cloudevents-http-restful-ws-jakarta-integration-tests-microprofile - - - diff --git a/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml b/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml index f29f7eaf4..b4db4b968 100644 --- a/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml +++ b/http/restful-ws-jakarta-integration-tests/restful-ws-resteasy/pom.xml @@ -1,14 +1,15 @@ - restful-ws-jakarta-integration-tests + cloudevents-http-restful-ws-jakarta-integration-tests io.cloudevents 2.4.0-SNAPSHOT + ../ 4.0.0 cloudevents-http-restful-ws-jakarta-integration-tests-resteasy - CloudEvents - JAX-RS Jakarta Integration Tests - RESTEasy + CloudEvents - JAX-RS Jakarta EE9+ Integration Tests - RESTEasy jar diff --git a/http/restful-ws-jakarta/pom.xml b/http/restful-ws-jakarta/pom.xml index 97ee6caa7..b4909068f 100644 --- a/http/restful-ws-jakarta/pom.xml +++ b/http/restful-ws-jakarta/pom.xml @@ -25,8 +25,8 @@ ../../pom.xml - cloudevents-http-restful-ws-ee9 - CloudEvents - Jakarta EE9 RESTful Web Services Http Binding + cloudevents-http-restful-ws-jakarta + CloudEvents - Jakarta EE 9+ - Jakarta RESTful Web Services Http Binding jar @@ -43,8 +43,8 @@ 3.0.0 3.0.8 - 3.9.0 - 4.5.3.Final + 4.4.3 + 6.0.3.Final io.cloudevents.http.restfulws @@ -79,9 +79,10 @@ - + + + + diff --git a/pom.xml b/pom.xml index 842002e70..dd99ae28f 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,6 @@ spring sql bom - http/restful-ws-jakarta-integration-tests @@ -211,6 +210,7 @@ benchmarks http/restful-ws-integration-tests + http/restful-ws-jakarta-integration-tests examples