Skip to content

Commit

Permalink
#154 added test for enrichment of timeZone data
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Aug 6, 2024
1 parent 1c19f53 commit 30e5bf8
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,16 @@ public void enrichData(Map<String, Matcher> in_queryMap, String in_entryName, St
e.getValue().put(in_entryName, in_entryValue);
});
}

/**
* Enriches the log data which have not been set with the given values
* @param in_entryName The name of the entry to be added
* @param in_entryValue The value of the entry to be added
*/
public void enrichUnset(String in_entryName, String in_entryValue) {
Map<String, Matcher> l_unsetSearchQuery = new HashMap<>();
l_unsetSearchQuery.put(in_entryName, Matchers.equalTo(""));

this.enrichData(l_unsetSearchQuery, in_entryName, in_entryValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
*/
package com.adobe.campaign.tests.logparser.core;

import com.adobe.campaign.tests.logparser.data.SDKCase2;
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.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -79,6 +82,35 @@ public void testDoubleEnrichment() {
l_cubeData.exportLogDataToHTML("dsd", "enriched");
}

@Test
public void testDoubleEnrichment_updateUnset() {
LogData<GenericEntry> 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<String, Matcher> l_queryMap = new HashMap<>();
l_queryMap.put("AAZ", Matchers.startsWith("12"));

l_cubeData.enrichData(l_queryMap, "TIT", "TAT");

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

l_cubeData.enrichUnset("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");
}

@Test
public void testDoubleEnrichment_SDK() throws StringParseException {

Expand All @@ -99,8 +131,32 @@ public void testDoubleEnrichment_SDK() throws StringParseException {

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")));
}

@Test
public void testDoubleEnrichment_SDK_timeBased() throws StringParseException {

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

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

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

l_entries.exportLogDataToHTML("", "time");

ZonedDateTime start = ZonedDateTime.parse("2024-06-13T03:00:10.727Z", DateTimeFormatter.ISO_ZONED_DATE_TIME);
ZonedDateTime end = ZonedDateTime.parse("2024-06-13T11:00:19.727Z", DateTimeFormatter.ISO_ZONED_DATE_TIME);


Map<String, Matcher> l_queryMap = Map.of("timeOfLog", Matchers.allOf(Matchers.greaterThanOrEqualTo(start), Matchers.lessThanOrEqualTo(end)));
l_entries.enrichData(l_queryMap, "test", "Test1");

assertThat("We should have the correct value", l_entries.get("INT-150612").get("test"), is(equalTo("Test1")));
assertThat("We should have the correct value", l_entries.get("SOP-338921").get("test"), is(equalTo("")));
assertThat("We should have the correct value", l_entries.get("INT-158912").get("test"), is(equalTo("")));
assertThat("We should have the correct value", l_entries.get("WEB-530007").get("test"), is(equalTo("Test1")));
}

private static LogData<GenericEntry> fetchTestLogEntry() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2022 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it.
*/
package com.adobe.campaign.tests.logparser.data;

import com.adobe.campaign.tests.logparser.core.StdLogEntry;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

public class SDKCase2 extends StdLogEntry {
String code;
String errorMessage;
ZonedDateTime timeOfLog;

public SDKCase2() {
}

public SDKCase2(SDKCase2 accstdErrors) {
this.code = accstdErrors.code;
this.errorMessage = accstdErrors.errorMessage;
}

@Override
public String makeKey() {
return code;
}

@Override
public SDKCase2 copy() {
return new SDKCase2(this);
}

@Override
public Set<String> fetchHeaders() {
Set<String> lr_headerSet = new LinkedHashSet<>();
lr_headerSet.addAll(Arrays.asList(StdLogEntry.STD_DATA_FILE_PATH, StdLogEntry.STD_DATA_FILE_NAME,"code", "errorMessage","timeOfLog", "frequence"));
return lr_headerSet;
}

@Override
public Map<String, Object> fetchValueMap() {
Map<String, Object> lr_map = new HashMap<>();
lr_map.put(StdLogEntry.STD_DATA_FILE_PATH, this.getFilePath());
lr_map.put(StdLogEntry.STD_DATA_FILE_NAME, this.getFileName());
lr_map.put("code", this.makeKey());
lr_map.put("errorMessage", this.errorMessage);
lr_map.put(StdLogEntry.STD_DATA_FREQUENCE, this.getFrequence());
lr_map.put("timeOfLog", this.timeOfLog);

getValuesMap().forEach(lr_map::putIfAbsent);

return lr_map;
}

@Override
public void setValuesFromMap(Map<String, String> in_valueMap) {
super.setValuesFromMap(in_valueMap);

var errorCode = in_valueMap.get("errorContent").split(" ")[0];
this.code = errorCode.contains("-") ? errorCode : in_valueMap.get("errorContent");
this.errorMessage = errorCode.contains("-") ? in_valueMap.get("errorContent")
.substring(in_valueMap.get("errorContent").indexOf(" ") + 1) : in_valueMap.get("errorContent");

this.timeOfLog = ZonedDateTime.parse(in_valueMap.get("timeStamp"), DateTimeFormatter.ISO_ZONED_DATE_TIME);

}

protected List<String> fetchValuesAsList() {

return this.fetchHeaders().stream().map(e -> fetchValueMap().get(e).toString()).collect(Collectors.toList());
}

}

0 comments on commit 30e5bf8

Please sign in to comment.