Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(apigateway): return integration defaults and patch timeout (#4798)

Aniket Shukla27bfb54c6e86
diff --git a/docs/services/api-gateway.md b/docs/services/api-gateway.md
index c3363d6fa1..2bf0fa44d8 100644
--- a/docs/services/api-gateway.md
+++ b/docs/services/api-gateway.md
@@ -352,6 +352,7 @@ Passthrough keeps repeated values repeated, in both directions: `?tag=a&tag=b` r
| `requestParameters` / `requestTemplates` | Applied at invoke time and returned on read-back |
| `passthroughBehavior` | `NEVER` and `WHEN_NO_TEMPLATES` reject an unmatched Content-Type with `415` |
| `timeoutInMillis` | Honoured; defaults to AWS's 29,000 ms. Values below 50 are rejected. The 29s ceiling is an edge-optimized limit, so Regional APIs may exceed it |
+| `responseTransferMode` | Defaults to `BUFFERED`. `STREAM` is accepted only for `HTTP_PROXY` and `AWS_PROXY` integrations and is stored and returned by the management API, but execution responses are still buffered; response streaming is not yet implemented |
| `tlsConfig.insecureSkipVerification` | Honoured, with AWS's semantics: it stops requiring the backend certificate to be issued by a trusted CA, so a private-CA or self-signed backend is reachable, but expiration, hostname and the presence of a root certificate authority are still checked |
| `contentHandling` | `CONVERT_TO_TEXT` base64-encodes a binary request for mapping templates; `CONVERT_TO_BINARY` base64-decodes a text request before sending it |
| `connectionType` / `connectionId` | `VPC_LINK` requires `connectionId` to name an existing, available VPC link; an unknown link yields `502` |
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
index eb9a11d166..c03cb97964 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
@@ -461,7 +461,7 @@ public class ApiGatewayController {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
MethodConfig method = service.putMethod(region, apiId, resourceId, httpMethod, request);
- return Response.status(201).entity(toMethodNode(method).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.status(201).entity(toMethodNode(method, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
@@ -474,7 +474,7 @@ public class ApiGatewayController {
@PathParam("resourceId") String resourceId,
@PathParam("httpMethod") String httpMethod) {
String region = regionResolver.resolveRegion(headers);
- return Response.ok(toMethodNode(service.getMethod(region, apiId, resourceId, httpMethod)).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.ok(toMethodNode(service.getMethod(region, apiId, resourceId, httpMethod), resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
}
@PATCH
@@ -487,7 +487,7 @@ public class ApiGatewayController {
String region = regionResolver.resolveRegion(headers);
List<Map<String, String>> patchOperations = parsePatchOperations(body);
MethodConfig method = service.updateMethod(region, apiId, resourceId, httpMethod, patchOperations);
- return Response.ok(toMethodNode(method).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.ok(toMethodNode(method, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
}
@DELETE
@@ -515,7 +515,7 @@ public class ApiGatewayController {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
io.github.hectorvent.floci.services.apigateway.model.Integration integration = service.putIntegration(region, apiId, resourceId, httpMethod, request);
- return Response.status(201).entity(toIntegrationNode(integration).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.status(201).entity(toIntegrationNode(integration, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
@@ -528,7 +528,7 @@ public class ApiGatewayController {
@PathParam("resourceId") String resourceId,
@PathParam("httpMethod") String httpMethod) {
String region = regionResolver.resolveRegion(headers);
- return Response.ok(toIntegrationNode(service.getIntegration(region, apiId, resourceId, httpMethod)).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.ok(toIntegrationNode(service.getIntegration(region, apiId, resourceId, httpMethod), resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
}
@PATCH
@@ -541,7 +541,7 @@ public class ApiGatewayController {
String region = regionResolver.resolveRegion(headers);
List<Map<String, String>> patchOperations = parsePatchOperations(body);
io.github.hectorvent.floci.services.apigateway.model.Integration integration = service.updateIntegration(region, apiId, resourceId, httpMethod, patchOperations);
- return Response.ok(toIntegrationNode(integration).toString()).type(MediaType.APPLICATION_JSON).build();
+ return Response.ok(toIntegrationNode(integration, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
}
@DELETE
@@ -2178,7 +2178,7 @@ public class ApiGatewayController {
return node;
}
- private ObjectNode toMethodNode(MethodConfig m) {
+ private ObjectNode toMethodNode(MethodConfig m, String resourceId) {
ObjectNode node = objectMapper.createObjectNode();
node.put("httpMethod", m.getHttpMethod());
node.put("authorizationType", m.getAuthorizationType());
@@ -2198,7 +2198,7 @@ public class ApiGatewayController {
node.set("requestModels", models);
}
if (m.getMethodIntegration() != null) {
- node.set("methodIntegration", toIntegrationNode(m.getMethodIntegration()));
+ node.set("methodIntegration", toIntegrationNode(m.getMethodIntegration(), resourceId));
}
return node;
}
@@ -2209,22 +2209,22 @@ public class ApiGatewayController {
return node;
}
- private ObjectNode toIntegrationNode(io.github.hectorvent.floci.services.apigateway.model.Integration i) {
+ private ObjectNode toIntegrationNode(io.github.hectorvent.floci.services.apigateway.model.Integration i,
+ String resourceId) {
ObjectNode node = objectMapper.createObjectNode();
node.put("type", i.getType());
node.put("httpMethod", i.getHttpMethod());
node.put("uri", i.getUri());
node.put("passthroughBehavior", i.getPassthroughBehavior());
if (i.getContentHandling() != null) node.put("contentHandling", i.getContentHandling());
- if (i.getTimeoutInMillis() != null) node.put("timeoutInMillis", i.getTimeoutInMillis());
+ node.put("timeoutInMillis", i.getTimeoutInMillis() != null ? i.getTimeoutInMillis() : 29000);
if (i.getConnectionType() != null) node.put("connectionType", i.getConnectionType());
if (i.getConnectionId() != null) node.put("connectionId", i.getConnectionId());
if (i.getCredentials() != null) node.put("credentials", i.getCredentials());
- if (i.getCacheNamespace() != null) node.put("cacheNamespace", i.getCacheNamespace());
- if (!i.getCacheKeyParameters().isEmpty()) {
- ArrayNode keys = node.putArray("cacheKeyParameters");
- i.getCacheKeyParameters().forEach(keys::add);
- }
+ node.put("cacheNamespace", i.getCacheNamespace() != null ? i.getCacheNamespace() : resourceId);
+ ArrayNode keys = node.putArray("cacheKeyParameters");
+ i.getCacheKeyParameters().forEach(keys::add);
+ node.put("responseTransferMode", i.getResponseTransferMode());
if (i.getTlsConfig() != null) {
node.putObject("tlsConfig")
.put("insecureSkipVerification", i.getTlsConfig().isInsecureSkipVerification());
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
index cdfc45bdd2..da5f88c163 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
@@ -590,20 +590,17 @@ public class ApiGatewayService implements ResourceProvider {
integration.setContentHandling((String) request.get("contentHandling"));
integration.setCredentials((String) request.get("credentials"));
- integration.setCacheNamespace((String) request.get("cacheNamespace"));
+ integration.setCacheNamespace(request.get("cacheNamespace") != null
+ ? (String) request.get("cacheNamespace") : resourceId);
+ integration.setResponseTransferMode(transferMode(request.get("responseTransferMode")));
+ validateTransferMode(integration.getResponseTransferMode(), integration.getType());
if (request.get("connectionType") != null) {
integration.setConnectionType((String) request.get("connectionType"));
}
integration.setConnectionId((String) request.get("connectionId"));
if (request.get("timeoutInMillis") instanceof Number timeout) {
- // AWS accepts 50ms upward; the 29s ceiling applies only to edge-optimized APIs, and
- // Regional/private APIs (Floci's default) may exceed it, so only the floor is enforced.
- if (timeout.intValue() < 50) {
- throw new AwsException("BadRequestException",
- "Invalid timeout value: " + timeout.intValue(), 400);
- }
- integration.setTimeoutInMillis(timeout.intValue());
+ integration.setTimeoutInMillis(parseIntegrationTimeout(timeout));
}
if (request.get("cacheKeyParameters") instanceof List<?> cacheKeys) {
@@ -2680,6 +2677,8 @@ public class ApiGatewayService implements ResourceProvider {
public Integration updateIntegration(String region, String apiId, String resourceId, String httpMethod, List<Map<String, String>> patchOperations) {
Integration integration = getIntegration(region, apiId, resourceId, httpMethod);
if (patchOperations != null) {
+ String nextType = integration.getType();
+ String nextTransferMode = integration.getResponseTransferMode();
for (Map<String, String> op : patchOperations) {
String opType = op.get("op");
if (!"add".equals(opType) && !"replace".equals(opType)) {
@@ -2692,14 +2691,23 @@ public class ApiGatewayService implements ResourceProvider {
}
switch (path) {
case "/type":
+ nextType = value;
+ break;
case "/httpMethod":
case "/uri":
case "/passthroughBehavior":
break;
+ case "/timeoutInMillis":
+ parseIntegrationTimeout(value);
+ break;
+ case "/responseTransferMode":
+ nextTransferMode = transferMode(value);
+ break;
default:
throw new AwsException("BadRequestException", "Unsupported path: " + path, 400);
}
}
+ validateTransferMode(nextTransferMode, nextType);
for (Map<String, String> op : patchOperations) {
String path = op.get("path");
String value = op.get("value");
@@ -2716,6 +2724,12 @@ public class ApiGatewayService implements ResourceProvider {
case "/passthroughBehavior":
integration.setPassthroughBehavior(value);
break;
+ case "/timeoutInMillis":
+ integration.setTimeoutInMillis(parseIntegrationTimeout(value));
+ break;
+ case "/responseTransferMode":
+ integration.setResponseTransferMode(transferMode(value));
+ break;
default:
throw new IllegalStateException("Unreachable: validated above");
}
@@ -2725,6 +2739,36 @@ public class ApiGatewayService implements ResourceProvider {
return integration;
}
+ private int parseIntegrationTimeout(Object value) {
+ try {
+ int timeout = Integer.parseInt(String.valueOf(value));
+ if (timeout >= 50) {
+ return timeout;
+ }
+ } catch (NumberFormatException ignored) {
+ // Return the same AWS-style error for non-numeric and out-of-range values.
+ }
+ throw new AwsException("BadRequestException", "Invalid timeout value: " + value, 400);
+ }
+
+ private String transferMode(Object value) {
+ if (value == null) {
+ return "BUFFERED";
+ }
+ if ("BUFFERED".equals(value) || "STREAM".equals(value)) {
+ return (String) value;
+ }
+ throw new AwsException("BadRequestException", "Invalid response transfer mode: " + value, 400);
+ }
+
+ private void validateTransferMode(String mode, String type) {
+ if ("STREAM".equals(mode) && !"HTTP_PROXY".equalsIgnoreCase(type)
+ && !"AWS_PROXY".equalsIgnoreCase(type)) {
+ throw new AwsException("BadRequestException",
+ "Response transfer mode STREAM requires HTTP_PROXY or AWS_PROXY integration type", 400);
+ }
+ }
+
// ──────────────────────────── Tags ────────────────────────────
public Map<String, String> getTags(String region, String apiId) {
@@ -3632,7 +3676,8 @@ public class ApiGatewayService implements ResourceProvider {
integrationRequest.put("uri", integrationExt.get("uri"));
integrationRequest.put("passthroughBehavior", integrationExt.get("passthroughBehavior"));
for (String field : List.of("contentHandling", "timeoutInMillis", "connectionType",
- "connectionId", "credentials", "cacheNamespace", "cacheKeyParameters", "tlsConfig")) {
+ "connectionId", "credentials", "cacheNamespace", "cacheKeyParameters", "tlsConfig",
+ "responseTransferMode")) {
if (integrationExt.get(field) != null) {
integrationRequest.put(field, integrationExt.get(field));
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/model/Integration.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/model/Integration.java
index 4742b7c8f3..f9f3ed8c67 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/model/Integration.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/model/Integration.java
@@ -18,12 +18,13 @@ public class Integration {
private String httpMethod;
private String passthroughBehavior = "WHEN_NO_MATCH"; // WHEN_NO_MATCH, WHEN_NO_TEMPLATES, NEVER
private String contentHandling; // CONVERT_TO_BINARY, CONVERT_TO_TEXT, or null to pass through
- private Integer timeoutInMillis; // 50–29000; AWS caps REST integrations at 29s
+ private Integer timeoutInMillis = 29000; // AWS default; regional/private APIs may use more
private String connectionType = "INTERNET"; // INTERNET or VPC_LINK
private String connectionId; // VpcLink id when connectionType is VPC_LINK
private String credentials; // IAM role ARN assumed for AWS integrations
private String cacheNamespace;
private List<String> cacheKeyParameters = new ArrayList<>();
+ private String responseTransferMode = "BUFFERED";
private TlsConfig tlsConfig;
private Map<String, String> requestParameters = new HashMap<>(); // integration.request.* → method.request.*
private Map<String, String> requestTemplates = new HashMap<>();
@@ -106,6 +107,14 @@ public class Integration {
this.cacheKeyParameters = cacheKeyParameters != null ? cacheKeyParameters : new ArrayList<>();
}
+ public String getResponseTransferMode() {
+ return responseTransferMode != null ? responseTransferMode : "BUFFERED";
+ }
+
+ public void setResponseTransferMode(String responseTransferMode) {
+ this.responseTransferMode = responseTransferMode;
+ }
+
public TlsConfig getTlsConfig() {
return tlsConfig;
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationFieldsRoundTripTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationFieldsRoundTripTest.java
index d4812ee2aa..797e6f9bb8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationFieldsRoundTripTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayIntegrationFieldsRoundTripTest.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.apigateway;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
+import jakarta.inject.Inject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -10,6 +11,7 @@ import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.notNullValue;
/**
@@ -26,6 +28,9 @@ import static org.hamcrest.Matchers.notNullValue;
@QuarkusTest
class ApiGatewayIntegrationFieldsRoundTripTest {
+ @Inject
+ ApiGatewayService service;
+
private String apiId;
private String resourceId;
@@ -113,6 +118,200 @@ class ApiGatewayIntegrationFieldsRoundTripTest {
.body("timeoutInMillis", equalTo(12000));
}
+ @Test
+ void integrationDefaultsAreReturnedByPutGetAndMethodReadBack() {
+ given().contentType(ContentType.JSON).body("{\"type\":\"MOCK\"}")
+ .when().put(integrationPath())
+ .then().statusCode(201)
+ .body("timeoutInMillis", equalTo(29000))
+ .body("cacheNamespace", equalTo(resourceId))
+ .body("cacheKeyParameters", empty())
+ .body("responseTransferMode", equalTo("BUFFERED"));
+
+ given().when().get(integrationPath())
+ .then().statusCode(200)
+ .body("timeoutInMillis", equalTo(29000))
+ .body("cacheNamespace", equalTo(resourceId))
+ .body("cacheKeyParameters", empty())
+ .body("responseTransferMode", equalTo("BUFFERED"));
+
+ given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/POST")
+ .then().statusCode(200)
+ .body("methodIntegration.timeoutInMillis", equalTo(29000))
+ .body("methodIntegration.cacheNamespace", equalTo(resourceId))
+ .body("methodIntegration.cacheKeyParameters", empty())
+ .body("methodIntegration.responseTransferMode", equalTo("BUFFERED"));
+ }
+
+ @Test
+ void explicitTransferModeRoundTripsAndCanBePatched() {
+ given().contentType(ContentType.JSON)
+ .body("{\"type\":\"HTTP_PROXY\",\"httpMethod\":\"GET\","
+ + "\"uri\":\"http://example.invalid/widget\",\"responseTransferMode\":\"STREAM\"}")
+ .when().put(integrationPath())
+ .then().statusCode(201).body("responseTransferMode", equalTo("STREAM"));
+ given().when().get(integrationPath())
+ .then().statusCode(200).body("responseTransferMode", equalTo("STREAM"));
+ given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/POST")
+ .then().statusCode(200)
+ .body("methodIntegration.responseTransferMode", equalTo("STREAM"));
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/responseTransferMode\",\"value\":\"BUFFERED\"}]}")
+ .when().patch(integrationPath())
+ .then().statusCode(200).body("responseTransferMode", equalTo("BUFFERED"));
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/responseTransferMode\",\"value\":\"UNKNOWN\"}]}")
+ .when().patch(integrationPath()).then().statusCode(400);
+ given().when().get(integrationPath())
+ .then().statusCode(200).body("responseTransferMode", equalTo("BUFFERED"));
+ }
+
+ @Test
+ void nonStringTransferModeIsRejectedWithBadRequest() {
+ given().contentType(ContentType.JSON)
+ .body("{\"type\":\"HTTP_PROXY\",\"responseTransferMode\":42}")
+ .when().put(integrationPath()).then().statusCode(400);
+
+ String importedSpec = """
+ {"openapi":"3.0.1","info":{"title":"invalid-mode","version":"1"},
+ "paths":{"/stream":{"get":{"x-amazon-apigateway-integration":{
+ "type":"http_proxy","httpMethod":"GET","uri":"http://example.invalid/stream",
+ "responseTransferMode":42}}}}}
+ """;
+ given().contentType(ContentType.JSON).queryParam("mode", "import")
+ .body(importedSpec).when().post("/restapis").then().statusCode(400);
+ }
+
+ @Test
+ void streamRequiresProxyTypeOnPutAndOpenApiImport() {
+ for (String type : new String[]{"MOCK", "HTTP", "AWS"}) {
+ given().contentType(ContentType.JSON)
+ .body("{\"type\":\"" + type + "\",\"responseTransferMode\":\"STREAM\"}")
+ .when().put(integrationPath())
+ .then().statusCode(400).body("__type", equalTo("BadRequestException"));
+ }
+ given().when().get(integrationPath()).then().statusCode(404);
+
+ given().contentType(ContentType.JSON)
+ .body("{\"type\":\"AWS_PROXY\",\"responseTransferMode\":\"STREAM\"}")
+ .when().put(integrationPath())
+ .then().statusCode(201).body("responseTransferMode", equalTo("STREAM"));
+
+ String importedSpec = """
+ {"openapi":"3.0.1","info":{"title":"invalid-stream","version":"1"},
+ "paths":{"/stream":{"get":{"x-amazon-apigateway-integration":{
+ "type":"mock","responseTransferMode":"STREAM"}}}}}
+ """;
+ given().contentType(ContentType.JSON).queryParam("mode", "import")
+ .body(importedSpec).when().post("/restapis").then().statusCode(400);
+ }
+
+ @Test
+ void streamPatchValidatesFinalTypeWithoutMutatingOnFailure() {
+ given().contentType(ContentType.JSON).body("{\"type\":\"MOCK\"}")
+ .when().put(integrationPath()).then().statusCode(201);
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/responseTransferMode\",\"value\":\"STREAM\"}]}")
+ .when().patch(integrationPath()).then().statusCode(400);
+ given().when().get(integrationPath())
+ .then().statusCode(200).body("type", equalTo("MOCK"))
+ .body("responseTransferMode", equalTo("BUFFERED"));
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/responseTransferMode\",\"value\":\"STREAM\"},"
+ + "{\"op\":\"replace\",\"path\":\"/type\",\"value\":\"HTTP_PROXY\"}]}")
+ .when().patch(integrationPath()).then().statusCode(200)
+ .body("type", equalTo("HTTP_PROXY"))
+ .body("responseTransferMode", equalTo("STREAM"));
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/type\",\"value\":\"MOCK\"}]}")
+ .when().patch(integrationPath()).then().statusCode(400);
+ given().when().get(integrationPath())
+ .then().statusCode(200).body("type", equalTo("HTTP_PROXY"))
+ .body("responseTransferMode", equalTo("STREAM"));
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/responseTransferMode\",\"value\":\"BUFFERED\"},"
+ + "{\"op\":\"replace\",\"path\":\"/type\",\"value\":\"MOCK\"}]}")
+ .when().patch(integrationPath()).then().statusCode(200)
+ .body("type", equalTo("MOCK"))
+ .body("responseTransferMode", equalTo("BUFFERED"));
+ }
+
+ @Test
+ void openApiImportPreservesExplicitTransferMode() {
+ String importedApi = given().contentType(ContentType.JSON).queryParam("mode", "import")
+ .body("""
+ {"openapi":"3.0.1","info":{"title":"streaming-import","version":"1"},
+ "paths":{"/stream":{"get":{"x-amazon-apigateway-integration":{
+ "type":"http_proxy","httpMethod":"GET","uri":"http://example.invalid/stream",
+ "responseTransferMode":"STREAM"}}}}}
+ """)
+ .when().post("/restapis").then().statusCode(201).extract().path("id");
+ try {
+ String importedResource = given().when().get("/restapis/" + importedApi + "/resources")
+ .then().statusCode(200).extract().path("item.find { it.path == '/stream' }.id");
+ given().when().get("/restapis/" + importedApi + "/resources/" + importedResource
+ + "/methods/GET/integration")
+ .then().statusCode(200).body("responseTransferMode", equalTo("STREAM"));
+ } finally {
+ given().when().delete("/restapis/" + importedApi).then().statusCode(202);
+ }
+ }
+
+ @Test
+ void olderIntegrationWithNullDefaultsStillReadsBackAwsValues() {
+ given().contentType(ContentType.JSON).body("{\"type\":\"MOCK\"}")
+ .when().put(integrationPath()).then().statusCode(201);
+ service.getIntegration("us-east-1", apiId, resourceId, "POST").setTimeoutInMillis(null);
+ service.getIntegration("us-east-1", apiId, resourceId, "POST").setCacheNamespace(null);
+
+ given().when().get(integrationPath())
+ .then().statusCode(200)
+ .body("timeoutInMillis", equalTo(29000))
+ .body("cacheNamespace", equalTo(resourceId));
+ given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/POST")
+ .then().statusCode(200)
+ .body("methodIntegration.timeoutInMillis", equalTo(29000))
+ .body("methodIntegration.cacheNamespace", equalTo(resourceId));
+ }
+
+ @Test
+ void updateIntegrationCanPatchTimeoutAndRejectsInvalidValuesWithoutMutation() {
+ given().contentType(ContentType.JSON).body("{\"type\":\"MOCK\",\"timeoutInMillis\":49}")
+ .when().put(integrationPath())
+ .then().statusCode(400).body("message", equalTo("Invalid timeout value: 49"));
+ given().contentType(ContentType.JSON).body("{\"type\":\"MOCK\"}")
+ .when().put(integrationPath()).then().statusCode(201);
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/timeoutInMillis\",\"value\":\"30000\"}]}")
+ .when().patch(integrationPath())
+ .then().statusCode(200).body("timeoutInMillis", equalTo(30000));
+
+ given().contentType(ContentType.JSON)
+ .body("{\"patchOperations\":[{\"op\":\"replace\","
+ + "\"path\":\"/passthroughBehavior\",\"value\":\"NEVER\"},"
+ + "{\"op\":\"replace\",\"path\":\"/timeoutInMillis\",\"value\":\"49\"}]}")
+ .when().patch(integrationPath())
+ .then().statusCode(400).body("message", equalTo("Invalid timeout value: 49"));
+
+ given().when().get(integrationPath())
+ .then().statusCode(200)
+ .body("timeoutInMillis", equalTo(30000))
+ .body("passthroughBehavior", equalTo("WHEN_NO_MATCH"));
+ }
+
@Test
void getIntegrationResponseReturnsItsContentHandling() {
putFullIntegration();