diff --git a/README.md b/README.md index f694e12..a3452c2 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ Below is a diagram representing the class structure: ![The Class relationship](diagrams/Log_Parser-Classes.drawio.png) ## Searching and organizing log data -As of versions 1.0.4 & 1.0.5 we have a series of search and organizing the log data. +We have a series of search and organizing the log data. ### Search and Filter Mechanisms We have introduced the filter and search mechanisms. These allow you to search the LogData for values for a given ParseDefinitionEntry. For this we have introduced the following methods: @@ -398,6 +398,7 @@ All reports are stored in the directory `./log-parser-reports/export/`. - **(new feature)** [#117](https://github.com/adobe/log-parser/issues/117) You can now include the file name in the result of the analysis. - **(new feature)** [#141](https://github.com/adobe/log-parser/issues/141) You can now export a LogData as a table in a HTML file. - **(new feature)** [#123](https://github.com/adobe/log-parser/issues/123) We now log the total number and size of the parsed files. +- **(new feature)** [#154](https://github.com/adobe/log-parser/issues/154) We have a data enrichment feature, where you can enrich the log data with additional information. - [#110](https://github.com/adobe/log-parser/issues/110) Moved to Java 11 - [#112](https://github.com/adobe/log-parser/issues/112) Updating License Headers - [#119](https://github.com/adobe/log-parser/issues/119) Cleanup of deprecated methods, and the consequences thereof. diff --git a/src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java b/src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java index 761f89f..aa7e47f 100644 --- a/src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java +++ b/src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java @@ -18,6 +18,8 @@ import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; import java.io.File; import java.io.FileWriter; @@ -293,10 +295,10 @@ public LogData groupBy(String in_parseDefinitionEntryKey) *

