diff --git a/README.md b/README.md
index 10f89b0..74e6e94 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,12 @@ Below is a diagram representing the class structure:
![The Class relationship](diagrams/Log_Parser-Classes.png)
## Release Notes
-
+- 1.0.4 Snapshot
+ - #8 Added the filter function
+ - #13 Added copy constructors
+ - #13 Added a copy method in the StdLogEntry (#13)
+ - #14 Added a set method to LogData. This allows you to change a Log data given a key value and ParseDefinition entry title
+ - Renamed exception IncorrectParseDefinitionTitleException to IncorrectParseDefinitionException
- 1.0.3
- Introduced the LogData Top Class. This encapsulates all results.
- Introduced the LogDataFactory
diff --git a/pom.xml b/pom.xml
index 8ee1583..42378f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,11 +87,13 @@
${project.organization.name}
${project.inceptionYear}
${founder-website}
+
src/main/java/**
src/test/java/**
+ true
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/GenericEntry.java b/src/main/java/com/adobe/campaign/tests/logparser/GenericEntry.java
index 9e1aaf8..074e126 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/GenericEntry.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/GenericEntry.java
@@ -34,6 +34,10 @@ public GenericEntry() {
super(new ParseDefinition("Created By Default"));
}
+ private GenericEntry(GenericEntry l_inputData) {
+ super(l_inputData);
+ }
+
@Override
public String makeKey() {
return String.join(getParseDefinition().getKeyPadding(), getParseDefinition().fetchKeyOrder().stream()
@@ -46,7 +50,6 @@ public Set fetchHeaders() {
return getParseDefinition().fetchHeaders();
}
-
/**
* Returns the values map as it is without any manipulation
@@ -56,5 +59,11 @@ public Map fetchValueMap() {
return valuesMap;
}
-
+
+ @Override
+ public GenericEntry copy() {
+ return new GenericEntry(this);
+ }
+
+
}
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/LogData.java b/src/main/java/com/adobe/campaign/tests/logparser/LogData.java
index 9432cc0..c76a6fe 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/LogData.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/LogData.java
@@ -18,7 +18,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionTitleException;
+import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionException;
public class LogData {
@@ -95,18 +95,17 @@ public T get(String in_dataEntryKey) {
* @param in_valueKey
* The identity of the value.
* @return The key value for the given entry. null if not found
- * @throws IncorrectParseDefinitionTitleException
+ * @throws IncorrectParseDefinitionException
* If the given valueKey was not found in the definition
*
*/
- public Object get(String in_dataEntryKey, String in_valueKey)
- throws IncorrectParseDefinitionTitleException {
+ public Object get(String in_dataEntryKey, String in_valueKey) throws IncorrectParseDefinitionException {
final T l_foundCubeEntry = this.get(in_dataEntryKey);
if (l_foundCubeEntry != null) {
if (!l_foundCubeEntry.fetchHeaders().contains(in_valueKey)) {
- throw new IncorrectParseDefinitionTitleException("The key " + in_valueKey
+ throw new IncorrectParseDefinitionException("The key " + in_valueKey
+ " was not defined in the parse definition for the ParseDefinition "
+ l_foundCubeEntry.getParseDefinition().getTitle() + " you have configured.");
}
@@ -117,6 +116,37 @@ public Object get(String in_dataEntryKey, String in_valueKey)
return null;
}
+ /**
+ * This method allows you to change a specific value in the log data. For
+ * this, you need the key and the parse definition title to find the value
+ *
+ * Author : gandomi
+ *
+ * @param in_dataEntryKey
+ * The key with which the data has been stored
+ * @param in_valueKey
+ * The identity of the value.
+ * @param in_newValue
+ * The new value of the entry value
+ * @throws IncorrectParseDefinitionException
+ * When there is no entry for the given in_dataEntryKey and
+ * in_valueKey
+ *
+ */
+ public void put(String in_dataEntryKey, String in_valueKey, Object in_newValue)
+ throws IncorrectParseDefinitionException {
+ if (get(in_dataEntryKey, in_valueKey) == null) {
+ throw new IncorrectParseDefinitionException("The given parse definition entry for key "
+ + in_dataEntryKey + " and the ParsedefinitionEntry title " + in_valueKey
+ + " could not be found. Operation failed.");
+ }
+
+ final T l_foundCubeEntry = this.get(in_dataEntryKey);
+
+ l_foundCubeEntry.fetchValueMap().put(in_valueKey, in_newValue);
+
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -145,12 +175,15 @@ public boolean equals(Object obj) {
* The key name of the parse definition perform the GroupBy on
* @param in_transformationClass
* The class to which we should transform the cube data
- * @param The return type of the group by cube.
+ * @param
+ * The return type of the group by cube.
* @return a new LogData Object containing the groupBy values
- * @throws IncorrectParseDefinitionTitleException
+ * @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
- * @throws IllegalAccessException if the class or its nullary constructor is not accessible.
- * @throws InstantiationException if this {@code Class} represents an abstract class, an interface,
+ * @throws IllegalAccessException
+ * if the class or its nullary constructor is not accessible.
+ * @throws InstantiationException
+ * if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
@@ -158,7 +191,7 @@ public boolean equals(Object obj) {
*/
public LogData groupBy(String in_parseDefinitionEntryKey,
Class in_transformationClass)
- throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
return groupBy(Arrays.asList(in_parseDefinitionEntryKey), in_transformationClass);
}
@@ -175,12 +208,15 @@ public LogData groupBy(String in_parseDefinitionEntry
* on
* @param in_transformationClass
* The class to which we should transform the cube data
- * @param The return type of the group by cube.
+ * @param
+ * The return type of the group by cube.
* @return a new LogData Object containing the groupBy values
- * @throws IncorrectParseDefinitionTitleException
+ * @throws IncorrectParseDefinitionException
* If the key is not in the ParseDefinitions of the Log data entry
- * @throws IllegalAccessException if the class or its nullary constructor is not accessible.
- * @throws InstantiationException if this {@code Class} represents an abstract class, an interface,
+ * @throws IllegalAccessException
+ * if the class or its nullary constructor is not accessible.
+ * @throws InstantiationException
+ * if this {@code Class} represents an abstract class, an interface,
* an array class, a primitive type, or void; or if the class has no
* nullary constructor; or if the instantiation fails for some other
* reason.
@@ -188,7 +224,7 @@ public LogData groupBy(String in_parseDefinitionEntry
*/
public LogData groupBy(List in_parseDefinitionEntryKeyList,
Class in_transformationClass)
- throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
LogData lr_cubeData = new LogData();
//Creating new Definition
@@ -207,7 +243,7 @@ public LogData groupBy(List in_parseDefinitio
for (String lt_parseDefinitionEntryKey : in_parseDefinitionEntryKeyList) {
if (!lt_entry.getParseDefinition().fetchHeaders().contains(lt_parseDefinitionEntryKey)) {
- throw new IncorrectParseDefinitionTitleException("The given header name "
+ throw new IncorrectParseDefinitionException("The given header name "
+ lt_parseDefinitionEntryKey + " was not among the stored data");
}
@@ -222,4 +258,79 @@ public LogData groupBy(List in_parseDefinitio
return lr_cubeData;
}
+ /**
+ * Here we create a new LogDataObject with the given ParseDefinitionEntry.
+ * This method performs a groupby for the given value. The frequence will
+ * also take into account the original frequence
+ *
+ * Author : gandomi
+ *
+ * @param in_parseDefinitionEntryKeyList
+ * The list of key names of the parse definition perform the GroupBy
+ * on
+ * @return a new LogData Object containing the groupBy values
+ * @throws IncorrectParseDefinitionException
+ * If the key is not in the ParseDefinitions of the Log data entry
+ * @throws IllegalAccessException
+ * if the class or its nullary constructor is not accessible.
+ * @throws InstantiationException
+ * if this {@code Class} represents an abstract class, an interface,
+ * an array class, a primitive type, or void; or if the class has no
+ * nullary constructor; or if the instantiation fails for some other
+ * reason.
+ *
+ */
+ public LogData groupBy(List in_parseDefinitionEntryKeyList)
+ throws InstantiationException, IllegalAccessException, IncorrectParseDefinitionException {
+ return groupBy(in_parseDefinitionEntryKeyList, GenericEntry.class);
+ }
+
+ /**
+ * Here we create a new LogDataObject with the given ParseDefinitionEntry.
+ * This method performs a groupby for the given value. The frequence will
+ * also take into account the original frequence
+ *
+ * Author : gandomi
+ *
+ * @param in_parseDefinitionEntryKey
+ * The key name of the parse definition perform the GroupBy on
+ * @return a new LogData Object containing the groupBy values
+ * @throws IncorrectParseDefinitionException
+ * If the key is not in the ParseDefinitions of the Log data entry
+ * @throws IllegalAccessException
+ * if the class or its nullary constructor is not accessible.
+ * @throws InstantiationException
+ * if this {@code Class} represents an abstract class, an interface,
+ * an array class, a primitive type, or void; or if the class has no
+ * nullary constructor; or if the instantiation fails for some other
+ * reason.
+ *
+ */
+ public LogData groupBy(String in_parseDefinitionEntryKey)
+ throws InstantiationException, IllegalAccessException, IncorrectParseDefinitionException {
+ return groupBy(in_parseDefinitionEntryKey, GenericEntry.class);
+ }
+
+ /**
+ * This method filters the LogData with the given properties
+ *
+ * Author : gandomi
+ *
+ * @param in_filterKeyValues
+ * A map of <String,Object> representation the values we want to find
+ * @return a new LogDataObject containing only the filtered values
+ *
+ */
+ public LogData filter(Map in_filterKeyValues) {
+ LogData lr_filteredLogData = new LogData<>();
+
+ for (String lt_logDataKey : this.getEntries().keySet()) {
+ if (this.get(lt_logDataKey).matches(in_filterKeyValues)) {
+ lr_filteredLogData.addEntry(this.get(lt_logDataKey));
+ }
+ }
+
+ return lr_filteredLogData;
+ }
+
}
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinition.java b/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinition.java
index cfeb57d..49d683b 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinition.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinition.java
@@ -55,6 +55,15 @@ public ParseDefinition(String in_title) {
definitionEntries = new ArrayList<>();
keyOrder = new ArrayList<>();
}
+
+ public ParseDefinition(ParseDefinition in_oldParseDefinition) {
+ super();
+ this.title = in_oldParseDefinition.title;
+ this.definitionEntries = in_oldParseDefinition.definitionEntries;
+ this.keyPadding = in_oldParseDefinition.keyPadding;
+ this.keyOrder = in_oldParseDefinition.keyOrder;
+ this.printOutPadding = in_oldParseDefinition.printOutPadding;
+ }
/**
* This method adds a definition entry to the definition entries of this
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinitionEntry.java b/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinitionEntry.java
index 7b45115..a879cfa 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinitionEntry.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/ParseDefinitionEntry.java
@@ -36,6 +36,15 @@ public ParseDefinitionEntry() {
}
+ public ParseDefinitionEntry(ParseDefinitionEntry in_oldDefinitionEntry) {
+ this.title = in_oldDefinitionEntry.title;
+ this.start = in_oldDefinitionEntry.start;
+ this.end = in_oldDefinitionEntry.end;
+ this.caseSensitive = in_oldDefinitionEntry.caseSensitive;
+ this.trimQuotes = in_oldDefinitionEntry.trimQuotes;
+ this.toPreserve = in_oldDefinitionEntry.toPreserve;
+ }
+
public String getTitle() {
return title;
}
@@ -145,7 +154,8 @@ public int fetchEndPosition(String in_stringValue) {
*
* Author : gandomi
*
- * @param in_logString The string/log line which we are searching through
+ * @param in_logString
+ * The string/log line which we are searching through
* @return A String that will be parsed by the subsequent
* ParseDefinitionEntry
*
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/StdLogEntry.java b/src/main/java/com/adobe/campaign/tests/logparser/StdLogEntry.java
index 647166d..205e5be 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/StdLogEntry.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/StdLogEntry.java
@@ -19,6 +19,8 @@
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
/**
* Abstract class for multiple definitions
@@ -28,7 +30,8 @@
*
*/
public abstract class StdLogEntry {
-
+ protected static Logger log = LogManager.getLogger();
+
private Integer frequence = 1;
private ParseDefinition parseDefinition;
@@ -40,10 +43,28 @@ public StdLogEntry(ParseDefinition in_definition) {
this.parseDefinition = in_definition;
}
+ public StdLogEntry(StdLogEntry in_oldLogEntry) {
+ super();
+ this.frequence = in_oldLogEntry.frequence;
+ this.parseDefinition = in_oldLogEntry.parseDefinition;
+ this.valuesMap = in_oldLogEntry.valuesMap;
+ }
+
public StdLogEntry() {
parseDefinition = new ParseDefinition("Created By Default");
}
+ /**
+ * Creates a clone of the current LogEntry. This requires that each child
+ * defines a copy constructor
+ *
+ * Author : gandomi
+ *
+ * @return A new constructed LogEntry Object
+ *
+ */
+ public abstract StdLogEntry copy();
+
/**
* Fetches a print out for listing purposed. It uses the header list as an
* index to fetch the correct order of the values
@@ -78,7 +99,8 @@ public String fetchPrintOut() {
public abstract Set fetchHeaders();
/**
- * Returns a set of objects you have defined for your log class. When using Genric Object no changes are made to it.
+ * Returns a set of objects you have defined for your log class. When using
+ * Genric Object no changes are made to it.
*
* Author : gandomi
*
@@ -104,7 +126,8 @@ protected void incrementUsage() {
*
* Author : gandomi
*
- * @param in_addedFrequence The amount we should add to the frequence
+ * @param in_addedFrequence
+ * The amount we should add to the frequence
*
*/
public void addFrequence(int in_addedFrequence) {
@@ -117,14 +140,16 @@ public Integer getFrequence() {
}
/**
- * @param frequence the frequence to set
+ * @param frequence
+ * the frequence to set
*/
protected void setFrequence(Integer frequence) {
this.frequence = frequence;
}
/**
- * @param valuesMap the valuesMap to set
+ * @param valuesMap
+ * the valuesMap to set
*/
protected void setValuesMap(Map valuesMap) {
this.valuesMap = valuesMap;
@@ -168,18 +193,43 @@ public void setValuesFromMap(Map in_valueMap) {
valuesMap.put(ParseDefinition.STD_DATA_KEY, this.makeKey());
}
-
-
+
public void put(String in_dataTitle, String in_value) {
this.fetchValueMap().put(in_dataTitle, in_value);
-
+
}
public Object get(String in_dataTitle) {
return this.fetchValueMap().get(in_dataTitle);
}
+
+ /**
+ * Given a map of <String,Object> this method returns true if all of the map
+ * values can be found in the values map of this StdLogEntry. If any of the
+ * keys cannot be found in the valueMap, we provide a warning
+ *
+ * Author : gandomi
+ *
+ * @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) {
-
+
+ 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.get(lt_filterKey).equals(in_filterMap.get(lt_filterKey))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public boolean equals(Object obj) {
@@ -207,7 +257,5 @@ public boolean equals(Object obj) {
return false;
return true;
}
-
-
}
diff --git a/src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionTitleException.java b/src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionException.java
similarity index 90%
rename from src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionTitleException.java
rename to src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionException.java
index fa72f41..e0b64df 100644
--- a/src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionTitleException.java
+++ b/src/main/java/com/adobe/campaign/tests/logparser/exceptions/IncorrectParseDefinitionException.java
@@ -11,7 +11,7 @@
*/
package com.adobe.campaign.tests.logparser.exceptions;
-public class IncorrectParseDefinitionTitleException extends Exception {
+public class IncorrectParseDefinitionException extends Exception {
/**
*
@@ -19,7 +19,7 @@ public class IncorrectParseDefinitionTitleException extends Exception {
private static final long serialVersionUID = 6462690423575172063L;
- public IncorrectParseDefinitionTitleException(String in_message) {
+ public IncorrectParseDefinitionException(String in_message) {
super(in_message);
}
diff --git a/src/test/java/com/adobe/campaign/tests/logparser/LogDataTest.java b/src/test/java/com/adobe/campaign/tests/logparser/LogDataTest.java
index 4991fc8..e47e447 100644
--- a/src/test/java/com/adobe/campaign/tests/logparser/LogDataTest.java
+++ b/src/test/java/com/adobe/campaign/tests/logparser/LogDataTest.java
@@ -13,6 +13,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.notNullValue;
@@ -29,7 +30,7 @@
import com.adobe.campaign.tests.logparser.GenericEntry;
import com.adobe.campaign.tests.logparser.ParseDefinition;
import com.adobe.campaign.tests.logparser.ParseDefinitionEntry;
-import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionTitleException;
+import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionException;
import com.adobe.campaign.tests.logparser.exceptions.StringParseException;
public class LogDataTest {
@@ -103,7 +104,7 @@ public void testHelloWorldSTDConstructor() {
}
@Test
- public void testSimpleAccessToDataMain() throws IncorrectParseDefinitionTitleException {
+ public void testSimpleAccessToDataMain() throws IncorrectParseDefinitionException {
ParseDefinition l_definition = new ParseDefinition("tmp");
final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ");
@@ -133,7 +134,7 @@ public void testSimpleAccessToDataMain() throws IncorrectParseDefinitionTitleExc
}
@Test
- public void testSimpleAccessToData() throws IncorrectParseDefinitionTitleException {
+ public void testSimpleAccessToData() throws IncorrectParseDefinitionException {
ParseDefinition l_definition = new ParseDefinition("tmp");
final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ");
@@ -156,8 +157,38 @@ public void testSimpleAccessToData() throws IncorrectParseDefinitionTitleExcepti
}
@Test
- public void testSimpleAccessToData_NegativeNoExistingKeyCube()
- throws IncorrectParseDefinitionTitleException {
+ public void testSimpleChangeOfData() throws IncorrectParseDefinitionException {
+
+ ParseDefinition l_definition = new ParseDefinition("tmp");
+ final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ");
+ l_definition.addEntry(l_parseDefinitionEntryKey);
+ l_definition.addEntry(new ParseDefinitionEntry("ZZZ"));
+ l_definition.addEntry(new ParseDefinitionEntry("BAU"));
+ l_definition.addEntry(new ParseDefinitionEntry("DAT"));
+ l_definition.defineKeys(l_parseDefinitionEntryKey);
+
+ GenericEntry l_inputData = new GenericEntry(l_definition);
+ l_inputData.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ LogData l_cubeData = new LogData<>(l_inputData);
+
+ assertThat("We should be able to get the values", l_cubeData.get("12", "ZZZ"), is(equalTo("14")));
+
+ l_cubeData.put("12", "ZZZ", "14,5");
+
+ assertThat("We should be able to get the values", l_cubeData.get("12", "ZZZ"), is(equalTo("14,5")));
+
+ assertThrows(IncorrectParseDefinitionException.class, () -> l_cubeData.put("1", "ZZZ", "14,5"));
+
+ assertThrows(IncorrectParseDefinitionException.class, () -> l_cubeData.put("12", "PPP", "14,5"));
+
+ }
+
+ @Test
+ public void testSimpleAccessToData_NegativeNoExistingKeyCube() throws IncorrectParseDefinitionException {
ParseDefinition l_definition = new ParseDefinition("tmp");
final ParseDefinitionEntry l_parseDefinitionEntryKey = new ParseDefinitionEntry("AAZ");
@@ -199,7 +230,7 @@ public void testSimpleAccessToData_NegativeBadTitleForEntryTitles() {
LogData l_cubeData = new LogData<>(l_inputData);
- assertThrows(IncorrectParseDefinitionTitleException.class, () -> l_cubeData.get("12", "NONo"));
+ assertThrows(IncorrectParseDefinitionException.class, () -> l_cubeData.get("12", "NONo"));
}
@@ -332,13 +363,14 @@ public void testAddEntryDuplicated() {
*
* Author : gandomi
*
- * @throws IncorrectParseDefinitionTitleException
- * @throws IllegalAccessException
- * @throws InstantiationException
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
*
*/
@Test
- public void testgroupBy() throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
+ public void testgroupBy()
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
ParseDefinition l_definition = new ParseDefinition("tmp");
@@ -373,9 +405,75 @@ public void testgroupBy() throws IncorrectParseDefinitionTitleException, Instant
l_cubeData.addEntry(l_inputData2);
l_cubeData.addEntry(l_inputData3);
- assertThrows(IncorrectParseDefinitionTitleException.class, () -> l_cubeData.groupBy("KAU",GenericEntry.class));
+ assertThrows(IncorrectParseDefinitionException.class,
+ () -> l_cubeData.groupBy("KAU", GenericEntry.class));
- LogData l_myCube = l_cubeData.groupBy("BAU",GenericEntry.class);
+ LogData l_myCube = l_cubeData.groupBy("BAU", GenericEntry.class);
+
+ assertThat(l_myCube.getEntries().values().iterator().next().getParseDefinition()
+ .getDefinitionEntries().size(), is(equalTo(1)));
+ assertThat(l_myCube.getEntries().values().iterator().next().getParseDefinition()
+ .getDefinitionEntries().get(0), is(equalTo(l_testParseDefinitionEntry)));
+
+ assertThat("We should have two entries in the new cube one fore 13 and the other for 113",
+ l_myCube.getEntries().size(), is(equalTo(2)));
+
+ assertThat("The entry BAU for 13 should be 2", l_myCube.get("13").getFrequence(), is(equalTo(2)));
+
+ assertThat("The entry BAU for 113 should be 1", l_myCube.get("113").getFrequence(), is(equalTo(1)));
+
+ }
+
+ /**
+ * Testing that we can do a group by
+ *
+ * Author : gandomi
+ *
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ *
+ */
+ @Test
+ public void testgroupBy_Default()
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
+
+ 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_testParseDefinitionEntry = new ParseDefinitionEntry("BAU");
+ l_definition.addEntry(l_testParseDefinitionEntry);
+ l_definition.addEntry(new ParseDefinitionEntry("DAT"));
+ l_definition.defineKeys(l_parseDefinitionEntryKey);
+
+ GenericEntry l_inputData = new GenericEntry(l_definition);
+ l_inputData.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ GenericEntry l_inputData2 = new GenericEntry(l_definition);
+ l_inputData2.fetchValueMap().put("AAZ", "112");
+ l_inputData2.fetchValueMap().put("ZZZ", "114");
+ l_inputData2.fetchValueMap().put("BAU", "113");
+ l_inputData2.fetchValueMap().put("DAT", "AAA");
+
+ GenericEntry l_inputData3 = new GenericEntry(l_definition);
+ l_inputData3.fetchValueMap().put("AAZ", "120");
+ l_inputData3.fetchValueMap().put("ZZZ", "14");
+ l_inputData3.fetchValueMap().put("BAU", "13");
+ l_inputData3.fetchValueMap().put("DAT", "AA");
+
+ LogData l_cubeData = new LogData();
+ l_cubeData.addEntry(l_inputData);
+ l_cubeData.addEntry(l_inputData2);
+ l_cubeData.addEntry(l_inputData3);
+
+ assertThrows(IncorrectParseDefinitionException.class, () -> l_cubeData.groupBy("KAU"));
+
+ LogData l_myCube = l_cubeData.groupBy("BAU");
assertThat(l_myCube.getEntries().values().iterator().next().getParseDefinition()
.getDefinitionEntries().size(), is(equalTo(1)));
@@ -396,13 +494,14 @@ public void testgroupBy() throws IncorrectParseDefinitionTitleException, Instant
*
* Author : gandomi
*
- * @throws IncorrectParseDefinitionTitleException
- * @throws IllegalAccessException
- * @throws InstantiationException
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
*
*/
@Test
- public void testMultipleGroupBy() throws IncorrectParseDefinitionTitleException, InstantiationException, IllegalAccessException {
+ public void testMultipleGroupBy()
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
ParseDefinition l_definition = new ParseDefinition("tmp");
@@ -456,7 +555,225 @@ public void testMultipleGroupBy() throws IncorrectParseDefinitionTitleException,
assertThat("The entry BAU for 13 should be 2", l_myCube.get("13#AA").getFrequence(), is(equalTo(2)));
- assertThat("The entry BAU for 113 should be 1", l_myCube.get("113#AAA").getFrequence(), is(equalTo(1)));
+ assertThat("The entry BAU for 113 should be 1", l_myCube.get("113#AAA").getFrequence(),
+ is(equalTo(1)));
+
+ }
+
+ /**
+ * Testing that we can do a group by with two values
+ *
+ * Author : gandomi
+ *
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ *
+ */
+ @Test
+ public void testMultipleGroupBy_Default()
+ throws IncorrectParseDefinitionException, InstantiationException, IllegalAccessException {
+
+ 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.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ GenericEntry l_inputData2 = new GenericEntry(l_definition);
+ l_inputData2.fetchValueMap().put("AAZ", "112");
+ l_inputData2.fetchValueMap().put("ZZZ", "114");
+ l_inputData2.fetchValueMap().put("BAU", "113");
+ l_inputData2.fetchValueMap().put("DAT", "AAA");
+
+ GenericEntry l_inputData3 = new GenericEntry(l_definition);
+ l_inputData3.fetchValueMap().put("AAZ", "120");
+ l_inputData3.fetchValueMap().put("ZZZ", "14");
+ l_inputData3.fetchValueMap().put("BAU", "13");
+ l_inputData3.fetchValueMap().put("DAT", "AA");
+
+ LogData l_cubeData = new LogData();
+ l_cubeData.addEntry(l_inputData);
+ l_cubeData.addEntry(l_inputData2);
+ l_cubeData.addEntry(l_inputData3);
+
+ LogData l_myCube = l_cubeData.groupBy(Arrays.asList("BAU", "DAT"));
+
+ final ParseDefinition l_gpParseDefinition = l_myCube.getEntries().values().iterator().next()
+ .getParseDefinition();
+ assertThat(l_gpParseDefinition.getDefinitionEntries().size(), is(equalTo(2)));
+
+ assertThat("The key since not defined is the parse definition entries in the order of the group by",
+ l_gpParseDefinition.fetchKeyOrder(),
+ Matchers.contains(l_testParseDefinitionEntryBAU, l_testParseDefinitionEntryDAT));
+
+ assertThat(l_gpParseDefinition.getDefinitionEntries().get(0),
+ is(equalTo(l_testParseDefinitionEntryBAU)));
+
+ assertThat("We should have two entries in the new cube one fore 13 and the other for 113",
+ l_myCube.getEntries().size(), is(equalTo(2)));
+
+ assertThat("The entry BAU for 13 should be 2", l_myCube.get("13#AA").getFrequence(), is(equalTo(2)));
+
+ assertThat("The entry BAU for 113 should be 1", l_myCube.get("113#AAA").getFrequence(),
+ is(equalTo(1)));
+
+ }
+
+ /**
+ * Testing that we can do a filter
+ *
+ * Author : gandomi
+ *
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ *
+ */
+ @Test
+ public void testFilter_Default() {
+
+ 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.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ GenericEntry l_inputData2 = new GenericEntry(l_definition);
+ l_inputData2.fetchValueMap().put("AAZ", "112");
+ l_inputData2.fetchValueMap().put("ZZZ", "114");
+ l_inputData2.fetchValueMap().put("BAU", "113");
+ l_inputData2.fetchValueMap().put("DAT", "AAA");
+
+ GenericEntry l_inputData3 = new GenericEntry(l_definition);
+ l_inputData3.fetchValueMap().put("AAZ", "120");
+ l_inputData3.fetchValueMap().put("ZZZ", "14");
+ l_inputData3.fetchValueMap().put("BAU", "13");
+ l_inputData3.fetchValueMap().put("DAT", "AA");
+
+ LogData l_cubeData = new LogData();
+ l_cubeData.addEntry(l_inputData);
+ l_cubeData.addEntry(l_inputData2);
+ l_cubeData.addEntry(l_inputData3);
+
+ Map l_filterProperties = new HashMap<>();
+ l_filterProperties.put("ZZZ", "114");
+ LogData l_myCube = l_cubeData.filter(l_filterProperties);
+
+ assertThat("We should have found one entry", l_myCube.getEntries().size(), is(equalTo(1)));
+
+ assertThat("We should have found the correct entry", l_myCube.getEntries().containsKey("112"));
+
+ //Adding another filter
+ l_filterProperties.put("DAT", "AAA");
+
+ LogData l_myCube2 = l_cubeData.filter(l_filterProperties);
+
+ 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
+ l_filterProperties.put("DAT", "AA");
+
+ LogData l_myCube3 = l_cubeData.filter(l_filterProperties);
+
+ assertThat("We should have found one entry", l_myCube3.getEntries().size(), is(equalTo(0)));
+
+ }
+
+ /**
+ * Testing that we can do a filter using multiple fields
+ *
+ * Author : gandomi
+ *
+ * @throws IncorrectParseDefinitionException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ *
+ */
+ @Test
+ public void testFilter_Multi() {
+
+ 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.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ GenericEntry l_inputData2 = new GenericEntry(l_definition);
+ l_inputData2.fetchValueMap().put("AAZ", "112");
+ l_inputData2.fetchValueMap().put("ZZZ", "114");
+ l_inputData2.fetchValueMap().put("BAU", "113");
+ l_inputData2.fetchValueMap().put("DAT", "AAA");
+
+ GenericEntry l_inputData3 = new GenericEntry(l_definition);
+ l_inputData3.fetchValueMap().put("AAZ", "120");
+ l_inputData3.fetchValueMap().put("ZZZ", "14");
+ l_inputData3.fetchValueMap().put("BAU", "13");
+ l_inputData3.fetchValueMap().put("DAT", "AAA");
+
+ LogData l_cubeData = new LogData();
+ l_cubeData.addEntry(l_inputData);
+ 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");
+
+ LogData l_myCube = l_cubeData.filter(l_filterProperties);
+
+ assertThat("We should have found one entry", l_myCube.getEntries().size(), is(equalTo(2)));
+
+ assertThat("We should have found the correct entry", l_myCube.getEntries().containsKey("120"));
+
+ l_filterProperties.remove("ZZZ");
+ LogData l_myCube2 = l_cubeData.filter(l_filterProperties);
+
+ assertThat("We should have found one entry", l_myCube2.getEntries().size(), is(equalTo(2)));
+
+ assertThat("We should have found the correct entry", l_myCube2.getEntries().containsKey("120"));
+
+ l_filterProperties.put("DAT", "AAA");
+ LogData l_myCube3 = l_cubeData.filter(l_filterProperties);
+
+ assertThat("We should have found one entry", l_myCube3.getEntries().size(), is(equalTo(1)));
+
+ assertThat("We should have found the correct entry", l_myCube3.getEntries().containsKey("120"));
}
diff --git a/src/test/java/com/adobe/campaign/tests/logparser/ParseDefinitionTests.java b/src/test/java/com/adobe/campaign/tests/logparser/ParseDefinitionTests.java
new file mode 100644
index 0000000..a8f77dd
--- /dev/null
+++ b/src/test/java/com/adobe/campaign/tests/logparser/ParseDefinitionTests.java
@@ -0,0 +1,171 @@
+/**
+ * MIT License
+ *
+ * © Copyright 2020 Adobe. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package com.adobe.campaign.tests.logparser;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import org.testng.annotations.Test;
+
+public class ParseDefinitionTests {
+
+ @Test
+ public void testcopyConstructorParseDefinitionEntry() {
+
+ //Create a parse definition
+ ParseDefinitionEntry l_verbDefinition = new ParseDefinitionEntry();
+
+ l_verbDefinition.setTitle("verb");
+ l_verbDefinition.setStart("\"");
+ l_verbDefinition.setEnd(" /");
+
+ ParseDefinitionEntry l_apiDefinition = new ParseDefinitionEntry();
+
+ l_apiDefinition.setTitle("path");
+ l_apiDefinition.setStart(" /rest/head/");
+ l_apiDefinition.setEnd(" ");
+
+ ParseDefinitionEntry l_verbDefinition2 = new ParseDefinitionEntry(l_verbDefinition);
+
+ assertThat("The two entries should be the same", l_verbDefinition, equalTo(l_verbDefinition2));
+
+ ParseDefinitionEntry l_apDefinition2 = new ParseDefinitionEntry(l_apiDefinition);
+
+ assertThat("The two new Definition entries should be different", l_apDefinition2,
+ not(equalTo(l_verbDefinition2)));
+
+ }
+
+
+ @Test
+ public void testcopyConstructorParseDefinition() {
+
+ //Create a parse definition
+ ParseDefinitionEntry l_verbDefinition = new ParseDefinitionEntry();
+
+ l_verbDefinition.setTitle("verb");
+ l_verbDefinition.setStart("\"");
+ l_verbDefinition.setEnd(" /");
+
+ ParseDefinitionEntry l_apiDefinition = new ParseDefinitionEntry();
+
+ l_apiDefinition.setTitle("path");
+ l_apiDefinition.setStart(" /rest/head/");
+ l_apiDefinition.setEnd(" ");
+
+ ParseDefinition l_parseDefinition = new ParseDefinition("rest calls");
+ l_parseDefinition.addEntry(l_apiDefinition);
+ l_parseDefinition.addEntry(l_verbDefinition);
+
+ ParseDefinition l_newParseDefinition = new ParseDefinition(l_parseDefinition);
+
+ assertThat("The created parse definitions should be the same as the old one", l_parseDefinition, equalTo(l_newParseDefinition));
+
+ }
+
+ @Test
+ public void testParseDefinitionEntryEquals1() {
+ ParseDefinitionEntry l_pd1 = new ParseDefinitionEntry("A");
+ ParseDefinitionEntry l_pd2 = new ParseDefinitionEntry("A");
+
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(new GenericEntry())));
+
+ l_pd1.setCaseSensitive(false);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd1.setCaseSensitive(true);
+ l_pd2.setEnd("D");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd1.setEnd("B");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setEnd("B");
+ l_pd2.setStart("D");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd1.setStart("B");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setStart("B");
+
+ l_pd1.setTitle(null);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setTitle(null);
+ assertThat("The two classes should not be equal", l_pd1, equalTo(l_pd2));
+
+ l_pd2.setTitle("D");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd1.setTitle("B");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setTitle("B");
+
+ l_pd2.setToPreserve(false);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setToPreserve(true);
+
+ l_pd2.setTrimQuotes(true);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ assertThat("The hashed should be different", l_pd1.hashCode(), not(equalTo(l_pd2.hashCode())));
+
+ l_pd2.setTrimQuotes(false);
+ assertThat("The two classes should now be equal", l_pd1, is(equalTo(l_pd2)));
+ assertThat("The hashed should be the same", l_pd1.hashCode(), is(equalTo(l_pd2.hashCode())));
+
+ }
+
+ @Test
+ public void testParseDefinitionEquals1() {
+ ParseDefinition l_pd1 = new ParseDefinition("A");
+ ParseDefinition l_pd2 = new ParseDefinition("A");
+
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(new GenericEntry())));
+
+ l_pd1.setDefinitionEntries(null);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setDefinitionEntries(null);
+ assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
+
+ }
+
+ @Test
+ public void testParseDefinitionEquals2() {
+ ParseDefinition l_pd1 = new ParseDefinition("A");
+ ParseDefinition l_pd2 = new ParseDefinition("A");
+ l_pd2.addEntry(new ParseDefinitionEntry("B"));
+
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd1.addEntry(new ParseDefinitionEntry("B"));
+ assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
+
+ l_pd1.setTitle(null);
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ l_pd2.setTitle(null);
+ assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
+
+ l_pd1.setTitle("A");
+ l_pd2.setTitle("B");
+ assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
+
+ }
+
+}
diff --git a/src/test/java/com/adobe/campaign/tests/logparser/ParseTesting.java b/src/test/java/com/adobe/campaign/tests/logparser/ParseTesting.java
index d735727..7b08c0f 100644
--- a/src/test/java/com/adobe/campaign/tests/logparser/ParseTesting.java
+++ b/src/test/java/com/adobe/campaign/tests/logparser/ParseTesting.java
@@ -964,98 +964,4 @@ public void testToPreserve() throws InstantiationException, IllegalAccessExcepti
assertThat("We should have values", l_parseResult.size(), is(equalTo(3)));
}
- @Test
- public void testParseDefinitionEquals1() {
- ParseDefinition l_pd1 = new ParseDefinition("A");
- ParseDefinition l_pd2 = new ParseDefinition("A");
-
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(new GenericEntry())));
-
- l_pd1.setDefinitionEntries(null);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setDefinitionEntries(null);
- assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
-
- }
-
- @Test
- public void testParseDefinitionEquals2() {
- ParseDefinition l_pd1 = new ParseDefinition("A");
- ParseDefinition l_pd2 = new ParseDefinition("A");
- l_pd2.addEntry(new ParseDefinitionEntry("B"));
-
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd1.addEntry(new ParseDefinitionEntry("B"));
- assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
-
- l_pd1.setTitle(null);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setTitle(null);
- assertThat("The two classes should be equal", l_pd1, is(equalTo(l_pd2)));
-
- l_pd1.setTitle("A");
- l_pd2.setTitle("B");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- }
-
- @Test
- public void testParseDefinitionEntryEquals1() {
- ParseDefinitionEntry l_pd1 = new ParseDefinitionEntry("A");
- ParseDefinitionEntry l_pd2 = new ParseDefinitionEntry("A");
-
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(new GenericEntry())));
-
- l_pd1.setCaseSensitive(false);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd1.setCaseSensitive(true);
- l_pd2.setEnd("D");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd1.setEnd("B");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setEnd("B");
- l_pd2.setStart("D");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd1.setStart("B");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setStart("B");
-
- l_pd1.setTitle(null);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setTitle(null);
- assertThat("The two classes should not be equal", l_pd1, equalTo(l_pd2));
-
- l_pd2.setTitle("D");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd1.setTitle("B");
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setTitle("B");
-
- l_pd2.setToPreserve(false);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- l_pd2.setToPreserve(true);
-
- l_pd2.setTrimQuotes(true);
- assertThat("The two classes should not be equal", l_pd1, not(equalTo(l_pd2)));
-
- assertThat("The hashed should be different", l_pd1.hashCode(),not(equalTo(l_pd2.hashCode())));
-
- l_pd2.setTrimQuotes(false);
- assertThat("The two classes should now be equal", l_pd1, is(equalTo(l_pd2)));
- assertThat("The hashed should be the same", l_pd1.hashCode(),is(equalTo(l_pd2.hashCode())));
-
- }
-
}
diff --git a/src/test/java/com/adobe/campaign/tests/logparser/StdLogEntryTests.java b/src/test/java/com/adobe/campaign/tests/logparser/StdLogEntryTests.java
index f543880..47cd1fb 100644
--- a/src/test/java/com/adobe/campaign/tests/logparser/StdLogEntryTests.java
+++ b/src/test/java/com/adobe/campaign/tests/logparser/StdLogEntryTests.java
@@ -17,87 +17,159 @@
import static org.hamcrest.Matchers.not;
import java.util.HashMap;
-
+import java.util.Map;
import org.testng.annotations.Test;
public class StdLogEntryTests {
@Test
- public void testSimplePut() {
-
+ public void testSimplePut() {
+
GenericEntry l_inputData = new GenericEntry();
l_inputData.fetchValueMap().put("AAZ", "12");
-
+
GenericEntry l_inputData2 = new GenericEntry();
l_inputData2.put("AAZ", "12");
assertThat(l_inputData, is(equalTo(l_inputData2)));
}
-
+
@Test
- public void testSimpleGet() {
-
-
+ public void testSimpleGet() {
+
GenericEntry l_inputData2 = new GenericEntry();
l_inputData2.put("AAZ", "12");
assertThat(l_inputData2.get("AAZ"), is(equalTo("12")));
}
-
+
@Test
public void testEqualsSimple() {
StdLogEntry l_myEntry = new GenericEntry();
-
+
StdLogEntry l_myEntry2 = new GenericEntry();
-
+
assertThat("Both should be equal", l_myEntry, is(equalTo(l_myEntry)));
assertThat("Both should be equal", l_myEntry, is(equalTo(l_myEntry2)));
-
+
assertThat("One being null is not allowed", l_myEntry, not(equalTo(null)));
-
- assertThat("One bein null is not allowed", l_myEntry, not(equalTo(new LogData<>())));
-
+
+ assertThat("One bein null is not allowed", l_myEntry, not(equalTo(new LogData<>())));
+
l_myEntry.setFrequence(null);
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
-
-
+
l_myEntry2.setFrequence(null);
assertThat("Both should be equal", l_myEntry, equalTo(l_myEntry2));
l_myEntry.setFrequence(1);
-
+
l_myEntry2.setFrequence(2);
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
l_myEntry2.setFrequence(1);
-
+
l_myEntry.setParseDefinition(null);
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
-
+
l_myEntry2.setParseDefinition(null);
assertThat("Both should be equal", l_myEntry, equalTo(l_myEntry2));
-
+
l_myEntry.setParseDefinition(new ParseDefinition("A"));
l_myEntry2.setParseDefinition(new ParseDefinition("B"));
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
-
+
l_myEntry.setParseDefinition(new ParseDefinition("B"));
-
-
+
l_myEntry.setValuesMap(null);
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
-
+
l_myEntry2.setValuesMap(null);
assertThat("Both should be equal", l_myEntry, equalTo(l_myEntry2));
-
+
l_myEntry2.setValuesMap(new HashMap());
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
-
+
l_myEntry.setValuesMap(new HashMap<>());
l_myEntry.put("A", "B");
-
+
l_myEntry2.put("C", "D");
-
+
assertThat("Both should not be equal", l_myEntry, not(equalTo(l_myEntry2)));
+
+ }
+
+ @Test
+ public void testCopyConstructor() {
+ 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.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ GenericEntry l_newEntry = l_inputData.copy();
+
+ assertThat("The new entry should be the same as the old one", l_inputData, equalTo(l_newEntry));
+
+ GenericEntry l_inputData2 = new GenericEntry(l_definition);
+ l_inputData2.fetchValueMap().put("AAZ", "12");
+ l_inputData2.fetchValueMap().put("ZZZ", "34");
+ l_inputData2.fetchValueMap().put("BAU", "14");
+ l_inputData2.fetchValueMap().put("DAT", "DDD");
+
+ GenericEntry l_newEntry2 = l_inputData2.copy();
+ assertThat("The new entry should be the same as the old one", l_inputData2, equalTo(l_newEntry2));
+
+ assertThat("The new entries should not be the same", l_newEntry2, not(equalTo(l_newEntry)));
+ l_newEntry2.fetchValueMap().put("BAU", "15");
+ assertThat("The new entry should no longer be the same as the old one", l_inputData2, equalTo(l_newEntry2));
+
+
+ }
+
+ @Test
+ public void testMatches() {
+ 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.fetchValueMap().put("AAZ", "12");
+ l_inputData.fetchValueMap().put("ZZZ", "14");
+ l_inputData.fetchValueMap().put("BAU", "13");
+ l_inputData.fetchValueMap().put("DAT", "AA");
+
+ Map l_filterMap = new HashMap<>();
+ l_filterMap.put("BAU", "13");
+ assertThat("Matches should be true", l_inputData.matches(l_filterMap));
+
+ Map l_filterMap2 = new HashMap<>();
+ l_filterMap2.put("NOTBAU", "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");
+ assertThat("We should not have a match if the entry value is incorrect",
+ !l_inputData.matches(l_filterMap3));
+
}
}