Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProtoDeserializationHandler : DeserializationHandler {
private val proto = MediaType.parse("application/x-protobuf")

override fun supports(input: APIGatewayProxyRequestEvent): Boolean =
MediaType.parse(input.contentType()).`is`(proto)
input.contentType() != null && MediaType.parse(input.contentType()).`is`(proto)

override fun deserialize(input: APIGatewayProxyRequestEvent, target: KType?): Any {
val bytes = Base64.getDecoder().decode(input.body)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.moia.router.proto

import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
import io.moia.router.withHeader
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

internal class ProtoDeserializationHandlerTest {

@Test
fun `Deserializer should not support if the content type of the input is null`() {
assertFalse(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent()))
}

@Test
fun `Deserializer should not support if the content type of the input is json`() {
assertFalse(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/json")))
}

@Test
fun `Deserializer should support if the content type of the input is protobuf`() {
assertTrue(ProtoDeserializationHandler().supports(APIGatewayProxyRequestEvent().withHeader("content-type", "application/x-protobuf")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.Base64

class RequestHandlerTest {

val testRequestHandler = TestRequestHandler()
private val testRequestHandler = TestRequestHandler()

@Test
fun `should match request to proto handler and return json`() {
Expand Down