/
EndpointTestSuite.java
94 lines (71 loc) · 2.44 KB
/
EndpointTestSuite.java
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
87
88
89
90
91
92
93
94
package software.amazon.awssdk.services.rules;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
import software.amazon.awssdk.services.restjsonendpointproviders.endpoints.internal.EndpointRuleset;
public class EndpointTestSuite {
public static final String SERVICE = "service";
public static final String TEST_CASES = "testCases";
private final List<EndpointTest> testCases;
private final String service;
public EndpointTestSuite(String service, List<EndpointTest> testCases) {
this.service = service;
this.testCases = testCases;
}
private EndpointTestSuite(Builder b) {
this(b.service, b.testCases);
}
public void execute(EndpointRuleset ruleset) {
for (EndpointTest test : this.getTestCases()) {
test.execute(ruleset);
}
}
public static EndpointTestSuite fromNode(JsonNode node) {
Map<String, JsonNode> objNode = node.asObject();
Builder b = builder();
b.service(objNode.get(SERVICE).asString());
objNode.get(TEST_CASES).asArray()
.stream().map(EndpointTest::fromNode)
.forEach(b::addTestCase);
return b.build();
}
public String getService() {
return service;
}
public List<EndpointTest> getTestCases() {
return testCases;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EndpointTestSuite that = (EndpointTestSuite) o;
if (!testCases.equals(that.testCases)) return false;
return service.equals(that.service);
}
@Override
public int hashCode() {
int result = testCases.hashCode();
result = 31 * result + service.hashCode();
return result;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String service;
private final List<EndpointTest> testCases = new ArrayList<>();
public Builder service(String service) {
this.service = service;
return this;
}
public Builder addTestCase(EndpointTest testCase) {
this.testCases.add(testCase);
return this;
}
public EndpointTestSuite build() {
return new EndpointTestSuite(this);
}
}
}