Skip to content

Commit

Permalink
#154 added test for enrichment in SDK, and corrected the test SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Aug 6, 2024
1 parent 3d4099e commit 1c19f53
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ public void enrichData(Map<String, Matcher> in_queryMap, String in_entryName, St

//Iterate over the entries
getEntries().entrySet().stream().filter(e -> e.getValue().matches(in_queryMap)).forEach(e -> {
e.getValue().getValuesMap().put(in_entryName, in_entryValue);
e.getValue().put(in_entryName, in_entryValue);
});
//for each entry meeting the querymap enrich with the given value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public void put(String in_dataTitle, String in_value) {
}

public Object get(String in_dataTitle) {
return this.fetchValueMap().get(in_dataTitle);

return this.fetchValueMap().containsKey(in_dataTitle) ? this.fetchValueMap().get(in_dataTitle) : "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
*/
package com.adobe.campaign.tests.logparser.core;

import com.adobe.campaign.tests.logparser.data.SDKCaseSTD;
import com.adobe.campaign.tests.logparser.exceptions.StringParseException;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.testng.Assert.assertThrows;

public class EnrichmentTests {
Expand All @@ -40,7 +45,7 @@ public void testSimpleEnrichment() {
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());
assertThat(l_cubeData.get("112").get("TIT"), Matchers.equalTo(""));

l_cubeData.exportLogDataToHTML("dsd", "enriched");
}
Expand All @@ -61,7 +66,7 @@ public void testDoubleEnrichment() {
l_cubeData.enrichData(l_queryMap, "TIT", "TAT");

Map<String, Matcher> l_queryMap2 = new HashMap<>();
l_queryMap2.put("TIT", Matchers.nullValue());
l_queryMap2.put("TIT", Matchers.equalTo(""));

l_cubeData.enrichData(l_queryMap2, "TIT", "TUT");

Expand All @@ -74,7 +79,29 @@ public void testDoubleEnrichment() {
l_cubeData.exportLogDataToHTML("dsd", "enriched");
}

@Test
public void testDoubleEnrichment_SDK() throws StringParseException {

ParseDefinition l_pDefinition = SDKTests.getTestParseDefinition();
l_pDefinition.setStoreFileName(true);

String l_file = "src/test/resources/sdk/useCase1.log";

LogData<SDKCaseSTD> l_entries = LogDataFactory.generateLogData(Arrays.asList(l_file), l_pDefinition,
SDKCaseSTD.class);

Map<String, Matcher> l_queryMap = Map.of("code", Matchers.startsWith("INT"));
l_entries.enrichData(l_queryMap, "category", "GREAT");

Map<String, Matcher> l_queryMap2 = Map.of("code", Matchers.startsWith("SOP"));
l_entries.enrichData(l_queryMap2, "category", "AVERAGE");


assertThat("We should have the correct value", l_entries.get("INT-150612").get("category"), is(equalTo("GREAT")));
assertThat("We should have the correct value", l_entries.get("SOP-338921").get("category"), is(equalTo("AVERAGE")));
//assertThat("We should have the correct value", l_entries.get("SOP-338921").get("category"), is(equalTo("AVERAGE")));

}

private static LogData<GenericEntry> fetchTestLogEntry() {
ParseDefinition l_definition = new ParseDefinition("tmp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
import com.adobe.campaign.tests.logparser.exceptions.LogDataExportToFileException;
import com.adobe.campaign.tests.logparser.exceptions.LogParserSDKDefinitionException;
import com.adobe.campaign.tests.logparser.exceptions.StringParseException;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.util.Arrays;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class SDKTests {

private static ParseDefinition getTestParseDefinition() {
static ParseDefinition getTestParseDefinition() {
ParseDefinitionEntry l_timeStamp = new ParseDefinitionEntry();
l_timeStamp.setTitle("timeStamp");
l_timeStamp.setStartStartOfLine();
Expand Down Expand Up @@ -192,6 +195,4 @@ public void testSimpleLogACC_SDK_negativePrivateConstructor() {

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public Map<String, Object> fetchValueMap() {
lr_map.put("code", this.makeKey());
lr_map.put("errorMessage", this.errorMessage);
lr_map.put(StdLogEntry.STD_DATA_FREQUENCE, this.getFrequence());
//lr_map.addAll(this.valuesMap);
getValuesMap().forEach(lr_map::putIfAbsent);

return lr_map;
}
Expand Down

0 comments on commit 1c19f53

Please sign in to comment.