From 9e77cac3fb7a7fd2b1789a413bd21d33597be6e7 Mon Sep 17 00:00:00 2001 From: baubakg Date: Fri, 19 Jul 2024 18:52:10 +0200 Subject: [PATCH] Fixed issue #148 groupBy did not work well with SDK --- .../tests/logparser/core/LogData.java | 7 +++-- .../tests/logparser/core/StdLogEntry.java | 2 +- .../tests/logparser/core/LogDataTest.java | 6 ++-- .../tests/logparser/core/SDKTests.java | 31 +++++++++++++++++-- 4 files changed, 37 insertions(+), 9 deletions(-) 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 8e97554..85d4446 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 @@ -196,7 +196,7 @@ public boolean equals(Object obj) { * @return a new LogData Object containing the groupBy values * @throws IncorrectParseDefinitionException If the key is not in the ParseDefinitions of the Log data entry */ - public LogData groupBy(String in_parseDefinitionEntryKey, + LogData groupBy(String in_parseDefinitionEntryKey, Class in_transformationClass) throws IncorrectParseDefinitionException { @@ -215,7 +215,7 @@ public LogData groupBy(String in_parseDefinitionEntry * @return a new LogData Object containing the groupBy values * @throws IncorrectParseDefinitionException If the key is not in the ParseDefinitions of the Log data entry */ - public LogData groupBy(List in_parseDefinitionEntryKeyList, + LogData groupBy(List in_parseDefinitionEntryKeyList, Class in_transformationClass) throws IncorrectParseDefinitionException { LogData lr_cubeData = new LogData<>(); @@ -240,7 +240,8 @@ public LogData groupBy(List in_parseDefinitio lt_cubeEntry.setParseDefinition(l_cubeDefinition); for (String lt_parseDefinitionEntryKey : in_parseDefinitionEntryKeyList) { - if (!lt_entry.getParseDefinition().fetchHeaders().contains(lt_parseDefinitionEntryKey)) { + //Merge with original headers + if (!lt_entry.fetchHeaders().contains(lt_parseDefinitionEntryKey)) { throw new IncorrectParseDefinitionException("The given header name " + lt_parseDefinitionEntryKey + " was not among the stored data"); } 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 d846d5d..76dc10b 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 @@ -206,7 +206,7 @@ public void put(String in_dataTitle, String in_value) { } public Object get(String in_dataTitle) { - return this.getValuesMap().get(in_dataTitle); + return this.fetchValueMap().get(in_dataTitle); } /** 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 f120c94..1f78e32 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 @@ -419,9 +419,9 @@ public void testgroupBy() l_cubeData.addEntry(l_inputData3); assertThrows(IncorrectParseDefinitionException.class, - () -> l_cubeData.groupBy("KAU", GenericEntry.class)); + () -> l_cubeData.groupBy("KAU")); - LogData l_myCube = l_cubeData.groupBy("BAU", GenericEntry.class); + LogData l_myCube = l_cubeData.groupBy("BAU"); assertThat(l_myCube.getEntries().values().iterator().next().getParseDefinition() .getDefinitionEntries().size(), is(equalTo(1))); @@ -531,7 +531,7 @@ public void testMultipleGroupBy() l_cubeData.addEntry(l_inputData2); l_cubeData.addEntry(l_inputData3); - LogData l_myCube = l_cubeData.groupBy(Arrays.asList("BAU", "DAT"), GenericEntry.class); + LogData l_myCube = l_cubeData.groupBy(Arrays.asList("BAU", "DAT")); final ParseDefinition l_gpParseDefinition = l_myCube.getEntries().values().iterator().next() .getParseDefinition(); diff --git a/src/test/java/com/adobe/campaign/tests/logparser/core/SDKTests.java b/src/test/java/com/adobe/campaign/tests/logparser/core/SDKTests.java index 9219d07..3cbcd96 100644 --- a/src/test/java/com/adobe/campaign/tests/logparser/core/SDKTests.java +++ b/src/test/java/com/adobe/campaign/tests/logparser/core/SDKTests.java @@ -13,6 +13,7 @@ import com.adobe.campaign.tests.logparser.data.SDKCasePrivateDefConstructor; import com.adobe.campaign.tests.logparser.data.SDKCaseNoDefConstructor; import com.adobe.campaign.tests.logparser.data.SDKCaseSTD; +import com.adobe.campaign.tests.logparser.exceptions.IncorrectParseDefinitionException; import com.adobe.campaign.tests.logparser.exceptions.LogDataExportToFileException; import com.adobe.campaign.tests.logparser.exceptions.LogParserSDKDefinitionException; import com.adobe.campaign.tests.logparser.exceptions.StringParseException; @@ -70,8 +71,34 @@ public void testSimpleLogACC_SDK() assertThat("We should have a file name", l_entries.getEntries().values().iterator().next().getFileName(), is(equalTo("useCase1.log"))); - //l_entries.exportLogDataToCSV(l_entries.getEntries().values().iterator().next().fetchHeaders(), - // "./z.csv"); + } + + @Test + public void testSimpleLogACC_groupBy_SDK() + throws StringParseException, LogDataExportToFileException, IncorrectParseDefinitionException { + + ParseDefinition l_pDefinition = getTestParseDefinition(); + l_pDefinition.setStoreFileName(true); + + String l_file = "src/test/resources/sdk/"; + + LogData l_entries = LogDataFactory.generateLogData(l_file, "*.log", l_pDefinition, + SDKCaseSTD.class); + + + assertThat("We should have a correct number of errors", l_entries.getEntries().size(), is(equalTo(14))); + AssertLogData.assertLogContains(l_entries, "errorMessage", + "The HTTP query returned a 'Internal Server Error' type error (500) (iRc=16384)"); + + assertThat("We should have a file name", l_entries.getEntries().values().iterator().next().getFileName(), + is(equalTo("useCase1.log"))); + + LogData l_gbEntry = l_entries.groupBy("fileName"); + + assertThat("We should get one entry", l_gbEntry.getEntries().size(), is(equalTo(1))); + assertThat("The entry should have the value useCase1.log", + l_gbEntry.getEntries().values().iterator().next().getValuesMap().get("fileName"), + is(equalTo("useCase1.log"))); } @Test