-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateSyntheticsAPITest_2106135939.java
More file actions
86 lines (81 loc) · 4.59 KB
/
CreateSyntheticsAPITest_2106135939.java
File metadata and controls
86 lines (81 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Create a multistep test with subtest returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.SyntheticsApi;
import com.datadog.api.client.v1.model.SyntheticsAPIStep;
import com.datadog.api.client.v1.model.SyntheticsAPISubtestStep;
import com.datadog.api.client.v1.model.SyntheticsAPISubtestStepSubtype;
import com.datadog.api.client.v1.model.SyntheticsAPITest;
import com.datadog.api.client.v1.model.SyntheticsAPITestConfig;
import com.datadog.api.client.v1.model.SyntheticsAPITestStep;
import com.datadog.api.client.v1.model.SyntheticsAPITestStepSubtype;
import com.datadog.api.client.v1.model.SyntheticsAPITestType;
import com.datadog.api.client.v1.model.SyntheticsAssertion;
import com.datadog.api.client.v1.model.SyntheticsAssertionOperator;
import com.datadog.api.client.v1.model.SyntheticsAssertionTarget;
import com.datadog.api.client.v1.model.SyntheticsAssertionTargetValue;
import com.datadog.api.client.v1.model.SyntheticsAssertionType;
import com.datadog.api.client.v1.model.SyntheticsBasicAuth;
import com.datadog.api.client.v1.model.SyntheticsBasicAuthWeb;
import com.datadog.api.client.v1.model.SyntheticsTestDetailsSubType;
import com.datadog.api.client.v1.model.SyntheticsTestOptions;
import com.datadog.api.client.v1.model.SyntheticsTestRequest;
import java.util.Arrays;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
SyntheticsApi apiInstance = new SyntheticsApi(defaultClient);
// there is a valid "synthetics_api_test" in the system
String SYNTHETICS_API_TEST_PUBLIC_ID = System.getenv("SYNTHETICS_API_TEST_PUBLIC_ID");
SyntheticsAPITest body =
new SyntheticsAPITest()
.config(
new SyntheticsAPITestConfig()
.steps(
Arrays.asList(
new SyntheticsAPIStep(
new SyntheticsAPITestStep()
.assertions(
Collections.singletonList(
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.type(SyntheticsAssertionType.STATUS_CODE)
.target(
new SyntheticsAssertionTargetValue(
200.0)))))
.name("request is sent")
.request(
new SyntheticsTestRequest()
.url("https://httpbin.org/status/200")
.method("GET")
.basicAuth(
new SyntheticsBasicAuth(
new SyntheticsBasicAuthWeb()
.password("password")
.username("username"))))
.subtype(SyntheticsAPITestStepSubtype.HTTP)),
new SyntheticsAPIStep(
new SyntheticsAPISubtestStep()
.subtype(SyntheticsAPISubtestStepSubtype.PLAY_SUB_TEST)
.subtestPublicId(SYNTHETICS_API_TEST_PUBLIC_ID)
.name("subtest step")))))
.locations(Collections.singletonList("aws:us-east-2"))
.message("BDD test payload: synthetics_api_test_multi_step_with_subtest.json")
.name("Example-Synthetic")
.options(new SyntheticsTestOptions().tickEvery(60L))
.subtype(SyntheticsTestDetailsSubType.MULTI)
.type(SyntheticsAPITestType.API);
try {
SyntheticsAPITest result = apiInstance.createSyntheticsAPITest(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SyntheticsApi#createSyntheticsAPITest");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}