Skip to content

Commit 969e6cd

Browse files
committed
Address code review feedback. Keep using the parameterized test structure.
1 parent ad77efc commit 969e6cd

File tree

1 file changed

+43
-52
lines changed
  • instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11

1 file changed

+43
-52
lines changed

instrumentation/aws-sdk/aws-sdk-1.11/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AbstractSnsClientTest.java

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import io.opentelemetry.testing.internal.armeria.common.HttpStatus;
2121
import io.opentelemetry.testing.internal.armeria.common.MediaType;
2222
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;
2428

2529
public abstract class AbstractSnsClientTest extends AbstractBaseAwsClientTest {
2630
private static final String publishResponseBody =
@@ -50,66 +54,53 @@ protected boolean hasRequestId() {
5054
return true;
5155
}
5256

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 {
5565
AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder.standard();
5666
AmazonSNS client =
5767
configureClient(clientBuilder)
5868
.withEndpointConfiguration(endpoint)
5969
.withCredentials(credentialsProvider)
6070
.build();
6171

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);
6974
assertRequestWithMockedResponse(
70-
response, client, "SNS", "Publish", "POST", additionalAttributes);
75+
response, client, "SNS", operation, "POST", additionalAttributes);
7176
}
7277

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"))));
114105
}
115106
}

0 commit comments

Comments
 (0)