From 885f486e0050fc5fbf83d482c6d0b13ebfbc5092 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 16 Jan 2024 10:33:55 +0100 Subject: [PATCH 1/2] AWS Lambda Rest: split the amazon-lambda-rest integration module - into amazon-lambda-rest-resteasy-reactive, amazon-lambda-rest-reactive-routes, amazon-lambda-rest-funqy and amazon-lambda-rest-servlet - to avoid errors/conflicts among HTTP frameworks - there was a regression in the tests caused by e2ae8180db5f4d80a27e7bef471998765ba476bd during upgrade to Vert.x 4.5.1 --- docs/src/main/asciidoc/aws-lambda-http.adoc | 2 + .../amazon-lambda-rest-funqy/pom.xml | 150 ++++++++++++++++++ .../lambda/rest/funqy}/FunqyGreeting.java | 2 +- .../src/main/resources/application.properties | 0 .../rest/funqy}/AmazonLambdaV1SimpleIT.java | 2 +- .../funqy/AmazonLambdaV1SimpleTestCase.java | 51 ++++++ .../pom.xml | 150 ++++++++++++++++++ .../rest/reactive/routes}/GreetingVertx.java | 2 +- .../reactive/routes}/SecurityCheckVertx.java | 2 +- .../src/main/resources/application.properties | 2 + .../routes/AmazonLambdaV1SimpleIT.java | 7 + .../routes/AmazonLambdaV1SimpleTestCase.java | 113 +++++++++++++ .../pom.xml | 55 +------ .../resteasy/reactive}/GreetingResource.java | 2 +- .../reactive}/SecurityCheckResource.java | 2 +- .../src/main/resources/application.properties | 2 + .../reactive/AmazonLambdaV1SimpleIT.java | 7 + .../AmazonLambdaV1SimpleTestCase.java | 71 +-------- .../amazon-lambda-rest-servlet/pom.xml | 150 ++++++++++++++++++ .../lambda/rest/servlet}/GreetingServlet.java | 2 +- .../lambda/rest/servlet}/SecurityServlet.java | 2 +- .../src/main/resources/application.properties | 2 + .../rest/servlet/AmazonLambdaV1SimpleIT.java | 7 + .../servlet/AmazonLambdaV1SimpleTestCase.java | 133 ++++++++++++++++ integration-tests/pom.xml | 5 +- 25 files changed, 791 insertions(+), 132 deletions(-) create mode 100644 integration-tests/amazon-lambda-rest-funqy/pom.xml rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-funqy/src/main/java/io/quarkus/it/amazon/lambda/rest/funqy}/FunqyGreeting.java (87%) rename integration-tests/{amazon-lambda-rest => amazon-lambda-rest-funqy}/src/main/resources/application.properties (100%) rename integration-tests/{amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda => amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy}/AmazonLambdaV1SimpleIT.java (76%) create mode 100644 integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleTestCase.java create mode 100644 integration-tests/amazon-lambda-rest-reactive-routes/pom.xml rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes}/GreetingVertx.java (96%) rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes}/SecurityCheckVertx.java (90%) create mode 100644 integration-tests/amazon-lambda-rest-reactive-routes/src/main/resources/application.properties create mode 100644 integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleIT.java create mode 100644 integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleTestCase.java rename integration-tests/{amazon-lambda-rest => amazon-lambda-rest-resteasy-reactive}/pom.xml (74%) rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive}/GreetingResource.java (96%) rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive}/SecurityCheckResource.java (91%) create mode 100644 integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/resources/application.properties create mode 100644 integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleIT.java rename integration-tests/{amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda => amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive}/AmazonLambdaV1SimpleTestCase.java (80%) create mode 100644 integration-tests/amazon-lambda-rest-servlet/pom.xml rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet}/GreetingServlet.java (95%) rename integration-tests/{amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1 => amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet}/SecurityServlet.java (93%) create mode 100644 integration-tests/amazon-lambda-rest-servlet/src/main/resources/application.properties create mode 100644 integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleIT.java create mode 100644 integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleTestCase.java diff --git a/docs/src/main/asciidoc/aws-lambda-http.adoc b/docs/src/main/asciidoc/aws-lambda-http.adoc index 969d448df56aa..49b7790237c26 100644 --- a/docs/src/main/asciidoc/aws-lambda-http.adoc +++ b/docs/src/main/asciidoc/aws-lambda-http.adoc @@ -16,6 +16,8 @@ With Quarkus you can deploy your favorite Java HTTP frameworks as AWS Lambda's u or https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html[AWS Gateway REST API]. This means that you can deploy your microservices written with RESTEasy Reactive (our Jakarta REST implementation), Undertow (servlet), Reactive Routes, xref:funqy-http.adoc[Funqy HTTP] or any other Quarkus HTTP framework as an AWS Lambda. +IMPORTANT: You should only use single HTTP framework together with AWS Lambda extension to avoid unexpected conflicts and errors. + You can deploy your Lambda as a pure Java jar, or you can compile your project to a native image and deploy that for a smaller memory footprint and startup time. Our integration also generates SAM deployment files that can be consumed by https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html[Amazon's SAM framework]. diff --git a/integration-tests/amazon-lambda-rest-funqy/pom.xml b/integration-tests/amazon-lambda-rest-funqy/pom.xml new file mode 100644 index 0000000000000..5a103a70f72c2 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-funqy/pom.xml @@ -0,0 +1,150 @@ + + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-integration-test-amazon-lambda-rest-funqy + Quarkus - Integration Tests - Amazon Lambda AWS Gateway REST API + Module that contains Amazon Lambda related tests for Funqy + + + io.quarkus + quarkus-funqy-http + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-amazon-lambda-rest + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + io.quarkus + quarkus-amazon-lambda-rest-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-funqy-http-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-smallrye-openapi-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + src/main/resources + true + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + + + + + native-image + + + native + + + + native + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${native.surefire.skip} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + + + + + + + diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/FunqyGreeting.java b/integration-tests/amazon-lambda-rest-funqy/src/main/java/io/quarkus/it/amazon/lambda/rest/funqy/FunqyGreeting.java similarity index 87% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/FunqyGreeting.java rename to integration-tests/amazon-lambda-rest-funqy/src/main/java/io/quarkus/it/amazon/lambda/rest/funqy/FunqyGreeting.java index 35f2d73271278..d63d2bd02640c 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/FunqyGreeting.java +++ b/integration-tests/amazon-lambda-rest-funqy/src/main/java/io/quarkus/it/amazon/lambda/rest/funqy/FunqyGreeting.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.funqy; import io.quarkus.funqy.Funq; import io.smallrye.mutiny.Uni; diff --git a/integration-tests/amazon-lambda-rest/src/main/resources/application.properties b/integration-tests/amazon-lambda-rest-funqy/src/main/resources/application.properties similarity index 100% rename from integration-tests/amazon-lambda-rest/src/main/resources/application.properties rename to integration-tests/amazon-lambda-rest-funqy/src/main/resources/application.properties diff --git a/integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleIT.java b/integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleIT.java similarity index 76% rename from integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleIT.java rename to integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleIT.java index 2206e1523cee2..05645eadcb4cc 100644 --- a/integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleIT.java +++ b/integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleIT.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda; +package io.quarkus.it.amazon.lambda.rest.funqy; import io.quarkus.test.junit.QuarkusIntegrationTest; diff --git a/integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleTestCase.java b/integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleTestCase.java new file mode 100644 index 0000000000000..18f360dcfc6cb --- /dev/null +++ b/integration-tests/amazon-lambda-rest-funqy/src/test/java/io/quarkus/it/amazon/lambda/rest/funqy/AmazonLambdaV1SimpleTestCase.java @@ -0,0 +1,51 @@ +package io.quarkus.it.amazon.lambda.rest.funqy; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class AmazonLambdaV1SimpleTestCase { + + @Test + public void testSwaggerUi() throws Exception { + // this tests the FileRegion support in the handler + given() + .when() + .get("/q/swagger-ui/") + .then() + .statusCode(200) + .body(containsString("OpenAPI UI")); + } + + @Test + public void test404() throws Exception { + given() + .when() + .get("/nowhere") + .then() + .statusCode(404); + } + + @ParameterizedTest + @ValueSource(strings = { "/funqy", "/funqyAsync" }) + public void testFunqy(String path) { + given() + .contentType("application/json") + .accept("application/json") + .body("\"Bill\"") + .when() + .post(path) + .then() + .statusCode(200) + .header("Content-Type", containsString("application/json")) + .body(equalTo("\"Make it funqy Bill\"")); + } + +} diff --git a/integration-tests/amazon-lambda-rest-reactive-routes/pom.xml b/integration-tests/amazon-lambda-rest-reactive-routes/pom.xml new file mode 100644 index 0000000000000..fedde86088ecb --- /dev/null +++ b/integration-tests/amazon-lambda-rest-reactive-routes/pom.xml @@ -0,0 +1,150 @@ + + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-integration-test-amazon-lambda-rest-reactive-routes + Quarkus - Integration Tests - Amazon Lambda AWS Gateway REST API + Module that contains Amazon Lambda related tests for Reactive Routes + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-reactive-routes + + + io.quarkus + quarkus-amazon-lambda-rest + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + io.quarkus + quarkus-amazon-lambda-rest-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-smallrye-openapi-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-reactive-routes-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + src/main/resources + true + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + + + + + native-image + + + native + + + + native + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${native.surefire.skip} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + + + + + + + diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingVertx.java b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/GreetingVertx.java similarity index 96% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingVertx.java rename to integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/GreetingVertx.java index 7655f65aa931e..65d8e21e17939 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingVertx.java +++ b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/GreetingVertx.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.reactive.routes; import static io.quarkus.vertx.web.Route.HttpMethod.GET; import static io.quarkus.vertx.web.Route.HttpMethod.POST; diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckVertx.java b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/SecurityCheckVertx.java similarity index 90% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckVertx.java rename to integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/SecurityCheckVertx.java index 61e7a7226eb90..d53f85cef5282 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckVertx.java +++ b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/SecurityCheckVertx.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.reactive.routes; import static io.quarkus.vertx.web.Route.HttpMethod.GET; diff --git a/integration-tests/amazon-lambda-rest-reactive-routes/src/main/resources/application.properties b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/resources/application.properties new file mode 100644 index 0000000000000..b5ab6f51a3ef5 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-reactive-routes/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.lambda-http.enable-security=true +quarkus.swagger-ui.always-include=true diff --git a/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleIT.java b/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleIT.java new file mode 100644 index 0000000000000..109ec4f67c45d --- /dev/null +++ b/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.amazon.lambda.rest.reactive.routes; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class AmazonLambdaV1SimpleIT extends AmazonLambdaV1SimpleTestCase { +} diff --git a/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleTestCase.java b/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleTestCase.java new file mode 100644 index 0000000000000..881b36a0044c5 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-reactive-routes/src/test/java/io/quarkus/it/amazon/lambda/rest/reactive/routes/AmazonLambdaV1SimpleTestCase.java @@ -0,0 +1,113 @@ +package io.quarkus.it.amazon.lambda.rest.reactive.routes; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; + +import org.junit.jupiter.api.Test; + +import io.quarkus.amazon.lambda.http.model.AwsProxyRequest; +import io.quarkus.amazon.lambda.http.model.Headers; +import io.quarkus.amazon.lambda.runtime.AmazonLambdaApi; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class AmazonLambdaV1SimpleTestCase { + + @Test + public void testGetText() throws Exception { + testGetTextByEvent("/vertx/hello"); + testGetText("/vertx/hello"); + } + + private void testGetTextByEvent(String path) { + AwsProxyRequest request = request(path); + given() + .contentType("application/json") + .accept("application/json") + .body(request) + .when() + .post(AmazonLambdaApi.API_BASE_PATH_TEST) + .then() + .statusCode(200) + .body("body", equalTo("hello")) + .body("multiValueHeaders.Content-Type", hasItem(containsString("text/plain"))); + } + + private void testGetText(String path) { + given() + .when() + .get(path) + .then() + .statusCode(200) + .header("Content-Type", containsString("text/plain")) + .body(equalTo("hello")); + } + + @Test + public void testSwaggerUi() throws Exception { + // this tests the FileRegion support in the handler + given() + .when() + .get("/q/swagger-ui/") + .then() + .statusCode(200) + .body(containsString("OpenAPI UI")); + } + + private AwsProxyRequest request(String path) { + AwsProxyRequest request = new AwsProxyRequest(); + request.setHttpMethod("GET"); + request.setPath(path); + return request; + } + + @Test + public void test404() throws Exception { + given() + .when() + .get("/nowhere") + .then() + .statusCode(404); + } + + @Test + public void testPostText() throws Exception { + testPostTextByEvent("/vertx/hello"); + testPostText("/vertx/hello"); + } + + private void testPostTextByEvent(String path) { + AwsProxyRequest request = new AwsProxyRequest(); + request.setHttpMethod("POST"); + request.setMultiValueHeaders(new Headers()); + request.getMultiValueHeaders().add("Content-Type", "text/plain"); + request.setPath(path); + request.setBody("Bill"); + + given() + .contentType("application/json") + .accept("application/json") + .body(request) + .when() + .post(AmazonLambdaApi.API_BASE_PATH_TEST) + .then() + .statusCode(200) + .body("body", equalTo("hello Bill")) + .body("multiValueHeaders.Content-Type", hasItem(containsString("text/plain"))); + } + + private void testPostText(String path) { + given() + .contentType("text/plain") + .body("Bill") + .when() + .post(path) + .then() + .statusCode(200) + .header("Content-Type", containsString("text/plain")) + .body(equalTo("hello Bill")); + } + +} diff --git a/integration-tests/amazon-lambda-rest/pom.xml b/integration-tests/amazon-lambda-rest-resteasy-reactive/pom.xml similarity index 74% rename from integration-tests/amazon-lambda-rest/pom.xml rename to integration-tests/amazon-lambda-rest-resteasy-reactive/pom.xml index 7dc64afe1ce81..df6bce6d70ec5 100644 --- a/integration-tests/amazon-lambda-rest/pom.xml +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/pom.xml @@ -9,14 +9,10 @@ 4.0.0 - quarkus-integration-test-amazon-lambda-rest + quarkus-integration-test-amazon-lambda-rest-resteasy-reactive Quarkus - Integration Tests - Amazon Lambda AWS Gateway REST API - Module that contains Amazon Lambda related tests for RESTEasy + Module that contains Amazon Lambda related tests for RESTEasy Reactive - - io.quarkus - quarkus-funqy-http - io.quarkus quarkus-resteasy-reactive @@ -25,14 +21,6 @@ io.quarkus quarkus-smallrye-openapi - - io.quarkus - quarkus-undertow - - - io.quarkus - quarkus-reactive-routes - io.quarkus quarkus-amazon-lambda-rest @@ -64,19 +52,6 @@ - - io.quarkus - quarkus-funqy-http-deployment - ${project.version} - pom - test - - - * - * - - - io.quarkus quarkus-resteasy-reactive-deployment @@ -103,32 +78,6 @@ - - io.quarkus - quarkus-undertow-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-reactive-routes-deployment - ${project.version} - pom - test - - - * - * - - - diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingResource.java b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/GreetingResource.java similarity index 96% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingResource.java rename to integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/GreetingResource.java index f41f8a578986f..e6cce16ef1242 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingResource.java +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/GreetingResource.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.resteasy.reactive; import jakarta.inject.Inject; import jakarta.ws.rs.Consumes; diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckResource.java b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/SecurityCheckResource.java similarity index 91% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckResource.java rename to integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/SecurityCheckResource.java index 66299971cf2a6..5c17c429d2eb9 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityCheckResource.java +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/SecurityCheckResource.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.resteasy.reactive; import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.GET; diff --git a/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/resources/application.properties b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/resources/application.properties new file mode 100644 index 0000000000000..b5ab6f51a3ef5 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.lambda-http.enable-security=true +quarkus.swagger-ui.always-include=true diff --git a/integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleIT.java b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleIT.java new file mode 100644 index 0000000000000..e9f958591d67a --- /dev/null +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.amazon.lambda.rest.resteasy.reactive; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class AmazonLambdaV1SimpleIT extends AmazonLambdaV1SimpleTestCase { +} diff --git a/integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleTestCase.java b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleTestCase.java similarity index 80% rename from integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleTestCase.java rename to integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleTestCase.java index 622e5386a146e..a5ee8870c2dc8 100644 --- a/integration-tests/amazon-lambda-rest/src/test/java/io/quarkus/it/amazon/lambda/AmazonLambdaV1SimpleTestCase.java +++ b/integration-tests/amazon-lambda-rest-resteasy-reactive/src/test/java/io/quarkus/it/amazon/lambda/rest/resteasy/reactive/AmazonLambdaV1SimpleTestCase.java @@ -1,26 +1,19 @@ -package io.quarkus.it.amazon.lambda; +package io.quarkus.it.amazon.lambda.rest.resteasy.reactive; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.*; import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import jakarta.ws.rs.core.MediaType; -import org.apache.commons.codec.binary.Base64; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import io.quarkus.amazon.lambda.http.model.ApiGatewayAuthorizerContext; import io.quarkus.amazon.lambda.http.model.ApiGatewayRequestIdentity; import io.quarkus.amazon.lambda.http.model.AwsProxyRequest; import io.quarkus.amazon.lambda.http.model.AwsProxyRequestContext; -import io.quarkus.amazon.lambda.http.model.AwsProxyResponse; import io.quarkus.amazon.lambda.http.model.CognitoAuthorizerClaims; import io.quarkus.amazon.lambda.http.model.Headers; import io.quarkus.amazon.lambda.runtime.AmazonLambdaApi; @@ -63,34 +56,6 @@ public void testJaxrsSecurityIAM() throws Exception { .body("body", equalTo("Bill")); } - @Test - public void testServletSecurityIAM() throws Exception { - AwsProxyRequest request = new AwsProxyRequest(); - request.setHttpMethod("GET"); - request.setPath("/servlet/security"); - request.setRequestContext(new AwsProxyRequestContext()); - request.getRequestContext().setIdentity(new ApiGatewayRequestIdentity()); - request.getRequestContext().getIdentity().setUser("Bill"); - given() - .contentType("application/json") - .accept("application/json") - .body(request) - .when() - .post(AmazonLambdaApi.API_BASE_PATH_TEST) - .then() - .statusCode(200) - .body("body", equalTo("Bill")); - } - - @Test - public void testRoleParse() { - Pattern p = Pattern.compile("[^\\[\\] \\t]+"); - Matcher m = p.matcher("[ hello world ]"); - while (m.find()) { - System.out.println(m.group()); - } - } - @Test public void testJaxrsCognitoSecurityContext() throws Exception { AwsProxyRequest request = new AwsProxyRequest(); @@ -195,11 +160,7 @@ public void testJaxrsCustomLambdaSecurityContext() throws Exception { @Test public void testGetText() throws Exception { - testGetTextByEvent("/vertx/hello"); - testGetTextByEvent("/servlet/hello"); testGetTextByEvent("/hello"); - testGetText("/vertx/hello"); - testGetText("/servlet/hello"); testGetText("/hello"); } @@ -238,12 +199,6 @@ public void testSwaggerUi() throws Exception { .body(containsString("OpenAPI UI")); } - private String body(AwsProxyResponse response) { - if (!response.isBase64Encoded()) - return response.getBody(); - return new String(Base64.decodeBase64(response.getBody())); - } - private AwsProxyRequest request(String path) { AwsProxyRequest request = new AwsProxyRequest(); request.setHttpMethod("GET"); @@ -263,16 +218,7 @@ public void test404() throws Exception { @Test public void testPostText() throws Exception { testPostTextByEvent("/hello"); - testPostTextByEvent("/vertx/hello"); testPostText("/hello"); - testPostText("/vertx/hello"); - } - - @Test - @Disabled("Does not work with Vert.x 4.5.1 - to be investigated") - public void testPostTextWithServlet() throws Exception { - testPostTextByEvent("/servlet/hello"); - testPostText("/servlet/hello"); } private void testPostTextByEvent(String path) { @@ -333,21 +279,6 @@ public void testPostEmpty() throws Exception { .statusCode(204); } - @ParameterizedTest - @ValueSource(strings = { "/funqy", "/funqyAsync" }) - public void testFunqy(String path) { - given() - .contentType("application/json") - .accept("application/json") - .body("\"Bill\"") - .when() - .post(path) - .then() - .statusCode(200) - .header("Content-Type", containsString("application/json")) - .body(equalTo("\"Make it funqy Bill\"")); - } - @Test public void testProxyRequestContext() throws Exception { given() diff --git a/integration-tests/amazon-lambda-rest-servlet/pom.xml b/integration-tests/amazon-lambda-rest-servlet/pom.xml new file mode 100644 index 0000000000000..77a90b5cfcaf3 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-servlet/pom.xml @@ -0,0 +1,150 @@ + + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-integration-test-amazon-lambda-rest-servlet + Quarkus - Integration Tests - Amazon Lambda AWS Gateway REST API + Module that contains Amazon Lambda related tests for Servlets + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-undertow + + + io.quarkus + quarkus-amazon-lambda-rest + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + io.quarkus + quarkus-amazon-lambda-rest-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-smallrye-openapi-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-undertow-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + src/main/resources + true + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + + + + + native-image + + + native + + + + native + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${native.surefire.skip} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + + + + + + + diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingServlet.java b/integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/GreetingServlet.java similarity index 95% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingServlet.java rename to integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/GreetingServlet.java index 3414d2f2b09ab..9bc135b2a0eb8 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/GreetingServlet.java +++ b/integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/GreetingServlet.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.servlet; import java.io.IOException; diff --git a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityServlet.java b/integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/SecurityServlet.java similarity index 93% rename from integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityServlet.java rename to integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/SecurityServlet.java index bfcba67a1e6a6..27ef80460489e 100644 --- a/integration-tests/amazon-lambda-rest/src/main/java/io/quarkus/it/amazon/lambda/v1/SecurityServlet.java +++ b/integration-tests/amazon-lambda-rest-servlet/src/main/java/io/quarkus/it/amazon/lambda/rest/servlet/SecurityServlet.java @@ -1,4 +1,4 @@ -package io.quarkus.it.amazon.lambda.v1; +package io.quarkus.it.amazon.lambda.rest.servlet; import java.io.IOException; diff --git a/integration-tests/amazon-lambda-rest-servlet/src/main/resources/application.properties b/integration-tests/amazon-lambda-rest-servlet/src/main/resources/application.properties new file mode 100644 index 0000000000000..b5ab6f51a3ef5 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-servlet/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.lambda-http.enable-security=true +quarkus.swagger-ui.always-include=true diff --git a/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleIT.java b/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleIT.java new file mode 100644 index 0000000000000..9e1a95f1090ca --- /dev/null +++ b/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.amazon.lambda.rest.servlet; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class AmazonLambdaV1SimpleIT extends AmazonLambdaV1SimpleTestCase { +} diff --git a/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleTestCase.java b/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleTestCase.java new file mode 100644 index 0000000000000..37e4a2116f0a6 --- /dev/null +++ b/integration-tests/amazon-lambda-rest-servlet/src/test/java/io/quarkus/it/amazon/lambda/rest/servlet/AmazonLambdaV1SimpleTestCase.java @@ -0,0 +1,133 @@ +package io.quarkus.it.amazon.lambda.rest.servlet; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; + +import org.junit.jupiter.api.Test; + +import io.quarkus.amazon.lambda.http.model.ApiGatewayRequestIdentity; +import io.quarkus.amazon.lambda.http.model.AwsProxyRequest; +import io.quarkus.amazon.lambda.http.model.AwsProxyRequestContext; +import io.quarkus.amazon.lambda.http.model.Headers; +import io.quarkus.amazon.lambda.runtime.AmazonLambdaApi; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class AmazonLambdaV1SimpleTestCase { + + @Test + public void testServletSecurityIAM() throws Exception { + AwsProxyRequest request = new AwsProxyRequest(); + request.setHttpMethod("GET"); + request.setPath("/servlet/security"); + request.setRequestContext(new AwsProxyRequestContext()); + request.getRequestContext().setIdentity(new ApiGatewayRequestIdentity()); + request.getRequestContext().getIdentity().setUser("Bill"); + given() + .contentType("application/json") + .accept("application/json") + .body(request) + .when() + .post(AmazonLambdaApi.API_BASE_PATH_TEST) + .then() + .statusCode(200) + .body("body", equalTo("Bill")); + } + + @Test + public void testGetText() throws Exception { + testGetTextByEvent("/servlet/hello"); + testGetText("/servlet/hello"); + } + + private void testGetTextByEvent(String path) { + AwsProxyRequest request = request(path); + given() + .contentType("application/json") + .accept("application/json") + .body(request) + .when() + .post(AmazonLambdaApi.API_BASE_PATH_TEST) + .then() + .statusCode(200) + .body("body", equalTo("hello")) + .body("multiValueHeaders.Content-Type", hasItem(containsString("text/plain"))); + } + + private void testGetText(String path) { + given() + .when() + .get(path) + .then() + .statusCode(200) + .header("Content-Type", containsString("text/plain")) + .body(equalTo("hello")); + } + + @Test + public void testSwaggerUi() throws Exception { + // this tests the FileRegion support in the handler + given() + .when() + .get("/q/swagger-ui/") + .then() + .statusCode(200) + .body(containsString("OpenAPI UI")); + } + + private AwsProxyRequest request(String path) { + AwsProxyRequest request = new AwsProxyRequest(); + request.setHttpMethod("GET"); + request.setPath(path); + return request; + } + + @Test + public void test404() throws Exception { + given() + .when() + .get("/nowhere") + .then() + .statusCode(404); + } + + public void testPostText() throws Exception { + testPostTextByEvent("/servlet/hello"); + testPostText("/servlet/hello"); + } + + private void testPostTextByEvent(String path) { + AwsProxyRequest request = new AwsProxyRequest(); + request.setHttpMethod("POST"); + request.setMultiValueHeaders(new Headers()); + request.getMultiValueHeaders().add("Content-Type", "text/plain"); + request.setPath(path); + request.setBody("Bill"); + + given() + .contentType("application/json") + .accept("application/json") + .body(request) + .when() + .post(AmazonLambdaApi.API_BASE_PATH_TEST) + .then() + .statusCode(200) + .body("body", equalTo("hello Bill")) + .body("multiValueHeaders.Content-Type", hasItem(containsString("text/plain"))); + } + + private void testPostText(String path) { + given() + .contentType("text/plain") + .body("Bill") + .when() + .post(path) + .then() + .statusCode(200) + .header("Content-Type", containsString("text/plain")) + .body(equalTo("hello Bill")); + } + +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index c03b3703e342b..2d9885d52f10a 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -300,7 +300,10 @@ amazon-lambda-s3event amazon-lambda-stream-handler amazon-lambda-http - amazon-lambda-rest + amazon-lambda-rest-resteasy-reactive + amazon-lambda-rest-reactive-routes + amazon-lambda-rest-funqy + amazon-lambda-rest-servlet amazon-lambda-http-resteasy amazon-lambda-http-resteasy-reactive container-image From 45388f8271939e2a084a5cd93beac2ecddc778aa Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 16 Jan 2024 10:36:17 +0100 Subject: [PATCH 2/2] AWS Lambda Rest: add native integration tests to the CI --- .github/native-tests.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/native-tests.json b/.github/native-tests.json index 577be470bb8eb..11d2eca78c18a 100644 --- a/.github/native-tests.json +++ b/.github/native-tests.json @@ -50,8 +50,8 @@ }, { "category": "Amazon", - "timeout": 50, - "test-modules": "amazon-lambda, amazon-lambda-http", + "timeout": 80, + "test-modules": "amazon-lambda, amazon-lambda-http, amazon-lambda-rest-funqy, amazon-lambda-rest-servlet, amazon-lambda-rest-reactive-routes, amazon-lambda-rest-resteasy-reactive", "os-name": "ubuntu-latest" }, {