Search in sources :

Example 1 with ClientYamlSuiteRestSpec

use of org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec in project elasticsearch by elastic.

the class ESClientYamlSuiteTestCase method initAndResetContext.

@Before
public void initAndResetContext() throws IOException {
    if (restTestExecutionContext == null) {
        assert adminExecutionContext == null;
        assert blacklistPathMatchers == null;
        String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH);
        ClientYamlSuiteRestSpec restSpec = null;
        FileSystem fileSystem = getFileSystem();
        // ... and you can't close() the default filesystem
        try {
            restSpec = ClientYamlSuiteRestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths);
        } finally {
            IOUtils.close(fileSystem);
        }
        validateSpec(restSpec);
        List<HttpHost> hosts = getClusterHosts();
        RestClient restClient = client();
        Version infoVersion = readVersionsFromInfo(restClient, hosts.size());
        Version esVersion;
        try {
            Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(restClient);
            esVersion = versionVersionTuple.v1();
            Version masterVersion = versionVersionTuple.v2();
            logger.info("initializing yaml client, minimum es version: [{}] master version: [{}] hosts: {}", esVersion, masterVersion, hosts);
        } catch (ResponseException ex) {
            if (ex.getResponse().getStatusLine().getStatusCode() == 403) {
                logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized");
                esVersion = infoVersion;
                logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts);
            } else {
                throw ex;
            }
        }
        ClientYamlTestClient clientYamlTestClient = new ClientYamlTestClient(restSpec, restClient, hosts, esVersion);
        restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
        adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
        String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
        blacklistPathMatchers = new ArrayList<>();
        for (String entry : blacklist) {
            blacklistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
        }
    }
    assert restTestExecutionContext != null;
    assert adminExecutionContext != null;
    assert blacklistPathMatchers != null;
    // admin context must be available for @After always, regardless of whether the test was blacklisted
    adminExecutionContext.clear();
    //skip test if it matches one of the blacklist globs
    for (BlacklistedPathPatternMatcher blacklistedPathMatcher : blacklistPathMatchers) {
        String testPath = testCandidate.getSuitePath() + "/" + testCandidate.getTestSection().getName();
        assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.isSuffixMatch(testPath));
    }
    restTestExecutionContext.clear();
    //skip test if the whole suite (yaml file) is disabled
    assumeFalse(testCandidate.getSetupSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getSetupSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
    //skip test if the whole suite (yaml file) is disabled
    assumeFalse(testCandidate.getTeardownSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getTeardownSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
    //skip test if test section is disabled
    assumeFalse(testCandidate.getTestSection().getSkipSection().getSkipMessage(testCandidate.getTestPath()), testCandidate.getTestSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
}
Also used : ResponseException(org.elasticsearch.client.ResponseException) RestClient(org.elasticsearch.client.RestClient) ClientYamlSuiteRestSpec(org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec) Version(org.elasticsearch.Version) HttpHost(org.apache.http.HttpHost) FileSystem(java.nio.file.FileSystem) Before(org.junit.Before)

Aggregations

FileSystem (java.nio.file.FileSystem)1 HttpHost (org.apache.http.HttpHost)1 Version (org.elasticsearch.Version)1 ResponseException (org.elasticsearch.client.ResponseException)1 RestClient (org.elasticsearch.client.RestClient)1 ClientYamlSuiteRestSpec (org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec)1 Before (org.junit.Before)1