You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2020/11/16 14:18:09 UTC
[unomi] branch unomi-1.5.x updated: UNOMI-400 More complete
hardcoded property accessor implementation
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch unomi-1.5.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/unomi-1.5.x by this push:
new cd8ad37 UNOMI-400 More complete hardcoded property accessor implementation
cd8ad37 is described below
commit cd8ad37e1af7ad9e630f81d616b43810170c5376
Author: Serge Huber <sh...@jahia.com>
AuthorDate: Mon Nov 16 14:24:53 2020 +0100
UNOMI-400 More complete hardcoded property accessor implementation
---
.../conditions/PropertyConditionEvaluator.java | 374 +++++++++++++--------
.../conditions/PropertyConditionEvaluatorTest.java | 74 ++--
2 files changed, 285 insertions(+), 163 deletions(-)
diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluator.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluator.java
index 90a94fa..f38d38a 100644
--- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluator.java
+++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluator.java
@@ -275,7 +275,7 @@ public class PropertyConditionEvaluator implements ConditionEvaluator {
if (useOGNLScripting) {
return getOGNLPropertyValue(item, expression);
} else {
- logger.warn("OGNL Off. Expression not evaluated : {}", expression);
+ logger.warn("OGNL Off. Expression not evaluated on item {} : {}", item.getClass().getName(), expression);
return null;
}
}
@@ -283,140 +283,7 @@ public class PropertyConditionEvaluator implements ConditionEvaluator {
protected Object getHardcodedPropertyValue(Item item, String expression) {
// the following are optimizations to avoid using the expressions that are slower. The main objective here is
// to avoid the most used expression that may also trigger calls to the Java Reflection API.
- if (item instanceof Event) {
- Event event = (Event) item;
- if (expression.startsWith("properties.")) {
- return getNestedPropertyValue(expression.substring("properties.".length()), event.getProperties());
- }
- if ("target.itemId".equals(expression)) {
- return event.getTarget().getItemId();
- }
- if (expression.startsWith("target.properties.")) {
- String expressionPart = expression.substring("target.properties.".length());
- Item targetItem = event.getTarget();
- if (targetItem instanceof CustomItem) {
- return getNestedPropertyValue(expressionPart, ((CustomItem) targetItem).getProperties());
- } else if (targetItem instanceof Session) {
- return getNestedPropertyValue(expressionPart, ((Session) targetItem).getProperties());
- } else if (targetItem instanceof Rule) {
- return null;
- } else if (targetItem instanceof Profile) {
- return getNestedPropertyValue(expressionPart, ((Profile) targetItem).getProperties());
- }
- }
- if ("target.scope".equals(expression)) {
- return event.getTarget().getScope();
- }
- if ("scope".equals(expression)) {
- return event.getScope();
- }
- if ("eventType".equals(expression)) {
- return event.getEventType();
- }
- if ("profile".equals(expression)) {
- return event.getProfile();
- }
- if ("profileId".equals(expression)) {
- return event.getProfileId();
- }
- if ("session".equals(expression)) {
- return event.getSession();
- }
- if ("sessionId".equals(expression)) {
- return event.getSessionId();
- }
- if ("source".equals(expression)) {
- return event.getSource();
- }
- if ("target".equals(expression)) {
- return event.getTarget();
- }
- if ("timeStamp".equals(expression)) {
- return event.getTimeStamp();
- }
- if ("itemId".equals(expression)) {
- return event.getItemId();
- }
- if ("itemType".equals(expression)) {
- return event.getItemType();
- }
- } else if (item instanceof Session) {
- Session session = (Session) item;
- if ("scope".equals(expression)) {
- return session.getScope();
- }
- if ("timeStamp".equals(expression)) {
- return session.getTimeStamp();
- }
- if ("duration".equals(expression)) {
- return session.getDuration();
- }
- if ("size".equals(expression)) {
- return session.getSize();
- }
- if ("lastEventDate".equals(expression)) {
- return session.getLastEventDate();
- }
- if (expression.startsWith("properties.")) {
- return getNestedPropertyValue(expression.substring("properties.".length()), session.getProperties());
- }
- if (expression.startsWith("systemProperties.")) {
- return getNestedPropertyValue(expression.substring("systemProperties.".length()), session.getSystemProperties());
- }
- if ("itemId".equals(expression)) {
- return session.getItemId();
- }
- if ("itemType".equals(expression)) {
- return session.getItemType();
- }
- if ("profile".equals(expression)) {
- return session.getProfile();
- }
- if ("profileId".equals(expression)) {
- return session.getProfileId();
- }
- } else if (item instanceof Profile) {
- Profile profile = (Profile) item;
- if ("segments".equals(expression)) {
- return profile.getSegments();
- }
- if ("consents".equals(expression)) {
- return profile.getConsents();
- }
- if (expression.startsWith("scores.")) {
- return profile.getScores().get(expression.substring("scores.".length()));
- }
- if (expression.startsWith("properties.")) {
- return getNestedPropertyValue(expression.substring("properties.".length()), profile.getProperties());
- }
- if (expression.startsWith("systemProperties.")) {
- return getNestedPropertyValue(expression.substring("systemProperties.".length()), profile.getSystemProperties());
- }
- if ("itemId".equals(expression)) {
- return profile.getItemId();
- }
- if ("itemType".equals(expression)) {
- return profile.getItemType();
- }
- if ("mergedWith".equals(expression)) {
- return profile.getMergedWith();
- }
- } else if (item instanceof CustomItem) {
- CustomItem customItem = (CustomItem) item;
- if (expression.startsWith("properties.")) {
- return getNestedPropertyValue(expression.substring("properties.".length()), customItem.getProperties());
- }
- if ("itemId".equals(expression)) {
- return customItem.getItemId();
- }
- if ("itemType".equals(expression)) {
- return customItem.getItemType();
- }
- if ("scope".equals(expression)) {
- return customItem.getScope();
- }
- }
- return NOT_OPTIMIZED_MARKER;
+ return getItemProperty(item, expression);
}
protected Object getOGNLPropertyValue(Item item, String expression) throws Exception {
@@ -426,7 +293,15 @@ public class PropertyConditionEvaluator implements ConditionEvaluator {
}
OgnlContext ognlContext = getOgnlContext(secureFilteringClassLoader);
ExpressionAccessor accessor = getPropertyAccessor(item, expression, ognlContext, secureFilteringClassLoader);
- return accessor != null ? accessor.get(ognlContext, item) : null;
+ if (accessor != null) {
+ try {
+ return accessor.get(ognlContext, item);
+ } catch (Throwable t) {
+ logger.error("Error evaluating expression {} on item {} : {}", expression, item.getClass().getName(), t);
+ return null;
+ }
+ }
+ return null;
}
private Object getNestedPropertyValue(String expressionPart, Map<String, Object> properties) {
@@ -547,4 +422,231 @@ public class PropertyConditionEvaluator implements ConditionEvaluator {
return Collections.singletonList(expectedValue);
}
}
+
+ private Object getEventProperty(Event event, String expression) {
+ if (expression.startsWith("properties.")) {
+ return getNestedPropertyValue(expression.substring("properties.".length()), event.getProperties());
+ }
+ if ("scope".equals(expression)) {
+ return event.getScope();
+ }
+ if ("eventType".equals(expression)) {
+ return event.getEventType();
+ }
+ if (expression.startsWith("profile")) {
+ if ("profile".equals(expression)) {
+ return event.getProfile();
+ } else {
+ return getProfileProperty(event.getProfile(), expression.substring("profile".length()+1));
+ }
+ }
+ if ("profileId".equals(expression)) {
+ return event.getProfileId();
+ }
+ if (expression.startsWith("session")) {
+ if ("session".equals(expression)) {
+ return event.getSession();
+ } else {
+ return getSessionProperty(event.getSession(), expression.substring("session".length()+1));
+ }
+ }
+ if ("sessionId".equals(expression)) {
+ return event.getSessionId();
+ }
+ if (expression.startsWith("source")) {
+ if ("source".equals(expression)) {
+ return event.getSource();
+ } else {
+ return getItemProperty(event.getSource(), expression.substring("source".length()+1));
+ }
+ }
+ if (expression.startsWith("target")) {
+ if ("target".equals(expression)) {
+ return event.getTarget();
+ } else {
+ return getItemProperty(event.getSource(), expression.substring("target".length()+1));
+ }
+ }
+ if ("timeStamp".equals(expression)) {
+ return event.getTimeStamp();
+ }
+ if ("itemId".equals(expression)) {
+ return event.getItemId();
+ }
+ if ("itemType".equals(expression)) {
+ return event.getItemType();
+ }
+ logger.warn("Requested unimplemented property {} on Event object", expression);
+ return NOT_OPTIMIZED_MARKER;
+ }
+
+ private Object getSessionProperty(Session session, String expression) {
+ if ("scope".equals(expression)) {
+ return session.getScope();
+ }
+ if ("timeStamp".equals(expression)) {
+ return session.getTimeStamp();
+ }
+ if ("duration".equals(expression)) {
+ return session.getDuration();
+ }
+ if ("size".equals(expression)) {
+ return session.getSize();
+ }
+ if ("lastEventDate".equals(expression)) {
+ return session.getLastEventDate();
+ }
+ if (expression.startsWith("properties.")) {
+ return getNestedPropertyValue(expression.substring("properties.".length()), session.getProperties());
+ }
+ if (expression.startsWith("systemProperties.")) {
+ return getNestedPropertyValue(expression.substring("systemProperties.".length()), session.getSystemProperties());
+ }
+ if ("itemId".equals(expression)) {
+ return session.getItemId();
+ }
+ if ("itemType".equals(expression)) {
+ return session.getItemType();
+ }
+ if (expression.startsWith("profile")) {
+ if ("profile".equals(expression)) {
+ return session.getProfile();
+ } else {
+ return getProfileProperty((Profile) session.getProfile(), expression.substring("profile".length()+1));
+ }
+ }
+ if ("profileId".equals(expression)) {
+ return session.getProfileId();
+ }
+ logger.warn("Requested unimplemented property {} on Session object", expression);
+ return NOT_OPTIMIZED_MARKER;
+ }
+
+ private Object getProfileProperty(Profile profile, String expression) {
+ if ("segments".equals(expression)) {
+ return profile.getSegments();
+ }
+ if (expression.startsWith("consents")) {
+ if ("consents".equals(expression)) {
+ return profile.getConsents();
+ } else {
+ String consentLookupName = null;
+ String leftoverExpression = expression;
+ if (expression.startsWith("consents[\"")) {
+ int lookupNameBeginPos = "consents[\"".length();
+ int lookupNameEndPos = expression.indexOf("\"].", lookupNameBeginPos);
+ if (lookupNameEndPos > lookupNameBeginPos) {
+ consentLookupName = expression.substring(lookupNameBeginPos, lookupNameEndPos);
+ leftoverExpression = expression.substring(lookupNameEndPos+3);
+ } else {
+ consentLookupName = expression.substring(lookupNameBeginPos);
+ leftoverExpression = null;
+ }
+ } else if (expression.startsWith("consents.")) {
+ int lookupNameBeginPos = "consents.".length();
+ int lookupNameEndPos = expression.indexOf(".", lookupNameBeginPos);
+ if (lookupNameEndPos > lookupNameBeginPos) {
+ consentLookupName = expression.substring(lookupNameBeginPos, lookupNameEndPos);
+ leftoverExpression = expression.substring(lookupNameEndPos+1);
+ } else {
+ consentLookupName = expression.substring(lookupNameBeginPos);
+ leftoverExpression = expression.substring(lookupNameEndPos);
+ }
+ }
+ Consent consent = profile.getConsents().get(consentLookupName);
+ if (consent == null) {
+ return null;
+ }
+ if (leftoverExpression == null) {
+ return consent;
+ }
+ return getConsentProperty(consent, leftoverExpression);
+ }
+ }
+ if (expression.startsWith("scores.")) {
+ return profile.getScores().get(expression.substring("scores.".length()));
+ }
+ if (expression.startsWith("properties.")) {
+ return getNestedPropertyValue(expression.substring("properties.".length()), profile.getProperties());
+ }
+ if (expression.startsWith("systemProperties.")) {
+ return getNestedPropertyValue(expression.substring("systemProperties.".length()), profile.getSystemProperties());
+ }
+ if ("itemId".equals(expression)) {
+ return profile.getItemId();
+ }
+ if ("itemType".equals(expression)) {
+ return profile.getItemType();
+ }
+ if ("mergedWith".equals(expression)) {
+ return profile.getMergedWith();
+ }
+ logger.warn("Requested unimplemented property {} on Profile object", expression);
+ return NOT_OPTIMIZED_MARKER;
+ }
+
+ private Object getCustomItemProperty(CustomItem customItem, String expression) {
+ if (expression.startsWith("properties.")) {
+ return getNestedPropertyValue(expression.substring("properties.".length()), customItem.getProperties());
+ }
+ if ("itemId".equals(expression)) {
+ return customItem.getItemId();
+ }
+ if ("itemType".equals(expression)) {
+ return customItem.getItemType();
+ }
+ if ("scope".equals(expression)) {
+ return customItem.getScope();
+ }
+ logger.warn("Requested unimplemented property {} on CustomItem object", expression);
+ return NOT_OPTIMIZED_MARKER;
+ }
+
+ private Object getRuleProperty(Rule rule, String expression) {
+ if ("itemId".equals(expression)) {
+ return rule.getItemId();
+ }
+ if ("itemType".equals(expression)) {
+ return rule.getItemType();
+ }
+ if ("scope".equals(expression)) {
+ return rule.getScope();
+ }
+ logger.warn("Requested unimplemented property {} on Rule object", expression);
+ return NOT_OPTIMIZED_MARKER;
+ }
+
+ private Object getItemProperty(Item item, String expression) {
+ if (item instanceof Profile) {
+ return getProfileProperty((Profile) item, expression);
+ } else if (item instanceof Session) {
+ return getSessionProperty((Session) item, expression);
+ } else if (item instanceof Rule) {
+ return getRuleProperty((Rule) item, expression);
+ } else if (item instanceof Event) {
+ return getEventProperty((Event) item, expression);
+ } else if (item instanceof CustomItem) {
+ return getCustomItemProperty((CustomItem) item, expression);
+ } else {
+ logger.warn("Requested unrecognized property {} on {} class", expression, item.getClass().getName());
+ return NOT_OPTIMIZED_MARKER;
+ }
+ }
+
+ private Object getConsentProperty(Consent consent, String expression) {
+ if ("typeIdentifier".equals(expression)) {
+ return consent.getTypeIdentifier();
+ } else if ("scope".equals(expression)) {
+ return consent.getScope();
+ } else if ("status".equals(expression)) {
+ return consent.getStatus();
+ } else if ("statusDate".equals(expression)) {
+ return consent.getStatusDate();
+ } else if ("revokeDate".equals(expression)) {
+ return consent.getRevokeDate();
+ } else {
+ logger.warn("Requested unrecognized property {} on Consent object {}", expression, consent);
+ return NOT_OPTIMIZED_MARKER;
+ }
+ }
}
diff --git a/plugins/baseplugin/src/test/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluatorTest.java b/plugins/baseplugin/src/test/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluatorTest.java
index 439bd80..9d4afe2 100644
--- a/plugins/baseplugin/src/test/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluatorTest.java
+++ b/plugins/baseplugin/src/test/java/org/apache/unomi/plugins/baseplugin/conditions/PropertyConditionEvaluatorTest.java
@@ -17,10 +17,7 @@
package org.apache.unomi.plugins.baseplugin.conditions;
import ognl.MethodFailedException;
-import org.apache.unomi.api.CustomItem;
-import org.apache.unomi.api.Event;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.Session;
+import org.apache.unomi.api.*;
import org.apache.unomi.scripting.ExpressionFilter;
import org.apache.unomi.scripting.ExpressionFilterFactory;
import org.junit.Before;
@@ -48,10 +45,14 @@ public class PropertyConditionEvaluatorTest {
public static final Date SESSION_LAST_EVENT_DATE = new Date();
public static final int THREAD_POOL_SIZE = 300;
public static final int WORKER_COUNT = 500000;
- private static final PropertyConditionEvaluator propertyConditionEvaluator = new PropertyConditionEvaluator();
- private static final Event mockEvent = generateMockEvent();
- private static final Profile mockProfile = generateMockProfile();
- private static final Session mockSession = generateMockSession();
+ public static final int SESSION_SIZE = 10;
+ public static final Date PROFILE_PREVIOUS_VISIT = new Date();
+ public static final String NEWSLETTER_CONSENT_ID = "newsLetterConsentId";
+ public static final String TRACKING_CONSENT_ID = "trackingConsentId";
+ private static PropertyConditionEvaluator propertyConditionEvaluator = new PropertyConditionEvaluator();
+ private static Profile mockProfile = generateMockProfile();
+ private static Session mockSession = generateMockSession(mockProfile);
+ private static Event mockEvent = generateMockEvent(mockProfile, mockSession);
@Before
public void setup() {
@@ -76,33 +77,37 @@ public class PropertyConditionEvaluatorTest {
@Test
public void testHardcodedEvaluator() {
- Event mockEvent = generateMockEvent();
+ Event mockEvent = generateMockEvent(mockProfile, mockSession);
assertEquals("Target itemId value is not correct", MOCK_ITEM_ID, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.itemId"));
assertEquals("Target scope is not correct", DIGITALL_SCOPE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.scope"));
assertEquals("Target page path value is not correct", PAGE_PATH_VALUE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.properties.pageInfo.pagePath"));
assertEquals("Target page url value is not correct", PAGE_URL_VALUE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "target.properties.pageInfo.pageURL"));
- assertEquals("Session size should be 10", 10, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "size"));
+ assertEquals("Session size should be 10", SESSION_SIZE, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "size"));
+ assertEquals("Session profile previous visit is not valid", PROFILE_PREVIOUS_VISIT, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession,"profile.properties.previousVisit"));
+ assertEquals("Page page couldn't be resolved on Event property", PAGE_PATH_VALUE, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "source.properties.pageInfo.pagePath"));
+ assertEquals("Tracking consent should be granted", ConsentStatus.GRANTED, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "profile.consents.digitall/trackingConsentId.status"));
+ assertEquals("Tracking consent should be granted", ConsentStatus.GRANTED, propertyConditionEvaluator.getHardcodedPropertyValue(mockEvent, "profile.consents[\"digitall/trackingConsentId\"].status"));
- assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached"));
- assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockProfile, "properties.email"));
+ assertEquals("Unexisting property should be null", null, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached"));
+ assertEquals("Unexisting property should be null", null, propertyConditionEvaluator.getHardcodedPropertyValue(mockProfile, "properties.email"));
// here let's make sure our reporting of non optimized expressions works.
- assertEquals("Should have received the non-optimized marker string", NOT_OPTIMIZED_MARKER, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "profile.itemId"));
+ assertEquals("Should have received the non-optimized marker string", NOT_OPTIMIZED_MARKER, propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "profile.non-existing-field"));
}
@Test
public void testOGNLEvaluator() throws Exception {
- Event mockEvent = generateMockEvent();
+ Event mockEvent = generateMockEvent(mockProfile, mockSession);
assertEquals("Target itemId value is not correct", MOCK_ITEM_ID, propertyConditionEvaluator.getOGNLPropertyValue(mockEvent, "target.itemId"));
assertEquals("Target scope is not correct", DIGITALL_SCOPE, propertyConditionEvaluator.getOGNLPropertyValue(mockEvent, "target.scope"));
assertEquals("Target page path value is not correct", PAGE_PATH_VALUE, propertyConditionEvaluator.getOGNLPropertyValue(mockEvent, "target.properties.pageInfo.pagePath"));
assertEquals("Target page url value is not correct", PAGE_URL_VALUE, propertyConditionEvaluator.getOGNLPropertyValue(mockEvent, "target.properties.pageInfo.pageURL"));
- assertEquals("Session size should be 10", 10, propertyConditionEvaluator.getOGNLPropertyValue(mockSession, "size"));
+ assertEquals("Session size should be 10", SESSION_SIZE, propertyConditionEvaluator.getOGNLPropertyValue(mockSession, "size"));
assertEquals("Should have received the proper last even date", SESSION_LAST_EVENT_DATE, propertyConditionEvaluator.getOGNLPropertyValue(mockSession, "lastEventDate"));
- assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached"));
- assertNull("Unexisting property should be null", propertyConditionEvaluator.getHardcodedPropertyValue(mockProfile, "properties.email"));
+ assertNull("Unexisting property should be null", propertyConditionEvaluator.getOGNLPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached"));
+ assertNull("Unexisting property should be null", propertyConditionEvaluator.getOGNLPropertyValue(mockProfile, "properties.email"));
}
@Test
@@ -123,7 +128,7 @@ public class PropertyConditionEvaluatorTest {
@Test
public void testPropertyEvaluator() throws Exception {
- Event mockEvent = generateMockEvent();
+ Event mockEvent = generateMockEvent(mockProfile, mockSession);
assertEquals("Target itemId value is not correct", MOCK_ITEM_ID, propertyConditionEvaluator.getPropertyValue(mockEvent, "target.itemId"));
assertEquals("Target scope is not correct", DIGITALL_SCOPE, propertyConditionEvaluator.getPropertyValue(mockEvent, "target.scope"));
assertEquals("Target page path value is not correct", PAGE_PATH_VALUE, propertyConditionEvaluator.getPropertyValue(mockEvent, "target.properties.pageInfo.pagePath"));
@@ -131,13 +136,13 @@ public class PropertyConditionEvaluatorTest {
assertNull("Unexisting property should be null", propertyConditionEvaluator.getPropertyValue(mockSession, "systemProperties.goals._csk6r4cgeStartReached"));
assertNull("Unexisting property should be null", propertyConditionEvaluator.getPropertyValue(mockProfile, "properties.email"));
- assertEquals("Session size should be 10", 10, propertyConditionEvaluator.getPropertyValue(mockSession, "size"));
+ assertEquals("Session size should be 10", SESSION_SIZE, propertyConditionEvaluator.getPropertyValue(mockSession, "size"));
assertEquals("Session last event date is not right", SESSION_LAST_EVENT_DATE, propertyConditionEvaluator.getPropertyValue(mockSession, "lastEventDate"));
}
@Test
public void testOGNLSecurity() throws Exception {
- Event mockEvent = generateMockEvent();
+ Event mockEvent = generateMockEvent(mockProfile, mockSession);
File vulnFile = new File("target/vuln-file.txt");
if (vulnFile.exists()) {
vulnFile.delete();
@@ -195,16 +200,23 @@ public class PropertyConditionEvaluatorTest {
System.out.println("OGNL workers completed execution in " + totalTime + "ms");
}
- private static Event generateMockEvent() {
+ private static Event generateMockEvent(Profile mockProfile, Session mockSession) {
Event mockEvent = new Event();
- CustomItem targetItem = new CustomItem();
- targetItem.setItemId(MOCK_ITEM_ID);
- targetItem.setScope(DIGITALL_SCOPE);
- mockEvent.setTarget(targetItem);
+ mockEvent.setProfile(mockProfile);
+ mockEvent.setSession(mockSession);
+ CustomItem sourceItem = new CustomItem();
+ sourceItem.setItemId(MOCK_ITEM_ID);
+ sourceItem.setScope(DIGITALL_SCOPE);
Map<String, Object> pageInfoMap = new HashMap<>();
pageInfoMap.put("pagePath", PAGE_PATH_VALUE);
pageInfoMap.put("pageURL", PAGE_URL_VALUE);
+ sourceItem.getProperties().put("pageInfo", pageInfoMap);
+ mockEvent.setSource(sourceItem);
+ CustomItem targetItem = new CustomItem();
+ targetItem.setItemId(MOCK_ITEM_ID);
+ targetItem.setScope(DIGITALL_SCOPE);
targetItem.getProperties().put("pageInfo", pageInfoMap);
+ mockEvent.setTarget(targetItem);
return mockEvent;
}
@@ -214,12 +226,20 @@ public class PropertyConditionEvaluatorTest {
mockProfile.getSegments().add("segment1");
mockProfile.getSegments().add("segment2");
mockProfile.getSegments().add("segment3");
+ mockProfile.getProperties().put("previousVisit", PROFILE_PREVIOUS_VISIT);
+
+ Consent newsLetterConsent = new Consent(DIGITALL_SCOPE, NEWSLETTER_CONSENT_ID, ConsentStatus.DENIED, new Date(), new Date());
+ mockProfile.setConsent(newsLetterConsent);
+ Consent trackingConsent = new Consent(DIGITALL_SCOPE, TRACKING_CONSENT_ID, ConsentStatus.GRANTED, new Date(), new Date());
+ mockProfile.setConsent(trackingConsent);
+
return mockProfile;
}
- public static Session generateMockSession() {
+ public static Session generateMockSession(Profile mockProfile) {
Session mockSession = new Session("mockSessionId", generateMockProfile(), new Date(), "digitall");
- mockSession.setSize(10);
+ mockSession.setProfile(mockProfile);
+ mockSession.setSize(SESSION_SIZE);
mockSession.setLastEventDate(SESSION_LAST_EVENT_DATE);
return mockSession;
}