TransformFilterExtractorDecorator extends ExtractorDecorator implements StatefulExtractor { @Override public Iterable<LookupKV> extract(String line) throws IOException { return extract(line, new AtomicReference<>(null)); } TransformFilterExtractorDecorator(Extractor decoratedExtractor); @Override void initialize(Map<String, Object> config); @Override Object initializeState(Map<String, Object> config); @Override Object mergeStates(List<? extends Object> states); @Override Set<ExtractorCapabilities> getCapabilities(); @Override Iterable<LookupKV> extract(String line); @Override Iterable<LookupKV> extract(String line, AtomicReference<Object> state); static final String STATE_KEY; static final String STATES_KEY; }
@Test public void transforms_values_and_indicators() throws IOException { final String indicatorVal = "val2"; EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", indicatorVal); EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {{ put("foo", "val1"); put("bar", indicatorVal); put("baz", "val3"); }}); LookupKV lkv = new LookupKV<>(lookupKey, lookupValue); List<LookupKV> extractedLkvs = new ArrayList<>(); extractedLkvs.add(lkv); Mockito.when(extractor.extract("val1,val2,val3")).thenReturn(extractedLkvs); Iterable<LookupKV> extracted = decorator.extract("val1,val2,val3"); EnrichmentKey expectedLookupKey = new EnrichmentKey("testenrichment", "VAL2"); EnrichmentValue expectedLookupValue = new EnrichmentValue(new HashMap<String, Object>() {{ put("foo", "VAL1"); put("bar", "val2"); put("baz", "val3"); put("newvar", "VAL1"); put("lowernewvar", "val1"); }}); LookupKV expectedLkv = new LookupKV<>(expectedLookupKey, expectedLookupValue); List<LookupKV> expectedLkvs = new ArrayList<>(); expectedLkvs.add(expectedLkv); assertThat(extracted, CoreMatchers.equalTo(expectedLkvs)); }
@Test public void filters_values() throws Exception { final String indicatorVal = "val2"; EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", indicatorVal); EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {{ put("foo", "val1"); put("bar", indicatorVal); put("baz", ""); }}); LookupKV lkv = new LookupKV<>(lookupKey, lookupValue); List<LookupKV> extractedLkvs = new ArrayList<>(); extractedLkvs.add(lkv); Mockito.when(extractor.extract("val1,val2,")).thenReturn(extractedLkvs); Iterable<LookupKV> extracted = decorator.extract("val1,val2,"); assertThat(extracted, CoreMatchers.equalTo(new ArrayList<>())); }
@Test public void filters_indicators() throws Exception { EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", ""); EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {{ put("foo", "val1"); put("bar", ""); put("baz", "val3"); }}); LookupKV lkv = new LookupKV<>(lookupKey, lookupValue); List<LookupKV> extractedLkvs = new ArrayList<>(); extractedLkvs.add(lkv); Mockito.when(extractor.extract("val1,,val3")).thenReturn(extractedLkvs); Iterable<LookupKV> extracted = decorator.extract("val1,,val3"); assertThat(extracted, CoreMatchers.equalTo(new ArrayList<>())); }