-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix correct parsing of collections in AmazonLambdaRecorder with Colle…
…ctionInputReader
- Loading branch information
Showing
6 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...eployment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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<List<Person>, String> { | ||
|
||
@Override | ||
public String handleRequest(List<Person> people, Context context) { | ||
return people.stream().map(Person::getName).collect(Collectors.joining(" ")); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...yment/src/test/java/io/quarkus/amazon/lambda/deployment/testing/PersonListLambdaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 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; | ||
|
||
public class PersonListLambdaTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap | ||
.create(JavaArchive.class) | ||
.addClasses(PersonListLambda.class, Person.class)); | ||
|
||
@Test | ||
void testFruitsLambda() throws Exception { | ||
|
||
List<Person> personList = new ArrayList<>(); | ||
personList.add(new Person("Chris")); | ||
personList.add(new Person("Fred")); | ||
|
||
given() | ||
.body(personList) | ||
.when() | ||
.post() | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("Chris Fred")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...untime/src/main/java/io/quarkus/amazon/lambda/runtime/handlers/CollectionInputReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.amazon.lambda.runtime.handlers; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Type; | ||
import java.util.Collection; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectReader; | ||
|
||
import io.quarkus.amazon.lambda.runtime.LambdaInputReader; | ||
|
||
public class CollectionInputReader<T> implements LambdaInputReader<Collection<T>> { | ||
final ObjectReader reader; | ||
|
||
public CollectionInputReader(ObjectMapper mapper, Method handler) { | ||
Type genericParameterType = handler.getGenericParameterTypes()[0]; | ||
JavaType constructParameterType = mapper.getTypeFactory().constructType(genericParameterType); | ||
this.reader = mapper.readerFor(constructParameterType); | ||
} | ||
|
||
@Override | ||
public Collection<T> readValue(InputStream is) throws IOException { | ||
return this.reader.readValue(is); | ||
} | ||
} |