AwsClientFactory { @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonSimpleEmailService getSesClient(AwsParamsDto awsParamsDto) { ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto); if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) { return AmazonSimpleEmailServiceClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider( new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()))) .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } else { return AmazonSimpleEmailServiceClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()) .build(); } }  @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) AmazonSNS getAmazonSNSClient(AwsParamsDto awsParamsDto); @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) AmazonSQS getAmazonSQSClient(AwsParamsDto awsParamsDto); @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto); @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) AmazonElasticMapReduce getEmrClient(AwsParamsDto awsParamsDto); @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) AmazonSimpleEmailService getSesClient(AwsParamsDto awsParamsDto);  }
@Test public void testGetSesClient() { assertNotNull(awsClientFactory.getSesClient( new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1))); }
@Test public void testGetSesClientCacheHitMiss() { AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1); AmazonSimpleEmailService amazonSimpleEmailService = awsClientFactory.getSesClient(awsParamsDto); assertEquals(amazonSimpleEmailService, awsClientFactory.getSesClient( new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1))); assertNotEquals(amazonSimpleEmailService, awsClientFactory.getSesClient( new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY_2, AWS_ASSUMED_ROLE_SECRET_KEY_2, AWS_ASSUMED_ROLE_SESSION_TOKEN_2, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1))); assertNotEquals(amazonSimpleEmailService, awsClientFactory.getSesClient( new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2, AWS_REGION_NAME_US_EAST_1))); cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear(); assertNotEquals(amazonSimpleEmailService, awsClientFactory.getSesClient(awsParamsDto)); }
@Test public void testGetSesClientNoAwsCredentials() { assertNotNull(awsClientFactory.getSesClient( new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1))); }