Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Nov 4, 2023
1 parent e8019c3 commit 8603bef
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import io.awspring.cloud.autoconfigure.ConfiguredAwsClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SECRETSMANAGER;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import io.awspring.cloud.autoconfigure.ConfiguredAwsClient;
Expand Down Expand Up @@ -272,8 +271,7 @@ void serviceSpecificEndpointTakesPrecedenceOverGlobalAwsRegion() {
"--spring.config.import=aws-secretsmanager:/config/spring;/config/second",
"--spring.cloud.aws.secretsmanager.region=" + REGION,
"--spring.cloud.aws.endpoint=http://non-existing-host/",
"--spring.cloud.aws.secretsmanager.endpoint="
+ localstack.getEndpoint(),
"--spring.cloud.aws.secretsmanager.endpoint=" + localstack.getEndpoint(),
"--spring.cloud.aws.credentials.access-key=noop", "--spring.cloud.aws.credentials.secret-key=noop",
"--spring.cloud.aws.region.static=eu-west-1")) {
assertThat(context.getEnvironment().getProperty("message")).isEqualTo("value from tests");
Expand All @@ -290,8 +288,8 @@ void secretsManagerClientUsesStsCredentials() throws IOException {

try (ConfigurableApplicationContext context = application.run(
"--spring.config.import=optional:aws-secretsmanager:/config/spring;/config/second",
"--spring.cloud.aws.endpoint=" + localstack.getEndpoint(),
"--spring.cloud.aws.region.static=" + REGION, "--spring.cloud.aws.credentials.sts.role-arn=develop",
"--spring.cloud.aws.endpoint=" + localstack.getEndpoint(), "--spring.cloud.aws.region.static=" + REGION,
"--spring.cloud.aws.credentials.sts.role-arn=develop",
"--spring.cloud.aws.credentials.sts.enabled=true",
"--spring.cloud.aws.credentials.sts.web-identity-token-file=" + tempFile.getAbsolutePath())) {
assertThat(context.getBean(AwsCredentialsProvider.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.awspring.cloud.autoconfigure.metrics;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.CLOUDWATCH;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import io.micrometer.core.instrument.Counter;
Expand Down Expand Up @@ -59,8 +57,7 @@ class CloudWatchExportAutoConfigurationIntegrationTests {

@DynamicPropertySource
static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.cloud.aws.cloudwatch.endpoint",
() -> localstack.getEndpoint());
registry.add("spring.cloud.aws.cloudwatch.endpoint", () -> localstack.getEndpoint());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ public class ConfiguredTransferManager {

ConfiguredTransferManager(S3TransferManager s3TransferManager) {
// todo: this is getting too hacky
if (s3TransferManager.getClass().getName().equals("software.amazon.awssdk.transfer.s3.internal.CrtS3TransferManager")) {
S3TransferManager delegate = (S3TransferManager) ReflectionTestUtils.getField(s3TransferManager, "delegate");
if (s3TransferManager.getClass().getName()
.equals("software.amazon.awssdk.transfer.s3.internal.CrtS3TransferManager")) {
S3TransferManager delegate = (S3TransferManager) ReflectionTestUtils.getField(s3TransferManager,
"delegate");
this.transferConfiguration = (TransferManagerConfiguration) ReflectionTestUtils.getField(delegate,
"transferConfiguration");
this.client = (S3AsyncClient) ReflectionTestUtils.getField(s3TransferManager, "s3AsyncClient");
} else {
}
else {
this.transferConfiguration = (TransferManagerConfiguration) ReflectionTestUtils.getField(s3TransferManager,
"transferConfiguration");
this.client = (S3AsyncClient) ReflectionTestUtils.getField(s3TransferManager, "s3AsyncClient");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.awspring.cloud.autoconfigure.sqs;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS;

import io.awspring.cloud.autoconfigure.core.AwsAutoConfiguration;
import io.awspring.cloud.autoconfigure.core.CredentialsProviderAutoConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class DynamoDbTemplateIntegrationTest {

@BeforeAll
public static void createTable() {
DynamoDbClient dynamoDbClient = DynamoDbClient.builder()
.endpointOverride(localstack.getEndpoint()).region(Region.of(localstack.getRegion()))
DynamoDbClient dynamoDbClient = DynamoDbClient.builder().endpointOverride(localstack.getEndpoint())
.region(Region.of(localstack.getRegion()))
.credentialsProvider(StaticCredentialsProvider
.create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public Object getProperty(String name) {
private void getParameters(GetParametersByPathRequest paramsRequest) {
GetParametersByPathResponse paramsResult = this.source.getParametersByPath(paramsRequest);
for (Parameter parameter : paramsResult.parameters()) {
String key = parameter.name().replace(this.parameterPath, "").replace('/', '.')
.replaceAll("_(\\d)_", "[$1]");
String key = parameter.name().replace(this.parameterPath, "").replace('/', '.').replaceAll("_(\\d)_",
"[$1]");
LOG.debug("Populating property retrieved from AWS Parameter Store: " + key);
String propertyKey = prefix != null ? prefix + key : key;
this.properties.put(propertyKey, parameter.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ static void beforeAll() {
// test work on environments without AWS cli configured
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider
.create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey()));
client = new CrossRegionS3Client(
S3Client.builder().region(Region.of(localstack.getRegion())).credentialsProvider(credentialsProvider)
.endpointOverride(localstack.getEndpoint()));
client = new CrossRegionS3Client(S3Client.builder().region(Region.of(localstack.getRegion()))
.credentialsProvider(credentialsProvider).endpointOverride(localstack.getEndpoint()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ private Resource[] findResourcesInBucketsWithPatterns(String locationPattern) {
String s3KeyPattern = substringAfter(locationPattern, s3BucketNamePattern + "/");
LOGGER.debug("The s3 key pattern is {}", s3KeyPattern);
return (pathMatcher.isPattern(s3BucketNamePattern) ? findMatchingBuckets(s3BucketNamePattern)
: List.of(s3BucketNamePattern)).stream().flatMap(
s3BucketName -> findResourcesInBucketWithKeyPattern(s3BucketName, s3KeyPattern).stream())
.toArray(Resource[]::new);
: List.of(s3BucketNamePattern)).stream()
.flatMap(s3BucketName -> findResourcesInBucketWithKeyPattern(s3BucketName, s3KeyPattern).stream())
.toArray(Resource[]::new);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest;
import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest;
Expand Down Expand Up @@ -80,7 +80,8 @@ public boolean bucketExists(String bucketName) {
Assert.notNull(bucketName, "bucketName is required");
try {
s3Client.headBucket(request -> request.bucket(bucketName));
} catch (NoSuchBucketException e) {
}
catch (NoSuchBucketException e) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ static void beforeAll() {
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider
.create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey()));
S3Client client = S3Client.builder().region(Region.of(localstack.getRegion()))
.credentialsProvider(credentialsProvider)
.endpointOverride(localstack.getEndpoint()).build();
.credentialsProvider(credentialsProvider).endpointOverride(localstack.getEndpoint()).build();

// prepare buckets and objects for tests
client.createBucket(request -> request.bucket("my-bucket"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.shaded.com.google.common.io.Files;
Expand Down Expand Up @@ -91,8 +90,7 @@ static void beforeAll() {
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider
.create(AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey()));
asyncClient = S3AsyncClient.builder().region(Region.of(localstack.getRegion()))
.credentialsProvider(credentialsProvider).endpointOverride(localstack.getEndpoint())
.build();
.credentialsProvider(credentialsProvider).endpointOverride(localstack.getEndpoint()).build();
client = S3Client.builder().region(Region.of(localstack.getRegion())).credentialsProvider(credentialsProvider)
.endpointOverride(localstack.getEndpoint()).build();
s3TransferManager = S3TransferManager.builder().s3Client(asyncClient).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ static void beforeAll() {
client = S3Client.builder().region(Region.of(localstack.getRegion())).credentialsProvider(credentialsProvider)
.endpointOverride(localstack.getEndpoint()).build();
presigner = S3Presigner.builder().region(Region.of(localstack.getRegion()))
.credentialsProvider(credentialsProvider)
.endpointOverride(localstack.getEndpoint()).build();
.credentialsProvider(credentialsProvider).endpointOverride(localstack.getEndpoint()).build();
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public InfrastructureStack(final Construct scope, final String id, final StackPr
.stringValue("Spring-cloud-aws value!").build();

StringParameter.Builder.create(this, "Parameter2").parameterName("/config/spring/messages_0_")
.stringValue("Spring-cloud-aws msg0!").build();
.stringValue("Spring-cloud-aws msg0!").build();

StringParameter.Builder.create(this, "Parameter3").parameterName("/config/spring/messages_1_")
.stringValue("Spring-cloud-aws msg1!").build();
.stringValue("Spring-cloud-aws msg1!").build();

// Secrets Manager
SecretStringGenerator secretStringGenerator = SecretStringGenerator.builder().generateStringKey("password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static void main(String[] args) {

@Bean
ApplicationRunner applicationRunner(@Value("${message}") String message, @Value("${messages[0]}") String msg1,
@Value("${messages[1]}") String msg2) {
@Value("${messages[1]}") String msg2) {
return args -> LOGGER.info("`messages` loaded from the AWS Parameter store: {}, {} and {}", message, msg1,
msg2);
msg2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import io.awspring.cloud.sqs.listener.SqsMessageListenerContainer;
import io.awspring.cloud.sqs.operations.SqsTemplate;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;

import java.util.UUID;

@Configuration
public class SqsManualContainerInstantiationSample {

Expand All @@ -36,30 +35,22 @@ public class SqsManualContainerInstantiationSample {
@Bean
public ApplicationRunner sendMessageToQueueManualContainerInstantiation(SqsTemplate sqsTemplate) {
LOGGER.info("Sending message");
return args -> sqsTemplate.send(to -> to.queue(NEW_USER_QUEUE)
.payload(new User(UUID.randomUUID(), "John"))
);
return args -> sqsTemplate.send(to -> to.queue(NEW_USER_QUEUE).payload(new User(UUID.randomUUID(), "John")));
}

@Bean
public SqsTemplate sqsTemplateManualContainerInstantiation(SqsAsyncClient sqsAsyncClient) {
return SqsTemplate.builder()
.sqsAsyncClient(sqsAsyncClient)
.build();
return SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient).build();
}

@Bean
SqsMessageListenerContainer<User> sqsMessageListenerContainer(SqsAsyncClient sqsAsyncClient) {
return new SqsMessageListenerContainer.Builder<User>()
.sqsAsyncClient(sqsAsyncClient)
.queueNames(NEW_USER_QUEUE)
.messageListener((message) -> {
LOGGER.info("Received message {}", message);
})
.build();
return new SqsMessageListenerContainer.Builder<User>().sqsAsyncClient(sqsAsyncClient).queueNames(NEW_USER_QUEUE)
.messageListener((message) -> {
LOGGER.info("Received message {}", message);
}).build();
}

public record User(UUID id, String name) {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ void sendMessage_validTextMessageAndSubject_returnsTrue() throws Exception {
assertThat(it.topicArn()).isEqualTo(TOPIC_ARN);
assertThat(it.message()).isEqualTo("Message content");
assertThat(it.messageAttributes()).containsKeys(MessageHeaders.ID, MessageHeaders.TIMESTAMP);
assertThat(it.messageAttributes().get(MessageHeaders.TIMESTAMP).dataType()).isEqualTo("Number.java.lang.Long");
assertThat(it.messageAttributes().get(MessageHeaders.TIMESTAMP).dataType())
.isEqualTo("Number.java.lang.Long");
assertThat(it.messageAttributes()).doesNotContainKey(NOTIFICATION_SUBJECT_HEADER);
}));
assertThat(sent).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void resolveArgument_wrongMessageType_reportsErrors() throws Exception {
// Assert
assertThatThrownBy(
() -> resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("@NotificationMessage annotated parameters are only allowed");
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("@NotificationMessage annotated parameters are only allowed");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void resolveArgument_wrongMessageType_reportsErrors() throws Exception {
// Assert
assertThatThrownBy(
() -> resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("NotificationStatus is only available");
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("NotificationStatus is only available");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void resolveArgument_wrongMessageType_reportsErrors() throws Exception {
// Assert
assertThatThrownBy(
() -> resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("@NotificationMessage annotated parameters are only allowed");
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("@NotificationMessage annotated parameters are only allowed");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void send_test_message_for_not_existing_topic_name() {
SnsTemplate snsTemplateTestCache = new SnsTemplate(snsClient, topicsListingTopicArnResolver, null);
assertThatThrownBy(
() -> snsTemplateTestCache.sendNotification("Some_random_topic", "message content", "subject"))
.isInstanceOf(TopicNotFoundException.class);
.isInstanceOf(TopicNotFoundException.class);
}

private static void createTopics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public void setObjectMapper(ObjectMapper objectMapper) {
}

/**
* Set the {@link Validator} instance used for payload validating in {@link HandlerMethodArgumentResolver} instances.
* Set the {@link Validator} instance used for payload validating in {@link HandlerMethodArgumentResolver}
* instances.
* @param validator payload validator.
*/
public void setValidator(Validator validator) {
Expand Down Expand Up @@ -180,7 +181,8 @@ public MessageHandlerMethodFactory getMessageHandlerMethodFactory() {
}

/**
* Return the {@link Validator} instance used for payload validating in {@link HandlerMethodArgumentResolver} instances.
* Return the {@link Validator} instance used for payload validating in {@link HandlerMethodArgumentResolver}
* instances.
* @return the payload validator.
*/
public Validator getValidator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected <V> V unwrapCompletionException(CompletableFuture<V> future) {
return future.join();
}
catch (CompletionException ex) {
if (ex.getCause()instanceof RuntimeException re) {
if (ex.getCause() instanceof RuntimeException re) {
throw re;
}
throw new RuntimeException("Unexpected exception", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void registerListenerContainer(MessageListenerContainer<?> listenerContai
String factoryName = "otherFactory";
MessageConverter converter = mock(MessageConverter.class);
HandlerMethodArgumentResolver resolver = mock(HandlerMethodArgumentResolver.class);
Validator validator = mock(Validator.class);
Validator validator = mock(Validator.class);

SqsListenerConfigurer customizer = registrar -> {
registrar.setDefaultListenerContainerFactoryBeanName(factoryName);
Expand All @@ -82,7 +82,7 @@ public void registerListenerContainer(MessageListenerContainer<?> listenerContai
registrar.setObjectMapper(objectMapper);
registrar.manageMessageConverters(converters -> converters.add(converter));
registrar.manageMethodArgumentResolvers(resolvers -> resolvers.add(resolver));
registrar.setValidator(validator);
registrar.setValidator(validator);
};

when(beanFactory.getBeansOfType(SqsListenerConfigurer.class))
Expand Down Expand Up @@ -119,15 +119,16 @@ protected EndpointRegistrar createEndpointRegistrar() {
assertThat(endpoint).extracting("handlerMethodFactory").extracting("delegate").isEqualTo(methodFactory)
.extracting("argumentResolvers").extracting("argumentResolvers")
.asInstanceOf(list(HandlerMethodArgumentResolver.class)).hasSizeGreaterThan(1).contains(resolver)
.filteredOn(thisResolver -> thisResolver instanceof PayloadMethodArgumentResolver || thisResolver instanceof BatchPayloadMethodArgumentResolver)
.allSatisfy(thisResolver -> {
assertThat(thisResolver).extracting("validator").isEqualTo(validator);
assertThat(thisResolver).extracting("converter").asInstanceOf(type(CompositeMessageConverter.class))
.extracting(CompositeMessageConverter::getConverters).asInstanceOf(list(MessageConverter.class))
.contains(converter)
.filteredOn(thisConverter -> thisConverter instanceof MappingJackson2MessageConverter).element(0)
.extracting("objectMapper").isEqualTo(objectMapper);
});
.filteredOn(thisResolver -> thisResolver instanceof PayloadMethodArgumentResolver
|| thisResolver instanceof BatchPayloadMethodArgumentResolver)
.allSatisfy(thisResolver -> {
assertThat(thisResolver).extracting("validator").isEqualTo(validator);
assertThat(thisResolver).extracting("converter").asInstanceOf(type(CompositeMessageConverter.class))
.extracting(CompositeMessageConverter::getConverters)
.asInstanceOf(list(MessageConverter.class)).contains(converter)
.filteredOn(thisConverter -> thisConverter instanceof MappingJackson2MessageConverter)
.element(0).extracting("objectMapper").isEqualTo(objectMapper);
});
}

@Test
Expand Down
Loading

0 comments on commit 8603bef

Please sign in to comment.