* Author : gandomi * - * @param in_filterKeyValues A map of <String,Object> representation the values we want to find + * @param in_filterKeyValues A map of <String,Matcher> representation the values we want to find * @return a new LogDataObject containing only the filtered values */ - public LogData filterBy(Map in_filterKeyValues) { + public LogData filterBy(Map in_filterKeyValues) { LogData lr_filteredLogData = new LogData<>(); for (String lt_logDataKey : this.getEntries().keySet()) { @@ -314,11 +316,11 @@ public LogData filterBy(Map in_filterKeyValues) { * Author : gandomi * * @param in_parseDefinitionName The name of the parse definition entry under which we search for a value - * @param in_searchValue The search value + * @param in_searchValue The matcher * @return a new LogDataObject containing only the searched values */ - public LogData searchEntries(String in_parseDefinitionName, String in_searchValue) { - Map l_filterProperties = new HashMap<>(); + public LogData searchEntries(String in_parseDefinitionName, Matcher in_searchValue) { + Map l_filterProperties = new HashMap<>(); l_filterProperties.put(in_parseDefinitionName, in_searchValue); return this.filterBy(l_filterProperties); @@ -329,10 +331,10 @@ public LogData searchEntries(String in_parseDefinitionName, String in_searchV *

* Author : gandomi * - * @param in_searchKeyValues A map of <String,Object> representation the values we want to find + * @param in_searchKeyValues A map of <String,Matcher> representation the values we want to find * @return a new LogDataObject containing only the filtered values */ - public LogData searchEntries(Map in_searchKeyValues) { + public LogData searchEntries(Map in_searchKeyValues) { return filterBy(in_searchKeyValues); } @@ -347,8 +349,8 @@ public LogData searchEntries(Map in_searchKeyValues) { * @return true if the search terms could be found. Otherwise false */ public boolean isEntryPresent(String in_parseDefinitionName, String in_searchValue) { - Map l_searchProperties = new HashMap<>(); - l_searchProperties.put(in_parseDefinitionName, in_searchValue); + Map l_searchProperties = new HashMap<>(); + l_searchProperties.put(in_parseDefinitionName, Matchers.equalTo(in_searchValue)); return isEntryPresent(l_searchProperties); } @@ -361,7 +363,7 @@ public boolean isEntryPresent(String in_parseDefinitionName, String in_searchVal * @param in_searchKeyValues A map of <String,Object> representation the values we want to find * @return true if the search terms could be found. Otherwise false */ - public boolean isEntryPresent(Map in_searchKeyValues) { + public boolean isEntryPresent(Map in_searchKeyValues) { return searchEntries(in_searchKeyValues).getEntries().size() > 0; } @@ -540,4 +542,21 @@ public ParseDefinition fetchParseDefinition() { return l_firstEntry.getParseDefinition(); } + + /** + * Enriches the log data with the given values provided there are lines that match the query map + * @param in_queryMap A map definition entry and Matchers + * @param in_entryName The name of the entry to be added + * @param in_entryValue The value of the entry to be added + */ + public void enrichData(Map in_queryMap, String in_entryName, String in_entryValue) { + //add the entry to the definition + fetchParseDefinition().addEntry(new ParseDefinitionEntry(in_entryName)); + + //Iterate over the entries + getEntries().entrySet().stream().filter(e -> e.getValue().matches(in_queryMap)).forEach(e -> { + e.getValue().getValuesMap().put(in_entryName, in_entryValue); + }); + //for each entry meeting the querymap enrich with the given value + } } diff --git a/src/main/java/com/adobe/campaign/tests/logparser/core/StdLogEntry.java b/src/main/java/com/adobe/campaign/tests/logparser/core/StdLogEntry.java index 76dc10b..20c7649 100644 --- a/src/main/java/com/adobe/campaign/tests/logparser/core/StdLogEntry.java +++ b/src/main/java/com/adobe/campaign/tests/logparser/core/StdLogEntry.java @@ -8,42 +8,32 @@ */ package com.adobe.campaign.tests.logparser.core; -import java.util.*; -import java.util.stream.Collectors; - import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hamcrest.Matcher; + +import java.util.*; +import java.util.stream.Collectors; /** * Abstract class for multiple definitions - * - * + *

+ *

* Author : gandomi - * */ public abstract class StdLogEntry { + public static final String STD_DATA_KEY = "key"; + public static final String STD_DATA_FREQUENCE = "frequence"; + public static final String STD_DATA_FILE_NAME = "fileName"; + public static final String STD_DATA_FILE_PATH = "filePath"; protected static Logger log = LogManager.getLogger(); - + Map valuesMap = new HashMap<>(); private Integer frequence = 1; private ParseDefinition parseDefinition; - Map valuesMap = new HashMap<>(); private String fileName; private String filePath; - - public static final String STD_DATA_KEY = "key"; - public static final String STD_DATA_FREQUENCE = "frequence"; - public static final String STD_DATA_FILE_NAME = "fileName"; - public static final String STD_DATA_FILE_PATH = "filePath"; - - /** - * A method that creates the key to identify each stored entry - * - * @return A constructed key - */ - public abstract String makeKey(); - public StdLogEntry(ParseDefinition in_definition) { this.parseDefinition = in_definition; } @@ -59,6 +49,13 @@ public StdLogEntry() { parseDefinition = new ParseDefinition("Created By Default"); } + /** + * A method that creates the key to identify each stored entry + * + * @return A constructed key + */ + public abstract String makeKey(); + /** * Creates a clone of the current LogEntry. This requires that each child defines a copy constructor *

@@ -77,6 +74,13 @@ public Map getValuesMap() { return valuesMap; } + /** + * @param valuesMap the valuesMap to set + */ + protected void setValuesMap(Map valuesMap) { + this.valuesMap = valuesMap; + } + /** * Fetches a print out for listing purposes. It uses the header list as an index to fetch the correct order of the * values @@ -103,11 +107,11 @@ protected List fetchValuesAsList() { */ public abstract Set fetchHeaders(); + ; + /** * Returns a set of objects you have defined for your log class. When using Generic Object no changes are made to - * it. - * When defining an SDK you should override this method. - * Author : gandomi + * it. When defining an SDK you should override this method. Author : gandomi * * @return A Maps of values for the LogEntry */ @@ -123,10 +127,10 @@ public Map fetchValueMap() { l_valueMap.put(STD_DATA_FILE_PATH, getFilePath()); } - l_valueMap.put(STD_DATA_FREQUENCE , getFrequence().toString()); + l_valueMap.put(STD_DATA_FREQUENCE, getFrequence().toString()); return valuesMap; - }; + } /** * Increments the frequence @@ -161,13 +165,6 @@ protected void setFrequence(Integer frequence) { this.frequence = frequence; } - /** - * @param valuesMap the valuesMap to set - */ - protected void setValuesMap(Map valuesMap) { - this.valuesMap = valuesMap; - } - public ParseDefinition getParseDefinition() { return parseDefinition; } @@ -218,44 +215,45 @@ public Object get(String in_dataTitle) { * @param in_filterMap A map of filter values * @return True if all of the values can be found in the valueMap */ - public boolean matches(Map in_filterMap) { + public boolean matches(Map in_filterMap) { - for (String lt_filterKey : in_filterMap.keySet()) { - if (!this.fetchHeaders().contains(lt_filterKey)) { - log.warn("The filter key {} could not be found among the log entry headers.", lt_filterKey); - return false; - } - if (!this.fetchValueMap().get(lt_filterKey).equals(in_filterMap.get(lt_filterKey))) { - return false; - } - } - return true; + return in_filterMap.entrySet().stream().allMatch(e -> e.getValue().matches(this.get(e.getKey()))); } + @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } StdLogEntry other = (StdLogEntry) obj; if (frequence == null) { - if (other.frequence != null) + if (other.frequence != null) { return false; - } else if (!frequence.equals(other.frequence)) + } + } else if (!frequence.equals(other.frequence)) { return false; + } if (parseDefinition == null) { - if (other.parseDefinition != null) + if (other.parseDefinition != null) { return false; - } else if (!parseDefinition.equals(other.parseDefinition)) + } + } else if (!parseDefinition.equals(other.parseDefinition)) { return false; + } if (valuesMap == null) { - if (other.valuesMap != null) + if (other.valuesMap != null) { return false; - } else if (!valuesMap.equals(other.valuesMap)) + } + } else if (!valuesMap.equals(other.valuesMap)) { return false; + } return true; } @@ -266,6 +264,7 @@ public int hashCode() { /** * Returns the headers as they are stored + * * @return An ordered set of the value names that are stored */ public Set fetchStoredHeaders() { @@ -284,16 +283,17 @@ public String getFilePath() { return filePath; } - public void setLogFileName(String in_logFile) { - this.fileName = in_logFile; - } - public void setFilePath(String in_logFile) { this.filePath = in_logFile; } + public void setLogFileName(String in_logFile) { + this.fileName = in_logFile; + } + /** * Updates the store path of the log entry. We also remove training "/" to have a clean path + * * @param in_newPath The path we want to store */ public void updatePath(String in_newPath) { @@ -303,5 +303,6 @@ public void updatePath(String in_newPath) { l_pathDelta = (l_pathDelta.endsWith("/")) ? l_pathDelta.substring(0, l_pathDelta.length() - 1) : l_pathDelta; setFilePath(l_pathDelta); } + } diff --git a/src/test/java/com/adobe/campaign/tests/logparser/core/EnrichmentTests.java b/src/test/java/com/adobe/campaign/tests/logparser/core/EnrichmentTests.java new file mode 100644 index 0000000..920a3e4 --- /dev/null +++ b/src/test/java/com/adobe/campaign/tests/logparser/core/EnrichmentTests.java @@ -0,0 +1,107 @@ +package com.adobe.campaign.tests.logparser.core; + +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.testng.annotations.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.testng.Assert.assertThrows; + +public class EnrichmentTests { + + @Test + public void testSimpleEnrichment() { + LogData l_cubeData = fetchTestLogEntry(); + + //Checks before enrichment + assertThat(l_cubeData.getEntries().size(), Matchers.is(3)); + assertThat(l_cubeData.get("12").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence")); + + + ////enrich logData + // Prepare inputs + Map l_queryMap = new HashMap<>(); + l_queryMap.put("AAZ", Matchers.startsWith("12")); + + l_cubeData.enrichData(l_queryMap, "TIT", "TAT"); + + assertThat(l_cubeData.get("12").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence", "TIT")); + assertThat(l_cubeData.get("12").get("TIT"), Matchers.equalTo("TAT")); + + assertThat(l_cubeData.get("112").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence", "TIT")); + assertThat(l_cubeData.get("112").get("TIT"), Matchers.nullValue()); + + l_cubeData.exportLogDataToHTML("dsd", "enriched"); + } + + @Test + public void testDoubleEnrichment() { + LogData l_cubeData = fetchTestLogEntry(); + + //Checks before enrichment + assertThat(l_cubeData.getEntries().size(), Matchers.is(3)); + assertThat(l_cubeData.get("12").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence")); + + ////enrich logData + // Prepare inputs + Map l_queryMap = new HashMap<>(); + l_queryMap.put("AAZ", Matchers.startsWith("12")); + + l_cubeData.enrichData(l_queryMap, "TIT", "TAT"); + + Map l_queryMap2 = new HashMap<>(); + l_queryMap2.put("TIT", Matchers.nullValue()); + + l_cubeData.enrichData(l_queryMap2, "TIT", "TUT"); + + assertThat(l_cubeData.get("12").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence", "TIT")); + assertThat(l_cubeData.get("12").get("TIT"), Matchers.equalTo("TAT")); + + assertThat(l_cubeData.get("112").fetchStoredHeaders(), Matchers.containsInAnyOrder("key","AAZ", "ZZZ", "BAU", "DAT", "frequence", "TIT")); + assertThat(l_cubeData.get("112").get("TIT"), Matchers.equalTo("TUT")); + + l_cubeData.exportLogDataToHTML("dsd", "enriched"); + } + + + + private static LogData fetchTestLogEntry() { + ParseDefinition l_definition = new ParseDefinition("tmp"); + + final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ"); + l_definition.addEntry(l_parseDefinitionEntryKey); + l_definition.addEntry(new ParseDefinitionEntry("ZZZ")); + final ParseDefinitionEntry l_testParseDefinitionEntryBAU = new ParseDefinitionEntry("BAU"); + l_definition.addEntry(l_testParseDefinitionEntryBAU); + final ParseDefinitionEntry l_testParseDefinitionEntryDAT = new ParseDefinitionEntry("DAT"); + l_definition.addEntry(l_testParseDefinitionEntryDAT); + l_definition.defineKeys(l_parseDefinitionEntryKey); + + GenericEntry l_inputData = new GenericEntry(l_definition); + l_inputData.getValuesMap().put("AAZ", "12"); + l_inputData.getValuesMap().put("ZZZ", "14"); + l_inputData.getValuesMap().put("BAU", "13"); + l_inputData.getValuesMap().put("DAT", "AA"); + + GenericEntry l_inputData2 = new GenericEntry(l_definition); + l_inputData2.getValuesMap().put("AAZ", "112"); + l_inputData2.getValuesMap().put("ZZZ", "114"); + l_inputData2.getValuesMap().put("BAU", "113"); + l_inputData2.getValuesMap().put("DAT", "AAA"); + + GenericEntry l_inputData3 = new GenericEntry(l_definition); + l_inputData3.getValuesMap().put("AAZ", "120"); + l_inputData3.getValuesMap().put("ZZZ", "14"); + l_inputData3.getValuesMap().put("BAU", "13"); + l_inputData3.getValuesMap().put("DAT", "AAA"); + + LogData l_cubeData = new LogData(); + l_cubeData.addEntry(l_inputData); + l_cubeData.addEntry(l_inputData2); + l_cubeData.addEntry(l_inputData3); + return l_cubeData; + } +} diff --git a/src/test/java/com/adobe/campaign/tests/logparser/core/LogDataTest.java b/src/test/java/com/adobe/campaign/tests/logparser/core/LogDataTest.java index e1f64b1..940e0f6 100644 --- a/src/test/java/com/adobe/campaign/tests/logparser/core/LogDataTest.java +++ b/src/test/java/com/adobe/campaign/tests/logparser/core/LogDataTest.java @@ -25,6 +25,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.testng.Assert; import org.testng.annotations.Test; @@ -746,8 +747,8 @@ public void testFilter_Default() { l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - Map l_filterProperties = new HashMap<>(); - l_filterProperties.put("ZZZ", "114"); + Map l_filterProperties = new HashMap<>(); + l_filterProperties.put("ZZZ", Matchers.equalTo("114")); LogData l_myCube = l_cubeData.filterBy(l_filterProperties); assertThat("We should have found one entry", l_myCube.getEntries().size(), is(equalTo(1))); @@ -755,7 +756,7 @@ public void testFilter_Default() { assertThat("We should have found the correct entry", l_myCube.getEntries().containsKey("112")); //Adding another filter - l_filterProperties.put("DAT", "AAA"); + l_filterProperties.put("DAT", Matchers.equalTo("AAA")); LogData l_myCube2 = l_cubeData.filterBy(l_filterProperties); @@ -764,7 +765,7 @@ public void testFilter_Default() { assertThat("We should have found the correct entry", l_myCube2.getEntries().containsKey("112")); //Negative test - l_filterProperties.put("DAT", "AA"); + l_filterProperties.put("DAT", Matchers.equalTo("AA")); LogData l_myCube3 = l_cubeData.filterBy(l_filterProperties); @@ -810,9 +811,9 @@ public void testFilter_Multi() { l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - Map l_filterProperties = new HashMap<>(); - l_filterProperties.put("ZZZ", "14"); - l_filterProperties.put("BAU", "13"); + Map l_filterProperties = new HashMap<>(); + l_filterProperties.put("ZZZ", Matchers.equalTo("14")); + l_filterProperties.put("BAU", Matchers.equalTo("13")); LogData l_myCube = l_cubeData.filterBy(l_filterProperties); @@ -827,7 +828,7 @@ public void testFilter_Multi() { assertThat("We should have found the correct entry", l_myCube2.getEntries().containsKey("120")); - l_filterProperties.put("DAT", "AAA"); + l_filterProperties.put("DAT", Matchers.equalTo("AAA")); LogData l_myCube3 = l_cubeData.filterBy(l_filterProperties); assertThat("We should have found one entry", l_myCube3.getEntries().size(), is(equalTo(1))); @@ -930,7 +931,7 @@ public void testSearch_Default() { l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - LogData l_myCube = l_cubeData.searchEntries("ZZZ", "114"); + LogData l_myCube = l_cubeData.searchEntries("ZZZ", Matchers.equalTo("114")); assertThat("We should have found one entry", l_myCube.getEntries().size(), is(equalTo(1))); @@ -938,14 +939,14 @@ public void testSearch_Default() { //Adding another filter - LogData l_myCube2 = l_cubeData.searchEntries("DAT", "AAA"); + LogData l_myCube2 = l_cubeData.searchEntries("DAT", Matchers.equalTo("AAA")); assertThat("We should have found one entry", l_myCube2.getEntries().size(), is(equalTo(1))); assertThat("We should have found the correct entry", l_myCube2.getEntries().containsKey("112")); //Negative test - LogData l_myCube3 = l_cubeData.searchEntries("DAT", "AAL"); + LogData l_myCube3 = l_cubeData.searchEntries("DAT", Matchers.equalTo("AAL")); assertThat("We should have found one entry", l_myCube3.getEntries().size(), is(equalTo(0))); @@ -989,9 +990,9 @@ public void testsearch_Multi() { l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - Map l_filterProperties = new HashMap<>(); - l_filterProperties.put("ZZZ", "14"); - l_filterProperties.put("BAU", "13"); + Map l_filterProperties = new HashMap<>(); + l_filterProperties.put("ZZZ", Matchers.equalTo("14")); + l_filterProperties.put("BAU", Matchers.equalTo("13")); LogData l_myCube = l_cubeData.searchEntries(l_filterProperties); @@ -1006,7 +1007,7 @@ public void testsearch_Multi() { assertThat("We should have found the correct entry", l_myCube2.getEntries().containsKey("120")); - l_filterProperties.put("DAT", "AAA"); + l_filterProperties.put("DAT", Matchers.equalTo("AAA")); LogData l_myCube3 = l_cubeData.searchEntries(l_filterProperties); assertThat("We should have found one entry", l_myCube3.getEntries().size(), is(equalTo(1))); @@ -1053,13 +1054,13 @@ public void testIsPresent() { l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - Map l_filterProperties = new HashMap<>(); - l_filterProperties.put("ZZZ", "14"); - l_filterProperties.put("BAU", "13"); + Map l_filterProperties = new HashMap<>(); + l_filterProperties.put("ZZZ", Matchers.equalTo("14")); + l_filterProperties.put("BAU", Matchers.equalTo("13")); assertThat("We should state that the given entry is present", l_cubeData.isEntryPresent(l_filterProperties)); - l_filterProperties.put("BAU", "1398"); + l_filterProperties.put("BAU", Matchers.equalTo("1398")); assertThat("We should state that the given entry is present", !l_cubeData.isEntryPresent(l_filterProperties)); diff --git a/src/test/java/com/adobe/campaign/tests/logparser/core/StdLogEntryTests.java b/src/test/java/com/adobe/campaign/tests/logparser/core/StdLogEntryTests.java index fe36865..97a7e82 100644 --- a/src/test/java/com/adobe/campaign/tests/logparser/core/StdLogEntryTests.java +++ b/src/test/java/com/adobe/campaign/tests/logparser/core/StdLogEntryTests.java @@ -17,6 +17,8 @@ import java.util.Map; import com.adobe.campaign.tests.logparser.core.*; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; import org.testng.annotations.Test; public class StdLogEntryTests { @@ -156,22 +158,90 @@ public void testMatches() { l_inputData.getValuesMap().put("BAU", "13"); l_inputData.getValuesMap().put("DAT", "AA"); - Map l_filterMap = new HashMap<>(); - l_filterMap.put("BAU", "13"); + Map l_filterMap = new HashMap<>(); + l_filterMap.put("BAU", Matchers.equalTo("13")); assertThat("Matches should be true", l_inputData.matches(l_filterMap)); - Map l_filterMap2 = new HashMap<>(); - l_filterMap2.put("NOTBAU", "13"); + Map l_filterMap2 = new HashMap<>(); + l_filterMap2.put("NOTBAU", Matchers.equalTo("13")); assertThat("We should not have a match if the header does not exist", !l_inputData.matches(l_filterMap2)); - Map l_filterMap3 = new HashMap<>(); - l_filterMap3.put("BAU", "16"); + Map l_filterMap3 = new HashMap<>(); + l_filterMap3.put("BAU", Matchers.equalTo("16")); assertThat("We should not have a match if the entry value is incorrect", !l_inputData.matches(l_filterMap3)); } + @Test + public void testMatchesAll() { + ParseDefinition l_definition = new ParseDefinition("tmp"); + + final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ"); + l_definition.addEntry(l_parseDefinitionEntryKey); + l_definition.addEntry(new ParseDefinitionEntry("ZZZ")); + final ParseDefinitionEntry l_testParseDefinitionEntryBAU = new ParseDefinitionEntry("BAU"); + l_definition.addEntry(l_testParseDefinitionEntryBAU); + final ParseDefinitionEntry l_testParseDefinitionEntryDAT = new ParseDefinitionEntry("DAT"); + l_definition.addEntry(l_testParseDefinitionEntryDAT); + l_definition.defineKeys(l_parseDefinitionEntryKey); + + GenericEntry l_inputData = new GenericEntry(l_definition); + l_inputData.getValuesMap().put("AAZ", "12"); + l_inputData.getValuesMap().put("ZZZ", "14"); + l_inputData.getValuesMap().put("BAU", "13"); + l_inputData.getValuesMap().put("DAT", "AA"); + + ////enrich logData + // Prepare inputs + Map l_queryMap = new HashMap<>(); + l_queryMap.put("AAZ", Matchers.startsWith("12")); + + assertThat("We should have a match", l_inputData.matches(l_queryMap)); + + l_queryMap.put("AAZ", Matchers.startsWith("13")); + assertThat("We should Not have a match", !l_inputData.matches(l_queryMap)); + + Map l_queryMap2 = new HashMap<>(); + l_queryMap2.put("FFF", Matchers.startsWith("12")); + + assertThat("We should Not have a match", !l_inputData.matches(l_queryMap2)); + + } + + @Test + public void testMatchesAll_multiple() { + ParseDefinition l_definition = new ParseDefinition("tmp"); + + final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ"); + l_definition.addEntry(l_parseDefinitionEntryKey); + l_definition.addEntry(new ParseDefinitionEntry("ZZZ")); + final ParseDefinitionEntry l_testParseDefinitionEntryBAU = new ParseDefinitionEntry("BAU"); + l_definition.addEntry(l_testParseDefinitionEntryBAU); + final ParseDefinitionEntry l_testParseDefinitionEntryDAT = new ParseDefinitionEntry("DAT"); + l_definition.addEntry(l_testParseDefinitionEntryDAT); + l_definition.defineKeys(l_parseDefinitionEntryKey); + + GenericEntry l_inputData = new GenericEntry(l_definition); + l_inputData.getValuesMap().put("AAZ", "12"); + l_inputData.getValuesMap().put("ZZZ", "14"); + l_inputData.getValuesMap().put("BAU", "13"); + l_inputData.getValuesMap().put("DAT", "AA"); + + ////enrich logData + // Prepare inputs + Map l_queryMap = new HashMap<>(); + l_queryMap.put("AAZ", Matchers.startsWith("12")); + l_queryMap.put("BAU", Matchers.endsWith("3")); + + assertThat("We should have a match", l_inputData.matches(l_queryMap)); + + l_queryMap.put("DAT", Matchers.containsString("E")); + assertThat("We should not have a match", !l_inputData.matches(l_queryMap)); + + } + @Test public void testInsertingOfAPath() { ParseDefinition l_definition = new ParseDefinition("tmp");