• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.services.dynamodb;
17 
18 import static org.junit.jupiter.api.Assertions.assertFalse;
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20 
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
24 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
25 import software.amazon.awssdk.core.exception.SdkException;
26 import software.amazon.awssdk.global.handlers.TestGlobalExecutionInterceptor;
27 import software.amazon.awssdk.regions.Region;
28 import software.amazon.awssdk.services.dynamodb.model.ListTablesRequest;
29 
30 public class GlobalRequestHandlerTest {
31 
32     @BeforeEach
setup()33     public void setup() {
34         TestGlobalExecutionInterceptor.reset();
35     }
36 
37     @Test
clientCreatedWithConstructor_RegistersGlobalHandlers()38     public void clientCreatedWithConstructor_RegistersGlobalHandlers() {
39         assertFalse(TestGlobalExecutionInterceptor.wasCalled());
40         DynamoDbClient client = DynamoDbClient.builder()
41                 .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
42                 .region(Region.US_WEST_2)
43                 .build();
44         callApi(client);
45         assertTrue(TestGlobalExecutionInterceptor.wasCalled());
46     }
47 
48     @Test
clientCreatedWithBuilder_RegistersGlobalHandlers()49     public void clientCreatedWithBuilder_RegistersGlobalHandlers() {
50         assertFalse(TestGlobalExecutionInterceptor.wasCalled());
51         DynamoDbClient client = DynamoDbClient.builder()
52                 .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
53                 .region(Region.US_WEST_2)
54                 .build();
55         callApi(client);
56         assertTrue(TestGlobalExecutionInterceptor.wasCalled());
57     }
58 
callApi(DynamoDbClient client)59     private void callApi(DynamoDbClient client) {
60         try {
61             client.listTables(ListTablesRequest.builder().build());
62         } catch (SdkException expected) {
63             // Ignored or expected.
64         }
65     }
66 }
67