Class KMSKeyEnabledServiceIntegrationTestBase

java.lang.Object
software.amazon.cloudformation.test.AbstractLifecycleTestBase
software.amazon.cloudformation.test.KMSKeyEnabledServiceIntegrationTestBase
Direct Known Subclasses:
CRUDLifecycleTestBase

@NotThreadSafe
@TestInstance(PER_CLASS)
public abstract class KMSKeyEnabledServiceIntegrationTestBase
extends AbstractLifecycleTestBase
Abstract base class we can derive from that adds support for a KMS key and has helpers methods to update Key policy for accessing the key for service principal
 
     package software.amazon.logs.loggroup;

     import org.junit.jupiter.api.*;
     import static org.assertj.core.api.Assertions.assertThat;

     import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
     import software.amazon.cloudformation.proxy.*;
     import software.amazon.cloudformation.test.*;

     @TestMethodOrder(MethodOrderer.OrderAnnotation.class) // we order the tests to follow C to U to D
     @ExtendWith(InjectProfileCredentials.class) // extend with profile based credentials
     @EnabledIfSystemProperty(named = "desktop", matches = "true")
     @TestInstance(TestInstance.Lifecycle.PER_CLASS) // IMP PER_CLASS
     public class LifecycleTest extends KMSKeyEnabledServiceIntegrationTestBase {

         //
         // At the annotation software.amazon.cloudformation.test.InjectSessionCredentials to the
         // constructor. This will inject the role's credentials
         //
         public LifecycleTest(@InjectSessionCredentials(profile = "cfn-integration") AwsSessionCredentials awsCredentials) {
              super(awsCredentials, ((apiCall, provided) -> override));
         }
         ...
         ...
         @Order(300)
         @Test
         void addValidKMS() {
             final ResourceModel current = ResourceModel.builder().arn(model.getArn())
                 .logGroupName(model.getLogGroupName()).retentionInDays(model.getRetentionInDays()).build();
             // Access a KMS key. The test ensures to only create one key and recycles despite any number of runs
             String kmsKeyId = getKmsKeyId();
             String kmsKeyArn = getKmsKeyArn();
             // Add your service to use KMS key
             addServiceAccess("logs", kmsKeyId);
             model.setKMSKey(kmsKeyArn);
             ProgressEvent<ResourceModel, CallbackContext> event = new UpdateHandler()
                 .handleRequest(getProxy(), createRequest(model, current), null, getLoggerProxy());
             assertThat(event.isSuccess()).isTrue();
             model = event.getResourceModel();
         }
         ...
         ...
     }
 
 
  • Method Summary

    Modifier and Type Method Description
    void deleteKmsKey()  

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details