use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.
the class AzureStorageSettingsFilterTests method testSettingsFiltering.
public void testSettingsFiltering() throws IOException {
AzureRepositoryPlugin p = new AzureRepositoryPlugin();
SettingsModule module = new SettingsModule(Settings.EMPTY, p.getSettings(), p.getSettingsFilter());
SettingsFilter settingsFilter = ModuleTestCase.bindAndGetInstance(module, SettingsFilter.class);
// Test using direct filtering
Settings filteredSettings = settingsFilter.filter(settings);
assertThat(filteredSettings.getAsMap().keySet(), contains("cloud.azure.storage.azure1.default"));
// Test using toXContent filtering
RestRequest request = new FakeRestRequest();
settingsFilter.addFilterSettingParams(request);
XContentBuilder xContentBuilder = XContentBuilder.builder(JsonXContent.jsonXContent);
xContentBuilder.startObject();
settings.toXContent(xContentBuilder, request);
xContentBuilder.endObject();
String filteredSettingsString = xContentBuilder.string();
filteredSettings = Settings.builder().loadFromSource(filteredSettingsString, xContentBuilder.contentType()).build();
assertThat(filteredSettings.getAsMap().keySet(), contains("cloud.azure.storage.azure1.default"));
}
use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.
the class RestTableTests method setup.
@Before
public void setup() {
restRequest = new FakeRestRequest();
table = new Table();
table.startHeaders();
table.addCell("bulk.foo", "alias:f;desc:foo");
table.addCell("bulk.bar", "alias:b;desc:bar");
// should be matched as well due to the aliases
table.addCell("aliasedBulk", "alias:bulkWhatever;desc:bar");
table.addCell("aliasedSecondBulk", "alias:foobar,bulkolicious,bulkotastic;desc:bar");
// no match
table.addCell("unmatched", "alias:un.matched;desc:bar");
// invalid alias
table.addCell("invalidAliasesBulk", "alias:,,,;desc:bar");
// timestamp
table.addCell("timestamp", "alias:ts");
table.addCell("epoch", "alias:t");
table.endHeaders();
}
use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.
the class RestTableTests method assertResponseContentType.
private RestResponse assertResponseContentType(Map<String, List<String>> headers, String mediaType) throws Exception {
FakeRestRequest requestWithAcceptHeader = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();
table.startRow();
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.addCell("foo");
table.endRow();
RestResponse response = buildResponse(table, new AbstractRestChannel(requestWithAcceptHeader, true) {
@Override
public void sendResponse(RestResponse response) {
}
});
assertThat(response.contentType(), equalTo(mediaType));
return response;
}
use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.
the class BytesRestResponseTests method testNonElasticsearchExceptionIsNotShownAsSimpleMessage.
public void testNonElasticsearchExceptionIsNotShownAsSimpleMessage() throws Exception {
RestRequest request = new FakeRestRequest();
RestChannel channel = new SimpleExceptionRestChannel(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, not(containsString("UnknownException[an error occurred reading data]")));
assertThat(text, not(containsString("FileNotFoundException[/foo/bar]")));
assertThat(text, not(containsString("error_trace")));
assertThat(text, containsString("\"error\":\"No ElasticsearchException found\""));
}
use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.
the class BytesRestResponseTests method testGuessRootCause.
public void testGuessRootCause() throws IOException {
RestRequest request = new FakeRestRequest();
RestChannel channel = new DetailedExceptionRestChannel(request);
{
Exception e = new ElasticsearchException("an error occurred reading data", new FileNotFoundException("/foo/bar"));
BytesRestResponse response = new BytesRestResponse(channel, e);
String text = response.content().utf8ToString();
assertThat(text, containsString("{\"root_cause\":[{\"type\":\"exception\",\"reason\":\"an error occurred reading data\"}]"));
}
{
Exception e = new FileNotFoundException("/foo/bar");
BytesRestResponse response = new BytesRestResponse(channel, e);
String text = response.content().utf8ToString();
assertThat(text, containsString("{\"root_cause\":[{\"type\":\"file_not_found_exception\",\"reason\":\"/foo/bar\"}]"));
}
}
Aggregations