Skip to content

Commit 9ce2d52

Browse files
committed
Add async tests for acm, apigateway, autoscaling
1 parent 883fe05 commit 9ce2d52

File tree

8 files changed

+928
-7
lines changed

8 files changed

+928
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2010-2019 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.acm;
17+
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
20+
import org.junit.Assert;
21+
import org.junit.BeforeClass;
22+
import org.junit.Test;
23+
import software.amazon.awssdk.services.acm.model.AcmException;
24+
import software.amazon.awssdk.services.acm.model.GetCertificateRequest;
25+
import software.amazon.awssdk.services.acm.model.ListCertificatesRequest;
26+
import software.amazon.awssdk.services.acm.model.ListCertificatesResponse;
27+
import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase;
28+
29+
public class AwsCertficateManagerAsyncIntegrationTest extends AwsIntegrationTestBase {
30+
private static AcmAsyncClient client;
31+
32+
@BeforeClass
33+
public static void setUp() {
34+
client = AcmAsyncClient.builder().credentialsProvider(getCredentialsProvider()).build();
35+
}
36+
37+
@Test
38+
public void list_certificates() {
39+
ListCertificatesResponse result = client.listCertificates(ListCertificatesRequest.builder().build())
40+
.join();
41+
Assert.assertTrue(result.certificateSummaryList().size() >= 0);
42+
}
43+
44+
@Test
45+
public void get_certificate_fake_arn_throws_exception() {
46+
assertThatThrownBy(() -> client.getCertificate(getCertificateRequest()).join())
47+
.hasCauseInstanceOf(AcmException.class);
48+
}
49+
50+
private GetCertificateRequest getCertificateRequest() {
51+
return GetCertificateRequest.builder()
52+
.certificateArn("arn:aws:acm:us-east-1:123456789:fakecert")
53+
.build();
54+
}
55+
}

services/acm/src/it/java/software/amazon/awssdk/services/acm/AwsCertficateManagerIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import org.junit.Assert;
1919
import org.junit.BeforeClass;
2020
import org.junit.Test;
21-
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
22-
import software.amazon.awssdk.core.exception.SdkServiceException;
2321
import software.amazon.awssdk.services.acm.model.AcmException;
2422
import software.amazon.awssdk.services.acm.model.GetCertificateRequest;
2523
import software.amazon.awssdk.services.acm.model.ListCertificatesRequest;
@@ -32,7 +30,7 @@ public class AwsCertficateManagerIntegrationTest extends AwsIntegrationTestBase
3230

3331
@BeforeClass
3432
public static void setUp() {
35-
client = AcmClient.builder().credentialsProvider(StaticCredentialsProvider.create(getCredentials())).build();
33+
client = AcmClient.builder().credentialsProvider(getCredentialsProvider()).build();
3634
}
3735

