15
15
import static io .opentelemetry .semconv .UrlAttributes .URL_FULL ;
16
16
import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_REQUEST_ID ;
17
17
import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_SECRETSMANAGER_SECRET_ARN ;
18
+ import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_SNS_TOPIC_ARN ;
18
19
import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_STEP_FUNCTIONS_ACTIVITY_ARN ;
19
20
import static io .opentelemetry .semconv .incubating .AwsIncubatingAttributes .AWS_STEP_FUNCTIONS_STATE_MACHINE_ARN ;
20
21
import static io .opentelemetry .semconv .incubating .MessagingIncubatingAttributes .MESSAGING_DESTINATION_NAME ;
98
99
import software .amazon .awssdk .services .sns .SnsAsyncClientBuilder ;
99
100
import software .amazon .awssdk .services .sns .SnsClient ;
100
101
import software .amazon .awssdk .services .sns .SnsClientBuilder ;
102
+ import software .amazon .awssdk .services .sns .model .CreateTopicRequest ;
103
+ import software .amazon .awssdk .services .sns .model .CreateTopicResponse ;
101
104
import software .amazon .awssdk .services .sns .model .PublishRequest ;
105
+ import software .amazon .awssdk .services .sns .model .PublishResponse ;
106
+ import software .amazon .awssdk .services .sns .model .SubscribeRequest ;
107
+ import software .amazon .awssdk .services .sns .model .SubscribeResponse ;
102
108
import software .amazon .awssdk .services .sqs .SqsAsyncClient ;
103
109
import software .amazon .awssdk .services .sqs .SqsAsyncClientBuilder ;
104
110
import software .amazon .awssdk .services .sqs .SqsClient ;
@@ -139,6 +145,36 @@ public abstract class AbstractAws2ClientTest extends AbstractAws2ClientCoreTest
139
145
+ " \" CreatedDate\" : \" 1.523477145713E9\" "
140
146
+ "}" ;
141
147
148
+ private static final String snsPublishResponseBody =
149
+ "<PublishResponse xmlns=\" https://sns.amazonaws.com/doc/2010-03-31/\" >"
150
+ + " <PublishResult>"
151
+ + " <MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>"
152
+ + " </PublishResult>"
153
+ + " <ResponseMetadata>"
154
+ + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>"
155
+ + " </ResponseMetadata>"
156
+ + "</PublishResponse>" ;
157
+
158
+ private static final String snsSubscribeResponseBody =
159
+ "<SubscribeResponse xmlns=\" https://sns.amazonaws.com/doc/2010-03-31/\" >"
160
+ + " <SubscribeResult>"
161
+ + " <SubscriptionArn>arn:aws:sns:us-west-2:123456789012:MyTopic:abc123</SubscriptionArn>"
162
+ + " </SubscribeResult>"
163
+ + " <ResponseMetadata>"
164
+ + " <RequestId>0ac9cda2-abcd-11d3-f92b-31fa5e8dbc67</RequestId>"
165
+ + " </ResponseMetadata>"
166
+ + " </SubscribeResponse>" ;
167
+
168
+ private static final String snsCreateTopicResponseBody =
169
+ "<CreateTopicResponse xmlns=\" https://sns.amazonaws.com/doc/2010-03-31/\" >"
170
+ + " <CreateTopicResult>"
171
+ + " <TopicArn>arn:aws:sns:us-east-1:123456789012:sns-topic-name-foo</TopicArn>"
172
+ + " </CreateTopicResult>"
173
+ + " <ResponseMetadata>"
174
+ + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>"
175
+ + " </ResponseMetadata>"
176
+ + "</CreateTopicResponse>" ;
177
+
142
178
private static void assumeSupportedConfig (String operation ) {
143
179
Assumptions .assumeFalse (
144
180
operation .equals ("SendMessage" ) && isSqsAttributeInjectionEnabled (),
@@ -223,7 +259,22 @@ private void clientAssertions(
223
259
}
224
260
225
261
if (service .equals ("Sns" )) {
226
- attributes .add (equalTo (MESSAGING_DESTINATION_NAME , "somearn" ));
262
+ switch (operation ) {
263
+ case "CreateTopic" :
264
+ attributes .add (
265
+ equalTo (AWS_SNS_TOPIC_ARN , "arn:aws:sns:us-east-1:123456789012:sns-topic-name-foo" ));
266
+ break ;
267
+ case "Publish" :
268
+ attributes .add (equalTo (MESSAGING_DESTINATION_NAME , "sns-target-arn" ));
269
+ break ;
270
+ case "Subscribe" :
271
+ attributes .add (equalTo (MESSAGING_DESTINATION_NAME , "sns-topic-arn" ));
272
+ attributes .add (equalTo (AWS_SNS_TOPIC_ARN , "sns-topic-arn" ));
273
+ break ;
274
+ default :
275
+ attributes .add (equalTo (AWS_SNS_TOPIC_ARN , "Bug-Unknown-Operation-ARN" ));
276
+ break ;
277
+ }
227
278
}
228
279
229
280
if (service .equals ("Sqs" ) && operation .equals ("CreateQueue" )) {
@@ -516,22 +567,43 @@ private static Stream<Arguments> provideSnsArguments() {
516
567
c ->
517
568
c .publish (
518
569
PublishRequest .builder ()
519
- .message ("somemessage" )
520
- .topicArn ("somearn" )
521
- .build ())),
570
+ .message ("sns-msg-foo" )
571
+ .targetArn ("sns-target-arn" )
572
+ .build ()),
573
+ "Publish" ,
574
+ "POST" ,
575
+ snsPublishResponseBody ,
576
+ "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0" ),
522
577
Arguments .of (
523
578
(Function <SnsClient , Object >)
524
579
c ->
525
- c .publish (
526
- PublishRequest .builder ()
527
- .message ("somemessage" )
528
- .targetArn ("somearn" )
529
- .build ())));
580
+ c .subscribe (
581
+ SubscribeRequest .builder ()
582
+ .topicArn ("sns-topic-arn" )
583
+ .protocol ("email" )
584
+
585
+ .build ()),
586
+ "Subscribe" ,
587
+ "POST" ,
588
+ snsSubscribeResponseBody ,
589
+ "0ac9cda2-abcd-11d3-f92b-31fa5e8dbc67" ),
590
+ Arguments .of (
591
+ (Function <SnsClient , Object >)
592
+ c -> c .createTopic (CreateTopicRequest .builder ().name ("sns-topic-name-foo" ).build ()),
593
+ "CreateTopic" ,
594
+ "POST" ,
595
+ snsCreateTopicResponseBody ,
596
+ "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0" ));
530
597
}
531
598
532
599
@ ParameterizedTest
533
600
@ MethodSource ("provideSnsArguments" )
534
- void testSnsSendOperationRequestWithBuilder (Function <SnsClient , Object > call ) {
601
+ void testSnsSendOperationRequestWithBuilder (
602
+ Function <SnsClient , Object > call ,
603
+ String operation ,
604
+ String method ,
605
+ String responseBody ,
606
+ String requestId ) {
535
607
SnsClientBuilder builder = SnsClient .builder ();
536
608
configureSdkClient (builder );
537
609
SnsClient client =
@@ -541,28 +613,25 @@ void testSnsSendOperationRequestWithBuilder(Function<SnsClient, Object> call) {
541
613
.credentialsProvider (CREDENTIALS_PROVIDER )
542
614
.build ();
543
615
544
- String body =
545
- "<PublishResponse xmlns=\" https://sns.amazonaws.com/doc/2010-03-31/\" >"
546
- + " <PublishResult>"
547
- + " <MessageId>567910cd-659e-55d4-8ccb-5aaf14679dc0</MessageId>"
548
- + " </PublishResult>"
549
- + " <ResponseMetadata>"
550
- + " <RequestId>d74b8436-ae13-5ab4-a9ff-ce54dfea72a0</RequestId>"
551
- + " </ResponseMetadata>"
552
- + "</PublishResponse>" ;
553
-
554
- server .enqueue (HttpResponse .of (HttpStatus .OK , MediaType .PLAIN_TEXT_UTF_8 , body ));
616
+ server .enqueue (HttpResponse .of (HttpStatus .OK , MediaType .PLAIN_TEXT_UTF_8 , responseBody ));
555
617
Object response = call .apply (client );
556
618
557
619
assertThat (response .getClass ().getSimpleName ())
558
620
.satisfiesAnyOf (
559
- v -> assertThat (v ).startsWith ("Publish" ),
560
- v -> assertThat (response ).isInstanceOf (ResponseInputStream .class ));
561
- clientAssertions ("Sns" , "Publish" , "POST" , response , "d74b8436-ae13-5ab4-a9ff-ce54dfea72a0" );
621
+ v -> assertThat (response ).isInstanceOf (CreateTopicResponse .class ),
622
+ v -> assertThat (response ).isInstanceOf (PublishResponse .class ),
623
+ v -> assertThat (response ).isInstanceOf (SubscribeResponse .class ));
624
+ clientAssertions ("Sns" , operation , method , response , requestId );
562
625
}
563
626
564
- @ Test
565
- void testSnsAsyncSendOperationRequestWithBuilder () {
627
+ @ ParameterizedTest
628
+ @ MethodSource ("provideSnsArguments" )
629
+ void testSnsAsyncSendOperationRequestWithBuilder (
630
+ Function <SnsClient , Object > call ,
631
+ String operation ,
632
+ String method ,
633
+ String responseBody ,
634
+ String requestId ) {
566
635
SnsAsyncClientBuilder builder = SnsAsyncClient .builder ();
567
636
configureSdkClient (builder );
568
637
SnsAsyncClient client =
@@ -572,20 +641,15 @@ void testSnsAsyncSendOperationRequestWithBuilder() {
572
641
.credentialsProvider (CREDENTIALS_PROVIDER )
573
642
.build ();
574
643
575
- String body =
576
- "<PublishResponse xmlns=\" https://sns.amazonaws.com/doc/2010-03-31/\" >"
577
- + " <PublishResult>"
578
- + " <MessageId>94f20ce6-13c5-43a0-9a9e-ca52d816e90b</MessageId>"
579
- + " </PublishResult>"
580
- + " <ResponseMetadata>"
581
- + " <RequestId>f187a3c1-376f-11df-8963-01868b7c937a</RequestId>"
582
- + " </ResponseMetadata>"
583
- + "</PublishResponse>" ;
584
-
585
- server .enqueue (HttpResponse .of (HttpStatus .OK , MediaType .PLAIN_TEXT_UTF_8 , body ));
586
- Object response = client .publish (r -> r .message ("hello" ).topicArn ("somearn" ));
644
+ server .enqueue (HttpResponse .of (HttpStatus .OK , MediaType .PLAIN_TEXT_UTF_8 , responseBody ));
645
+ Object response = call .apply (wrapClient (SnsClient .class , SnsAsyncClient .class , client ));
587
646
588
- clientAssertions ("Sns" , "Publish" , "POST" , response , "f187a3c1-376f-11df-8963-01868b7c937a" );
647
+ assertThat (response .getClass ().getSimpleName ())
648
+ .satisfiesAnyOf (
649
+ v -> assertThat (response ).isInstanceOf (CreateTopicResponse .class ),
650
+ v -> assertThat (response ).isInstanceOf (PublishResponse .class ),
651
+ v -> assertThat (response ).isInstanceOf (SubscribeResponse .class ));
652
+ clientAssertions ("Sns" , operation , method , response , requestId );
589
653
}
590
654
591
655
@ Test
0 commit comments