mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(apigatewayv2): add WebSocket API support, Update ops, Route/Integration Responses, Models, and Tagging (#682)
Closes #526 Add 27 new API Gateway v2 operations (21 → 48 total): - WebSocket protocol: CreateApi with WEBSOCKET, wss:// endpoints, routeSelectionExpression validation, routeResponseSelectionExpression - Update operations: UpdateApi, UpdateRoute, UpdateIntegration, UpdateAuthorizer, UpdateStage, UpdateDeployment - Route Responses: full CRUD (5 ops) - Integration Responses: full CRUD (5 ops) - Models: full CRUD (5 ops) - Tagging: TagResource, UntagResource, GetTags
This commit is contained in:
1 parent
0b5f9e183e
commit
8fe2bf4c97
29 files changed
+6179
-16
No files matched your search
+229
@@ -0,0 +1,229 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2IntegrationResponseIntegrationTest {
|
||||
|
||||
private static String apiId;
|
||||
private static String integrationId;
|
||||
private static String integrationResponseId;
|
||||
|
||||
// ──────────────────────────── Prerequisites ────────────────────────────
|
||||
|
||||
@Test @Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"test-http-api","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.body("name", equalTo("test-http-api"))
|
||||
.body("protocolType", equalTo("HTTP"))
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
@Test @Order(2)
|
||||
void createIntegration() {
|
||||
integrationId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationType":"HTTP_PROXY","integrationUri":"http://example.com","payloadFormatVersion":"2.0"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("integrationId", notNullValue())
|
||||
.extract().path("integrationId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── Integration Response CRUD ────────────────────────────
|
||||
|
||||
@Test @Order(3)
|
||||
void createIntegrationResponse() {
|
||||
integrationResponseId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"integrationResponseKey": "$default",
|
||||
"contentHandlingStrategy": "CONVERT_TO_TEXT",
|
||||
"templateSelectionExpression": "$default",
|
||||
"responseTemplates": {"application/json": "{}"},
|
||||
"responseParameters": {"append:header.X-Custom": "integration.response.header.X-Custom"}
|
||||
}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("integrationResponseId", notNullValue())
|
||||
.body("integrationResponseKey", equalTo("$default"))
|
||||
.body("integrationId", equalTo(integrationId))
|
||||
.body("contentHandlingStrategy", equalTo("CONVERT_TO_TEXT"))
|
||||
.body("templateSelectionExpression", equalTo("$default"))
|
||||
.body("responseTemplates", notNullValue())
|
||||
.body("responseParameters", notNullValue())
|
||||
.extract().path("integrationResponseId");
|
||||
}
|
||||
|
||||
@Test @Order(4)
|
||||
void getIntegrationResponse() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/" + integrationResponseId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("integrationResponseId", equalTo(integrationResponseId))
|
||||
.body("integrationResponseKey", equalTo("$default"))
|
||||
.body("integrationId", equalTo(integrationId))
|
||||
.body("contentHandlingStrategy", equalTo("CONVERT_TO_TEXT"))
|
||||
.body("templateSelectionExpression", equalTo("$default"))
|
||||
.body("responseTemplates", notNullValue())
|
||||
.body("responseParameters", notNullValue());
|
||||
}
|
||||
|
||||
@Test @Order(5)
|
||||
void getIntegrationResponses() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items", notNullValue())
|
||||
.body("items.size()", greaterThanOrEqualTo(1))
|
||||
.body("items.integrationResponseId", hasItem(integrationResponseId));
|
||||
}
|
||||
|
||||
@Test @Order(6)
|
||||
void updateIntegrationResponse() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"contentHandlingStrategy": "CONVERT_TO_BINARY"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/" + integrationResponseId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("integrationResponseId", equalTo(integrationResponseId))
|
||||
.body("contentHandlingStrategy", equalTo("CONVERT_TO_BINARY"))
|
||||
.body("integrationResponseKey", equalTo("$default"));
|
||||
}
|
||||
|
||||
@Test @Order(7)
|
||||
void deleteIntegrationResponse() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/" + integrationResponseId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test @Order(8)
|
||||
void getIntegrationResponseAfterDelete() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/" + integrationResponseId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Parent Validation ────────────────────────────
|
||||
|
||||
@Test @Order(9)
|
||||
void createIntegrationResponseWithNonExistentApi() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/nonexistent/integrations/nonexistent/integrationresponses")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(10)
|
||||
void createIntegrationResponseWithNonExistentIntegration() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations/nonexistent/integrationresponses")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Not Found Errors ────────────────────────────
|
||||
|
||||
@Test @Order(11)
|
||||
void getIntegrationResponseNotFound() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(12)
|
||||
void updateIntegrationResponseNotFound() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"contentHandlingStrategy": "CONVERT_TO_BINARY"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(13)
|
||||
void deleteIntegrationResponseNotFound() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Listing Isolation ────────────────────────────
|
||||
|
||||
@Test @Order(14)
|
||||
void listingIsolation() {
|
||||
// Create a second integration
|
||||
String secondIntegrationId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationType":"HTTP_PROXY","integrationUri":"http://other.example.com","payloadFormatVersion":"2.0"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("integrationId", notNullValue())
|
||||
.extract().path("integrationId");
|
||||
|
||||
// Create an integration response on the second integration
|
||||
String secondIntegrationResponseId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations/" + secondIntegrationId + "/integrationresponses")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("integrationResponseId", notNullValue())
|
||||
.extract().path("integrationResponseId");
|
||||
|
||||
// List integration responses for the first integration — the second integration's response must NOT appear
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/integrations/" + integrationId + "/integrationresponses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.integrationResponseId", not(hasItem(secondIntegrationResponseId)));
|
||||
}
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for API Gateway v2 Integration Response CRUD via the JSON 1.1 path.
|
||||
* Verifies PascalCase key normalization and all Integration Response CRUD operations
|
||||
* through the AmazonApiGatewayV2.* X-Amz-Target header.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2IntegrationResponseJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String apiId;
|
||||
private static String integrationId;
|
||||
private static String integrationResponseId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"ir-json11-test","ProtocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("ir-json11-test"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateIntegration ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createIntegration() {
|
||||
integrationId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateIntegration")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationType":"HTTP_PROXY","IntegrationUri":"http://example.com","PayloadFormatVersion":"2.0"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("IntegrationId", notNullValue())
|
||||
.extract().path("IntegrationId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateIntegrationResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createIntegrationResponse() {
|
||||
integrationResponseId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateIntegrationResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationResponseKey":"$default","ContentHandlingStrategy":"CONVERT_TO_TEXT","TemplateSelectionExpression":"$default"}
|
||||
""".formatted(apiId, integrationId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("IntegrationResponseId", notNullValue())
|
||||
.body("IntegrationResponseKey", equalTo("$default"))
|
||||
.body("ContentHandlingStrategy", equalTo("CONVERT_TO_TEXT"))
|
||||
.body("TemplateSelectionExpression", equalTo("$default"))
|
||||
.extract().path("IntegrationResponseId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetIntegrationResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getIntegrationResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetIntegrationResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationResponseId":"%s"}
|
||||
""".formatted(apiId, integrationId, integrationResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("IntegrationResponseId", equalTo(integrationResponseId))
|
||||
.body("IntegrationResponseKey", equalTo("$default"))
|
||||
.body("ContentHandlingStrategy", equalTo("CONVERT_TO_TEXT"))
|
||||
.body("TemplateSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetIntegrationResponses ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getIntegrationResponses() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetIntegrationResponses")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s"}
|
||||
""".formatted(apiId, integrationId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items", notNullValue())
|
||||
.body("Items.IntegrationResponseId", hasItem(integrationResponseId));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateIntegrationResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updateIntegrationResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateIntegrationResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationResponseId":"%s","ContentHandlingStrategy":"CONVERT_TO_BINARY"}
|
||||
""".formatted(apiId, integrationId, integrationResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ContentHandlingStrategy", equalTo("CONVERT_TO_BINARY"))
|
||||
.body("IntegrationResponseKey", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteIntegrationResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteIntegrationResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteIntegrationResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationResponseId":"%s"}
|
||||
""".formatted(apiId, integrationId, integrationResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetIntegrationResponse after delete ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void getIntegrationResponseAfterDelete() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetIntegrationResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationResponseId":"%s"}
|
||||
""".formatted(apiId, integrationId, integrationResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(not(equalTo(200)));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -36,6 +36,9 @@ class ApiGatewayV2IntegrationTest {
|
||||
.body("name", equalTo("test-http-api"))
|
||||
.body("protocolType", equalTo("HTTP"))
|
||||
.body("apiEndpoint", notNullValue())
|
||||
// AWS defaults must be populated
|
||||
.body("routeSelectionExpression", equalTo("${request.method} ${request.path}"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
@@ -46,7 +49,9 @@ class ApiGatewayV2IntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("apiId", equalTo(apiId))
|
||||
.body("name", equalTo("test-http-api"));
|
||||
.body("name", equalTo("test-http-api"))
|
||||
.body("routeSelectionExpression", equalTo("${request.method} ${request.path}"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"));
|
||||
}
|
||||
|
||||
@Test @Order(3)
|
||||
|
||||
+3
@@ -56,6 +56,9 @@ class ApiGatewayV2JsonHandlerTest {
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("json11-test"))
|
||||
.body("ProtocolType", equalTo("HTTP"))
|
||||
// AWS defaults must be populated
|
||||
.body("RouteSelectionExpression", equalTo("${request.method} ${request.path}"))
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2ModelsIntegrationTest {
|
||||
|
||||
private static String apiId;
|
||||
private static String modelId;
|
||||
|
||||
// ──────────────────────────── Prerequisites ────────────────────────────
|
||||
|
||||
@Test @Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"models-rest-test","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.body("name", equalTo("models-rest-test"))
|
||||
.body("protocolType", equalTo("HTTP"))
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── Model CRUD ────────────────────────────
|
||||
|
||||
@Test @Order(2)
|
||||
void createModel() {
|
||||
modelId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"name": "PetModel",
|
||||
"schema": "{\\"$schema\\":\\"http://json-schema.org/draft-04/schema#\\",\\"title\\":\\"Pet\\",\\"type\\":\\"object\\"}",
|
||||
"description": "Schema for a pet object",
|
||||
"contentType": "application/json"
|
||||
}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/models")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("modelId", notNullValue())
|
||||
.body("name", equalTo("PetModel"))
|
||||
.body("schema", notNullValue())
|
||||
.body("description", equalTo("Schema for a pet object"))
|
||||
.body("contentType", equalTo("application/json"))
|
||||
.extract().path("modelId");
|
||||
}
|
||||
|
||||
@Test @Order(3)
|
||||
void getModel() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/models/" + modelId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("modelId", equalTo(modelId))
|
||||
.body("name", equalTo("PetModel"))
|
||||
.body("schema", notNullValue())
|
||||
.body("description", equalTo("Schema for a pet object"))
|
||||
.body("contentType", equalTo("application/json"));
|
||||
}
|
||||
|
||||
@Test @Order(4)
|
||||
void getModels() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/models")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items", notNullValue())
|
||||
.body("items.size()", greaterThanOrEqualTo(1))
|
||||
.body("items.modelId", hasItem(modelId));
|
||||
}
|
||||
|
||||
@Test @Order(5)
|
||||
void updateModel() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"updated description"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/models/" + modelId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("modelId", equalTo(modelId))
|
||||
.body("description", equalTo("updated description"))
|
||||
.body("name", equalTo("PetModel"))
|
||||
.body("contentType", equalTo("application/json"));
|
||||
}
|
||||
|
||||
@Test @Order(6)
|
||||
void deleteModel() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/models/" + modelId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test @Order(7)
|
||||
void getModelAfterDelete() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/models/" + modelId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Parent Validation ────────────────────────────
|
||||
|
||||
@Test @Order(8)
|
||||
void createModelWithNonExistentApi() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"test"}
|
||||
""")
|
||||
.when().post("/v2/apis/nonexistent/models")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Not Found Errors ────────────────────────────
|
||||
|
||||
@Test @Order(9)
|
||||
void getModelNotFound() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/models/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(10)
|
||||
void updateModelNotFound() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"x"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/models/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(11)
|
||||
void deleteModelNotFound() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/models/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Listing Isolation ────────────────────────────
|
||||
|
||||
@Test @Order(12)
|
||||
void listingIsolation() {
|
||||
// Create a second API
|
||||
String secondApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"models-rest-test-2","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.extract().path("apiId");
|
||||
|
||||
// Create a Model on the second API
|
||||
String secondModelId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"OtherModel","contentType":"application/json"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + secondApiId + "/models")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("modelId", notNullValue())
|
||||
.extract().path("modelId");
|
||||
|
||||
// List Models for the first API — the second API's Model must NOT appear
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/models")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.modelId", not(hasItem(secondModelId)));
|
||||
}
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for API Gateway v2 Models CRUD via the JSON 1.1 path.
|
||||
* Verifies PascalCase key normalization and all Model CRUD operations
|
||||
* through the AmazonApiGatewayV2.* X-Amz-Target header.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2ModelsJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String apiId;
|
||||
private static String modelId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"models-json11-test","ProtocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("models-json11-test"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateModel ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createModel() {
|
||||
modelId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateModel")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"ApiId": "%s",
|
||||
"Name": "PetModel",
|
||||
"Schema": "{\\"$schema\\":\\"http://json-schema.org/draft-04/schema#\\",\\"title\\":\\"Pet\\",\\"type\\":\\"object\\"}",
|
||||
"ContentType": "application/json"
|
||||
}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ModelId", notNullValue())
|
||||
.body("Name", equalTo("PetModel"))
|
||||
.body("Schema", notNullValue())
|
||||
.body("ContentType", equalTo("application/json"))
|
||||
.extract().path("ModelId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetModel ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getModel() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetModel")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","ModelId":"%s"}
|
||||
""".formatted(apiId, modelId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ModelId", equalTo(modelId))
|
||||
.body("Name", equalTo("PetModel"))
|
||||
.body("Schema", notNullValue())
|
||||
.body("ContentType", equalTo("application/json"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetModels ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getModels() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetModels")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items", notNullValue())
|
||||
.body("Items.ModelId", hasItem(modelId));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateModel ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateModel() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateModel")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","ModelId":"%s","Description":"updated description"}
|
||||
""".formatted(apiId, modelId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ModelId", equalTo(modelId))
|
||||
.body("Description", equalTo("updated description"))
|
||||
.body("Name", equalTo("PetModel"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteModel ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteModel() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteModel")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","ModelId":"%s"}
|
||||
""".formatted(apiId, modelId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetModel after delete ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void getModelAfterDelete() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetModel")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","ModelId":"%s"}
|
||||
""".formatted(apiId, modelId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(not(equalTo(200)));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2RouteResponseIntegrationTest {
|
||||
|
||||
private static String apiId;
|
||||
private static String routeId;
|
||||
private static String routeResponseId;
|
||||
|
||||
// ──────────────────────────── Prerequisites ────────────────────────────
|
||||
|
||||
@Test @Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"test-ws-api","protocolType":"WEBSOCKET","routeSelectionExpression":"$request.body.action"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.body("name", equalTo("test-ws-api"))
|
||||
.body("protocolType", equalTo("WEBSOCKET"))
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
@Test @Order(2)
|
||||
void createRoute() {
|
||||
routeId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeId", notNullValue())
|
||||
.body("routeKey", equalTo("$default"))
|
||||
.extract().path("routeId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── Route Response CRUD ────────────────────────────
|
||||
|
||||
@Test @Order(3)
|
||||
void createRouteResponse() {
|
||||
routeResponseId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"routeResponseKey": "$default",
|
||||
"modelSelectionExpression": "$default",
|
||||
"responseModels": {"application/json": "Empty"},
|
||||
"responseParameters": {"method.response.header.Content-Type": "integration.response.header.Content-Type"}
|
||||
}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeResponseId", notNullValue())
|
||||
.body("routeResponseKey", equalTo("$default"))
|
||||
.body("routeId", equalTo(routeId))
|
||||
.body("modelSelectionExpression", equalTo("$default"))
|
||||
.body("responseModels", notNullValue())
|
||||
.body("responseParameters", notNullValue())
|
||||
.extract().path("routeResponseId");
|
||||
}
|
||||
|
||||
@Test @Order(4)
|
||||
void getRouteResponse() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/" + routeResponseId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("routeResponseId", equalTo(routeResponseId))
|
||||
.body("routeResponseKey", equalTo("$default"))
|
||||
.body("routeId", equalTo(routeId))
|
||||
.body("modelSelectionExpression", equalTo("$default"))
|
||||
.body("responseModels", notNullValue())
|
||||
.body("responseParameters", notNullValue());
|
||||
}
|
||||
|
||||
@Test @Order(5)
|
||||
void getRouteResponses() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items", notNullValue())
|
||||
.body("items.size()", greaterThanOrEqualTo(1))
|
||||
.body("items.routeResponseId", hasItem(routeResponseId));
|
||||
}
|
||||
|
||||
@Test @Order(6)
|
||||
void updateRouteResponse() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey": "$updated"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/" + routeResponseId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("routeResponseId", equalTo(routeResponseId))
|
||||
.body("routeResponseKey", equalTo("$updated"))
|
||||
.body("modelSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
@Test @Order(7)
|
||||
void deleteRouteResponse() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/" + routeResponseId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test @Order(8)
|
||||
void getRouteResponseAfterDelete() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/" + routeResponseId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Parent Validation ────────────────────────────
|
||||
|
||||
@Test @Order(9)
|
||||
void createRouteResponseWithNonExistentApi() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/nonexistent/routes/nonexistent/routeresponses")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(10)
|
||||
void createRouteResponseWithNonExistentRoute() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes/nonexistent/routeresponses")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Not Found Errors ────────────────────────────
|
||||
|
||||
@Test @Order(11)
|
||||
void getRouteResponseNotFound() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(12)
|
||||
void updateRouteResponseNotFound() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey": "$default"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test @Order(13)
|
||||
void deleteRouteResponseNotFound() {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses/nonexistent")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Listing Isolation ────────────────────────────
|
||||
|
||||
@Test @Order(14)
|
||||
void listingIsolation() {
|
||||
// Create a second route
|
||||
String secondRouteId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$connect"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeId", notNullValue())
|
||||
.extract().path("routeId");
|
||||
|
||||
// Create a route response on the second route
|
||||
String secondRouteResponseId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeResponseKey": "$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/routes/" + secondRouteId + "/routeresponses")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeResponseId", notNullValue())
|
||||
.extract().path("routeResponseId");
|
||||
|
||||
// List route responses for the first route — the second route's response must NOT appear
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId + "/routes/" + routeId + "/routeresponses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.routeResponseId", not(hasItem(secondRouteResponseId)));
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for API Gateway v2 Route Response CRUD via the JSON 1.1 path.
|
||||
* Verifies PascalCase key normalization and all Route Response CRUD operations
|
||||
* through the AmazonApiGatewayV2.* X-Amz-Target header.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2RouteResponseJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String apiId;
|
||||
private static String routeId;
|
||||
private static String routeResponseId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"rr-json11-test","ProtocolType":"WEBSOCKET","RouteSelectionExpression":"$request.body.action"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("rr-json11-test"))
|
||||
.body("ProtocolType", equalTo("WEBSOCKET"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createRoute() {
|
||||
routeId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteKey":"$default","AuthorizationType":"NONE","RouteResponseSelectionExpression":"$default"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("RouteId", notNullValue())
|
||||
.body("RouteKey", equalTo("$default"))
|
||||
.extract().path("RouteId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateRouteResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createRouteResponse() {
|
||||
routeResponseId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateRouteResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseKey":"$default","ModelSelectionExpression":"$default"}
|
||||
""".formatted(apiId, routeId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("RouteResponseId", notNullValue())
|
||||
.body("RouteResponseKey", equalTo("$default"))
|
||||
.body("ModelSelectionExpression", equalTo("$default"))
|
||||
.extract().path("RouteResponseId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRouteResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getRouteResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRouteResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseId":"%s"}
|
||||
""".formatted(apiId, routeId, routeResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteResponseId", equalTo(routeResponseId))
|
||||
.body("RouteResponseKey", equalTo("$default"))
|
||||
.body("ModelSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRouteResponses ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getRouteResponses() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRouteResponses")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s"}
|
||||
""".formatted(apiId, routeId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items", notNullValue())
|
||||
.body("Items.RouteResponseId", hasItem(routeResponseId));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateRouteResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updateRouteResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateRouteResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseId":"%s","RouteResponseKey":"$updated"}
|
||||
""".formatted(apiId, routeId, routeResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteResponseId", equalTo(routeResponseId))
|
||||
.body("RouteResponseKey", equalTo("$updated"))
|
||||
.body("ModelSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteRouteResponse ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteRouteResponse() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteRouteResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseId":"%s"}
|
||||
""".formatted(apiId, routeId, routeResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRouteResponse after delete ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void getRouteResponseAfterDelete() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRouteResponse")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseId":"%s"}
|
||||
""".formatted(apiId, routeId, routeResponseId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(not(equalTo(200)));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* JSON 1.1 path integration tests for the three standalone tagging operations:
|
||||
* AmazonApiGatewayV2.TagResource, AmazonApiGatewayV2.UntagResource, and
|
||||
* AmazonApiGatewayV2.GetTags.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2TaggingJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String apiId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
/** Builds the ARN for the given API ID. */
|
||||
private static String arn(String id) {
|
||||
return "arn:aws:apigateway:us-east-1::/apis/" + id;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Setup: create shared API ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"tagging-json11-test-api","ProtocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("tagging-json11-test-api"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource — HTTP 201 + empty body ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.TagResource with PascalCase ResourceArn and Tags,
|
||||
* verify HTTP 201 and {} response.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void tagResource_returns200AndEmptyBody() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "TagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","Tags":{"env":"production","team":"platform"}}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("{}"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags after TagResource ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.GetTags after tagging — verify Tags map in response
|
||||
* contains the added tags.
|
||||
*/
|
||||
@Test
|
||||
@Order(11)
|
||||
void getTags_afterTagResource_containsAddedTags() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetTags")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s"}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.env", equalTo("production"))
|
||||
.body("Tags.team", equalTo("platform"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource merge semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.TagResource twice with different keys — verify merge
|
||||
* semantics via GetTags (both sets present).
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
void tagResource_mergeSemantics_bothSetsPresent() {
|
||||
// First call: add "env" and "team"
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "TagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","Tags":{"env":"staging","team":"backend"}}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Second call: add a different key "owner"
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "TagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","Tags":{"owner":"alice"}}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Both sets must be present
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetTags")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s"}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.env", equalTo("staging"))
|
||||
.body("Tags.team", equalTo("backend"))
|
||||
.body("Tags.owner", equalTo("alice"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.TagResource with a non-existent ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(30)
|
||||
void tagResource_notFound_returns404() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "TagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"arn:aws:apigateway:us-east-1::/apis/nonexistent","Tags":{"key":"value"}}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource — removes keys ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.UntagResource with a TagKeys array — verify HTTP 204
|
||||
* and keys are removed via GetTags.
|
||||
*/
|
||||
@Test
|
||||
@Order(40)
|
||||
void untagResource_removesKeys_returns204() {
|
||||
// Ensure tags are present first
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "TagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","Tags":{"env":"to-be-removed","keep":"this"}}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Remove "env"
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UntagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","TagKeys":["env"]}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// "env" must be absent; "keep" must still be present
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetTags")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s"}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", not(hasKey("env")))
|
||||
.body("Tags.keep", equalTo("this"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource silent-ignore ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.UntagResource with a key that does not exist —
|
||||
* verify HTTP 204 (silent ignore).
|
||||
*/
|
||||
@Test
|
||||
@Order(41)
|
||||
void untagResource_nonexistentKey_silentIgnore_returns204() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UntagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s","TagKeys":["this-key-does-not-exist"]}
|
||||
""".formatted(arn(apiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.UntagResource with a non-existent ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(50)
|
||||
void untagResource_notFound_returns404() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UntagResource")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"arn:aws:apigateway:us-east-1::/apis/nonexistent","TagKeys":["somekey"]}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags on API with no tags ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.GetTags on an API with no tags — verify HTTP 200
|
||||
* and {"Tags": {}}.
|
||||
*/
|
||||
@Test
|
||||
@Order(60)
|
||||
void getTags_noTags_returnsEmptyMap() {
|
||||
// Create a fresh API with no tags
|
||||
String freshApiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"tagging-json11-notags-api","ProtocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("ApiId");
|
||||
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetTags")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"%s"}
|
||||
""".formatted(arn(freshApiId)))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", anEmptyMap());
|
||||
|
||||
// Cleanup the fresh API
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(freshApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* Send AmazonApiGatewayV2.GetTags on a non-existent ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(70)
|
||||
void getTags_notFound_returns404() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetTags")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn":"arn:aws:apigateway:us-east-1::/apis/nonexistent"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* REST path integration tests for the three standalone tagging operations:
|
||||
* TagResource (POST /v2/tags/{arn}), UntagResource (DELETE /v2/tags/{arn}),
|
||||
* and GetTags (GET /v2/tags/{arn}).
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2TaggingRestTest {
|
||||
|
||||
private static String apiId;
|
||||
|
||||
/** Builds the ARN for the given API ID. */
|
||||
private static String arn(String id) {
|
||||
return "arn:aws:apigateway:us-east-1::/apis/" + id;
|
||||
}
|
||||
|
||||
/** Builds the /v2/tags/{arn} path. Colons are valid in URL paths; slashes in the ARN
|
||||
* are captured by the {@code {resourceArn: .+}} regex in the controller. */
|
||||
private static String tagsPath(String id) {
|
||||
return "/v2/tags/" + arn(id);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Setup: create shared API ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"tagging-rest-test-api","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource — HTTP 201 + empty body ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API, POST /v2/tags/{arn} with a tags map, verify HTTP 201 and {} response body.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void tagResource_returns201AndEmptyBody() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"env":"production","team":"platform"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body(equalTo("{}"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags after TagResource ────────────────────────────
|
||||
|
||||
/**
|
||||
* GET /v2/tags/{arn} after tagging — verify the response tags map contains the added keys.
|
||||
*/
|
||||
@Test
|
||||
@Order(11)
|
||||
void getTags_afterTagResource_containsAddedTags() {
|
||||
given()
|
||||
.when().get(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.env", equalTo("production"))
|
||||
.body("tags.team", equalTo("platform"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource merge semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Call PUT twice with different keys — verify both sets are present via GetTags.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
void tagResource_mergeSemantics_bothSetsPresent() {
|
||||
// First PUT: add "env" and "team" (already done in order 10, but re-add to be explicit)
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"env":"staging","team":"backend"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
// Second PUT: add a different key "owner"
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"owner":"alice"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
// Both sets must be present
|
||||
given()
|
||||
.when().get(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.env", equalTo("staging"))
|
||||
.body("tags.team", equalTo("backend"))
|
||||
.body("tags.owner", equalTo("alice"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── TagResource overwrite ────────────────────────────
|
||||
|
||||
/**
|
||||
* Call PUT with an existing key and new value — verify the value is updated via GetTags.
|
||||
*/
|
||||
@Test
|
||||
@Order(21)
|
||||
void tagResource_overwrite_updatesExistingValue() {
|
||||
// "env" was "staging" from order 20; overwrite it
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"env":"production-overwritten"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when().get(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.env", equalTo("production-overwritten"))
|
||||
// Other keys must still be present
|
||||
.body("tags.team", equalTo("backend"))
|
||||
.body("tags.owner", equalTo("alice"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── 4.5 TagResource not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* 4.5 PUT /v2/tags/{arn} with a non-existent API ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(30)
|
||||
void tagResource_notFound_returns404() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"key":"value"}}
|
||||
""")
|
||||
.when().post(tagsPath("nonexistent"))
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource — removes key ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API with tags, DELETE /v2/tags/{arn}?tagKeys=key1, verify HTTP 204 and key absent.
|
||||
*/
|
||||
@Test
|
||||
@Order(40)
|
||||
void untagResource_removesKey_returns204() {
|
||||
// Ensure "env" is present first
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"env":"to-be-removed","keep":"this"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
// Remove "env"
|
||||
given()
|
||||
.when().delete(tagsPath(apiId) + "?tagKeys=env")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// "env" must be absent; "keep" must still be present
|
||||
given()
|
||||
.when().get(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags", not(hasKey("env")))
|
||||
.body("tags.keep", equalTo("this"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource silent-ignore ────────────────────────────
|
||||
|
||||
/**
|
||||
* DELETE /v2/tags/{arn}?tagKeys=nonexistent — verify HTTP 204 (silent ignore).
|
||||
*/
|
||||
@Test
|
||||
@Order(41)
|
||||
void untagResource_nonexistentKey_silentIgnore_returns204() {
|
||||
given()
|
||||
.when().delete(tagsPath(apiId) + "?tagKeys=this-key-does-not-exist")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource multiple keys ────────────────────────────
|
||||
|
||||
/**
|
||||
* DELETE /v2/tags/{arn}?tagKeys=key1&tagKeys=key2 — verify both keys are removed.
|
||||
*/
|
||||
@Test
|
||||
@Order(42)
|
||||
void untagResource_multipleKeys_bothRemoved() {
|
||||
// Add two keys to remove
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"alpha":"1","beta":"2","gamma":"3"}}
|
||||
""")
|
||||
.when().post(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
// Remove alpha and beta in one call using repeated query params (AWS SDK format)
|
||||
given()
|
||||
.queryParam("tagKeys", "alpha")
|
||||
.queryParam("tagKeys", "beta")
|
||||
.when().delete(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// alpha and beta must be gone; gamma must remain
|
||||
given()
|
||||
.when().get(tagsPath(apiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags", not(hasKey("alpha")))
|
||||
.body("tags", not(hasKey("beta")))
|
||||
.body("tags.gamma", equalTo("3"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UntagResource not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* DELETE /v2/tags/{arn} with a non-existent API ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(50)
|
||||
void untagResource_notFound_returns404() {
|
||||
given()
|
||||
.when().delete(tagsPath("nonexistent") + "?tagKeys=somekey")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags on API with no tags ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create an API with no tags, GET /v2/tags/{arn} — verify HTTP 200 and {"tags": {}}.
|
||||
*/
|
||||
@Test
|
||||
@Order(60)
|
||||
void getTags_noTags_returnsEmptyMap() {
|
||||
// Create a fresh API with no tags
|
||||
String freshApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"tagging-rest-notags-api","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("apiId");
|
||||
|
||||
given()
|
||||
.when().get(tagsPath(freshApiId))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags", anEmptyMap());
|
||||
|
||||
// Cleanup the fresh API
|
||||
given()
|
||||
.when().delete("/v2/apis/" + freshApiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetTags not-found ────────────────────────────
|
||||
|
||||
/**
|
||||
* GET /v2/tags/{arn} with a non-existent API ARN — verify HTTP 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(70)
|
||||
void getTags_notFound_returns404() {
|
||||
given()
|
||||
.when().get(tagsPath("nonexistent"))
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+404
@@ -0,0 +1,404 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* JSON 1.1 path integration tests for the four missing Update operations:
|
||||
* UpdateIntegration, UpdateAuthorizer, UpdateStage, UpdateDeployment.
|
||||
*
|
||||
* Verifies PascalCase key normalization and merge-patch semantics through
|
||||
* the AmazonApiGatewayV2.* X-Amz-Target header.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2UpdateOperationsJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String apiId;
|
||||
private static String integrationId;
|
||||
private static String authorizerId;
|
||||
private static String stageName;
|
||||
private static String deploymentId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Setup: create shared resources ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void setupCreateApi() {
|
||||
apiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"update-ops-json11-api","ProtocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void setupCreateIntegration() {
|
||||
integrationId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateIntegration")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationType":"HTTP_PROXY","IntegrationUri":"https://original.example.com","PayloadFormatVersion":"2.0"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("IntegrationId", notNullValue())
|
||||
.body("IntegrationUri", equalTo("https://original.example.com"))
|
||||
.extract().path("IntegrationId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void setupCreateAuthorizer() {
|
||||
authorizerId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateAuthorizer")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","AuthorizerType":"JWT","Name":"original-authorizer","IdentitySource":["$request.header.Authorization"],"JwtConfiguration":{"Issuer":"https://original-issuer.example.com","Audience":["original-audience"]}}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("AuthorizerId", notNullValue())
|
||||
.body("Name", equalTo("original-authorizer"))
|
||||
.extract().path("AuthorizerId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void setupCreateDeployment() {
|
||||
deploymentId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeployment")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","Description":"initial-deployment"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("DeploymentId", notNullValue())
|
||||
.extract().path("DeploymentId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void setupCreateStage() {
|
||||
stageName = "test-stage-json11";
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateStage")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","StageName":"%s","DeploymentId":"%s","AutoDeploy":false}
|
||||
""".formatted(apiId, stageName, deploymentId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("StageName", equalTo(stageName))
|
||||
.body("DeploymentId", equalTo(deploymentId));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateIntegration: PascalCase request/response ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test AmazonApiGatewayV2.UpdateIntegration: send PascalCase request,
|
||||
* verify HTTP 200 and PascalCase response fields.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void updateIntegrationViaPascalCaseKeys() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateIntegration")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationUri":"https://updated.example.com"}
|
||||
""".formatted(apiId, integrationId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("IntegrationId", equalTo(integrationId))
|
||||
.body("IntegrationUri", equalTo("https://updated.example.com"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateIntegration: merge-patch semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test UpdateIntegration merge-patch via JSON 1.1:
|
||||
* verify only provided fields are updated, others preserved.
|
||||
*/
|
||||
@Test
|
||||
@Order(11)
|
||||
void updateIntegrationMergePatchPreservesUnprovidedFields() {
|
||||
// PATCH only IntegrationUri; IntegrationType and PayloadFormatVersion must be preserved
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateIntegration")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s","IntegrationUri":"https://patched.example.com"}
|
||||
""".formatted(apiId, integrationId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("IntegrationUri", equalTo("https://patched.example.com"))
|
||||
// Fields not in request must be preserved
|
||||
.body("IntegrationType", equalTo("HTTP_PROXY"))
|
||||
.body("PayloadFormatVersion", equalTo("2.0"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateAuthorizer: PascalCase request/response ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test AmazonApiGatewayV2.UpdateAuthorizer: send PascalCase request,
|
||||
* verify HTTP 200 and PascalCase response fields.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
void updateAuthorizerViaPascalCaseKeys() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateAuthorizer")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","AuthorizerId":"%s","Name":"updated-authorizer"}
|
||||
""".formatted(apiId, authorizerId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AuthorizerId", equalTo(authorizerId))
|
||||
.body("Name", equalTo("updated-authorizer"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateAuthorizer: merge-patch semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test UpdateAuthorizer merge-patch via JSON 1.1:
|
||||
* verify only provided fields are updated, others preserved.
|
||||
*/
|
||||
@Test
|
||||
@Order(21)
|
||||
void updateAuthorizerMergePatchPreservesUnprovidedFields() {
|
||||
// PATCH only Name; AuthorizerType and IdentitySource must be preserved
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateAuthorizer")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","AuthorizerId":"%s","Name":"merge-patch-authorizer"}
|
||||
""".formatted(apiId, authorizerId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Name", equalTo("merge-patch-authorizer"))
|
||||
// Fields not in request must be preserved
|
||||
.body("AuthorizerType", equalTo("JWT"))
|
||||
.body("IdentitySource", hasItem("$request.header.Authorization"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateStage: PascalCase request/response ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test AmazonApiGatewayV2.UpdateStage: send PascalCase request,
|
||||
* verify HTTP 200 and PascalCase response fields.
|
||||
*/
|
||||
@Test
|
||||
@Order(30)
|
||||
void updateStageViaPascalCaseKeys() {
|
||||
// Create a second deployment to use as the new DeploymentId
|
||||
String newDeploymentId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeployment")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","Description":"second-deployment"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("DeploymentId");
|
||||
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateStage")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","StageName":"%s","DeploymentId":"%s"}
|
||||
""".formatted(apiId, stageName, newDeploymentId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("StageName", equalTo(stageName))
|
||||
.body("DeploymentId", equalTo(newDeploymentId));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateStage: merge-patch semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test UpdateStage merge-patch via JSON 1.1:
|
||||
* verify only provided fields are updated, others preserved.
|
||||
*/
|
||||
@Test
|
||||
@Order(31)
|
||||
void updateStageMergePatchPreservesUnprovidedFields() {
|
||||
// PATCH only AutoDeploy; StageName and DeploymentId must be preserved
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateStage")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","StageName":"%s","AutoDeploy":true}
|
||||
""".formatted(apiId, stageName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("StageName", equalTo(stageName))
|
||||
.body("AutoDeploy", equalTo(true))
|
||||
// DeploymentId set in order 30 must still be present
|
||||
.body("DeploymentId", notNullValue())
|
||||
// LastUpdatedDate must be present (updated on every PATCH)
|
||||
.body("LastUpdatedDate", notNullValue());
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateDeployment: PascalCase request/response ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test AmazonApiGatewayV2.UpdateDeployment: send PascalCase request,
|
||||
* verify HTTP 200 and PascalCase response fields.
|
||||
*/
|
||||
@Test
|
||||
@Order(40)
|
||||
void updateDeploymentViaPascalCaseKeys() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateDeployment")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","DeploymentId":"%s","Description":"updated-description"}
|
||||
""".formatted(apiId, deploymentId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeploymentId", equalTo(deploymentId))
|
||||
.body("Description", equalTo("updated-description"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateDeployment: merge-patch semantics ────────────────────────────
|
||||
|
||||
/**
|
||||
* Test UpdateDeployment merge-patch via JSON 1.1:
|
||||
* verify only provided fields are updated, others preserved.
|
||||
*/
|
||||
@Test
|
||||
@Order(41)
|
||||
void updateDeploymentMergePatchPreservesUnprovidedFields() {
|
||||
// PATCH only Description; DeploymentStatus must be preserved
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateDeployment")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","DeploymentId":"%s","Description":"merge-patch-description"}
|
||||
""".formatted(apiId, deploymentId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Description", equalTo("merge-patch-description"))
|
||||
// DeploymentStatus should be preserved
|
||||
.body("DeploymentStatus", equalTo("DEPLOYED"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (apiId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete stage
|
||||
if (stageName != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteStage")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","StageName":"%s"}
|
||||
""".formatted(apiId, stageName))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// Delete authorizer
|
||||
if (authorizerId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteAuthorizer")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","AuthorizerId":"%s"}
|
||||
""".formatted(apiId, authorizerId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// Delete integration
|
||||
if (integrationId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteIntegration")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","IntegrationId":"%s"}
|
||||
""".formatted(apiId, integrationId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// Delete API (cascades deployments)
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(apiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
+411
@@ -0,0 +1,411 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* REST path integration tests for the four missing Update operations:
|
||||
* UpdateIntegration, UpdateAuthorizer, UpdateStage, UpdateDeployment.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2UpdateOperationsRestTest {
|
||||
|
||||
private static String apiId;
|
||||
private static String integrationId;
|
||||
private static String authorizerId;
|
||||
private static String deploymentId;
|
||||
|
||||
// ──────────────────────────── Setup: create shared API ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createApi() {
|
||||
apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"update-ops-test-api","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateIntegration ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API + integration, PATCH with new integrationUri, verify HTTP 200 and updated field.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void createIntegrationForUpdate() {
|
||||
integrationId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationType":"HTTP_PROXY","integrationUri":"https://original.example.com","payloadFormatVersion":"2.0"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/integrations")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("integrationId", notNullValue())
|
||||
.body("integrationUri", equalTo("https://original.example.com"))
|
||||
.extract().path("integrationId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void updateIntegrationUri() {
|
||||
// PATCH with new integrationUri, verify HTTP 200 and updated field
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationUri":"https://updated.example.com"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("integrationId", equalTo(integrationId))
|
||||
.body("integrationUri", equalTo("https://updated.example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void updateIntegrationMergePatch() {
|
||||
// Verify fields not in PATCH body are preserved
|
||||
// PATCH only integrationUri; integrationType and payloadFormatVersion must be preserved
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationUri":"https://patched.example.com"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/integrations/" + integrationId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("integrationUri", equalTo("https://patched.example.com"))
|
||||
// Fields not in PATCH body must be preserved
|
||||
.body("integrationType", equalTo("HTTP_PROXY"))
|
||||
.body("payloadFormatVersion", equalTo("2.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void updateIntegrationNotFound() {
|
||||
// PATCH non-existent integrationId, verify HTTP 404
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"integrationUri":"https://ghost.example.com"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/integrations/nonexistent-integration-id")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateAuthorizer ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API + authorizer, PATCH with new name, verify HTTP 200 and updated field.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
void createAuthorizerForUpdate() {
|
||||
authorizerId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"authorizerType":"JWT","name":"original-authorizer","identitySource":["$request.header.Authorization"],"jwtConfiguration":{"issuer":"https://original-issuer.example.com","audience":["original-audience"]}}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("authorizerId", notNullValue())
|
||||
.body("name", equalTo("original-authorizer"))
|
||||
.extract().path("authorizerId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void updateAuthorizerName() {
|
||||
// PATCH with new name, verify HTTP 200 and updated field
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"updated-authorizer"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("authorizerId", equalTo(authorizerId))
|
||||
.body("name", equalTo("updated-authorizer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void updateAuthorizerJwtConfiguration() {
|
||||
// PATCH with new audience and issuer, verify nested fields updated
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"jwtConfiguration":{"audience":["new-client-id"],"issuer":"https://new-issuer.example.com"}}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("authorizerId", equalTo(authorizerId))
|
||||
.body("jwtConfiguration.audience", hasItem("new-client-id"))
|
||||
.body("jwtConfiguration.issuer", equalTo("https://new-issuer.example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void updateAuthorizerMergePatch() {
|
||||
// Verify fields not in PATCH body are preserved
|
||||
// PATCH only name; authorizerType and identitySource must be preserved
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"merge-patch-authorizer"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("merge-patch-authorizer"))
|
||||
// Fields not in PATCH body must be preserved
|
||||
.body("authorizerType", equalTo("JWT"))
|
||||
.body("identitySource", hasItem("$request.header.Authorization"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void updateAuthorizerNotFound() {
|
||||
// PATCH non-existent authorizerId, verify HTTP 404
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ghost-authorizer"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/authorizers/nonexistent-authorizer-id")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateStage ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API + stage, PATCH with new deploymentId, verify HTTP 200 and updated field.
|
||||
*/
|
||||
@Test
|
||||
@Order(30)
|
||||
void createDeploymentAndStageForUpdate() {
|
||||
// Create a deployment first (needed for stage)
|
||||
deploymentId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"initial-deployment"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("deploymentId", notNullValue())
|
||||
.extract().path("deploymentId");
|
||||
|
||||
// Create stage with autoDeploy=false and initial deploymentId
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"stageName":"test-stage","deploymentId":"%s","autoDeploy":false}
|
||||
""".formatted(deploymentId))
|
||||
.when().post("/v2/apis/" + apiId + "/stages")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("stageName", equalTo("test-stage"))
|
||||
.body("deploymentId", equalTo(deploymentId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void updateStageDeploymentId() {
|
||||
// PATCH with new deploymentId, verify HTTP 200 and updated field
|
||||
// Create a second deployment to use as the new deploymentId
|
||||
String newDeploymentId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"second-deployment"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + apiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("deploymentId");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"deploymentId":"%s"}
|
||||
""".formatted(newDeploymentId))
|
||||
.when().patch("/v2/apis/" + apiId + "/stages/test-stage")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageName", equalTo("test-stage"))
|
||||
.body("deploymentId", equalTo(newDeploymentId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void updateStageLastUpdatedDate() {
|
||||
// Verify lastUpdatedDate is present and non-null after PATCH
|
||||
// First GET to capture current state
|
||||
String lastUpdatedBefore = given()
|
||||
.when().get("/v2/apis/" + apiId + "/stages/test-stage")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("lastUpdatedDate", notNullValue())
|
||||
.extract().path("lastUpdatedDate").toString();
|
||||
|
||||
// PATCH and verify lastUpdatedDate is present (and changes)
|
||||
String lastUpdatedAfter = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"autoDeploy":true}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/stages/test-stage")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("lastUpdatedDate", notNullValue())
|
||||
.extract().path("lastUpdatedDate").toString();
|
||||
|
||||
// lastUpdatedDate should have changed after the PATCH
|
||||
Assertions.assertNotEquals(lastUpdatedBefore, lastUpdatedAfter,
|
||||
"lastUpdatedDate should change after PATCH");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(33)
|
||||
void updateStageMergePatch() {
|
||||
// Verify fields not in PATCH body are preserved
|
||||
// PATCH only autoDeploy; stageName must be preserved (it's the key, always present)
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"autoDeploy":false}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/stages/test-stage")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("stageName", equalTo("test-stage"))
|
||||
.body("autoDeploy", equalTo(false))
|
||||
// deploymentId set in order 31 must still be present
|
||||
.body("deploymentId", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(34)
|
||||
void updateStageNotFound() {
|
||||
// PATCH non-existent stageName, verify HTTP 404
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"autoDeploy":true}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/stages/nonexistent-stage-name")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateDeployment ────────────────────────────
|
||||
|
||||
/**
|
||||
* Create API + deployment, PATCH with new description, verify HTTP 200 and updated field.
|
||||
*/
|
||||
@Test
|
||||
@Order(40)
|
||||
void updateDeploymentDescription() {
|
||||
// PATCH with new description, verify HTTP 200 and updated field
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"updated-description"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/deployments/" + deploymentId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("deploymentId", equalTo(deploymentId))
|
||||
.body("description", equalTo("updated-description"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void updateDeploymentMergePatch() {
|
||||
// Verify fields not in PATCH body are preserved
|
||||
// PATCH only description; deploymentStatus must be preserved
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"merge-patch-description"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/deployments/" + deploymentId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("merge-patch-description"))
|
||||
// deploymentStatus should be preserved
|
||||
.body("deploymentStatus", equalTo("DEPLOYED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(42)
|
||||
void updateDeploymentNotFound() {
|
||||
// PATCH non-existent deploymentId, verify HTTP 404
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"description":"ghost-description"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + apiId + "/deployments/nonexistent-deployment-id")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
// Delete stage
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/stages/test-stage")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
|
||||
// Delete authorizer
|
||||
if (authorizerId != null) {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// Delete integration
|
||||
if (integrationId != null) {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/integrations/" + integrationId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
|
||||
// Delete API (cascades deployments)
|
||||
if (apiId != null) {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+440
@@ -0,0 +1,440 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2WebSocketIntegrationTest {
|
||||
|
||||
private static String wsApiId;
|
||||
private static String wsRouteId;
|
||||
private static String httpApiId;
|
||||
private static String taggedApiId;
|
||||
|
||||
// ──────────────────────────── WebSocket API Creation ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createWebSocketApi() {
|
||||
wsApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ws-test-api","protocolType":"WEBSOCKET","routeSelectionExpression":"$request.body.action","description":"A test WS API","apiKeySelectionExpression":"$request.header.x-api-key"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.body("name", equalTo("ws-test-api"))
|
||||
.body("protocolType", equalTo("WEBSOCKET"))
|
||||
.body("routeSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("description", equalTo("A test WS API"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("apiEndpoint", startsWith("wss://"))
|
||||
.extract().path("apiId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createWebSocketApiMissingRouteSelectionExpression() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ws-no-rse","protocolType":"WEBSOCKET"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getWebSocketApi() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + wsApiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("apiId", equalTo(wsApiId))
|
||||
.body("name", equalTo("ws-test-api"))
|
||||
.body("protocolType", equalTo("WEBSOCKET"))
|
||||
.body("routeSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("description", equalTo("A test WS API"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("apiEndpoint", startsWith("wss://"))
|
||||
.body("createdDate", notNullValue());
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetApis ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getApisIncludesWebSocket() {
|
||||
given()
|
||||
.when().get("/v2/apis")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.apiId", hasItem(wsApiId))
|
||||
.body("items.find { it.apiId == '" + wsApiId + "' }.routeSelectionExpression",
|
||||
equalTo("$request.body.action"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateWebSocketApi() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ws-updated-api","description":"Updated description"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + wsApiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("apiId", equalTo(wsApiId))
|
||||
.body("name", equalTo("ws-updated-api"))
|
||||
.body("description", equalTo("Updated description"))
|
||||
// Non-provided fields should be preserved
|
||||
.body("protocolType", equalTo("WEBSOCKET"))
|
||||
.body("routeSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("apiEndpoint", startsWith("wss://"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updateApiNotFound() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ghost"}
|
||||
""")
|
||||
.when().patch("/v2/apis/nonexistent999")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteWebSocketApiAndVerify() {
|
||||
// Create a temporary API to delete
|
||||
String tempApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ws-to-delete","protocolType":"WEBSOCKET","routeSelectionExpression":"$request.body.action"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("apiId");
|
||||
|
||||
// Delete it
|
||||
given()
|
||||
.when().delete("/v2/apis/" + tempApiId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Verify it's gone
|
||||
given()
|
||||
.when().get("/v2/apis/" + tempApiId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void createApiWithTagsAndVerifyInGetApi() {
|
||||
taggedApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"ws-tagged","protocolType":"WEBSOCKET","routeSelectionExpression":"$request.body.action","tags":{"env":"dev","team":"platform"}}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("tags.env", equalTo("dev"))
|
||||
.body("tags.team", equalTo("platform"))
|
||||
.extract().path("apiId");
|
||||
|
||||
// GetApi returns tags
|
||||
given()
|
||||
.when().get("/v2/apis/" + taggedApiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.env", equalTo("dev"))
|
||||
.body("tags.team", equalTo("platform"));
|
||||
|
||||
// GetApis returns tags
|
||||
given()
|
||||
.when().get("/v2/apis")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.find { it.apiId == '" + taggedApiId + "' }.tags.env", equalTo("dev"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void updateApiTagsReplacement() {
|
||||
// Replace tags entirely
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"tags":{"env":"prod","version":"2"}}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + taggedApiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.env", equalTo("prod"))
|
||||
.body("tags.version", equalTo("2"))
|
||||
.body("tags.team", nullValue())
|
||||
// Non-tag fields preserved
|
||||
.body("name", equalTo("ws-tagged"))
|
||||
.body("routeSelectionExpression", equalTo("$request.body.action"));
|
||||
|
||||
// Cleanup
|
||||
given().when().delete("/v2/apis/" + taggedApiId).then().statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateRoute with routeResponseSelectionExpression ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void createRouteWithRouteResponseSelectionExpression() {
|
||||
wsRouteId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$default","authorizationType":"NONE","routeResponseSelectionExpression":"$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + wsApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeId", notNullValue())
|
||||
.body("routeKey", equalTo("$default"))
|
||||
.body("authorizationType", equalTo("NONE"))
|
||||
.body("routeResponseSelectionExpression", equalTo("$default"))
|
||||
.extract().path("routeId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── WebSocket lifecycle route keys ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void createConnectRoute() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$connect","authorizationType":"NONE","routeResponseSelectionExpression":"$default"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + wsApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeKey", equalTo("$connect"))
|
||||
.body("routeResponseSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void createDisconnectRoute() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$disconnect","authorizationType":"NONE"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + wsApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeKey", equalTo("$disconnect"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void getRouteReturnsRouteResponseSelectionExpression() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + wsApiId + "/routes/" + wsRouteId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("routeId", equalTo(wsRouteId))
|
||||
.body("routeKey", equalTo("$default"))
|
||||
.body("routeResponseSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRoutes ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void getRoutesReturnsAllRoutesWithRouteResponseSelectionExpression() {
|
||||
given()
|
||||
.when().get("/v2/apis/" + wsApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("items.routeId", hasItem(wsRouteId))
|
||||
.body("items.find { it.routeId == '" + wsRouteId + "' }.routeResponseSelectionExpression",
|
||||
equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void updateRouteMergePatch() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"target":"integrations/int123","routeResponseSelectionExpression":"$default"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + wsApiId + "/routes/" + wsRouteId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("routeId", equalTo(wsRouteId))
|
||||
.body("target", equalTo("integrations/int123"))
|
||||
.body("routeResponseSelectionExpression", equalTo("$default"))
|
||||
// Non-provided fields preserved
|
||||
.body("routeKey", equalTo("$default"))
|
||||
.body("authorizationType", equalTo("NONE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void updateRouteNotFound() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"$connect"}
|
||||
""")
|
||||
.when().patch("/v2/apis/" + wsApiId + "/routes/nonexistent999")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void deleteRouteAndVerify() {
|
||||
// Create a temporary route to delete
|
||||
String tempRouteId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"temp-route","authorizationType":"NONE"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + wsApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("routeId");
|
||||
|
||||
// Delete it
|
||||
given()
|
||||
.when().delete("/v2/apis/" + wsApiId + "/routes/" + tempRouteId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Verify it's gone
|
||||
given()
|
||||
.when().get("/v2/apis/" + wsApiId + "/routes/" + tempRouteId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── HTTP API backward compatibility ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void httpApiCrudStillWorks() {
|
||||
// Create HTTP API
|
||||
httpApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"http-compat-api","protocolType":"HTTP"}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("apiId", notNullValue())
|
||||
.body("name", equalTo("http-compat-api"))
|
||||
.body("protocolType", equalTo("HTTP"))
|
||||
.body("apiEndpoint", startsWith("https://"))
|
||||
// AWS defaults must be populated even when not provided
|
||||
.body("routeSelectionExpression", equalTo("${request.method} ${request.path}"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.extract().path("apiId");
|
||||
|
||||
// Get HTTP API — verify defaults are persisted
|
||||
given()
|
||||
.when().get("/v2/apis/" + httpApiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("apiId", equalTo(httpApiId))
|
||||
.body("protocolType", equalTo("HTTP"))
|
||||
.body("routeSelectionExpression", equalTo("${request.method} ${request.path}"))
|
||||
.body("apiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("createdDate", notNullValue());
|
||||
|
||||
// Create route on HTTP API
|
||||
String httpRouteId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"routeKey":"GET /health","authorizationType":"NONE"}
|
||||
""")
|
||||
.when().post("/v2/apis/" + httpApiId + "/routes")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("routeId", notNullValue())
|
||||
.body("routeKey", equalTo("GET /health"))
|
||||
.extract().path("routeId");
|
||||
|
||||
// Get route on HTTP API
|
||||
given()
|
||||
.when().get("/v2/apis/" + httpApiId + "/routes/" + httpRouteId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("routeId", equalTo(httpRouteId))
|
||||
.body("routeKey", equalTo("GET /health"));
|
||||
|
||||
// Delete route
|
||||
given()
|
||||
.when().delete("/v2/apis/" + httpApiId + "/routes/" + httpRouteId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Delete HTTP API
|
||||
given()
|
||||
.when().delete("/v2/apis/" + httpApiId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Verify deleted
|
||||
given()
|
||||
.when().get("/v2/apis/" + httpApiId)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanupWebSocketApi() {
|
||||
if (wsApiId != null) {
|
||||
given()
|
||||
.when().delete("/v2/apis/" + wsApiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+470
@@ -0,0 +1,470 @@
|
||||
package io.github.hectorvent.floci.services.apigatewayv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests for API Gateway v2 WebSocket support via the JSON 1.1 path.
|
||||
* Verifies PascalCase key normalization and all WebSocket CRUD operations
|
||||
* through the AmazonApiGatewayV2.* X-Amz-Target header.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ApiGatewayV2WebSocketJson11Test {
|
||||
|
||||
private static final String AMZ_JSON = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "AmazonApiGatewayV2.";
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260413/us-east-1/apigatewayv2/aws4_request";
|
||||
|
||||
private static String wsApiId;
|
||||
private static String wsRouteId;
|
||||
private static String taggedApiId;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateApi (WebSocket) ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void json11CreateWebSocketApiWithPascalCaseKeys() {
|
||||
wsApiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"ws-json11-test","ProtocolType":"WEBSOCKET","RouteSelectionExpression":"$request.body.action","Description":"JSON 1.1 WS API","ApiKeySelectionExpression":"$request.header.x-api-key"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ApiId", notNullValue())
|
||||
.body("Name", equalTo("ws-json11-test"))
|
||||
.body("ProtocolType", equalTo("WEBSOCKET"))
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("Description", equalTo("JSON 1.1 WS API"))
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("ApiEndpoint", startsWith("wss://"))
|
||||
.extract().path("ApiId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void json11GetWebSocketApiReturnsPascalCaseFields() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApiId", equalTo(wsApiId))
|
||||
.body("Name", equalTo("ws-json11-test"))
|
||||
.body("ProtocolType", equalTo("WEBSOCKET"))
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("Description", equalTo("JSON 1.1 WS API"))
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("ApiEndpoint", startsWith("wss://"))
|
||||
.body("CreatedDate", notNullValue());
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetApis ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void json11GetApisReturnsPascalCaseWebSocketFields() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetApis")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("{}")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items.ApiId", hasItem(wsApiId))
|
||||
.body("Items.find { it.ApiId == '" + wsApiId + "' }.RouteSelectionExpression",
|
||||
equalTo("$request.body.action"))
|
||||
.body("Items.find { it.ApiId == '" + wsApiId + "' }.ProtocolType",
|
||||
equalTo("WEBSOCKET"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void json11UpdateApiViaPascalCaseKeys() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","Name":"ws-json11-updated","Description":"Updated via JSON 1.1"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ApiId", equalTo(wsApiId))
|
||||
.body("Name", equalTo("ws-json11-updated"))
|
||||
.body("Description", equalTo("Updated via JSON 1.1"))
|
||||
// Non-provided fields should be preserved
|
||||
.body("ProtocolType", equalTo("WEBSOCKET"))
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.action"))
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.x-api-key"))
|
||||
.body("ApiEndpoint", startsWith("wss://"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── CreateRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void json11CreateRouteWithRouteResponseSelectionExpression() {
|
||||
wsRouteId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteKey":"$default","AuthorizationType":"NONE","RouteResponseSelectionExpression":"$default"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("RouteId", notNullValue())
|
||||
.body("RouteKey", equalTo("$default"))
|
||||
.body("AuthorizationType", equalTo("NONE"))
|
||||
.body("RouteResponseSelectionExpression", equalTo("$default"))
|
||||
.extract().path("RouteId");
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void json11GetRouteReturnsPascalCaseRouteResponseSelectionExpression() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s"}
|
||||
""".formatted(wsApiId, wsRouteId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteId", equalTo(wsRouteId))
|
||||
.body("RouteKey", equalTo("$default"))
|
||||
.body("AuthorizationType", equalTo("NONE"))
|
||||
.body("RouteResponseSelectionExpression", equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── GetRoutes ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void json11GetRoutesReturnsPascalCaseRouteResponseSelectionExpression() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRoutes")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Items.RouteId", hasItem(wsRouteId))
|
||||
.body("Items.find { it.RouteId == '" + wsRouteId + "' }.RouteResponseSelectionExpression",
|
||||
equalTo("$default"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void json11UpdateRouteViaPascalCaseKeys() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","Target":"integrations/int456","RouteResponseSelectionExpression":"$default"}
|
||||
""".formatted(wsApiId, wsRouteId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteId", equalTo(wsRouteId))
|
||||
.body("Target", equalTo("integrations/int456"))
|
||||
.body("RouteResponseSelectionExpression", equalTo("$default"))
|
||||
// Non-provided fields preserved
|
||||
.body("RouteKey", equalTo("$default"))
|
||||
.body("AuthorizationType", equalTo("NONE"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteRoute ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void json11DeleteRouteViaJson11Path() {
|
||||
// Create a temporary route to delete
|
||||
String tempRouteId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteKey":"$connect","AuthorizationType":"NONE"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("RouteId");
|
||||
|
||||
// Delete it via JSON 1.1
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s"}
|
||||
""".formatted(wsApiId, tempRouteId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Verify it's gone
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s"}
|
||||
""".formatted(wsApiId, tempRouteId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── DeleteApi ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void json11DeleteApiViaJson11Path() {
|
||||
// Create a temporary API to delete
|
||||
String tempApiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"ws-to-delete-json11","ProtocolType":"WEBSOCKET","RouteSelectionExpression":"$request.body.action"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("ApiId");
|
||||
|
||||
// Delete it via JSON 1.1
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(tempApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
// Verify it's gone
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(tempApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags via JSON 1.1 ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void json11CreateApiWithTagsAndVerifyInGetApi() {
|
||||
taggedApiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"ws-tagged-json11","ProtocolType":"WEBSOCKET","RouteSelectionExpression":"$request.body.action","Tags":{"env":"staging","team":"backend"}}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("Tags.env", equalTo("staging"))
|
||||
.body("Tags.team", equalTo("backend"))
|
||||
.extract().path("ApiId");
|
||||
|
||||
// GetApi returns tags
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "GetApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(taggedApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.env", equalTo("staging"))
|
||||
.body("Tags.team", equalTo("backend"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void json11UpdateApiTagsReplacement() {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","Tags":{"env":"prod","release":"v3"}}
|
||||
""".formatted(taggedApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.env", equalTo("prod"))
|
||||
.body("Tags.release", equalTo("v3"))
|
||||
.body("Tags.team", nullValue())
|
||||
.body("Name", equalTo("ws-tagged-json11"))
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.action"));
|
||||
|
||||
// Cleanup
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(taggedApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── PascalCase normalization verification ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void json11PascalCaseNormalizationWorksForAllNewFields() {
|
||||
// Create an API with all WebSocket-specific fields using PascalCase
|
||||
String verifyApiId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Name":"ws-pascal-verify","ProtocolType":"WEBSOCKET","RouteSelectionExpression":"$request.body.type","Description":"Pascal test","ApiKeySelectionExpression":"$request.header.key"}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.type"))
|
||||
.body("Description", equalTo("Pascal test"))
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.key"))
|
||||
.extract().path("ApiId");
|
||||
|
||||
// Create a route with RouteResponseSelectionExpression using PascalCase
|
||||
String verifyRouteId = given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "CreateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteKey":"$disconnect","AuthorizationType":"NONE","RouteResponseSelectionExpression":"$default"}
|
||||
""".formatted(verifyApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("RouteResponseSelectionExpression", equalTo("$default"))
|
||||
.extract().path("RouteId");
|
||||
|
||||
// Update the API with PascalCase keys and verify normalization
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteSelectionExpression":"$request.body.updated","Description":"Updated pascal"}
|
||||
""".formatted(verifyApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteSelectionExpression", equalTo("$request.body.updated"))
|
||||
.body("Description", equalTo("Updated pascal"))
|
||||
// Preserved fields
|
||||
.body("ApiKeySelectionExpression", equalTo("$request.header.key"))
|
||||
.body("Name", equalTo("ws-pascal-verify"));
|
||||
|
||||
// Update the route with PascalCase keys and verify normalization
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "UpdateRoute")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s","RouteId":"%s","RouteResponseSelectionExpression":"$custom","Target":"integrations/int789"}
|
||||
""".formatted(verifyApiId, verifyRouteId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RouteResponseSelectionExpression", equalTo("$custom"))
|
||||
.body("Target", equalTo("integrations/int789"))
|
||||
// Preserved fields
|
||||
.body("RouteKey", equalTo("$disconnect"))
|
||||
.body("AuthorizationType", equalTo("NONE"));
|
||||
|
||||
// Cleanup
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(verifyApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Cleanup ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void cleanup() {
|
||||
if (wsApiId != null) {
|
||||
given()
|
||||
.contentType(AMZ_JSON)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + "DeleteApi")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ApiId":"%s"}
|
||||
""".formatted(wsApiId))
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(204), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user