Skip to content

Commit

Permalink
AWS SDK 2 upgrade: Fix compile errors in integration tests - spring-a…
Browse files Browse the repository at this point in the history
  • Loading branch information
tinexw committed Feb 13, 2020
1 parent 0a05361 commit 2b6e744
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 120 deletions.
8 changes: 4 additions & 4 deletions spring-cloud-aws-integration-test/pom.xml
Expand Up @@ -46,8 +46,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sns</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -121,8 +121,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elasticache</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>elasticache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws;

import com.amazonaws.services.cloudformation.AmazonCloudFormation;
import software.amazon.awssdk.services.cloudformation.CloudFormationClient;

import org.springframework.cloud.aws.context.config.annotation.EnableContextCredentials;
import org.springframework.cloud.aws.context.config.annotation.EnableContextRegion;
Expand Down Expand Up @@ -45,13 +45,13 @@ public static PropertySourcesPlaceholderConfigurer configurer() {

@Bean
public TestStackEnvironment testStackEnvironment(
AmazonCloudFormation amazonCloudFormation) {
CloudFormationClient amazonCloudFormation) {
return new TestStackEnvironment(amazonCloudFormation);
}

@Bean
public TestStackInstanceIdService testStackInstanceIdService(
AmazonCloudFormation amazonCloudFormation) {
CloudFormationClient amazonCloudFormation) {
return TestStackInstanceIdService.fromStackOutputKey(
TestStackEnvironment.DEFAULT_STACK_NAME,
TestStackEnvironment.INSTANCE_ID_STACK_OUTPUT_KEY, amazonCloudFormation);
Expand Down
Expand Up @@ -16,18 +16,19 @@

package org.springframework.cloud.aws.context.support.io;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ObjectMetadata;
import org.junit.Test;
import org.junit.runner.RunWith;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry;
Expand Down Expand Up @@ -56,13 +57,13 @@ public abstract class PathMatchingResourceLoaderAwsTest {
private ResourcePatternResolver resourceLoader;

@Autowired
private AmazonS3 amazonS3;
private S3Client amazonS3;

@Autowired
private StackResourceRegistry stackResourceRegistry;

@Autowired
public void setupResolver(ApplicationContext applicationContext, AmazonS3 amazonS3) {
public void setupResolver(ApplicationContext applicationContext, S3Client amazonS3) {
this.resourceLoader = new PathMatchingSimpleStorageResourcePatternResolver(
amazonS3, applicationContext);
}
Expand Down Expand Up @@ -143,22 +144,23 @@ private static class CreateFileCallable implements Callable<String> {

private final String fileName;

private final AmazonS3 amazonS3;
private final S3Client amazonS3;

private final String bucketName;

private CreateFileCallable(String bucketName, String fileName,
AmazonS3 amazonS3) {
S3Client amazonS3) {
this.fileName = fileName;
this.amazonS3 = amazonS3;
this.bucketName = bucketName;
}

@Override
public String call() {
this.amazonS3.putObject(this.bucketName, this.fileName,
new ByteArrayInputStream(this.fileName.getBytes()),
new ObjectMetadata());
this.amazonS3.putObject(PutObjectRequest.builder()
.bucket(this.bucketName)
.key(this.fileName)
.build(), RequestBody.fromBytes(this.fileName.getBytes()));
return this.fileName;
}

Expand All @@ -168,20 +170,20 @@ private static class DeleteFileCallable implements Callable<String> {

private final String fileName;

private final AmazonS3 amazonS3;
private final S3Client amazonS3;

private final String bucketName;

private DeleteFileCallable(String bucketName, String fileName,
AmazonS3 amazonS3) {
S3Client amazonS3) {
this.fileName = fileName;
this.amazonS3 = amazonS3;
this.bucketName = bucketName;
}

@Override
public String call() {
this.amazonS3.deleteObject(this.bucketName, this.fileName);
this.amazonS3.deleteObject(DeleteObjectRequest.builder().bucket(this.bucketName).key(this.fileName).build());
return this.fileName;
}

Expand Down
Expand Up @@ -20,7 +20,6 @@

package org.springframework.cloud.aws.context.support.io;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -34,11 +33,13 @@
import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.ObjectMetadata;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.core.env.stack.StackResourceRegistry;
Expand Down Expand Up @@ -70,7 +71,7 @@ public abstract class ResourceLoaderAwsTest {

@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
private AmazonS3 amazonS3;
private S3Client amazonS3;

@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
Expand Down Expand Up @@ -123,10 +124,8 @@ public void testUploadFileWithRelativePath() throws Exception {

private void uploadFileTestFile(String bucketName, String objectKey, String content)
throws UnsupportedEncodingException {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(content.length());
this.amazonS3.putObject(bucketName, objectKey,
new ByteArrayInputStream(content.getBytes("UTF-8")), objectMetadata);
this.amazonS3.putObject(PutObjectRequest.builder().bucket(bucketName).key(objectKey).contentLength((long) content.length()).build(),
RequestBody.fromBytes(content.getBytes("UTF-8")));
this.createdObjects.add(objectKey);
}

Expand Down Expand Up @@ -217,7 +216,7 @@ public void tearDown() {
String bucketName = this.stackResourceRegistry
.lookupPhysicalResourceId("EmptyBucket");
for (String createdObject : this.createdObjects) {
this.amazonS3.deleteObject(bucketName, createdObject);
this.amazonS3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(createdObject).build());
}

}
Expand Down
Expand Up @@ -21,7 +21,6 @@
import java.lang.reflect.Field;
import java.net.InetSocketAddress;

import com.amazonaws.SDKGlobalConfiguration;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
Expand All @@ -30,6 +29,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import software.amazon.awssdk.core.SdkSystemSetting;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils;
Expand Down Expand Up @@ -77,13 +77,13 @@ public static void shutdownHttpServer() throws Exception {
private static void overwriteMetadataEndpointUrl(
String localMetadataServiceEndpointUrl) {
System.setProperty(
SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY,
SdkSystemSetting.AWS_EC2_METADATA_SERVICE_ENDPOINT.property(),
localMetadataServiceEndpointUrl);
}

private static void resetMetadataEndpointUrlOverwrite() {
System.clearProperty(
SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY);
SdkSystemSetting.AWS_EC2_METADATA_SERVICE_ENDPOINT.property());
}

private static void restContextInstanceDataCondition() throws IllegalAccessException {
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sns.AmazonSNS;
import software.amazon.awssdk.services.sns.SnsClient;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -41,7 +41,7 @@ protected static class NotificationMessagingTemplateIntegrationTestConfiguration

@Bean
public NotificationMessagingTemplate notificationMessagingTemplate(
AmazonSNS amazonSns, ResourceIdResolver resourceIdResolver) {
SnsClient amazonSns, ResourceIdResolver resourceIdResolver) {
NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(
amazonSns, resourceIdResolver);
notificationMessagingTemplate
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -54,7 +54,7 @@ public QueueMessageHandlerFactory queueMessageHandlerFactory() {
}

@Bean
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSqs,
public QueueMessagingTemplate queueMessagingTemplate(SqsClient amazonSqs,
ResourceIdResolver resourceIdResolver,
QueueMessageHandlerFactory factory) {
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -42,7 +42,7 @@ protected static class QueueMessagingTemplateIntegrationTestConfiguration {

@Bean
public QueueMessagingTemplate defaultQueueMessagingTemplate(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
SqsClient amazonSqs, ResourceIdResolver resourceIdResolver) {
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs, resourceIdResolver);
queueMessagingTemplate.setDefaultDestinationName("JsonQueue");
Expand All @@ -52,7 +52,7 @@ public QueueMessagingTemplate defaultQueueMessagingTemplate(

@Bean
public QueueMessagingTemplate queueMessagingTemplateWithCustomConverter(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
SqsClient amazonSqs, ResourceIdResolver resourceIdResolver) {
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs, resourceIdResolver);
queueMessagingTemplate.setDefaultDestinationName("StreamQueue");
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sns.AmazonSNS;
import software.amazon.awssdk.services.sns.SnsClient;

import org.springframework.cloud.aws.IntegrationTestConfig;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
Expand All @@ -43,7 +43,7 @@ protected static class NotificationMessagingTemplateIntegrationTestConfiguration

@Bean
public NotificationMessagingTemplate notificationMessagingTemplate(
AmazonSNS amazonSns, ResourceIdResolver resourceIdResolver) {
SnsClient amazonSns, ResourceIdResolver resourceIdResolver) {
NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(
amazonSns, resourceIdResolver);
notificationMessagingTemplate
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.cloud.aws.IntegrationTestConfig;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
Expand Down Expand Up @@ -58,7 +58,7 @@ public QueueMessageHandlerFactory queueMessageHandlerFactory(
}

@Bean
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSqs,
public QueueMessagingTemplate queueMessagingTemplate(SqsClient amazonSqs,
ResourceIdResolver resourceIdResolver) {
return new QueueMessagingTemplate(amazonSqs, resourceIdResolver);
}
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.aws.messaging;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.cloud.aws.IntegrationTestConfig;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
Expand All @@ -42,7 +42,7 @@ protected static class QueueMessagingTemplateIntegrationTestConfiguration {

@Bean
public QueueMessagingTemplate defaultQueueMessagingTemplate(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
SqsClient amazonSqs, ResourceIdResolver resourceIdResolver) {
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs, resourceIdResolver);
queueMessagingTemplate.setDefaultDestinationName("JsonQueue");
Expand All @@ -52,7 +52,7 @@ public QueueMessagingTemplate defaultQueueMessagingTemplate(

@Bean
public QueueMessagingTemplate queueMessagingTemplateWithCustomConverter(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
SqsClient amazonSqs, ResourceIdResolver resourceIdResolver) {
QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(
amazonSqs, resourceIdResolver);
queueMessagingTemplate.setDefaultDestinationName("StreamQueue");
Expand Down

0 comments on commit 2b6e744

Please sign in to comment.