diff --git a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java index 8301264e0e..1bf4b3599c 100644 --- a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java +++ b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java @@ -1152,7 +1152,7 @@ public class ServiceCatalogService implements PassedRoleLookup { ObjectNode record = objectMapper.createObjectNode(); record.put("RecordId", "rec-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16)); record.put("Status", "SUCCEEDED"); - record.put("CreatedTime", System.currentTimeMillis() / 1000.0); + record.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); return record; } diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java index 34c1c51606..f1c22beb0b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java @@ -1,8 +1,11 @@ package io.github.hectorvent.floci.services.servicecatalog; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.testing.MutableClock; import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; +import jakarta.inject.Inject; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -10,6 +13,7 @@ import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Wire-level tests for {@code CreateProvisionedProductPlan}, @@ -39,6 +43,12 @@ class ServiceCatalogProvisionedProductPlanConsumerTest { private static final String AUTH_HEADER = "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request"; + @Inject + ObjectMapper objectMapper; + + @Inject + MutableClock clock; + @BeforeAll static void configureRestAssured() { RestAssuredJsonUtils.configureAwsContentTypes(); @@ -146,16 +156,22 @@ class ServiceCatalogProvisionedProductPlanConsumerTest { // ---------- ExecuteProvisionedProductPlan ---------- @Test - void executeProvisionedProductPlan_returnsRecordDetail() { + void executeProvisionedProductPlan_returnsRecordDetail() throws Exception { String productId = createProduct("ab-plan-execute-product"); String artifactId = firstArtifactId(productId); String planId = createPlan(productId, artifactId, "ab-execute-plan"); - call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId + double beforeExecution = clock.instant().toEpochMilli() / 1000.0; + Response executed = call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\",\"IdempotencyToken\":\"tok-execute-plan\"}") .then() .statusCode(200) - .body("RecordDetail.Status", equalTo("SUCCEEDED")); + .body("RecordDetail.Status", equalTo("SUCCEEDED")) + .extract().response(); + double afterExecution = clock.instant().toEpochMilli() / 1000.0; + double createdTime = objectMapper.readTree(executed.asString()) + .path("RecordDetail").path("CreatedTime").asDouble(); + assertTrue(createdTime >= beforeExecution && createdTime <= afterExecution); } @Test