3836
@Test
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright 2010-2019 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.apigateway;
17+
18+
import java.util.List;
19+
import org.junit.AfterClass;
20+
import org.junit.Assert;
21+
import org.junit.BeforeClass;
22+
import org.junit.Test;
23+
import software.amazon.awssdk.services.apigateway.model.CreateApiKeyRequest;
24+
import software.amazon.awssdk.services.apigateway.model.CreateApiKeyResponse;
25+
import software.amazon.awssdk.services.apigateway.model.CreateResourceRequest;
26+
import software.amazon.awssdk.services.apigateway.model.CreateResourceResponse;
27+
import software.amazon.awssdk.services.apigateway.model.CreateRestApiRequest;
28+
import software.amazon.awssdk.services.apigateway.model.CreateRestApiResponse;
29+
import software.amazon.awssdk.services.apigateway.model.DeleteRestApiRequest;
30+
import software.amazon.awssdk.services.apigateway.model.GetApiKeyRequest;
31+
import software.amazon.awssdk.services.apigateway.model.GetApiKeyResponse;
32+
import software.amazon.awssdk.services.apigateway.model.GetResourceRequest;
33+
import software.amazon.awssdk.services.apigateway.model.GetResourceResponse;
34+
import software.amazon.awssdk.services.apigateway.model.GetResourcesRequest;
35+
import software.amazon.awssdk.services.apigateway.model.GetResourcesResponse;
36+
import software.amazon.awssdk.services.apigateway.model.GetRestApiRequest;
37+
import software.amazon.awssdk.services.apigateway.model.GetRestApiResponse;
38+
import software.amazon.awssdk.services.apigateway.model.IntegrationType;
39+
import software.amazon.awssdk.services.apigateway.model.Op;
40+
import software.amazon.awssdk.services.apigateway.model.PatchOperation;
41+
import software.amazon.awssdk.services.apigateway.model.PutIntegrationRequest;
42+
import software.amazon.awssdk.services.apigateway.model.PutIntegrationResponse;
43+
import software.amazon.awssdk.services.apigateway.model.PutMethodRequest;
44+
import software.amazon.awssdk.services.apigateway.model.PutMethodResponse;
45+
import software.amazon.awssdk.services.apigateway.model.Resource;
46+
import software.amazon.awssdk.services.apigateway.model.UpdateApiKeyRequest;
47+
import software.amazon.awssdk.services.apigateway.model.UpdateResourceRequest;
48+
import software.amazon.awssdk.services.apigateway.model.UpdateRestApiRequest;
49+
50+
public class AsyncClientIntegrationTest extends IntegrationTestBase {
51+
52+
private static final String NAME = "java-sdk-apig-integration-" + System.currentTimeMillis();
53+
private static final String DESCRIPTION = "fooDesc";
54+
55+
private static String restApiId = null;
56+
57+
@BeforeClass
58+
public static void createRestApi() {
59+
CreateRestApiResponse createRestApiResult = asyncClient.createRestApi(CreateRestApiRequest.builder().name(NAME)
60+
.description(DESCRIPTION)
61+
.build())
62+
.join();
63+
64+
Assert.assertNotNull(createRestApiResult);
65+
Assert.assertNotNull(createRestApiResult.description());
66+
Assert.assertNotNull(createRestApiResult.id());
67+
Assert.assertNotNull(createRestApiResult.name());
68+
Assert.assertNotNull(createRestApiResult.createdDate());
69+
Assert.assertEquals(createRestApiResult.name(), NAME);
70+
Assert.assertEquals(createRestApiResult.description(), DESCRIPTION);
71+
72+
restApiId = createRestApiResult.id();
73+
}
74+
75+
@AfterClass
76+
public static void deleteRestApiKey() {
77+
if (restApiId != null) {
78+
asyncClient.deleteRestApi(DeleteRestApiRequest.builder().restApiId(restApiId).build()).join();
79+
}
80+
}
81+
82+
@Test
83+
public void testUpdateRetrieveRestApi() {
84+
PatchOperation patch = PatchOperation.builder().op(Op.REPLACE)
85+
.path("/description").value("updatedDesc").build();
86+
asyncClient.updateRestApi(UpdateRestApiRequest.builder()
87+
.restApiId(restApiId)
88+
.patchOperations(patch)
89+
.build())
90+
.join();
91+
92+
GetRestApiResponse getRestApiResult = asyncClient.getRestApi(GetRestApiRequest.builder().restApiId(restApiId).build())
93+
.join();
94+
95+
Assert.assertNotNull(getRestApiResult);
96+
Assert.assertNotNull(getRestApiResult.description());
97+
Assert.assertNotNull(getRestApiResult.id());
98+
Assert.assertNotNull(getRestApiResult.name());
99+
Assert.assertNotNull(getRestApiResult.createdDate());
100+
Assert.assertEquals(getRestApiResult.name(), NAME);
101+
Assert.assertEquals(getRestApiResult.description(), "updatedDesc");
102+
}
103+
104+
@Test
105+
public void testCreateUpdateRetrieveApiKey() {
106+
CreateApiKeyResponse createApiKeyResult = asyncClient.createApiKey(CreateApiKeyRequest.builder().name(NAME)
107+
.description(DESCRIPTION).build())
108+
.join();
109+
110+
Assert.assertNotNull(createApiKeyResult);
111+
Assert.assertNotNull(createApiKeyResult.description());
112+
Assert.assertNotNull(createApiKeyResult.id());
113+
Assert.assertNotNull(createApiKeyResult.name());
114+
Assert.assertNotNull(createApiKeyResult.createdDate());
115+
Assert.assertNotNull(createApiKeyResult.enabled());
116+
Assert.assertNotNull(createApiKeyResult.lastUpdatedDate());
117+
Assert.assertNotNull(createApiKeyResult.stageKeys());
118+
119+
String apiKeyId = createApiKeyResult.id();
120+
Assert.assertEquals(createApiKeyResult.name(), NAME);
121+
Assert.assertEquals(createApiKeyResult.description(), DESCRIPTION);
122+
123+
PatchOperation patch = PatchOperation.builder().op(Op.REPLACE)
124+
.path("/description").value("updatedDesc").build();
125+
asyncClient.updateApiKey(UpdateApiKeyRequest.builder().apiKey(apiKeyId)
126+
.patchOperations(patch).build())
127+
.join();
128+
129+
GetApiKeyResponse getApiKeyResult = asyncClient.getApiKey(GetApiKeyRequest.builder().apiKey(apiKeyId).build()).join();
130+
131+
Assert.assertNotNull(getApiKeyResult);
132+
Assert.assertNotNull(getApiKeyResult.description());
133+
Assert.assertNotNull(getApiKeyResult.id());
134+
Assert.assertNotNull(getApiKeyResult.name());
135+
Assert.assertNotNull(getApiKeyResult.createdDate());
136+
Assert.assertNotNull(getApiKeyResult.enabled());
137+
Assert.assertNotNull(getApiKeyResult.lastUpdatedDate());
138+
Assert.assertNotNull(getApiKeyResult.stageKeys());
139+
Assert.assertEquals(getApiKeyResult.id(), apiKeyId);
140+
Assert.assertEquals(getApiKeyResult.name(), NAME);
141+
Assert.assertEquals(getApiKeyResult.description(), "updatedDesc");
142+
}
143+
144+
@Test
145+
public void testResourceOperations() {
146+
GetResourcesResponse resourcesResult = asyncClient.getResources(GetResourcesRequest.builder()
147+
.restApiId(restApiId)
148+
.build())
149+
.join();
150+
151+
List<Resource> resources = resourcesResult.items();
152+
Assert.assertEquals(resources.size(), 1);
153+
Resource rootResource = resources.get(0);
154+
Assert.assertNotNull(rootResource);
155+
Assert.assertEquals(rootResource.path(), "/");
156+
String rootResourceId = rootResource.id();
157+
158+
CreateResourceResponse createResourceResult = asyncClient
159+
.createResource(CreateResourceRequest.builder()
160+
.restApiId(restApiId)
161+
.pathPart("fooPath")
162+
.parentId(rootResourceId).build())
163+
.join();
164+
Assert.assertNotNull(createResourceResult);
165+
Assert.assertNotNull(createResourceResult.id());
166+
Assert.assertNotNull(createResourceResult.parentId());
167+
Assert.assertNotNull(createResourceResult.path());
168+
Assert.assertNotNull(createResourceResult.pathPart());
169+
Assert.assertEquals(createResourceResult.pathPart(), "fooPath");
170+
Assert.assertEquals(createResourceResult.parentId(), rootResourceId);
171+
172+
PatchOperation patch = PatchOperation.builder().op(Op.REPLACE)
173+
.path("/pathPart").value("updatedPath").build();
174+
asyncClient.updateResource(UpdateResourceRequest.builder()
175+
.restApiId(restApiId)
176+
.resourceId(createResourceResult.id())
177+
.patchOperations(patch).build())
178+
.join();
179+
180+
GetResourceResponse getResourceResult = asyncClient
181+
.getResource(GetResourceRequest.builder()
182+
.restApiId(restApiId)
183+
.resourceId(createResourceResult.id()).build())
184+
.join();
185+
Assert.assertNotNull(getResourceResult);
186+
Assert.assertNotNull(getResourceResult.id());
187+
Assert.assertNotNull(getResourceResult.parentId());
188+
Assert.assertNotNull(getResourceResult.path());
189+
Assert.assertNotNull(getResourceResult.pathPart());
190+
Assert.assertEquals(getResourceResult.pathPart(), "updatedPath");
191+
Assert.assertEquals(getResourceResult.parentId(), rootResourceId);
192+
193+
PutMethodResponse putMethodResult = asyncClient
194+
.putMethod(PutMethodRequest.builder().restApiId(restApiId)
195+
.resourceId(createResourceResult.id())
196+
.authorizationType("AWS_IAM").httpMethod("PUT").build()).join();
197+
Assert.assertNotNull(putMethodResult);
198+
Assert.assertNotNull(putMethodResult.authorizationType());
199+
Assert.assertNotNull(putMethodResult.apiKeyRequired());
200+
Assert.assertNotNull(putMethodResult.httpMethod());
201+
Assert.assertEquals(putMethodResult.authorizationType(), "AWS_IAM");
202+
Assert.assertEquals(putMethodResult.httpMethod(), "PUT");
203+
204+
PutIntegrationResponse putIntegrationResult = asyncClient
205+
.putIntegration(PutIntegrationRequest.builder()
206+
.restApiId(restApiId)
207+
.resourceId(createResourceResult.id())
208+
.httpMethod("PUT").type(IntegrationType.MOCK)
209+
.uri("http://foo.bar")
210+
.integrationHttpMethod("GET").build())
211+
.join();
212+
Assert.assertNotNull(putIntegrationResult);
213+
Assert.assertNotNull(putIntegrationResult.cacheNamespace());
214+
Assert.assertNotNull(putIntegrationResult.type());
215+
Assert.assertEquals(putIntegrationResult.type(),
216+
IntegrationType.MOCK);
217+
}
218+
}

