mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): page GetUsagePlans by limit and position (#9125)
* fix(apigateway): page GetUsagePlans by limit and position * test(apigateway): list every usage plan when a test searches the collection
This commit is contained in:
1 parent
93dc80a177
commit
e6345cf331
6 files changed
+150
-13
No files matched your search
+6
-6
@@ -92,7 +92,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
.body("apiStages[0].apiId", equalTo("a1"))
|
||||
.body("apiStages[0].stage", equalTo("v1"));
|
||||
|
||||
given().get("/usageplans")
|
||||
given().queryParam("limit", 500).get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.find { it.id == '" + usagePlanId + "' }.apiStages[0].stage", equalTo("v1"));
|
||||
@@ -261,7 +261,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body("tags", anEmptyMap());
|
||||
|
||||
given().get("/usageplans")
|
||||
given().queryParam("limit", 500).get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.find { it.id == '" + usagePlanId + "' }", not(hasKey("tags")));
|
||||
@@ -387,7 +387,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid API Stage specified"));
|
||||
|
||||
given().get("/usageplans")
|
||||
given().queryParam("limit", 500).get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.findAll { it.name == 'stage-without-api' }", hasSize(0));
|
||||
@@ -414,7 +414,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
|
||||
given().get("/usageplans")
|
||||
given().queryParam("limit", 500).get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.findAll { it.name == 'structured-stage' }", hasSize(0));
|
||||
@@ -430,7 +430,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("class java.lang.String can not be converted to an Integer"));
|
||||
|
||||
given().get("/usageplans")
|
||||
given().queryParam("limit", 500).get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.findAll { it.name == 'string-limit' }", hasSize(0));
|
||||
@@ -714,7 +714,7 @@ class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
}
|
||||
|
||||
private static int planCount() {
|
||||
return given().get("/usageplans").then().statusCode(200).extract().path("item.size()");
|
||||
return given().queryParam("limit", 500).get("/usageplans").then().statusCode(200).extract().path("item.size()");
|
||||
}
|
||||
|
||||
/** Posts {@code body}, expects a 400 of {@code type} with {@code message}, and that no plan was stored. */
|
||||
|
||||
@@ -35,6 +35,7 @@ class ApiGatewayUsagePlanIntegrationTest {
|
||||
@Test @Order(2)
|
||||
void getUsagePlans_returnsTagsWithoutReservedKeys() {
|
||||
given()
|
||||
.queryParam("limit", 500)
|
||||
.when().get("/usageplans")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package io.floci.aws.services.apigateway;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.http.apache5.Apache5HttpClient;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.apigateway.ApiGatewayClient;
|
||||
import software.amazon.awssdk.services.apigateway.model.BadRequestException;
|
||||
import software.amazon.awssdk.services.apigateway.model.GetUsagePlansResponse;
|
||||
import software.amazon.awssdk.services.apigateway.model.UsagePlan;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* GetUsagePlans honours {@code limit} and {@code position}. Runs in a region no other test uses so the
|
||||
* account-wide usage plan collection holds only this class's plans.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ApiGatewayUsagePlanPagingIntegrationTest {
|
||||
|
||||
private static final Region REGION = Region.CA_WEST_1;
|
||||
|
||||
private ApiGatewayClient client() {
|
||||
return AwsTestClients.create(ApiGatewayClient.builder(), "test", REGION, Apache5HttpClient.builder());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void deleteRegionPlans() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
for (UsagePlan plan : client.getUsagePlans(request -> request.limit(500)).items()) {
|
||||
client.deleteUsagePlan(request -> request.usagePlanId(plan.id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> createPlans(ApiGatewayClient client, int count) {
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String name = "paging-plan-" + i;
|
||||
ids.add(client.createUsagePlan(request -> request.name(name)).id());
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Test
|
||||
void limitOneReturnsPositionAndFollowsToTerminalPage() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
Set<String> created = createPlans(client, 3);
|
||||
|
||||
GetUsagePlansResponse first = client.getUsagePlans(request -> request.limit(1));
|
||||
assertEquals(1, first.items().size());
|
||||
assertNotNull(first.position());
|
||||
|
||||
List<String> seen = ApiGatewayPagingWalk.oneItemPerPageIds(
|
||||
position -> client.getUsagePlans(request -> request.limit(1).position(position)),
|
||||
GetUsagePlansResponse::items, GetUsagePlansResponse::position, UsagePlan::id);
|
||||
assertEquals(created, new HashSet<>(seen));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedLimitReturnsFirstTwentyFivePlans() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
createPlans(client, 26);
|
||||
|
||||
GetUsagePlansResponse first = client.getUsagePlans(request -> { });
|
||||
assertEquals(25, first.items().size());
|
||||
assertNotNull(first.position());
|
||||
|
||||
GetUsagePlansResponse second = client.getUsagePlans(request -> request.position(first.position()));
|
||||
assertEquals(1, second.items().size());
|
||||
assertNull(second.position());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void limitLargerThanCollectionReturnsEverythingWithoutPosition() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
createPlans(client, 3);
|
||||
|
||||
GetUsagePlansResponse page = client.getUsagePlans(request -> request.limit(5));
|
||||
assertEquals(3, page.items().size());
|
||||
assertNull(page.position());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void keyIdFilterIsPagedToo() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
Set<String> plans = createPlans(client, 4);
|
||||
String keyId = client.createApiKey(request -> request.name("paging-key").enabled(true)).id();
|
||||
Set<String> keyed = new HashSet<>();
|
||||
for (String planId : plans) {
|
||||
if (keyed.size() == 2) {
|
||||
break;
|
||||
}
|
||||
client.createUsagePlanKey(request -> request.usagePlanId(planId).keyId(keyId).keyType("API_KEY"));
|
||||
keyed.add(planId);
|
||||
}
|
||||
try {
|
||||
List<String> seen = ApiGatewayPagingWalk.oneItemPerPageIds(
|
||||
position -> client.getUsagePlans(request -> request.keyId(keyId).limit(1).position(position)),
|
||||
GetUsagePlansResponse::items, GetUsagePlansResponse::position, UsagePlan::id);
|
||||
assertEquals(keyed, new HashSet<>(seen));
|
||||
} finally {
|
||||
client.deleteApiKey(request -> request.apiKey(keyId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownPositionIsRejected() {
|
||||
try (ApiGatewayClient client = client()) {
|
||||
createPlans(client, 2);
|
||||
|
||||
assertThrows(BadRequestException.class,
|
||||
() -> client.getUsagePlans(request -> request.limit(1).position("not-a-plan")));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -130,7 +130,7 @@ class ApiGatewayUsagePlanCfnRollbackIntegrationTest {
|
||||
cloudFormation(stack, "UpdateStack", PLAN_TEMPLATE.formatted(properties + ", \"Description\": \"changed\"",
|
||||
FAILING_RESOURCE.formatted("Plan", stack)));
|
||||
describeStacks(stack, "UPDATE_ROLLBACK_COMPLETE");
|
||||
given().when().get("/usageplans").then()
|
||||
given().queryParam("limit", 500).when().get("/usageplans").then()
|
||||
.statusCode(200)
|
||||
.body("item.name", not(hasItem(name)));
|
||||
|
||||
|
||||
Reference in new issue
Block a user