Search in sources :

Example 1 with UserAgentProcessor

use of org.elasticsearch.ingest.useragent.UserAgentProcessor in project elasticsearch by elastic.

the class UserAgentProcessorTests method testNullValueWithIgnoreMissing.

public void testNullValueWithIgnoreMissing() throws Exception {
    UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), true);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("source_field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 2 with UserAgentProcessor

use of org.elasticsearch.ingest.useragent.UserAgentProcessor in project elasticsearch by elastic.

the class UserAgentProcessorTests method setupProcessor.

@BeforeClass
public static void setupProcessor() throws IOException {
    InputStream regexStream = UserAgentProcessor.class.getResourceAsStream("/regexes.yaml");
    assertNotNull(regexStream);
    UserAgentParser parser = new UserAgentParser(randomAsciiOfLength(10), regexStream, new UserAgentCache(1000));
    processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", parser, EnumSet.allOf(UserAgentProcessor.Property.class), false);
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) InputStream(java.io.InputStream) BeforeClass(org.junit.BeforeClass)

Example 3 with UserAgentProcessor

use of org.elasticsearch.ingest.useragent.UserAgentProcessor in project elasticsearch by elastic.

the class UserAgentProcessorTests method testNonExistentWithoutIgnoreMissing.

public void testNonExistentWithoutIgnoreMissing() throws Exception {
    UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), false);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
    assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]"));
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) IOException(java.io.IOException)

Example 4 with UserAgentProcessor

use of org.elasticsearch.ingest.useragent.UserAgentProcessor in project elasticsearch by elastic.

the class UserAgentProcessorTests method testNonExistentWithIgnoreMissing.

public void testNonExistentWithIgnoreMissing() throws Exception {
    UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), true);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 5 with UserAgentProcessor

use of org.elasticsearch.ingest.useragent.UserAgentProcessor in project elasticsearch by elastic.

the class UserAgentProcessorTests method testNullWithoutIgnoreMissing.

public void testNullWithoutIgnoreMissing() throws Exception {
    UserAgentProcessor processor = new UserAgentProcessor(randomAsciiOfLength(10), "source_field", "target_field", null, EnumSet.allOf(UserAgentProcessor.Property.class), false);
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("source_field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
    assertThat(exception.getMessage(), equalTo("field [source_field] is null, cannot parse user-agent."));
}
Also used : UserAgentProcessor(org.elasticsearch.ingest.useragent.UserAgentProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) IOException(java.io.IOException)

Aggregations

UserAgentProcessor (org.elasticsearch.ingest.useragent.UserAgentProcessor)5 IngestDocument (org.elasticsearch.ingest.IngestDocument)4 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 BeforeClass (org.junit.BeforeClass)1