services/apigateway/src/it/java/software/amazon/awssdk/services/apigateway/IntegrationTestBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
public class IntegrationTestBase extends AwsTestBase {
2424

2525
protected static ApiGatewayClient apiGateway;
26+
protected static ApiGatewayAsyncClient asyncClient;
2627

2728
@BeforeClass
2829
public static void setUp() throws IOException {
2930
apiGateway = ApiGatewayClient.builder().region(Region.US_EAST_1).credentialsProvider(CREDENTIALS_PROVIDER_CHAIN).build();
31+
asyncClient = ApiGatewayAsyncClient.builder().region(Region.US_EAST_1).credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
32+
.build();
3033
}
3134

3235
}

services/apigateway/src/it/java/software/amazon/awssdk/services/apigateway/ServiceIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package software.amazon.awssdk.services.apigateway;
1717

1818
import java.util.List;
19-
import junit.framework.Assert;
2019
import org.junit.AfterClass;
20+
import org.junit.Assert;
2121
import org.junit.BeforeClass;
2222
import org.junit.Test;
2323
import software.amazon.awssdk.services.apigateway.model.CreateApiKeyRequest;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package software.amazon.awssdk.services.applicationautoscaling;
2+
3+
import org.junit.Assert;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesRequest;
7+
import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesResponse;
8+
import software.amazon.awssdk.services.applicationautoscaling.model.ServiceNamespace;
9+
import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase;
10+
11+
public class AsyncClientIntegrationTest extends AwsIntegrationTestBase {
12+
private static ApplicationAutoScalingAsyncClient autoscaling;
13+
14+
@BeforeClass
15+
public static void setUp() {
16+
autoscaling = ApplicationAutoScalingAsyncClient.builder()
17+
.credentialsProvider(getCredentialsProvider())
18+
.build();
19+
}
20+
21+
@Test
22+
public void testScalingPolicy() {
23+
DescribeScalingPoliciesResponse res = autoscaling.describeScalingPolicies(
24+
DescribeScalingPoliciesRequest.builder().serviceNamespace(ServiceNamespace.ECS).build())
25+
.join();
26+
27+
Assert.assertNotNull(res);
28+
Assert.assertNotNull(res.scalingPolicies());
29+
}
30+
}

services/applicationautoscaling/src/it/java/software/amazon/awssdk/services/applicationautoscaling/ServiceIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.junit.Assert;
1919
import org.junit.BeforeClass;
2020
import org.junit.Test;
21-
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
2221
import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesRequest;
2322
import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesResponse;
2423
import software.amazon.awssdk.services.applicationautoscaling.model.ServiceNamespace;
@@ -31,8 +30,8 @@ public class ServiceIntegrationTest extends AwsIntegrationTestBase {
3130
@BeforeClass
3231
public static void setUp() {
3332
autoscaling = ApplicationAutoScalingClient.builder()
34-
.credentialsProvider(StaticCredentialsProvider.create(getCredentials()))
35-
.build();
33+
.credentialsProvider(getCredentialsProvider())
34+
.build();
3635
}
3736

3837
@Test

0 commit comments

Comments
 (0)