|
20 | 20 | import io.opentelemetry.testing.internal.armeria.common.HttpStatus; |
21 | 21 | import io.opentelemetry.testing.internal.armeria.common.MediaType; |
22 | 22 | import java.util.List; |
23 | | -import org.junit.jupiter.api.Test; |
| 23 | +import java.util.function.Function; |
| 24 | +import java.util.stream.Stream; |
| 25 | +import org.junit.jupiter.params.ParameterizedTest; |
| 26 | +import org.junit.jupiter.params.provider.Arguments; |
| 27 | +import org.junit.jupiter.params.provider.MethodSource; |
24 | 28 |
|
25 | 29 | public abstract class AbstractSnsClientTest extends AbstractBaseAwsClientTest { |
26 | 30 | private static final String publishResponseBody = |
@@ -50,66 +54,53 @@ protected boolean hasRequestId() { |
50 | 54 | return true; |
51 | 55 | } |
52 | 56 |
|
53 | | - @Test |
54 | | - public void testPublishRequestWithTargetArnAndMockedResponse() throws Exception { |
| 57 | + @ParameterizedTest |
| 58 | + @MethodSource("provideArguments") |
| 59 | + void testSendRequestWithMockedResponse( |
| 60 | + Function<AmazonSNS, Object> call, |
| 61 | + String operation, |
| 62 | + String responseBody, |
| 63 | + List<AttributeAssertion> additionalAttributes) |
| 64 | + throws Exception { |
55 | 65 | AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder.standard(); |
56 | 66 | AmazonSNS client = |
57 | 67 | configureClient(clientBuilder) |
58 | 68 | .withEndpointConfiguration(endpoint) |
59 | 69 | .withCredentials(credentialsProvider) |
60 | 70 | .build(); |
61 | 71 |
|
62 | | - server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, publishResponseBody)); |
63 | | - List<AttributeAssertion> additionalAttributes = |
64 | | - singletonList(equalTo(MESSAGING_DESTINATION_NAME, "target-arn-foo")); |
65 | | - |
66 | | - Object response = |
67 | | - client.publish( |
68 | | - new PublishRequest().withMessage("somemessage").withTargetArn("target-arn-foo")); |
| 72 | + server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, responseBody)); |
| 73 | + Object response = call.apply(client); |
69 | 74 | assertRequestWithMockedResponse( |
70 | | - response, client, "SNS", "Publish", "POST", additionalAttributes); |
| 75 | + response, client, "SNS", operation, "POST", additionalAttributes); |
71 | 76 | } |
72 | 77 |
|
73 | | - @Test |
74 | | - public void testPublishRequestWithTopicArnAndMockedResponse() throws Exception { |
75 | | - AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder.standard(); |
76 | | - AmazonSNS client = |
77 | | - configureClient(clientBuilder) |
78 | | - .withEndpointConfiguration(endpoint) |
79 | | - .withCredentials(credentialsProvider) |
80 | | - .build(); |
81 | | - |
82 | | - server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, publishResponseBody)); |
83 | | - List<AttributeAssertion> additionalAttributes = |
84 | | - asList( |
85 | | - equalTo(MESSAGING_DESTINATION_NAME, "topic-arn-foo"), |
86 | | - equalTo(AWS_SNS_TOPIC_ARN, "topic-arn-foo")); |
87 | | - |
88 | | - Object response = |
89 | | - client.publish( |
90 | | - new PublishRequest().withMessage("somemessage").withTopicArn("topic-arn-foo")); |
91 | | - |
92 | | - assertRequestWithMockedResponse( |
93 | | - response, client, "SNS", "Publish", "POST", additionalAttributes); |
94 | | - } |
95 | | - |
96 | | - @Test |
97 | | - public void testCreateTopicRequestWithMockedResponse() throws Exception { |
98 | | - AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder.standard(); |
99 | | - AmazonSNS client = |
100 | | - configureClient(clientBuilder) |
101 | | - .withEndpointConfiguration(endpoint) |
102 | | - .withCredentials(credentialsProvider) |
103 | | - .build(); |
104 | | - |
105 | | - server.enqueue( |
106 | | - HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, createTopicResponseBody)); |
107 | | - List<AttributeAssertion> additionalAttributes = |
108 | | - asList(equalTo(AWS_SNS_TOPIC_ARN, "arn:aws:sns:us-east-1:123456789012:sns-topic-foo")); |
109 | | - |
110 | | - Object response = client.createTopic(new CreateTopicRequest().withName("sns-topic-foo")); |
111 | | - |
112 | | - assertRequestWithMockedResponse( |
113 | | - response, client, "SNS", "CreateTopic", "POST", additionalAttributes); |
| 78 | + private static Stream<Arguments> provideArguments() { |
| 79 | + return Stream.of( |
| 80 | + Arguments.of( |
| 81 | + (Function<AmazonSNS, Object>) |
| 82 | + c -> |
| 83 | + c.publish( |
| 84 | + new PublishRequest().withMessage("somemessage").withTopicArn("somearn")), |
| 85 | + "Publish", |
| 86 | + publishResponseBody, |
| 87 | + asList( |
| 88 | + equalTo(MESSAGING_DESTINATION_NAME, "somearn"), |
| 89 | + equalTo(AWS_SNS_TOPIC_ARN, "somearn"))), |
| 90 | + Arguments.of( |
| 91 | + (Function<AmazonSNS, Object>) |
| 92 | + c -> |
| 93 | + c.publish( |
| 94 | + new PublishRequest().withMessage("somemessage").withTargetArn("somearn")), |
| 95 | + "Publish", |
| 96 | + publishResponseBody, |
| 97 | + singletonList(equalTo(MESSAGING_DESTINATION_NAME, "somearn"))), |
| 98 | + Arguments.of( |
| 99 | + (Function<AmazonSNS, Object>) |
| 100 | + c -> c.createTopic(new CreateTopicRequest().withName("sns-topic-foo")), |
| 101 | + "CreateTopic", |
| 102 | + createTopicResponseBody, |
| 103 | + singletonList( |
| 104 | + equalTo(AWS_SNS_TOPIC_ARN, "arn:aws:sns:us-east-1:123456789012:sns-topic-foo")))); |
114 | 105 | } |
115 | 106 | } |
0 commit comments