jamesnetherton commented on code in PR #8664: URL: https://github.com/apache/camel-quarkus/pull/8664#discussion_r3257512952
########## integration-test-groups/aws2/aws2-kms/src/test/java/org/apache/camel/quarkus/component/aws2/kms/it/Aws2KmsTest.java: ########## @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.aws2.kms.it; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.camel.quarkus.test.support.aws2.Aws2Client; +import org.apache.camel.quarkus.test.support.aws2.Aws2TestResource; +import org.apache.camel.quarkus.test.support.aws2.BaseAWs2TestSupport; +import org.apache.camel.quarkus.test.support.aws2.Service; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.kms.KmsClient; +import software.amazon.awssdk.services.kms.model.DescribeKeyRequest; +import software.amazon.awssdk.services.kms.model.KeyState; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.matchesPattern; +import static org.hamcrest.Matchers.not; + +@QuarkusTest +@QuarkusTestResource(Aws2TestResource.class) +class Aws2KmsTest extends BaseAWs2TestSupport { + + @Aws2Client(Service.KMS) + KmsClient client; + + public Aws2KmsTest() { + super("/aws2-kms"); + } + + @Test + public void createListDescribeAndScheduleDeletion() { + // createKey + final String keyId = given() + .post("/aws2-kms/keys") + .then() + .statusCode(200) + .body(matchesPattern("[A-Za-z0-9-]+")) + .extract() + .asString(); + + try { + // describeKey via the Camel route — newly created keys start enabled + given() + .get("/aws2-kms/keys/" + keyId) + .then() + .statusCode(200) + .body(matchesPattern(KeyState.ENABLED.toString())); + + // listKeys — the new key must be visible + given() + .get("/aws2-kms/keys") + .then() + .statusCode(200) + .body("$", hasItem(keyId)); + + // cross-check via the AWS SDK that the key exists and is enabled + KeyState awsState = client + .describeKey(DescribeKeyRequest.builder().keyId(keyId).build()) + .keyMetadata() + .keyState(); + org.assertj.core.api.Assertions.assertThat(awsState).isEqualTo(KeyState.ENABLED); + } finally { + // scheduleKeyDeletion as cleanup; AWS minimum window is 7 days + given() + .contentType("text/plain") + .body("7") + .delete("/aws2-kms/keys/" + keyId) + .then() + .statusCode(200) + .body(matchesPattern(".*" + keyId + ".*")); + } + } + + @Test + public void disableEnableThenSchedule() { + final String keyId = given() + .post("/aws2-kms/keys") + .then() + .statusCode(200) + .extract() + .asString(); + + try { + // disableKey + given() + .post("/aws2-kms/keys/" + keyId + "/disable") + .then() + .statusCode(204); + + KeyState afterDisable = client + .describeKey(DescribeKeyRequest.builder().keyId(keyId).build()) + .keyMetadata() + .keyState(); + org.assertj.core.api.Assertions.assertThat(afterDisable).isEqualTo(KeyState.DISABLED); Review Comment: Please avoid FQCN and use imports. Applies to all instances where FQCN is used in this PR changeset. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
