From 10905377af3532d1d715000ae2708fcd435bdd4f Mon Sep 17 00:00:00 2001 From: Michael Hamburger Date: Mon, 3 Jun 2024 20:37:24 +0200 Subject: [PATCH] Add Test with generic output --- ...bdaWithCollectionAsInputAndReturnType.java | 15 +++++++ ...thCollectionAsInputAndReturnTypeTest.java} | 24 ++++++------ ...ionStringInputAndListPersonReturnType.java | 17 ++++++++ ...tringInputAndListPersonReturnTypeTest.java | 39 +++++++++++++++++++ .../deployment/testing/PersonListLambda.java | 15 ------- 5 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnType.java rename extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/{PersonListLambdaTest.java => LambdaWithCollectionAsInputAndReturnTypeTest.java} (65%) create mode 100644 extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnType.java create mode 100644 extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnTypeTest.java delete mode 100644 extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambda.java diff --git a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnType.java b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnType.java new file mode 100644 index 00000000000000..c71460448553a9 --- /dev/null +++ b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnType.java @@ -0,0 +1,15 @@ +package io.quarkus.amazon.lambda.deployment.testing; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; + +import java.util.ArrayList; +import java.util.List; + +public class LambdaWithCollectionAsInputAndReturnType implements RequestHandler, List> { + + @Override + public List handleRequest(List people, Context context) { + return new ArrayList<>(people); + } +} diff --git a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambdaTest.java b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnTypeTest.java similarity index 65% rename from extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambdaTest.java rename to extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnTypeTest.java index 0e37d6a34ad03e..6aa89f95e2193b 100644 --- a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambdaTest.java +++ b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionAsInputAndReturnTypeTest.java @@ -1,27 +1,28 @@ package io.quarkus.amazon.lambda.deployment.testing; -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.containsString; - -import java.util.ArrayList; -import java.util.List; - +import io.quarkus.test.QuarkusUnitTest; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import io.quarkus.test.QuarkusUnitTest; +import java.util.ArrayList; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasItems; -public class PersonListLambdaTest { +public class LambdaWithCollectionAsInputAndReturnTypeTest { @RegisterExtension static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap .create(JavaArchive.class) - .addClasses(PersonListLambda.class, Person.class)); + .addClasses(LambdaWithCollectionAsInputAndReturnType.class, Person.class)); @Test - void testFruitsLambda() throws Exception { + void testCollectionLambda() { List personList = new ArrayList<>(); personList.add(new Person("Chris")); @@ -33,6 +34,7 @@ void testFruitsLambda() throws Exception { .post() .then() .statusCode(200) - .body(containsString("Chris Fred")); + .body("", hasItem(hasEntry("name", "Chris"))) + .body("", hasItem(hasEntry("name", "Fred"))); } } diff --git a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnType.java b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnType.java new file mode 100644 index 00000000000000..829d847bce9462 --- /dev/null +++ b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnType.java @@ -0,0 +1,17 @@ +package io.quarkus.amazon.lambda.deployment.testing; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; + +import java.util.ArrayList; +import java.util.List; + +public class LambdaWithCollectionStringInputAndListPersonReturnType implements RequestHandler, List> { + + @Override + public List handleRequest(List strings, Context context) { + List personList = new ArrayList<>(); + strings.forEach(name -> personList.add(new Person(name))); + return personList; + } +} diff --git a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnTypeTest.java b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnTypeTest.java new file mode 100644 index 00000000000000..d1134e819bd3d2 --- /dev/null +++ b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/LambdaWithCollectionStringInputAndListPersonReturnTypeTest.java @@ -0,0 +1,39 @@ +package io.quarkus.amazon.lambda.deployment.testing; + +import io.quarkus.test.QuarkusUnitTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.ArrayList; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.Matchers.hasEntry; + +public class LambdaWithCollectionStringInputAndListPersonReturnTypeTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap + .create(JavaArchive.class) + .addClasses(LambdaWithCollectionStringInputAndListPersonReturnType.class, Person.class)); + + @Test + void testCollectionLambda() { + + List personList = new ArrayList<>(); + personList.add("Chris"); + personList.add("Fred"); + + given() + .body(personList) + .when() + .post() + .then() + .statusCode(200) + .body("", hasItem(hasEntry("name", "Chris"))) + .body("", hasItem(hasEntry("name", "Fred"))); + } +} diff --git a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambda.java b/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambda.java deleted file mode 100644 index e873d3c600d694..00000000000000 --- a/extensions/amazon-lambda/deployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambda.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.quarkus.amazon.lambda.deployment.testing; - -import java.util.List; -import java.util.stream.Collectors; - -import com.amazonaws.services.lambda.runtime.Context; -import com.amazonaws.services.lambda.runtime.RequestHandler; - -public class PersonListLambda implements RequestHandler, String> { - - @Override - public String handleRequest(List people, Context context) { - return people.stream().map(Person::getName).collect(Collectors.joining(" ")); - } -}