/
IntegrationTest.java
101 lines (87 loc) · 3.69 KB
/
IntegrationTest.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
95
96
97
98
99
100
101
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package software.amazon.awssdk.services.rules;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
import software.amazon.awssdk.services.restjsonendpointproviders.endpoints.internal.EndpointRuleset;
import software.amazon.awssdk.services.rules.testutil.TestDiscovery;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class IntegrationTest {
private static final TestDiscovery TEST_DISCOVERY = new TestDiscovery();
@ParameterizedTest
@MethodSource("validTestcases")
void checkValidRules(ValidationTestCase validationTestCase) {
EndpointRuleset ruleset = EndpointRuleset.fromNode(validationTestCase.contents());
List<ValidationError> errors = new ValidateUriScheme().visitRuleset(ruleset)
.collect(Collectors.toList());
assertEquals(errors, Collections.emptyList());
}
@ParameterizedTest
@MethodSource("checkableTestCases")
void executeTestSuite(TestDiscovery.RulesTestcase testcase) {
testcase.testcase().execute(testcase.ruleset());
}
private Stream<ValidationTestCase> validTestcases() {
return TEST_DISCOVERY.getValidRules()
.stream()
.map(name -> new ValidationTestCase(name, TEST_DISCOVERY.validRulesetUrl(name), TEST_DISCOVERY.testCaseUrl(name)));
}
private Stream<TestDiscovery.RulesTestcase> checkableTestCases() {
return TEST_DISCOVERY.testSuites()
.flatMap(
suite -> suite.testSuites()
.stream()
.flatMap(ts -> ts.getTestCases()
.stream()
.map(tc -> new TestDiscovery.RulesTestcase(suite.ruleset(), tc))));
}
public static final class ValidationTestCase {
private final String name;
private final URL ruleSet;
private final URL testCase;
public ValidationTestCase(String name, URL ruleSet, URL testCase) {
this.name = name;
this.ruleSet = ruleSet;
this.testCase = testCase;
}
JsonNode contents() {
try {
return JsonNode.parser().parse(ruleSet.openStream());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public URL ruleSet() {
return ruleSet;
}
public URL testCase() {
return testCase;
}
@Override
public String toString() {
return name;
}
}
}