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));
}
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;
}
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")));
}
}
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);
}
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 []"));
}
Aggregations