Skip to content

Commit

Permalink
Add Test with generic output
Browse files Browse the repository at this point in the history
  • Loading branch information
hamburml committed Jun 3, 2024
1 parent 06d24d4 commit 1090537
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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<Person>, List<Person>> {

@Override
public List<Person> handleRequest(List<Person> people, Context context) {
return new ArrayList<>(people);
}
}
Original file line number Diff line number Diff line change
@@ -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<Person> personList = new ArrayList<>();
personList.add(new Person("Chris"));
Expand All @@ -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")));
}
}
Original file line number Diff line number Diff line change
@@ -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<String>, List<Person>> {

@Override
public List<Person> handleRequest(List<String> strings, Context context) {
List<Person> personList = new ArrayList<>();
strings.forEach(name -> personList.add(new Person(name)));
return personList;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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")));
}
}

This file was deleted.

0 comments on commit 1090537

Please sign in to comment.