public void testEncryptedPdf() throws Exception { try { parseDocument("encrypted.pdf", processor); } catch (ElasticsearchParseException e) { assertThat(e.getDetailedMessage(), containsString("document is encrypted")); } }
public void testBuildMissingPatterns() throws Exception { GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap()); Map<String, Object> config = new HashMap<>(); config.put("field", "foo"); ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> factory.create("tag", config)); assertThat(e.getMessage(), equalTo("[patterns] required property is missing")); }
public void testBuildEmptyPatternsList() throws Exception { GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap()); Map<String, Object> config = new HashMap<>(); config.put("field", "foo"); config.put("patterns", Collections.emptyList()); ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> factory.create("tag", config)); assertThat(e.getMessage(), equalTo("[patterns] List of patterns must not be empty")); }
public void testReadStringPropertyInvalidType() { try { ConfigurationUtils.readStringProperty(null, null, config, "arr"); } catch (ElasticsearchParseException e) { assertThat( e.getMessage(), equalTo("[arr] property isn't a string, but of type [java.util.Arrays$ArrayList]")); } }
public void testDuplicateKeysFromBytesThrowsException() throws IOException { PropertiesSettingsLoader loader = new PropertiesSettingsLoader(); try { loader.load("foo=bar\nfoo=baz".getBytes(Charset.defaultCharset())); } catch (ElasticsearchParseException e) { assertEquals( e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); } }
public void testCreateMissingField() throws Exception { UppercaseProcessor.Factory factory = new UppercaseProcessor.Factory(); Map<String, Object> config = new HashMap<>(); try { factory.create(null, config); fail("factory create should have failed"); } catch (ElasticsearchParseException e) { assertThat(e.getMessage(), equalTo("[field] required property is missing")); } }
public void testCreateNoToPresent() throws Exception { RenameProcessor.Factory factory = new RenameProcessor.Factory(); Map<String, Object> config = new HashMap<>(); config.put("field", "old_field"); try { factory.create(null, config); fail("factory create should have failed"); } catch (ElasticsearchParseException e) { assertThat(e.getMessage(), equalTo("[target_field] required property is missing")); } }
public void testDuplicateKeyFromStringThrowsException() throws IOException { PropertiesSettingsLoader loader = new PropertiesSettingsLoader(); try { loader.load("foo=bar\nfoo=baz"); fail("expected exception"); } catch (ElasticsearchParseException e) { assertEquals( e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); } }
public void testCreateWithInvalidPattern() throws Exception { GrokProcessor.Factory factory = new GrokProcessor.Factory(Collections.emptyMap()); Map<String, Object> config = new HashMap<>(); config.put("field", "_field"); config.put("patterns", Collections.singletonList("[")); ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> factory.create("tag", config)); assertThat( e.getMessage(), equalTo("[patterns] Invalid regex pattern found in: [[]. premature end of char-class")); }
public void testCreateNoSeparatorPresent() throws Exception { JoinProcessor.Factory factory = new JoinProcessor.Factory(); Map<String, Object> config = new HashMap<>(); config.put("field", "field1"); try { factory.create(config); fail("factory create should have failed"); } catch (ElasticsearchParseException e) { assertThat(e.getMessage(), equalTo("[separator] required property is missing")); } }
public void testReverseOptionFailsBuildWhenInvalidGeoHashString() throws IOException { String json = "{\n" + " \"reverse\" : \"false\"\n" + "}"; XContentParser itemParser = XContentHelper.createParser(new BytesArray(json)); itemParser.nextToken(); QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT); try { GeoDistanceSortBuilder item = GeoDistanceSortBuilder.fromXContent(context, ""); item.validation(GeoValidationMethod.STRICT); item.build(createMockShardContext()); fail("adding reverse sorting option should fail with an exception"); } catch (ElasticsearchParseException e) { assertEquals( "illegal latitude value [269.384765625] for [GeoDistanceSort] for field [reverse].", e.getMessage()); } }
public void testReadProcessors() throws Exception { Processor processor = mock(Processor.class); ProcessorsRegistry.Builder builder = new ProcessorsRegistry.Builder(); builder.registerProcessor("test_processor", (templateService, registry) -> config -> processor); ProcessorsRegistry registry = builder.build(TestTemplateService.instance()); List<Map<String, Map<String, Object>>> config = new ArrayList<>(); Map<String, Object> emptyConfig = Collections.emptyMap(); config.add(Collections.singletonMap("test_processor", emptyConfig)); config.add(Collections.singletonMap("test_processor", emptyConfig)); List<Processor> result = ConfigurationUtils.readProcessorConfigs(config, registry); assertThat(result.size(), equalTo(2)); assertThat(result.get(0), sameInstance(processor)); assertThat(result.get(1), sameInstance(processor)); config.add(Collections.singletonMap("unknown_processor", emptyConfig)); try { ConfigurationUtils.readProcessorConfigs(config, registry); fail("exception expected"); } catch (ElasticsearchParseException e) { assertThat(e.getMessage(), equalTo("No processor type exists with name [unknown_processor]")); } }
public void testEncryptedPdf() throws Exception { ElasticsearchParseException e = expectThrows( ElasticsearchParseException.class, () -> parseDocument("encrypted.pdf", processor)); assertThat(e.getDetailedMessage(), containsString("document is encrypted")); }