# ApitestConfig.java

    package cloud.wconnect.frontoffice.apitest;

    import java.net.URI;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Profile;

    import cloud.wconnect.aws.sns.messaging.core.AwsSignatureVerifier;
    import cloud.wconnect.aws.sns.messaging.core.VerificationProperties;
    import cloud.wconnect.commonlib.apitest.S3ControllerUtilApitest;
    import cloud.wconnect.commonlib.util.S3ControllerUtil;
    import cloud.wconnect.frontoffice.service.AmazonS3Service;
    import cloud.wconnect.frontoffice.service.AmazonSqsService;
    import cloud.wconnect.sns.http.configuration.SnsHttpProperties;
    import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
    import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
    import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.sns.SnsClient;

    @Profile("apitest-2")
    @Configuration
    @ComponentScan(basePackages = "cloud.wconnect.commonlib.apitest")
    public class ApitestConfig {

        @Value("${w-connect.module-event.access-key}")
        private String moduleEventAccessKey;

        @Value("${w-connect.module-event.secret-key}")
        private String moduleEventSecretKey;

        @Value("${w-connect.module-event.region}")
        private String moduleEventRegion;

        @Value("${w-connect.module-event.max-life-time-of-message}")
        private long maxLifeTimeOfMessage;

        @Value("${localstack.endpoint}")
        private String localstackEndpoint;

        @Autowired(required = false)
        private SnsHttpProperties snsHttpProperties;

        @Bean
        public S3ControllerUtil s3ControllerUtil() {
            return new S3ControllerUtilApitest();
        }

        @Bean
        public AmazonS3Service amazonS3Service() {
            return new AmazonS3ServiceApitest();
        }

        @Bean
        public AmazonSqsService sqsService() {
            return new AmazonSqsServiceApitest();
        }

        @ConditionalOnProperty(prefix = "w-connect.module-event", name = "status", havingValue = "active")
        @Bean("moduleEventSnsClient")
        public SnsClient getSnsClient1() {
            return SnsClient.builder()
                    .endpointOverride(URI.create(localstackEndpoint))
                    .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(moduleEventAccessKey, moduleEventSecretKey)))
                    .region(Region.of(moduleEventRegion))
                    .httpClient(UrlConnectionHttpClient.builder().build())
                    .build();
        }

        @ConditionalOnProperty(prefix = "w-connect.module-event", name = "status", havingValue = "active")
        @Bean("moduleAwsSignatureVerifier")
        public AwsSignatureVerifier getAwsSignatureVerifier1() {
            VerificationProperties config = new VerificationProperties();
            config.setMaxLifeTimeOfMessage(maxLifeTimeOfMessage);
            return new AwsSignatureVerifierApitest(config);
        }

        @ConditionalOnProperty(prefix = "third-party", value = "enabled", havingValue = "true")
        @Bean("3pSnsClient")
        public SnsClient getSnsClient2(){
            return SnsClient.builder()
                    .endpointOverride(URI.create(localstackEndpoint))
                    .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(snsHttpProperties.getAccessKey(), snsHttpProperties.getSecretKey())))
                    .region(Region.of(snsHttpProperties.getRegion()))
                    .httpClient(UrlConnectionHttpClient.builder().build())
                    .build();
        }

        @ConditionalOnProperty(prefix = "third-party", value = "enabled", havingValue = "true")
        @Bean("3pAwsSignatureVerifier")
        public AwsSignatureVerifier getAwsSignatureVerifier2() {
            VerificationProperties config = new VerificationProperties();
            config.setMaxLifeTimeOfMessage(snsHttpProperties.getMaxLifeTimeOfMessage());
            return new AwsSignatureVerifierApitest(config);
        }
    }