Skip to content

Commit 4aef06e

Browse files
api-clients-generation-pipeline[bot]nmueschci.datadog-api-spec
authored
Add scenario for each error response code that isn't 401 or 403 (#606)
* Create mock response with proper status code on exceptions * Add cassettes * Make sure we're using the right constructor * Cleaner detection of exception type * Regenerate client from commit 426d7a0 of spec repo Co-authored-by: Nicholas Muesch <nicholas.muesch@datadoghq.com> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 05f84a3 commit 4aef06e

40 files changed

+2224
-12
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.4.1.dev2",
7-
"regenerated": "2021-01-13 11:21:00.106464",
8-
"spec_repo_commit": "166fecc"
7+
"regenerated": "2021-01-13 15:26:31.275709",
8+
"spec_repo_commit": "426d7a0"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev2",
12-
"regenerated": "2021-01-13 11:21:08.667923",
13-
"spec_repo_commit": "166fecc"
12+
"regenerated": "2021-01-13 15:26:41.380079",
13+
"spec_repo_commit": "426d7a0"
1414
}
1515
}
1616
}

src/test/java/com/datadog/api/ClientSteps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void setBody(String data) throws java.lang.IllegalAccessException, java.l
123123
}
124124

125125
@Then("the response status is {int} {}")
126-
public void theResponseStatusIsOK(Integer statusCode, String _)
126+
public void theResponseStatusIs(Integer statusCode, String _)
127127
throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException,
128128
java.lang.InstantiationException, java.lang.NoSuchMethodException, java.lang.ClassNotFoundException {
129129
Integer responseStatusCode = (Integer) 0;

src/test/java/com/datadog/api/World.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.datadog.api;
22

3+
import java.lang.reflect.Constructor;
34
import java.lang.reflect.Field;
45
import java.lang.reflect.Method;
56
import java.time.Clock;
@@ -288,9 +289,22 @@ public void sendRequest()
288289
responseClass = responseMethod.getReturnType();
289290

290291
String apiVersion = getVersion();
292+
Class<?> exceptionClass = Class.forName("com.datadog.api." + apiVersion + ".client.ApiException");
293+
291294
Undo undoSettings = UndoAction.UndoAction().getUndo(apiVersion, requestBuilder.getName());
292295

293-
response = responseMethod.invoke(request);
296+
try {
297+
response = responseMethod.invoke(request);
298+
} catch (Exception e) {
299+
// Return a new response object with the response code set
300+
// so we can make assertions on it
301+
int responseCode = (int) exceptionClass.getMethod("getCode").invoke(e.getCause());
302+
for (Constructor<?> c : responseClass.getConstructors()) {
303+
if (c.getParameterCount() == 2) {
304+
response = c.newInstance(responseCode, new HashMap<String, String>());
305+
}
306+
}
307+
}
294308

295309
if (undoSettings != null) {
296310
Method dataMethod = responseClass.getMethod("getData");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2021-01-06T23:47:16.314Z
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[{
2+
"id" : "bef20c81-49fd-4566-a38e-69da4185a9e6",
3+
"httpRequest" : {
4+
"method" : "GET",
5+
"path" : "/api/v1/monitor/12345",
6+
"headers" : {
7+
"Accept" : [ "application/json" ],
8+
"JAVA-TEST-NAME" : [ "Get_a_monitor_s_details_returns_Monitor_Not_Found_error_response" ],
9+
"DD-OPERATION-ID" : [ "getMonitor" ],
10+
"content-length" : [ "0" ]
11+
},
12+
"keepAlive" : false,
13+
"secure" : true
14+
},
15+
"times" : {
16+
"remainingTimes" : 1
17+
},
18+
"timeToLive" : {
19+
"unlimited" : true
20+
},
21+
"httpResponse" : {
22+
"statusCode" : 404,
23+
"reasonPhrase" : "Not Found",
24+
"headers" : {
25+
"Date" : [ "Wed, 06 Jan 2021 23:47:20 GMT" ],
26+
"Content-Type" : [ "application/json" ],
27+
"Connection" : [ "keep-alive" ],
28+
"vary" : [ "Accept-Encoding" ],
29+
"pragma" : [ "no-cache" ],
30+
"cache-control" : [ "no-cache" ],
31+
"x-ratelimit-limit" : [ "3000" ],
32+
"x-ratelimit-period" : [ "10" ],
33+
"x-ratelimit-reset" : [ "10" ],
34+
"x-ratelimit-remaining" : [ "2999" ],
35+
"x-dd-version" : [ "35.3654104" ],
36+
"x-content-type-options" : [ "nosniff" ],
37+
"strict-transport-security" : [ "max-age=15724800;" ],
38+
"content-security-policy" : [ "frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report" ],
39+
"x-frame-options" : [ "SAMEORIGIN" ],
40+
"content-length" : [ "32" ]
41+
},
42+
"body" : "{\"errors\":[\"Monitor not found\"]}"
43+
}
44+
}]

src/test/resources/com/datadog/api/v1/client/api/aws_integration.feature

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,78 @@ Feature: AWS Integration
6868
And body {}
6969
When the request is sent
7070
Then the response status is 200 OK
71+
72+
@generated @skip
73+
Scenario: Delete an AWS integration returns "Bad Request" response
74+
Given new "DeleteAWSAccount" request
75+
And body {}
76+
When the request is sent
77+
Then the response status is 400 Bad Request
78+
79+
@generated @skip
80+
Scenario: Delete an AWS integration returns "Conflict Error" response
81+
Given new "DeleteAWSAccount" request
82+
And body {}
83+
When the request is sent
84+
Then the response status is 409 Conflict Error
85+
86+
@generated @skip
87+
Scenario: List all AWS integrations returns "Bad Request" response
88+
Given new "ListAWSAccounts" request
89+
When the request is sent
90+
Then the response status is 400 Bad Request
91+
92+
@generated @skip
93+
Scenario: Create an AWS integration returns "Bad Request" response
94+
Given new "CreateAWSAccount" request
95+
And body {}
96+
When the request is sent
97+
Then the response status is 400 Bad Request
98+
99+
@generated @skip
100+
Scenario: Create an AWS integration returns "Conflict Error" response
101+
Given new "CreateAWSAccount" request
102+
And body {}
103+
When the request is sent
104+
Then the response status is 409 Conflict Error
105+
106+
@generated @skip
107+
Scenario: Update an AWS integration returns "Bad Request" response
108+
Given new "UpdateAWSAccount" request
109+
And body {}
110+
When the request is sent
111+
Then the response status is 400 Bad Request
112+
113+
@generated @skip
114+
Scenario: Update an AWS integration returns "Conflict Error" response
115+
Given new "UpdateAWSAccount" request
116+
And body {}
117+
When the request is sent
118+
Then the response status is 409 Conflict Error
119+
120+
@generated @skip
121+
Scenario: Delete a tag filtering entry returns "Bad Request" response
122+
Given new "DeleteAWSTagFilter" request
123+
And body {}
124+
When the request is sent
125+
Then the response status is 400 Bad Request
126+
127+
@generated @skip
128+
Scenario: Get all AWS tag filters returns "Bad Request" response
129+
Given new "ListAWSTagFilters" request
130+
When the request is sent
131+
Then the response status is 400 Bad Request
132+
133+
@generated @skip
134+
Scenario: Set an AWS tag filter returns "Bad Request" response
135+
Given new "CreateAWSTagFilter" request
136+
And body {}
137+
When the request is sent
138+
Then the response status is 400 Bad Request
139+
140+
@generated @skip
141+
Scenario: Generate a new external ID returns "Bad Request" response
142+
Given new "CreateNewAWSExternalID" request
143+
And body {}
144+
When the request is sent
145+
Then the response status is 400 Bad Request

src/test/resources/com/datadog/api/v1/client/api/aws_logs_integration.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,44 @@ Feature: AWS Logs Integration
5555
And body {}
5656
When the request is sent
5757
Then the response status is 200 OK
58+
59+
@generated @skip
60+
Scenario: Delete an AWS Logs integration returns "Bad Request" response
61+
Given new "DeleteAWSLambdaARN" request
62+
And body {}
63+
When the request is sent
64+
Then the response status is 400 Bad Request
65+
66+
@generated @skip
67+
Scenario: List all AWS Logs integrations returns "Bad Request" response
68+
Given new "ListAWSLogsIntegrations" request
69+
When the request is sent
70+
Then the response status is 400 Bad Request
71+
72+
@generated @skip
73+
Scenario: Add AWS Log Lambda ARN returns "Bad Request" response
74+
Given new "CreateAWSLambdaARN" request
75+
And body {}
76+
When the request is sent
77+
Then the response status is 400 Bad Request
78+
79+
@generated @skip
80+
Scenario: Check that an AWS Lambda Function exists returns "Bad Request" response
81+
Given new "CheckAWSLogsLambdaAsync" request
82+
And body {}
83+
When the request is sent
84+
Then the response status is 400 Bad Request
85+
86+
@generated @skip
87+
Scenario: Enable an AWS Logs integration returns "Bad Request" response
88+
Given new "EnableAWSLogServices" request
89+
And body {}
90+
When the request is sent
91+
Then the response status is 400 Bad Request
92+
93+
@generated @skip
94+
Scenario: Check permissions for log services returns "Bad Request" response
95+
Given new "CheckAWSLogsServicesAsync" request
96+
And body {}
97+
When the request is sent
98+
Then the response status is 400 Bad Request

src/test/resources/com/datadog/api/v1/client/api/azure_integration.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,37 @@ Feature: Azure Integration
4242
And body {}
4343
When the request is sent
4444
Then the response status is 200 OK
45+
46+
@generated @skip
47+
Scenario: Delete an Azure integration returns "Bad Request" response
48+
Given new "DeleteAzureIntegration" request
49+
And body {}
50+
When the request is sent
51+
Then the response status is 400 Bad Request
52+
53+
@generated @skip
54+
Scenario: List all Azure integrations returns "Bad Request" response
55+
Given new "ListAzureIntegration" request
56+
When the request is sent
57+
Then the response status is 400 Bad Request
58+
59+
@generated @skip
60+
Scenario: Create an Azure integration returns "Bad Request" response
61+
Given new "CreateAzureIntegration" request
62+
And body {}
63+
When the request is sent
64+
Then the response status is 400 Bad Request
65+
66+
@generated @skip
67+
Scenario: Update an Azure integration returns "Bad Request" response
68+
Given new "UpdateAzureIntegration" request
69+
And body {}
70+
When the request is sent
71+
Then the response status is 400 Bad Request
72+
73+
@generated @skip
74+
Scenario: Update Azure integration host filters returns "Bad Request" response
75+
Given new "UpdateAzureHostFilters" request
76+
And body {}
77+
When the request is sent
78+
Then the response status is 400 Bad Request

src/test/resources/com/datadog/api/v1/client/api/dashboard_lists.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,40 @@ Feature: Dashboard Lists
4242
And body {}
4343
When the request is sent
4444
Then the response status is 200 OK
45+
46+
@generated @skip
47+
Scenario: Create a dashboard list returns "Bad Request" response
48+
Given new "CreateDashboardList" request
49+
And body {}
50+
When the request is sent
51+
Then the response status is 400 Bad Request
52+
53+
@generated @skip
54+
Scenario: Delete a dashboard list returns "Not Found" response
55+
Given new "DeleteDashboardList" request
56+
And request contains "list_id" parameter from "<PATH>"
57+
When the request is sent
58+
Then the response status is 404 Not Found
59+
60+
@generated @skip
61+
Scenario: Get a dashboard list returns "Not Found" response
62+
Given new "GetDashboardList" request
63+
And request contains "list_id" parameter from "<PATH>"
64+
When the request is sent
65+
Then the response status is 404 Not Found
66+
67+
@generated @skip
68+
Scenario: Update a dashboard list returns "Bad Request" response
69+
Given new "UpdateDashboardList" request
70+
And request contains "list_id" parameter from "<PATH>"
71+
And body {}
72+
When the request is sent
73+
Then the response status is 400 Bad Request
74+
75+
@generated @skip
76+
Scenario: Update a dashboard list returns "Not Found" response
77+
Given new "UpdateDashboardList" request
78+
And request contains "list_id" parameter from "<PATH>"
79+
And body {}
80+
When the request is sent
81+
Then the response status is 404 Not Found

src/test/resources/com/datadog/api/v1/client/api/dashboards.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,40 @@ Feature: Dashboards
4343
And body {}
4444
When the request is sent
4545
Then the response status is 200 OK
46+
47+
@generated @skip
48+
Scenario: Create a new dashboard returns "Bad Request" response
49+
Given new "CreateDashboard" request
50+
And body {}
51+
When the request is sent
52+
Then the response status is 400 Bad Request
53+
54+
@generated @skip
55+
Scenario: Delete a dashboard returns "Dashboards Not Found" response
56+
Given new "DeleteDashboard" request
57+
And request contains "dashboard_id" parameter from "<PATH>"
58+
When the request is sent
59+
Then the response status is 404 Dashboards Not Found
60+
61+
@generated @skip
62+
Scenario: Get a dashboard returns "Item Not Found" response
63+
Given new "GetDashboard" request
64+
And request contains "dashboard_id" parameter from "<PATH>"
65+
When the request is sent
66+
Then the response status is 404 Item Not Found
67+
68+
@generated @skip
69+
Scenario: Update a dashboard returns "Bad Request" response
70+
Given new "UpdateDashboard" request
71+
And request contains "dashboard_id" parameter from "<PATH>"
72+
And body {}
73+
When the request is sent
74+
Then the response status is 400 Bad Request
75+
76+
@generated @skip
77+
Scenario: Update a dashboard returns "Item Not Found" response
78+
Given new "UpdateDashboard" request
79+
And request contains "dashboard_id" parameter from "<PATH>"
80+
And body {}
81+
When the request is sent
82+
Then the response status is 404 Item Not Found

0 commit comments

Comments
 (0)