Search in sources :

Example 6 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class VerifyVersionConstantsIT method testLuceneVersionConstant.

public void testLuceneVersionConstant() throws IOException, ParseException {
    final Response response = client().performRequest(new Request("GET", "/"));
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    final ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final String opensearchVersionString = objectPath.evaluate("version.number").toString();
    final Version opensearchVersion = Version.fromString(opensearchVersionString.replace("-SNAPSHOT", ""));
    final String luceneVersionString = objectPath.evaluate("version.lucene_version").toString();
    final org.apache.lucene.util.Version luceneVersion = org.apache.lucene.util.Version.parse(luceneVersionString);
    assertThat(opensearchVersion.luceneVersion, equalTo(luceneVersion));
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Version(org.opensearch.Version) Request(org.opensearch.client.Request)

Example 7 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class IndexingIT method buildNodeAndVersions.

private Nodes buildNodeAndVersions() throws IOException {
    Response response = client().performRequest(new Request("GET", "_nodes"));
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
    Nodes nodes = new Nodes();
    for (String id : nodesAsMap.keySet()) {
        nodes.add(new Node(id, objectPath.evaluate("nodes." + id + ".name"), Version.fromString(objectPath.evaluate("nodes." + id + ".version")), HttpHost.create(objectPath.evaluate("nodes." + id + ".http.publish_address"))));
    }
    response = client().performRequest(new Request("GET", "_cluster/state"));
    nodes.setMasterNodeId(ObjectPath.createFromResponse(response).evaluate("master_node"));
    return nodes;
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request)

Example 8 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class ExceptionIT method logClusterNodes.

private void logClusterNodes() throws IOException {
    ObjectPath objectPath = ObjectPath.createFromResponse(client().performRequest(new Request("GET", "_nodes")));
    Map<String, ?> nodes = objectPath.evaluate("nodes");
    String master = EntityUtils.toString(client().performRequest(new Request("GET", "_cat/master?h=id")).getEntity()).trim();
    logger.info("cluster discovered: master id='{}'", master);
    for (String id : nodes.keySet()) {
        logger.info("{}: id='{}', name='{}', version={}", objectPath.evaluate("nodes." + id + ".http.publish_address"), id, objectPath.evaluate("nodes." + id + ".name"), Version.fromString(objectPath.evaluate("nodes." + id + ".version")));
    }
}
Also used : ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Request(org.opensearch.client.Request)

Example 9 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class XContentTestUtils method insertIntoXContent.

/**
 * Inserts key/value pairs into xContent passed in as {@link BytesReference} and returns a new {@link XContentBuilder}
 * The paths argument uses dot separated fieldnames and numbers for array indices, similar to what we do in
 * {@link ObjectPath}.
 * The key/value arguments can suppliers that either return fixed or random values.
 */
public static XContentBuilder insertIntoXContent(XContent xContent, BytesReference original, List<String> paths, Supplier<String> key, Supplier<Object> value) throws IOException {
    ObjectPath object = ObjectPath.createFromXContent(xContent, original);
    for (String path : paths) {
        Map<String, Object> insertMap = object.evaluate(path);
        insertMap.put(key.get(), value.get());
    }
    return object.toXContentBuilder(xContent);
}
Also used : ObjectPath(org.opensearch.test.rest.yaml.ObjectPath)

Example 10 with ObjectPath

use of org.opensearch.test.rest.yaml.ObjectPath in project OpenSearch by opensearch-project.

the class Netty4BadRequestIT method testInvalidHeaderValue.

public void testInvalidHeaderValue() throws IOException {
    final Request request = new Request("GET", "/_cluster/settings");
    final RequestOptions.Builder options = request.getOptions().toBuilder();
    options.addHeader("Content-Type", "\t");
    request.setOptions(options);
    final ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(request));
    final Response response = e.getResponse();
    assertThat(response.getStatusLine().getStatusCode(), equalTo(400));
    final ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final Map<String, Object> map = objectPath.evaluate("error");
    assertThat(map.get("type"), equalTo("content_type_header_exception"));
    assertThat(map.get("reason"), equalTo("java.lang.IllegalArgumentException: invalid Content-Type header []"));
}
Also used : Response(org.opensearch.client.Response) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) RequestOptions(org.opensearch.client.RequestOptions) ResponseException(org.opensearch.client.ResponseException) Request(org.opensearch.client.Request) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 Request (org.opensearch.client.Request)11 Response (org.opensearch.client.Response)10 ArrayList (java.util.ArrayList)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.hasToString (org.hamcrest.Matchers.hasToString)3 Version (org.opensearch.Version)3 ResponseException (org.opensearch.client.ResponseException)3 Settings (org.opensearch.common.settings.Settings)3 IndexSettings (org.opensearch.index.IndexSettings)3 List (java.util.List)2 LegacyESVersion (org.opensearch.LegacyESVersion)2 Map (java.util.Map)1 RequestOptions (org.opensearch.client.RequestOptions)1 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)1