generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* (feat) add Localstack SNS * fix (simplify) test * specify build enabled after 2.6.0
- Loading branch information
1 parent
5b5d13b
commit 504224f
Showing
10 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test-resources-localstack/test-resources-localstack-sns/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id 'io.micronaut.build.internal.localstack-module' | ||
} | ||
|
||
micronautBuild { | ||
binaryCompatibility { | ||
enabledAfter '2.6.0' | ||
} | ||
} | ||
|
||
description = """ | ||
Provides support for Localstack SNS. | ||
""" | ||
|
||
dependencies { | ||
implementation(project(":micronaut-test-resources-localstack-core")) | ||
runtimeOnly(libs.amazon.awssdk.v1.sns) { | ||
because "Localstack requires the AWS SDK in version 1 at runtime" | ||
} | ||
testImplementation(testFixtures(project(":micronaut-test-resources-localstack-core"))) | ||
testImplementation(libs.amazon.awssdk.v2.sns) | ||
} |
49 changes: 49 additions & 0 deletions
49
...ack-sns/src/main/java/io/micronaut/testresources/localstack/sns/LocalStackSNSService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.testresources.localstack.sns; | ||
|
||
import io.micronaut.testresources.localstack.LocalStackService; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Adds support for Localstack SNS. | ||
*/ | ||
public class LocalStackSNSService implements LocalStackService { | ||
|
||
private static final String AWS_SNS_ENDPOINT_OVERRIDE = "aws.services.sns.endpoint-override"; | ||
|
||
@Override | ||
public LocalStackContainer.Service getServiceKind() { | ||
return LocalStackContainer.Service.SNS; | ||
} | ||
|
||
@Override | ||
public List<String> getResolvableProperties() { | ||
return Collections.singletonList(AWS_SNS_ENDPOINT_OVERRIDE); | ||
} | ||
|
||
@Override | ||
public Optional<String> resolveProperty(String propertyName, LocalStackContainer container) { | ||
if (AWS_SNS_ENDPOINT_OVERRIDE.equals(propertyName)) { | ||
return Optional.of(container.getEndpointOverride(LocalStackContainer.Service.SNS).toString()); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../main/resources/META-INF/services/io.micronaut.testresources.localstack.LocalStackService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.micronaut.testresources.localstack.sns.LocalStackSNSService |
27 changes: 27 additions & 0 deletions
27
...ck-sns/src/test/groovy/io/micronaut/testresources/localstack/sns/LocalStackSNSTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.micronaut.testresources.localstack.sns | ||
|
||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import io.micronaut.testresources.localstack.AbstractLocalStackSpec | ||
import jakarta.inject.Inject | ||
import org.junit.Assert | ||
import software.amazon.awssdk.services.sns.SnsClient | ||
import software.amazon.awssdk.services.sns.model.Topic | ||
|
||
@MicronautTest | ||
class LocalStackSNSTest extends AbstractLocalStackSpec { | ||
|
||
@Inject | ||
SnsClient client | ||
|
||
def "automatically starts a SNS container"() { | ||
when: | ||
client.createTopic { | ||
it.name("test-topic") | ||
} | ||
|
||
then: | ||
List<Topic> topics = client.listTopics().topics() | ||
Assert.assertEquals(1, topics.size()) | ||
Assert.assertTrue(topics[0].topicArn().endsWith("test-topic")) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...sns/src/test/groovy/io/micronaut/testresources/localstack/sns/TestSnsClientFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.micronaut.testresources.localstack.sns | ||
|
||
import io.micronaut.context.annotation.Factory | ||
import jakarta.inject.Singleton | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.sns.SnsClient | ||
|
||
@Factory | ||
class TestSnsClientFactory { | ||
|
||
@Singleton | ||
SnsClient snsClient(TestSnsConfig testSnsConfig) { | ||
return SnsClient.builder() | ||
.endpointOverride(new URI(testSnsConfig.sns.endpointOverride)) | ||
.credentialsProvider( | ||
StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create(testSnsConfig.accessKeyId, testSnsConfig.secretKey) | ||
) | ||
) | ||
.region(Region.of(testSnsConfig.region)) | ||
.build() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lstack-sns/src/test/groovy/io/micronaut/testresources/localstack/sns/TestSnsConfig.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.micronaut.testresources.localstack.sns | ||
|
||
import io.micronaut.context.annotation.ConfigurationBuilder | ||
import io.micronaut.context.annotation.ConfigurationProperties | ||
|
||
@ConfigurationProperties("aws") | ||
class TestSnsConfig { | ||
String accessKeyId | ||
String secretKey | ||
String region | ||
|
||
@ConfigurationBuilder(configurationPrefix = "services.sns") | ||
final Sns sns = new Sns() | ||
|
||
static class Sns { | ||
String endpointOverride | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test-resources-localstack/test-resources-localstack-sns/src/test/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |