Search in sources :

Example 1 with FakeRestRequest

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"));
}
Also used : RestRequest(org.elasticsearch.rest.RestRequest) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) AzureRepositoryPlugin(org.elasticsearch.plugin.repository.azure.AzureRepositoryPlugin) SettingsModule(org.elasticsearch.common.settings.SettingsModule) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter)

Example 2 with FakeRestRequest

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();
}
Also used : Table(org.elasticsearch.common.Table) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) Before(org.junit.Before)

Example 3 with FakeRestRequest

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;
}
Also used : RestResponse(org.elasticsearch.rest.RestResponse) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) AbstractRestChannel(org.elasticsearch.rest.AbstractRestChannel)

Example 4 with FakeRestRequest

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\""));
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FileNotFoundException(java.io.FileNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Example 5 with FakeRestRequest

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\"}]"));
    }
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FileNotFoundException(java.io.FileNotFoundException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Aggregations

FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)30 IOException (java.io.IOException)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 ThreadContext (org.elasticsearch.common.util.concurrent.ThreadContext)10 NodeClient (org.elasticsearch.client.node.NodeClient)7 BytesArray (org.elasticsearch.common.bytes.BytesArray)7 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)6 ParsingException (org.elasticsearch.common.ParsingException)6 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 RemoteTransportException (org.elasticsearch.transport.RemoteTransportException)6 FileNotFoundException (java.io.FileNotFoundException)5 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)5 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)5 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)5 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)4 RestRequest (org.elasticsearch.rest.RestRequest)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Settings (org.elasticsearch.common.settings.Settings)3 Table (org.elasticsearch.common.Table)2