From f03c10c319a790b38e1bd644e42053e3f57b676b Mon Sep 17 00:00:00 2001 From: miregel Date: Wed, 29 Aug 2018 14:44:14 +0200 Subject: [PATCH] remove s3-properties, consolidate aws config, remove ssm bean Co-authored-by: Stefan Lier Co-authored-by: Micha Regel --- .../aws/configuration/AwsConfiguration.java | 17 ++- .../paramstore/ParamStoreConfiguration.java | 21 --- ...ParamStorePropertySourcePostProcessor.java | 19 ++- .../edison/aws/s3/S3BucketPropertyReader.java | 48 ------- .../S3BucketPropertySourcePostProcessor.java | 65 --------- .../edison/aws/s3/configuration/S3Config.java | 35 ----- .../aws/s3/configuration/S3Properties.java | 44 ------ .../aws/s3/togglz/S3StateRepository.java | 1 - .../S3TogglzConfiguration.java | 4 +- .../S3TogglzProperties.java | 2 +- ...mStorePropertySourcePostProcessorTest.java | 131 ------------------ .../aws/s3/S3BucketPropertyReaderTest.java | 57 -------- .../aws/s3/S3ServiceIntegrationTest.java | 6 +- .../aws/s3/togglz/S3StateRepositoryTest.java | 1 - .../org.mockito.plugins.MockMaker | 1 - 15 files changed, 30 insertions(+), 422 deletions(-) delete mode 100644 edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStoreConfiguration.java delete mode 100755 edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertyReader.java delete mode 100755 edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertySourcePostProcessor.java delete mode 100755 edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Config.java delete mode 100755 edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Properties.java rename edison-aws/src/main/java/de/otto/edison/aws/s3/{configuration => togglz}/S3TogglzConfiguration.java (89%) rename edison-aws/src/main/java/de/otto/edison/aws/s3/{configuration => togglz}/S3TogglzProperties.java (96%) delete mode 100644 edison-aws/src/test/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessorTest.java delete mode 100644 edison-aws/src/test/java/de/otto/edison/aws/s3/S3BucketPropertyReaderTest.java delete mode 100644 edison-aws/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/edison-aws/src/main/java/de/otto/edison/aws/configuration/AwsConfiguration.java b/edison-aws/src/main/java/de/otto/edison/aws/configuration/AwsConfiguration.java index 50d624ac5..6ab2fb213 100644 --- a/edison-aws/src/main/java/de/otto/edison/aws/configuration/AwsConfiguration.java +++ b/edison-aws/src/main/java/de/otto/edison/aws/configuration/AwsConfiguration.java @@ -1,5 +1,6 @@ package de.otto.edison.aws.configuration; +import de.otto.edison.aws.s3.S3Service; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -11,8 +12,11 @@ import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; +import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.ssm.SsmClient; +import static software.amazon.awssdk.regions.Region.of; + @Configuration @EnableConfigurationProperties(AwsProperties.class) public class AwsConfiguration { @@ -35,10 +39,19 @@ public AwsCredentialsProvider awsCredentialsProvider(final AwsProperties awsProp } @Bean - public SsmClient ssmClient(final AwsCredentialsProvider awsCredentialsProvider) { - return SsmClient.builder() + @ConditionalOnMissingBean(S3Client.class) + public S3Client s3Client(final AwsProperties awsProperties, + final AwsCredentialsProvider awsCredentialsProvider) { + return S3Client + .builder() + .region(of(awsProperties.getRegion())) .credentialsProvider(awsCredentialsProvider) .build(); + } + @Bean + @ConditionalOnMissingBean + public S3Service s3Service(final S3Client s3Client) { + return new S3Service(s3Client); } } diff --git a/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStoreConfiguration.java b/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStoreConfiguration.java deleted file mode 100644 index a11f64b6b..000000000 --- a/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStoreConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.otto.edison.aws.paramstore; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.services.ssm.SsmClient; - -@Configuration -@EnableConfigurationProperties(ParamStoreProperties.class) -@ConditionalOnProperty(name = "edison.aws.config.paramstore.enabled", havingValue = "true") -public class ParamStoreConfiguration { - - @Bean - public SsmClient awsSSM(AwsCredentialsProvider awsCredentialsProvider) { - return SsmClient.builder() - .credentialsProvider(awsCredentialsProvider) - .build(); - } -} diff --git a/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessor.java b/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessor.java index cf5bfe666..9cb6c6f80 100644 --- a/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessor.java +++ b/edison-aws/src/main/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessor.java @@ -1,9 +1,10 @@ package de.otto.edison.aws.paramstore; +import de.otto.edison.aws.configuration.AwsConfiguration; +import de.otto.edison.aws.configuration.AwsProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -23,6 +24,7 @@ import static io.netty.util.internal.StringUtil.isNullOrEmpty; import static java.util.Objects.requireNonNull; +import static software.amazon.awssdk.regions.Region.EU_CENTRAL_1; import static software.amazon.awssdk.services.ssm.model.ParameterType.SECURE_STRING; @Component @@ -32,14 +34,9 @@ public class ParamStorePropertySourcePostProcessor implements BeanFactoryPostPro private static final Logger LOG = LoggerFactory.getLogger(ParamStorePropertySourcePostProcessor.class); private static final String PARAMETER_STORE_PROPERTY_SOURCE = "parameterStorePropertySource"; - private final SsmClient ssmClient; + private SsmClient ssmClient; private ParamStoreProperties properties; - @Autowired - public ParamStorePropertySourcePostProcessor(final SsmClient ssmClient) { - this.ssmClient = ssmClient; - } - @Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { final Properties propertiesSource = new Properties(); @@ -91,6 +88,14 @@ public void setEnvironment(final Environment environment) { properties.setAddWithLowestPrecedence( Boolean.parseBoolean(environment.getProperty("edison.aws.config.paramstore.addWithLowestPrecedence", "false"))); properties.setPath(path); + + final AwsProperties awsProperties = new AwsProperties(); + awsProperties.setProfile(environment.getProperty("aws.profile", "default")); + awsProperties.setRegion(environment.getProperty("aws.region", EU_CENTRAL_1.id())); + final AwsConfiguration awsConfig = new AwsConfiguration(); + this.ssmClient = SsmClient.builder() + .credentialsProvider(awsConfig.awsCredentialsProvider(awsProperties)) + .build(); } } diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertyReader.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertyReader.java deleted file mode 100755 index 2073a7b67..000000000 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertyReader.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.otto.edison.aws.s3; - -import de.otto.edison.aws.s3.configuration.S3Properties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.stereotype.Component; -import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.model.GetObjectRequest; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -@Component -@EnableConfigurationProperties(S3Properties.class) -@ConditionalOnProperty(name = "edison.aws.config.s3.enabled", havingValue = "true") -public class S3BucketPropertyReader { - - private final S3Client s3Client; - private final S3Properties s3Properties; - - @Autowired - public S3BucketPropertyReader(final S3Client s3Client, - final S3Properties s3Properties) { - this.s3Client = s3Client; - this.s3Properties = s3Properties; - } - - Properties getPropertiesFromS3() { - return s3Client.getObject(GetObjectRequest.builder() - .bucket(s3Properties.getBucketname()) - .key(s3Properties.getFilename()) - .build(), - (response, in) -> makeProperties(in)); - } - - private Properties makeProperties(InputStream inputStream) { - try { - Properties properties = new Properties(); - properties.load(inputStream); - return properties; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertySourcePostProcessor.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertySourcePostProcessor.java deleted file mode 100755 index 2f89f752e..000000000 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/S3BucketPropertySourcePostProcessor.java +++ /dev/null @@ -1,65 +0,0 @@ -package de.otto.edison.aws.s3; - -import de.otto.edison.aws.configuration.AwsProperties; -import de.otto.edison.aws.configuration.AwsConfiguration; -import de.otto.edison.aws.s3.configuration.S3Properties; -import de.otto.edison.aws.s3.configuration.S3Config; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.env.MutablePropertySources; -import org.springframework.core.env.PropertiesPropertySource; -import org.springframework.stereotype.Component; -import software.amazon.awssdk.services.s3.S3Client; - -import static java.util.Objects.requireNonNull; - -@Component -@ConditionalOnProperty(name = "edison.aws.config.s3.enabled", havingValue = "true") -public class S3BucketPropertySourcePostProcessor implements BeanFactoryPostProcessor, EnvironmentAware { - - private static final String BUCKET_PROPERTY_SOURCE = "bucketPropertySource"; - private static final String EDISON_S3_PROPERTIES_BUCKETNAME = "edison.aws.config.s3.bucketname"; - private static final String EDISON_S3_PROPERTIES_FILENAME = "edison.aws.config.s3.filename"; - private final AwsProperties awsProperties; - private S3Properties secretsProperties; - - public S3BucketPropertySourcePostProcessor(final AwsProperties awsProperties) { - this.awsProperties = awsProperties; - } - - @Override - public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { - - final AwsConfiguration awsConfig = new AwsConfiguration(); - final S3Config s3Config = new S3Config(); - - final S3Client s3Client = s3Config.s3Client(awsProperties, awsConfig.awsCredentialsProvider(awsProperties)); - - final S3BucketPropertyReader s3BucketPropertyReader = new S3BucketPropertyReader(s3Client, secretsProperties); - - final ConfigurableEnvironment env = beanFactory.getBean(ConfigurableEnvironment.class); - final MutablePropertySources propertySources = env.getPropertySources(); - propertySources.addLast(new PropertiesPropertySource(BUCKET_PROPERTY_SOURCE, s3BucketPropertyReader.getPropertiesFromS3())); - } - - - @Override - public void setEnvironment(final Environment environment) { - - final String bucketName = requireNonNull( - environment.getProperty(EDISON_S3_PROPERTIES_BUCKETNAME), - "property '" + EDISON_S3_PROPERTIES_BUCKETNAME + "' must not be null"); - final String filename = requireNonNull( - environment.getProperty(EDISON_S3_PROPERTIES_FILENAME), - "property '" + EDISON_S3_PROPERTIES_FILENAME + "' must not be null"); - - secretsProperties = new S3Properties(); - secretsProperties.setBucketname(bucketName); - secretsProperties.setFilename(filename); - } -} diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Config.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Config.java deleted file mode 100755 index 6d2e3f407..000000000 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Config.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.otto.edison.aws.s3.configuration; - -import de.otto.edison.aws.configuration.AwsProperties; -import de.otto.edison.aws.s3.S3Service; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.services.s3.S3Client; - -import static software.amazon.awssdk.regions.Region.of; - - -@Configuration -@EnableConfigurationProperties(AwsProperties.class) -public class S3Config { - - @Bean - @ConditionalOnMissingBean(S3Client.class) - public S3Client s3Client(final AwsProperties awsProperties, - final AwsCredentialsProvider awsCredentialsProvider) { - return S3Client - .builder() - .region(of(awsProperties.getRegion())) - .credentialsProvider(awsCredentialsProvider) - .build(); - } - - @Bean - @ConditionalOnMissingBean - public S3Service s3Service(final S3Client s3Client) { - return new S3Service(s3Client); - } -} diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Properties.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Properties.java deleted file mode 100755 index 93e1bb73c..000000000 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3Properties.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.otto.edison.aws.s3.configuration; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "edison.aws.config.s3") -public class S3Properties { - - private String bucketname; - private String filename; - private boolean enabled; - - public String getBucketname() { - return bucketname; - } - - public void setBucketname(final String bucketname) { - this.bucketname = bucketname; - } - - public String getFilename() { - return filename; - } - - public void setFilename(final String filename) { - this.filename = filename; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - - @Override - public String toString() { - return "S3Properties{" + - "bucketname='" + bucketname + '\'' + - ", filename='" + filename + '\'' + - ", enabled=" + enabled + - '}'; - } -} diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3StateRepository.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3StateRepository.java index a362b5b35..504aae67b 100644 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3StateRepository.java +++ b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3StateRepository.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import de.otto.edison.aws.s3.configuration.S3TogglzProperties; import org.togglz.core.Feature; import org.togglz.core.repository.FeatureState; import org.togglz.core.repository.StateRepository; diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzConfiguration.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzConfiguration.java similarity index 89% rename from edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzConfiguration.java rename to edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzConfiguration.java index 30a9e9a61..55e4678b6 100644 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzConfiguration.java +++ b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzConfiguration.java @@ -1,7 +1,5 @@ -package de.otto.edison.aws.s3.configuration; +package de.otto.edison.aws.s3.togglz; -import de.otto.edison.aws.s3.togglz.PrefetchCachingStateRepository; -import de.otto.edison.aws.s3.togglz.S3StateRepository; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; diff --git a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzProperties.java b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzProperties.java similarity index 96% rename from edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzProperties.java rename to edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzProperties.java index 6cfa18e8e..e9680fc03 100644 --- a/edison-aws/src/main/java/de/otto/edison/aws/s3/configuration/S3TogglzProperties.java +++ b/edison-aws/src/main/java/de/otto/edison/aws/s3/togglz/S3TogglzProperties.java @@ -1,4 +1,4 @@ -package de.otto.edison.aws.s3.configuration; +package de.otto.edison.aws.s3.togglz; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; diff --git a/edison-aws/src/test/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessorTest.java b/edison-aws/src/test/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessorTest.java deleted file mode 100644 index c462fb06d..000000000 --- a/edison-aws/src/test/java/de/otto/edison/aws/paramstore/ParamStorePropertySourcePostProcessorTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package de.otto.edison.aws.paramstore; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.env.MutablePropertySources; -import org.springframework.core.env.PropertiesPropertySource; -import org.springframework.core.env.PropertySource; -import org.springframework.mock.env.MockEnvironment; -import software.amazon.awssdk.services.ssm.SsmClient; -import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest; -import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse; -import software.amazon.awssdk.services.ssm.model.Parameter; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class ParamStorePropertySourcePostProcessorTest { - - @Mock - private Environment environment; - - @Mock - private ConfigurableListableBeanFactory beanFactory; - - @Mock - private SsmClient ssmClient; - - private ParamStorePropertySourcePostProcessor postProcessor; - - @Before - public void setUp() { - initMocks(this); - when(environment.getProperty("edison.aws.config.paramstore.path")).thenReturn("/the/path"); - - postProcessor = new ParamStorePropertySourcePostProcessor(ssmClient); - postProcessor.setEnvironment(environment); - } - - @Test - public void shouldReadPropertiesFromSsm() { - // given - final GetParametersByPathResponse resultMock = mock(GetParametersByPathResponse.class); - final List parameters = new ArrayList<>(); - parameters.add(Parameter.builder().name("/the/path/param1").value("val1").build()); - parameters.add(Parameter.builder().name("/the/path/param2").value("val2").build()); - when(resultMock.parameters()).thenReturn(parameters); - when(ssmClient.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(resultMock); - final ConfigurableEnvironment envMock = mock(ConfigurableEnvironment.class); - when(beanFactory.getBean(ConfigurableEnvironment.class)).thenReturn(envMock); - final MutablePropertySources propertySourcesMock = mock(MutablePropertySources.class); - when(envMock.getPropertySources()).thenReturn(propertySourcesMock); - - final GetParametersByPathRequest expectedRequest = GetParametersByPathRequest - .builder() - .path("/the/path") - .withDecryption(true) - .recursive(true) - .build(); - final Properties propertiesSource = new Properties(); - propertiesSource.setProperty("/the/path/param1", "val1"); - propertiesSource.setProperty("/the/path/param2", "val2"); - final PropertiesPropertySource parameterStorePropertySource = - new PropertiesPropertySource("parameterStorePropertySource", propertiesSource); - - // when - postProcessor.postProcessBeanFactory(beanFactory); - - // then - verify(ssmClient).getParametersByPath(eq(expectedRequest)); - verify(propertySourcesMock).addFirst(parameterStorePropertySource); - } - - @Test - public void shouldReadPropertiesFromSsmWithPaging() { - // given - final GetParametersByPathResponse firstPage = mock(GetParametersByPathResponse.class); - final List parametersFirstPage = new ArrayList<>(); - parametersFirstPage.add(Parameter.builder().name("/the/path/param1").value("val1").build()); - parametersFirstPage.add(Parameter.builder().name("/the/path/param2").value("val2").build()); - when(firstPage.parameters()).thenReturn(parametersFirstPage); - when(firstPage.nextToken()).thenReturn("firstPageNextToken"); - final GetParametersByPathRequest firstRequest = GetParametersByPathRequest.builder() - .path("/the/path") - .withDecryption(true) - .recursive(true) - .nextToken(null) - .build(); - when(ssmClient.getParametersByPath(eq(firstRequest))).thenReturn(firstPage); - - final GetParametersByPathResponse secondPage = mock(GetParametersByPathResponse.class); - final List parametersSecondPage = new ArrayList<>(); - parametersSecondPage.add(Parameter.builder().name("/the/path/param3").value("val3").build()); - when(secondPage.parameters()).thenReturn(parametersSecondPage); - when(secondPage.nextToken()).thenReturn(null); - final GetParametersByPathRequest secondRequest = GetParametersByPathRequest.builder() - .path("/the/path") - .withDecryption(true) - .recursive(true) - .nextToken("firstPageNextToken") - .build(); - when(ssmClient.getParametersByPath(eq(secondRequest))).thenReturn(secondPage); - - final ConfigurableEnvironment envMock = new MockEnvironment(); - when(beanFactory.getBean(ConfigurableEnvironment.class)).thenReturn(envMock); - - // when - postProcessor.postProcessBeanFactory(beanFactory); - - // then - final PropertySource propertySource = envMock.getPropertySources().get("parameterStorePropertySource"); - assertThat(propertySource.getProperty("param1"), is("val1")); - assertThat(propertySource.getProperty("param2"), is("val2")); - assertThat(propertySource.getProperty("param3"), is("val3")); - } -} diff --git a/edison-aws/src/test/java/de/otto/edison/aws/s3/S3BucketPropertyReaderTest.java b/edison-aws/src/test/java/de/otto/edison/aws/s3/S3BucketPropertyReaderTest.java deleted file mode 100644 index ce19ec791..000000000 --- a/edison-aws/src/test/java/de/otto/edison/aws/s3/S3BucketPropertyReaderTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.otto.edison.aws.s3; - -import de.otto.edison.aws.s3.configuration.S3Properties; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import software.amazon.awssdk.core.sync.ResponseTransformer; -import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.model.GetObjectRequest; -import software.amazon.awssdk.services.s3.model.GetObjectResponse; - -import java.util.Properties; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class S3BucketPropertyReaderTest { - - @Mock - private S3Client s3Client; - - @Mock - private S3Properties s3Properties; - - @InjectMocks - private S3BucketPropertyReader testee; - - @Before - public void setUp() { - initMocks(this); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldReadPropertiesFromS3() { - // given - final Properties properties = new Properties(); - properties.put("foo", "bar"); - properties.put("key", "value"); - - when(s3Properties.getBucketname()).thenReturn("someBucket"); - when(s3Properties.getFilename()).thenReturn("someFileName"); - when(s3Client.getObject(any(GetObjectRequest.class), (ResponseTransformer) any(ResponseTransformer.class))).thenReturn(properties); - - // when - final Properties propertiesFromS3 = testee.getPropertiesFromS3(); - - //then - assertThat(propertiesFromS3.getProperty("foo"), is("bar")); - assertThat(propertiesFromS3.getProperty("key"), is("value")); - } -} diff --git a/edison-aws/src/test/java/de/otto/edison/aws/s3/S3ServiceIntegrationTest.java b/edison-aws/src/test/java/de/otto/edison/aws/s3/S3ServiceIntegrationTest.java index aef225088..f69fdb822 100644 --- a/edison-aws/src/test/java/de/otto/edison/aws/s3/S3ServiceIntegrationTest.java +++ b/edison-aws/src/test/java/de/otto/edison/aws/s3/S3ServiceIntegrationTest.java @@ -1,18 +1,14 @@ package de.otto.edison.aws.s3; import de.otto.edison.aws.configuration.AwsConfiguration; -import de.otto.edison.aws.configuration.AwsProperties; -import de.otto.edison.aws.s3.configuration.S3Config; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.context.annotation.PropertySource; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.testcontainers.containers.GenericContainer; @@ -30,7 +26,7 @@ import static org.junit.Assert.assertThat; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = {AwsTestconfiguration.class, AwsConfiguration.class, S3Config.class}) +@ContextConfiguration(classes = {AwsTestconfiguration.class, AwsConfiguration.class}) @ActiveProfiles("test") public class S3ServiceIntegrationTest { diff --git a/edison-aws/src/test/java/de/otto/edison/aws/s3/togglz/S3StateRepositoryTest.java b/edison-aws/src/test/java/de/otto/edison/aws/s3/togglz/S3StateRepositoryTest.java index b3d4ea670..e1ebdc0a6 100644 --- a/edison-aws/src/test/java/de/otto/edison/aws/s3/togglz/S3StateRepositoryTest.java +++ b/edison-aws/src/test/java/de/otto/edison/aws/s3/togglz/S3StateRepositoryTest.java @@ -1,6 +1,5 @@ package de.otto.edison.aws.s3.togglz; -import de.otto.edison.aws.s3.configuration.S3TogglzProperties; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; diff --git a/edison-aws/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/edison-aws/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index ca6ee9cea..000000000 --- a/edison-aws/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline \ No newline at end of file