|
@@ -53,7 +53,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase {
|
|
|
for (Tuple<String, String> tuple : randomValues) {
|
|
|
valuesConfig.add(Map.of("source", tuple.v1(), "target", tuple.v2()));
|
|
|
}
|
|
|
- config.put("enrich_values", valuesConfig);
|
|
|
+ config.put("set_from", valuesConfig);
|
|
|
|
|
|
ExactMatchProcessor result = (ExactMatchProcessor) factory.create(Collections.emptyMap(), "_tag", config);
|
|
|
assertThat(result, notNullValue());
|
|
@@ -96,7 +96,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase {
|
|
|
for (Tuple<String, String> tuple : randomValues) {
|
|
|
valuesConfig.add(Map.of("source", tuple.v1(), "target", tuple.v2()));
|
|
|
}
|
|
|
- config.put("enrich_values", valuesConfig);
|
|
|
+ config.put("set_from", valuesConfig);
|
|
|
|
|
|
Exception e = expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), "_tag", config));
|
|
|
assertThat(e.getMessage(), equalTo("policy [majestic] does not exists"));
|
|
@@ -126,7 +126,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase {
|
|
|
for (Tuple<String, String> tuple : randomValues) {
|
|
|
valuesConfig.add(Map.of("source", tuple.v1(), "target", tuple.v2()));
|
|
|
}
|
|
|
- config.put("enrich_values", valuesConfig);
|
|
|
+ config.put("set_from", valuesConfig);
|
|
|
|
|
|
Exception e = expectThrows(ElasticsearchParseException.class, () -> factory.create(Collections.emptyMap(), "_tag", config));
|
|
|
assertThat(e.getMessage(), equalTo("[policy_name] required property is missing"));
|
|
@@ -156,7 +156,7 @@ public class EnrichProcessorFactoryTests extends ESTestCase {
|
|
|
for (Tuple<String, String> tuple : randomValues) {
|
|
|
valuesConfig.add(Map.of("source", tuple.v1(), "target", tuple.v2()));
|
|
|
}
|
|
|
- config.put("enrich_values", valuesConfig);
|
|
|
+ config.put("set_from", valuesConfig);
|
|
|
|
|
|
Exception e = expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), "_tag", config));
|
|
|
assertThat(e.getMessage(), equalTo("unsupported policy type [unsupported]"));
|
|
@@ -173,10 +173,55 @@ public class EnrichProcessorFactoryTests extends ESTestCase {
|
|
|
config.put("policy_name", "majestic");
|
|
|
config.put("enrich_key", "host");
|
|
|
List<Map<String, Object>> valuesConfig = List.of(Map.of("source", "rank", "target", "rank"));
|
|
|
- config.put("enrich_values", valuesConfig);
|
|
|
+ config.put("set_from", valuesConfig);
|
|
|
|
|
|
Exception e = expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), "_tag", config));
|
|
|
assertThat(e.getMessage(), equalTo("source field [rank] does not exist in policy [majestic]"));
|
|
|
}
|
|
|
|
|
|
+ public void testCompactEnrichValuesFormat() throws Exception {
|
|
|
+ List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
|
|
|
+ EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("source_index"), "host",
|
|
|
+ enrichValues);
|
|
|
+ EnrichProcessorFactory factory = new EnrichProcessorFactory(null);
|
|
|
+ factory.policies = Map.of("majestic", policy);
|
|
|
+
|
|
|
+ Map<String, Object> config = new HashMap<>();
|
|
|
+ config.put("policy_name", "majestic");
|
|
|
+ config.put("targets", enrichValues);
|
|
|
+
|
|
|
+ ExactMatchProcessor result = (ExactMatchProcessor) factory.create(Collections.emptyMap(), "_tag", config);
|
|
|
+ assertThat(result, notNullValue());
|
|
|
+ assertThat(result.getPolicyName(), equalTo("majestic"));
|
|
|
+ assertThat(result.getEnrichKey(), equalTo("host"));
|
|
|
+ assertThat(result.getSpecifications().size(), equalTo(enrichValues.size()));
|
|
|
+ for (int i = 0; i < enrichValues.size(); i++) {
|
|
|
+ EnrichSpecification actual = result.getSpecifications().get(i);
|
|
|
+ String expected = enrichValues.get(i);
|
|
|
+ assertThat(actual.sourceField, equalTo(expected));
|
|
|
+ assertThat(actual.targetField, equalTo(expected));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testNoEnrichValues() throws Exception {
|
|
|
+ List<String> enrichValues = List.of("globalRank", "tldRank", "tld");
|
|
|
+ EnrichPolicy policy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null, List.of("source_index"), "host",
|
|
|
+ enrichValues);
|
|
|
+ EnrichProcessorFactory factory = new EnrichProcessorFactory(null);
|
|
|
+ factory.policies = Map.of("majestic", policy);
|
|
|
+
|
|
|
+ Map<String, Object> config1 = new HashMap<>();
|
|
|
+ config1.put("policy_name", "majestic");
|
|
|
+ config1.put("set_from", List.of());
|
|
|
+
|
|
|
+ Exception e = expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), "_tag", config1));
|
|
|
+ assertThat(e.getMessage(), equalTo("provided set_from is empty"));
|
|
|
+
|
|
|
+ Map<String, Object> config2 = new HashMap<>();
|
|
|
+ config2.put("policy_name", "majestic");
|
|
|
+ config2.put("targets", List.of());
|
|
|
+ e = expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), "_tag", config2));
|
|
|
+ assertThat(e.getMessage(), equalTo("provided targets is empty"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|