|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. |
| 3 | + * |
| 4 | + * This file is part of Imposter. |
| 5 | + * |
| 6 | + * "Commons Clause" License Condition v1.0 |
| 7 | + * |
| 8 | + * The Software is provided to you by the Licensor under the License, as |
| 9 | + * defined below, subject to the following condition. |
| 10 | + * |
| 11 | + * Without limiting other conditions in the License, the grant of rights |
| 12 | + * under the License will not include, and the License does not grant to |
| 13 | + * you, the right to Sell the Software. |
| 14 | + * |
| 15 | + * For purposes of the foregoing, "Sell" means practicing any or all of |
| 16 | + * the rights granted to you under the License to provide to third parties, |
| 17 | + * for a fee or other consideration (including without limitation fees for |
| 18 | + * hosting or consulting/support services related to the Software), a |
| 19 | + * product or service whose value derives, entirely or substantially, from |
| 20 | + * the functionality of the Software. Any license notice or attribution |
| 21 | + * required by the License must also include this Commons Clause License |
| 22 | + * Condition notice. |
| 23 | + * |
| 24 | + * Software: Imposter |
| 25 | + * |
| 26 | + * License: GNU Lesser General Public License version 3 |
| 27 | + * |
| 28 | + * Licensor: Peter Cornish |
| 29 | + * |
| 30 | + * Imposter is free software: you can redistribute it and/or modify |
| 31 | + * it under the terms of the GNU Lesser General Public License as published by |
| 32 | + * the Free Software Foundation, either version 3 of the License, or |
| 33 | + * (at your option) any later version. |
| 34 | + * |
| 35 | + * Imposter is distributed in the hope that it will be useful, |
| 36 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 | + * GNU Lesser General Public License for more details. |
| 39 | + * |
| 40 | + * You should have received a copy of the GNU Lesser General Public License |
| 41 | + * along with Imposter. If not, see <https://www.gnu.org/licenses/>. |
| 42 | + */ |
| 43 | + |
| 44 | +package io.gatehill.imposter.awslambda |
| 45 | + |
| 46 | +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent |
| 47 | +import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent |
| 48 | +import com.amazonaws.services.lambda.runtime.tests.annotations.Event |
| 49 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 50 | +import org.junit.jupiter.api.Assertions.assertNotNull |
| 51 | +import org.junit.jupiter.api.BeforeEach |
| 52 | +import org.junit.jupiter.params.ParameterizedTest |
| 53 | + |
| 54 | +/** |
| 55 | + * Test event handling for requests with queries. |
| 56 | + */ |
| 57 | +class Handled404Test : AbstractHandlerTest() { |
| 58 | + private var handlerV1: Handler? = null |
| 59 | + private var handlerV2: HandlerV2? = null |
| 60 | + |
| 61 | + override val configDir = "/handled-404/config" |
| 62 | + |
| 63 | + @BeforeEach |
| 64 | + fun setUp() { |
| 65 | + configure() |
| 66 | + handlerV1 = Handler() |
| 67 | + handlerV2 = HandlerV2() |
| 68 | + } |
| 69 | + |
| 70 | + @ParameterizedTest |
| 71 | + @Event(value = "handled-404/requests_v1/request.json", type = APIGatewayProxyRequestEvent::class) |
| 72 | + fun `v1 request returning 404`(event: APIGatewayProxyRequestEvent) { |
| 73 | + val responseEvent = handlerV1!!.handleRequest(event, context!!) |
| 74 | + |
| 75 | + assertNotNull(responseEvent, "Response event should be returned") |
| 76 | + assertEquals(404, responseEvent.statusCode) |
| 77 | + assertEquals("Not Found", responseEvent.body) |
| 78 | + } |
| 79 | + |
| 80 | + @ParameterizedTest |
| 81 | + @Event(value = "handled-404/requests_v2/request.json", type = APIGatewayV2HTTPEvent::class) |
| 82 | + fun `v2 request returning 404`(event: APIGatewayV2HTTPEvent) { |
| 83 | + val responseEvent = handlerV2!!.handleRequest(event, context!!) |
| 84 | + |
| 85 | + assertNotNull(responseEvent, "Response event should be returned") |
| 86 | + assertEquals(404, responseEvent.statusCode) |
| 87 | + assertEquals("Not Found", responseEvent.body) |
| 88 | + } |
| 89 | +} |
0 commit comments