From 949eb894e9f8e779ac28c4f262ee98bb804a799b Mon Sep 17 00:00:00 2001 From: Jimmy Liu Jia <91264074+JimmyLiuJia@users.noreply.github.com> Date: Sat, 7 Nov 2026 07:57:23 +0800 Subject: [PATCH] test(cloudformation): reuse physical ID helpers in group and API tests (#7688) --- ...CfnUpdateRollbackRetryIntegrationTest.java | 9 +++---- ...onCognitoUserPoolGroupIntegrationTest.java | 25 +++---------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest.java index 9719849622..34e685c984 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import static io.floci.aws.testing.CfnRequests.cfn; +import static io.floci.aws.testing.CfnRequests.physicalIdUnauthenticated; import static io.restassured.RestAssured.given; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -69,7 +70,7 @@ class ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest { try { stackAction(stack, "CreateStack", TEMPLATE.formatted(name, "first", "REGIONAL", "")); assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stack).status()); - String apiId = physicalId(stack); + String apiId = physicalIdUnauthenticated(stack, "Api"); // After putRestApi accepted the document, applying the declared name and description // again (just those two operations) fails once. Mockito.doThrow(new AwsException("TooManyRequestsException", "Too Many Requests", 429)) @@ -108,7 +109,7 @@ class ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest { try { stackAction(stack, "CreateStack", TEMPLATE.formatted(name, "first", "REGIONAL", "")); assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stack).status()); - String apiId = physicalId(stack); + String apiId = physicalIdUnauthenticated(stack, "Api"); // The import rejects the document, and the first restore of the patch fails. ArgumentMatcher>> restore = operations -> operations != null && operations.contains(replace("/description", "first")); @@ -152,10 +153,6 @@ class ApiGatewayRestApiCfnUpdateRollbackRetryIntegrationTest { .body("item.path", containsInAnyOrder(paths)); } - private static String physicalId(String stack) { - return XmlParser.extractFirst(apiResource(stack), "PhysicalResourceId", null); - } - private static String apiResourceReason(String stack) { return XmlParser.extractFirst(apiResource(stack), "ResourceStatusReason", null); } diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java index f904cbf86f..4ba4d8ae51 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationCognitoUserPoolGroupIntegrationTest.java @@ -1,6 +1,7 @@ package io.floci.aws.services.cloudformation; import io.floci.aws.core.common.XmlParser; +import io.floci.aws.testing.CfnRequests; import io.floci.aws.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @@ -218,17 +219,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(stackName); assertEquals("UPDATE_ROLLBACK_COMPLETE", state.status(), state.reason()); assertEquals(name, output(describeStack(stackName), "GroupRef")); - given() - .contentType("application/x-www-form-urlencoded") - .header("Authorization", CFN_AUTH) - .formParam("Action", "DescribeStackResource") - .formParam("StackName", stackName) - .formParam("LogicalResourceId", "Group") - .when() - .post("/") - .then() - .statusCode(200) - .body(containsString("" + name + "")); + assertEquals(name, CfnRequests.physicalId(stackName, "Group", CFN_AUTH)); cognito("GetGroup", "{\"UserPoolId\": \"" + firstPool + "\", \"GroupName\": \"" + name + "\"}") .statusCode(200) .body("Group.Description", equalTo("d1")) @@ -277,17 +268,7 @@ class CloudFormationCognitoUserPoolGroupIntegrationTest { assertThat(failures, contains(containsString("CloudFormation cannot update a stack when a custom-named" + " resource requires replacing. Rename " + generated + " and update the stack again."))); assertEquals(generated, output(describeStack(stackName), "GroupRef")); - given() - .contentType("application/x-www-form-urlencoded") - .header("Authorization", CFN_AUTH) - .formParam("Action", "DescribeStackResource") - .formParam("StackName", stackName) - .formParam("LogicalResourceId", "Group") - .when() - .post("/") - .then() - .statusCode(200) - .body(containsString("" + generated + "")); + assertEquals(generated, CfnRequests.physicalId(stackName, "Group", CFN_AUTH)); cognito("GetGroup", "{\"UserPoolId\": \"" + poolId + "\", \"GroupName\": \"" + generated + "\"}") .statusCode(200) .body("Group.Description", equalTo("d1"))