Search in sources :

Example 1 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class GrokProcessorFactoryTests method testBuildEmptyPatternsList.

public void testBuildEmptyPatternsList() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap(), MatcherWatchdog.noop());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "foo");
    config.put("patterns", Collections.emptyList());
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] List of patterns must not be empty"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap)

Example 2 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class GrokProcessorFactoryTests method testCreateWithInvalidPattern.

public void testCreateWithInvalidPattern() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap(), MatcherWatchdog.noop());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("patterns", Collections.singletonList("["));
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] Invalid regex pattern found in: [[]. premature end of char-class"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap)

Example 3 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class GrokProcessorFactoryTests method testBuildMissingPatterns.

public void testBuildMissingPatterns() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap(), MatcherWatchdog.noop());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "foo");
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] required property is missing"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap)

Example 4 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class GrokProcessorFactoryTests method testCreateWithInvalidPatternDefinition.

public void testCreateWithInvalidPatternDefinition() throws Exception {
    GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap(), MatcherWatchdog.noop());
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("patterns", Collections.singletonList("%{MY_PATTERN:name}!"));
    config.put("pattern_definitions", Collections.singletonMap("MY_PATTERN", "["));
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[patterns] Invalid regex pattern found in: [%{MY_PATTERN:name}!]. premature end of char-class"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap)

Example 5 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class DateProcessorFactoryTests method testMatchFieldIsMandatory.

public void testMatchFieldIsMandatory() throws Exception {
    Map<String, Object> config = new HashMap<>();
    String targetField = randomAlphaOfLengthBetween(1, 10);
    config.put("target_field", targetField);
    config.put("formats", Collections.singletonList("dd/MM/yyyyy"));
    try {
        factory.create(null, null, null, config);
        fail("processor creation should have failed");
    } catch (OpenSearchParseException e) {
        assertThat(e.getMessage(), containsString("[field] required property is missing"));
    }
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

OpenSearchParseException (org.opensearch.OpenSearchParseException)105 XContentParser (org.opensearch.common.xcontent.XContentParser)34 HashMap (java.util.HashMap)27 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)15 ArrayList (java.util.ArrayList)14 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Map (java.util.Map)11 IOException (java.io.IOException)10 List (java.util.List)7 ParsingException (org.opensearch.common.ParsingException)5 GeoPoint (org.opensearch.common.geo.GeoPoint)5 Token (org.opensearch.common.xcontent.XContentParser.Token)5 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)5 GeometryCollectionBuilder (org.opensearch.common.geo.builders.GeometryCollectionBuilder)4 UncheckedIOException (java.io.UncheckedIOException)3 DateTimeParseException (java.time.format.DateTimeParseException)3 HashSet (java.util.HashSet)3 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)3 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)3 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)3