|
@@ -17,7 +17,7 @@
|
|
|
* under the License.
|
|
|
*/
|
|
|
|
|
|
-package org.elasticsearch.test.rest;
|
|
|
+package org.elasticsearch.test.rest.yaml;
|
|
|
|
|
|
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
|
|
|
|
@@ -25,16 +25,17 @@ import org.apache.lucene.util.IOUtils;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.SuppressForbidden;
|
|
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
-import org.elasticsearch.test.rest.parser.RestTestParseException;
|
|
|
-import org.elasticsearch.test.rest.parser.RestTestSuiteParser;
|
|
|
-import org.elasticsearch.test.rest.section.DoSection;
|
|
|
-import org.elasticsearch.test.rest.section.ExecutableSection;
|
|
|
-import org.elasticsearch.test.rest.section.RestTestSuite;
|
|
|
-import org.elasticsearch.test.rest.section.SkipSection;
|
|
|
-import org.elasticsearch.test.rest.section.TestSection;
|
|
|
-import org.elasticsearch.test.rest.spec.RestApi;
|
|
|
-import org.elasticsearch.test.rest.spec.RestSpec;
|
|
|
-import org.elasticsearch.test.rest.support.FileUtils;
|
|
|
+import org.elasticsearch.test.rest.ESRestTestCase;
|
|
|
+import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException;
|
|
|
+import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParser;
|
|
|
+import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi;
|
|
|
+import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
|
|
|
+import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite;
|
|
|
+import org.elasticsearch.test.rest.yaml.section.DoSection;
|
|
|
+import org.elasticsearch.test.rest.yaml.section.ExecutableSection;
|
|
|
+import org.elasticsearch.test.rest.yaml.section.SkipSection;
|
|
|
+import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection;
|
|
|
+import org.elasticsearch.test.rest.yaml.support.FileUtils;
|
|
|
import org.junit.AfterClass;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.BeforeClass;
|
|
@@ -97,12 +98,12 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
private static final String PATHS_SEPARATOR = "(?<!\\\\),";
|
|
|
|
|
|
private final List<BlacklistedPathPatternMatcher> blacklistPathMatchers = new ArrayList<>();
|
|
|
- private static RestTestExecutionContext restTestExecutionContext;
|
|
|
- private static RestTestExecutionContext adminExecutionContext;
|
|
|
+ private static ClientYamlTestExecutionContext restTestExecutionContext;
|
|
|
+ private static ClientYamlTestExecutionContext adminExecutionContext;
|
|
|
|
|
|
- private final RestTestCandidate testCandidate;
|
|
|
+ private final ClientYamlTestCandidate testCandidate;
|
|
|
|
|
|
- public ESClientYamlSuiteTestCase(RestTestCandidate testCandidate) {
|
|
|
+ public ESClientYamlSuiteTestCase(ClientYamlTestCandidate testCandidate) {
|
|
|
this.testCandidate = testCandidate;
|
|
|
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
|
|
|
for (String entry : blacklist) {
|
|
@@ -117,34 +118,34 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
super.afterIfFailed(errors);
|
|
|
}
|
|
|
|
|
|
- public static Iterable<Object[]> createParameters(int id, int count) throws IOException, RestTestParseException {
|
|
|
+ public static Iterable<Object[]> createParameters(int id, int count) throws IOException, ClientYamlTestParseException {
|
|
|
//parse tests only if rest test group is enabled, otherwise rest tests might not even be available on file system
|
|
|
- List<RestTestCandidate> restTestCandidates = collectTestCandidates(id, count);
|
|
|
+ List<ClientYamlTestCandidate> restTestCandidates = collectTestCandidates(id, count);
|
|
|
List<Object[]> objects = new ArrayList<>();
|
|
|
- for (RestTestCandidate restTestCandidate : restTestCandidates) {
|
|
|
+ for (ClientYamlTestCandidate restTestCandidate : restTestCandidates) {
|
|
|
objects.add(new Object[]{restTestCandidate});
|
|
|
}
|
|
|
return objects;
|
|
|
}
|
|
|
|
|
|
- private static List<RestTestCandidate> collectTestCandidates(int id, int count) throws RestTestParseException, IOException {
|
|
|
- List<RestTestCandidate> testCandidates = new ArrayList<>();
|
|
|
+ private static List<ClientYamlTestCandidate> collectTestCandidates(int id, int count) throws ClientYamlTestParseException, IOException {
|
|
|
+ List<ClientYamlTestCandidate> testCandidates = new ArrayList<>();
|
|
|
FileSystem fileSystem = getFileSystem();
|
|
|
// don't make a try-with, getFileSystem returns null
|
|
|
// ... and you can't close() the default filesystem
|
|
|
try {
|
|
|
String[] paths = resolvePathsProperty(REST_TESTS_SUITE, DEFAULT_TESTS_PATH);
|
|
|
Map<String, Set<Path>> yamlSuites = FileUtils.findYamlSuites(fileSystem, DEFAULT_TESTS_PATH, paths);
|
|
|
- RestTestSuiteParser restTestSuiteParser = new RestTestSuiteParser();
|
|
|
+ ClientYamlTestSuiteParser restTestSuiteParser = new ClientYamlTestSuiteParser();
|
|
|
//yaml suites are grouped by directory (effectively by api)
|
|
|
for (String api : yamlSuites.keySet()) {
|
|
|
List<Path> yamlFiles = new ArrayList<>(yamlSuites.get(api));
|
|
|
for (Path yamlFile : yamlFiles) {
|
|
|
String key = api + yamlFile.getFileName().toString();
|
|
|
if (mustExecute(key, id, count)) {
|
|
|
- RestTestSuite restTestSuite = restTestSuiteParser.parse(api, yamlFile);
|
|
|
- for (TestSection testSection : restTestSuite.getTestSections()) {
|
|
|
- testCandidates.add(new RestTestCandidate(restTestSuite, testSection));
|
|
|
+ ClientYamlTestSuite restTestSuite = restTestSuiteParser.parse(api, yamlFile);
|
|
|
+ for (ClientYamlTestSection testSection : restTestSuite.getTestSections()) {
|
|
|
+ testCandidates.add(new ClientYamlTestCandidate(restTestSuite, testSection));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -154,9 +155,9 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
//sort the candidates so they will always be in the same order before being shuffled, for repeatability
|
|
|
- Collections.sort(testCandidates, new Comparator<RestTestCandidate>() {
|
|
|
+ Collections.sort(testCandidates, new Comparator<ClientYamlTestCandidate>() {
|
|
|
@Override
|
|
|
- public int compare(RestTestCandidate o1, RestTestCandidate o2) {
|
|
|
+ public int compare(ClientYamlTestCandidate o1, ClientYamlTestCandidate o2) {
|
|
|
return o1.getTestPath().compareTo(o2.getTestPath());
|
|
|
}
|
|
|
});
|
|
@@ -209,29 +210,29 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
@BeforeClass
|
|
|
public static void initExecutionContext() throws IOException {
|
|
|
String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH);
|
|
|
- RestSpec restSpec = null;
|
|
|
+ ClientYamlSuiteRestSpec restSpec = null;
|
|
|
FileSystem fileSystem = getFileSystem();
|
|
|
// don't make a try-with, getFileSystem returns null
|
|
|
// ... and you can't close() the default filesystem
|
|
|
try {
|
|
|
- restSpec = RestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths);
|
|
|
+ restSpec = ClientYamlSuiteRestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths);
|
|
|
} finally {
|
|
|
IOUtils.close(fileSystem);
|
|
|
}
|
|
|
validateSpec(restSpec);
|
|
|
- restTestExecutionContext = new RestTestExecutionContext(restSpec);
|
|
|
- adminExecutionContext = new RestTestExecutionContext(restSpec);
|
|
|
+ restTestExecutionContext = new ClientYamlTestExecutionContext(restSpec);
|
|
|
+ adminExecutionContext = new ClientYamlTestExecutionContext(restSpec);
|
|
|
}
|
|
|
|
|
|
- protected RestTestExecutionContext getAdminExecutionContext() {
|
|
|
+ protected ClientYamlTestExecutionContext getAdminExecutionContext() {
|
|
|
return adminExecutionContext;
|
|
|
}
|
|
|
|
|
|
- private static void validateSpec(RestSpec restSpec) {
|
|
|
+ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) {
|
|
|
boolean validateSpec = RandomizedTest.systemPropertyAsBoolean(REST_TESTS_VALIDATE_SPEC, true);
|
|
|
if (validateSpec) {
|
|
|
StringBuilder errorMessage = new StringBuilder();
|
|
|
- for (RestApi restApi : restSpec.getApis()) {
|
|
|
+ for (ClientYamlSuiteRestApi restApi : restSpec.getApis()) {
|
|
|
if (restApi.getMethods().contains("GET") && restApi.isBodySupported()) {
|
|
|
if (!restApi.getMethods().contains("POST")) {
|
|
|
errorMessage.append("\n- ").append(restApi.getName()).append(" supports GET with a body but doesn't support POST");
|