use of org.opensearch.test.rest.FakeRestRequest in project OpenSearch by opensearch-project.
the class MultiSearchRequestTests method testDefaultIndicesOptions.
public void testDefaultIndicesOptions() throws IOException {
final String requestContent = "{\"index\":\"test\", \"expand_wildcards\" : \"open,closed\"}}\r\n" + "{\"query\" : {\"match_all\" :{}}}\r\n";
FakeRestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(requestContent), XContentType.JSON).withParams(Collections.singletonMap("ignore_unavailable", "true")).build();
MultiSearchRequest request = RestMultiSearchAction.parseRequest(restRequest, null, true);
assertThat(request.requests().size(), equalTo(1));
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
assertThat(request.requests().get(0).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, true, true, true, SearchRequest.DEFAULT_INDICES_OPTIONS)));
}
use of org.opensearch.test.rest.FakeRestRequest in project OpenSearch by opensearch-project.
the class MultiSearchRequestTests method testFailWithUnknownKey.
public void testFailWithUnknownKey() {
final String requestContent = "{\"index\":\"test\", \"ignore_unavailable\" : true, \"unknown_key\" : \"open,closed\"}}\r\n" + "{\"query\" : {\"match_all\" :{}}}\r\n";
FakeRestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(requestContent), XContentType.JSON).build();
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> RestMultiSearchAction.parseRequest(restRequest, null, true));
assertEquals("key [unknown_key] is not supported in the metadata section", ex.getMessage());
}
use of org.opensearch.test.rest.FakeRestRequest in project OpenSearch by opensearch-project.
the class SettingsFilterTests method testFiltering.
private void testFiltering(Settings source, Settings filtered, String... patterns) throws IOException {
SettingsFilter settingsFilter = new SettingsFilter(Arrays.asList(patterns));
// Test using direct filtering
Settings filteredSettings = settingsFilter.filter(source);
assertThat(filteredSettings, equalTo(filtered));
// Test using toXContent filtering
RestRequest request = new FakeRestRequest();
settingsFilter.addFilterSettingParams(request);
XContentBuilder xContentBuilder = XContentBuilder.builder(JsonXContent.jsonXContent);
xContentBuilder.startObject();
source.toXContent(xContentBuilder, request);
xContentBuilder.endObject();
String filteredSettingsString = Strings.toString(xContentBuilder);
filteredSettings = Settings.builder().loadFromSource(filteredSettingsString, xContentBuilder.contentType()).build();
assertThat(filteredSettings, equalTo(filtered));
}
use of org.opensearch.test.rest.FakeRestRequest in project OpenSearch by opensearch-project.
the class BytesRestResponseTests method testErrorTrace.
public void testErrorTrace() throws Exception {
RestRequest request = new FakeRestRequest();
request.params().put("error_trace", "true");
RestChannel channel = new DetailedExceptionRestChannel(request);
Exception t = new UnknownException("an error occurred reading data", new FileNotFoundException("/foo/bar"));
BytesRestResponse response = new BytesRestResponse(channel, t);
String text = response.content().utf8ToString();
assertThat(text, containsString("\"type\":\"unknown_exception\",\"reason\":\"an error occurred reading data\""));
assertThat(text, containsString("{\"type\":\"file_not_found_exception\""));
assertThat(text, containsString("\"stack_trace\":\"[an error occurred reading data]"));
}
use of org.opensearch.test.rest.FakeRestRequest in project OpenSearch by opensearch-project.
the class RestNodesActionTests method testCatNodesWithLocalDeprecationWarning.
public void testCatNodesWithLocalDeprecationWarning() {
TestThreadPool threadPool = new TestThreadPool(RestNodesActionTests.class.getName());
NodeClient client = new NodeClient(Settings.EMPTY, threadPool);
FakeRestRequest request = new FakeRestRequest();
request.params().put("local", randomFrom("", "true", "false"));
action.doCatRequest(request, client);
assertWarnings(RestNodesAction.LOCAL_DEPRECATED_MESSAGE);
terminate(threadPool);
}
Aggregations