|
@@ -40,12 +40,12 @@ public class UserAgentProcessorTests extends ESTestCase {
|
|
|
UserAgentParser parser = new UserAgentParser(randomAlphaOfLength(10), regexStream, deviceTypeRegexStream, new UserAgentCache(1000));
|
|
|
|
|
|
processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", parser,
|
|
|
- EnumSet.allOf(UserAgentProcessor.Property.class), false);
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), true, false);
|
|
|
}
|
|
|
|
|
|
public void testNullValueWithIgnoreMissing() throws Exception {
|
|
|
UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", null,
|
|
|
- EnumSet.allOf(UserAgentProcessor.Property.class), true);
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), false, true);
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(),
|
|
|
Collections.singletonMap("source_field", null));
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
@@ -55,7 +55,7 @@ public class UserAgentProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testNonExistentWithIgnoreMissing() throws Exception {
|
|
|
UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", null,
|
|
|
- EnumSet.allOf(UserAgentProcessor.Property.class), true);
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), false, true);
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
processor.execute(ingestDocument);
|
|
@@ -64,7 +64,7 @@ public class UserAgentProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testNullWithoutIgnoreMissing() throws Exception {
|
|
|
UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", null,
|
|
|
- EnumSet.allOf(UserAgentProcessor.Property.class), false);
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), false, false);
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(),
|
|
|
Collections.singletonMap("source_field", null));
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
@@ -74,7 +74,7 @@ public class UserAgentProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testNonExistentWithoutIgnoreMissing() throws Exception {
|
|
|
UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", null,
|
|
|
- EnumSet.allOf(UserAgentProcessor.Property.class), false);
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), false, false);
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
|
|
@@ -243,4 +243,34 @@ public class UserAgentProcessorTests extends ESTestCase {
|
|
|
device.put("type", "Other");
|
|
|
assertThat(target.get("device"), is(device));
|
|
|
}
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void testExtractDeviceTypeDisabled() {
|
|
|
+ Map<String, Object> document = new HashMap<>();
|
|
|
+ document.put("source_field",
|
|
|
+ "Something I made up v42.0.1");
|
|
|
+ IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
+
|
|
|
+ InputStream regexStream = UserAgentProcessor.class.getResourceAsStream("/regexes.yml");
|
|
|
+ InputStream deviceTypeRegexStream = UserAgentProcessor.class.getResourceAsStream("/device_type_regexes.yml");
|
|
|
+ UserAgentParser parser = new UserAgentParser(randomAlphaOfLength(10), regexStream, deviceTypeRegexStream, new UserAgentCache(1000));
|
|
|
+ UserAgentProcessor processor = new UserAgentProcessor(randomAlphaOfLength(10), null, "source_field", "target_field", parser,
|
|
|
+ EnumSet.allOf(UserAgentProcessor.Property.class), false, false);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ Map<String, Object> data = ingestDocument.getSourceAndMetadata();
|
|
|
+
|
|
|
+ assertThat(data, hasKey("target_field"));
|
|
|
+ Map<String, Object> target = (Map<String, Object>) data.get("target_field");
|
|
|
+
|
|
|
+ assertThat(target.get("name"), is("Other"));
|
|
|
+ assertNull(target.get("major"));
|
|
|
+ assertNull(target.get("minor"));
|
|
|
+ assertNull(target.get("patch"));
|
|
|
+ assertNull(target.get("build"));
|
|
|
+
|
|
|
+ assertNull(target.get("os"));
|
|
|
+ Map<String, String> device = new HashMap<>();
|
|
|
+ device.put("name", "Other");
|
|
|
+ assertThat(target.get("device"), is(device));
|
|
|
+ }
|
|
|
}
|