Skip to content

Commit

Permalink
Fixed issue #148 groupBy did not work well with SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Jul 19, 2024
1 parent cde3efd commit 9e77cac
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <U extends StdLogEntry> LogData<U> groupBy(String in_parseDefinitionEntryKey,
<U extends StdLogEntry> LogData<U> groupBy(String in_parseDefinitionEntryKey,
Class<U> in_transformationClass)
throws IncorrectParseDefinitionException {

Expand All @@ -215,7 +215,7 @@ public <U extends StdLogEntry> LogData<U> 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 <U extends StdLogEntry> LogData<U> groupBy(List<String> in_parseDefinitionEntryKeyList,
<U extends StdLogEntry> LogData<U> groupBy(List<String> in_parseDefinitionEntryKeyList,
Class<U> in_transformationClass)
throws IncorrectParseDefinitionException {
LogData<U> lr_cubeData = new LogData<>();
Expand All @@ -240,7 +240,8 @@ public <U extends StdLogEntry> LogData<U> groupBy(List<String> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericEntry> l_myCube = l_cubeData.groupBy("BAU", GenericEntry.class);
LogData<GenericEntry> l_myCube = l_cubeData.groupBy("BAU");

assertThat(l_myCube.getEntries().values().iterator().next().getParseDefinition()
.getDefinitionEntries().size(), is(equalTo(1)));
Expand Down Expand Up @@ -531,7 +531,7 @@ public void testMultipleGroupBy()
l_cubeData.addEntry(l_inputData2);
l_cubeData.addEntry(l_inputData3);

LogData<GenericEntry> l_myCube = l_cubeData.groupBy(Arrays.asList("BAU", "DAT"), GenericEntry.class);
LogData<GenericEntry> l_myCube = l_cubeData.groupBy(Arrays.asList("BAU", "DAT"));

final ParseDefinition l_gpParseDefinition = l_myCube.getEntries().values().iterator().next()
.getParseDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SDKCaseSTD> 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<GenericEntry> 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
Expand Down

0 comments on commit 9e77cac

Please sign in to comment.