jkevan commented on a change in pull request #355:
URL: https://github.com/apache/unomi/pull/355#discussion_r733775531
##########
File path: itests/src/test/resources/testClickEventCondition.json
##########
@@ -0,0 +1,58 @@
+{
+ "metadata": {
+ "id": "clickEventCondition",
+ "name": "clickEventCondition",
+ "description": "",
+ "systemTags": [
+ "availableToEndUser",
+ "behavioral",
+ "profileTags",
+ "event",
+ "condition",
+ "eventCondition",
+ "usableInPastEventCondition",
+ "trackedCondition"
+ ],
+ "readOnly": true
+ },
+ "parentCondition": {
+ "type": "booleanCondition",
+ "parameterValues": {
+ "subConditions": [
+ {
+ "type": "eventTypeCondition",
+ "parameterValues": {
+ "eventTypeId": "click"
+ }
+ },
+ {
+ "type": "sourceEventPropertyCondition",
+ "parameterValues": {
+ "path": "parameter::tracked.properties.pageInfo.pagePath"
Review comment:
should use underscore instead of dot according to implem, even if this
rule is not really triggered for the test.
IT woud be more clear to have a correct representation of an example in the
test.
##########
File path: itests/src/test/resources/testClickEventCondition.json
##########
@@ -0,0 +1,58 @@
+{
+ "metadata": {
+ "id": "clickEventCondition",
+ "name": "clickEventCondition",
+ "description": "",
+ "systemTags": [
+ "availableToEndUser",
+ "behavioral",
+ "profileTags",
+ "event",
+ "condition",
+ "eventCondition",
+ "usableInPastEventCondition",
+ "trackedCondition"
+ ],
+ "readOnly": true
+ },
+ "parentCondition": {
+ "type": "booleanCondition",
+ "parameterValues": {
+ "subConditions": [
+ {
+ "type": "eventTypeCondition",
+ "parameterValues": {
+ "eventTypeId": "click"
+ }
+ },
+ {
+ "type": "sourceEventPropertyCondition",
+ "parameterValues": {
+ "path": "parameter::tracked.properties.pageInfo.pagePath"
+ }
+ },
+ {
+ "type": "eventPropertyCondition",
+ "parameterValues": {
+ "propertyName": "target.itemId",
+ "propertyValue": "parameter::itemId",
+ "comparisonOperator": "equals"
+ }
+ }
+ ],
+ "operator": "and"
+ }
+ },
+ "parameters": [
+ {
+ "id": "tracked.properties.pageInfo.pagePath",
Review comment:
should use underscore instead of dot according to implem, even if this
rule is not really triggered for the test.
IT woud be more clear to have a correct representation of an example in the
test.
##########
File path: itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
##########
@@ -176,6 +182,41 @@ private Event generateViewEvent(Session session, Profile
profile) {
return new Event(UUID.randomUUID().toString(), "view", session,
profile, TEST_SCOPE, sourceItem, targetItem, new Date());
}
+ @Test
+ public void testGetTrackedConditions() throws InterruptedException,
IOException {
+ // Add custom condition with parameter
+ ConditionType conditionType =
CustomObjectMapper.getObjectMapper().readValue(
+ new
File("data/tmp/testClickEventCondition.json").toURI().toURL(),
ConditionType.class);
+ definitionsService.setConditionType(conditionType);
+ refreshPersistence();
+ rulesService.refreshRules();
+ // Test tracked parameter
+ // Add rule that has a trackParameter condition that matches
+ ConditionBuilder builder = new ConditionBuilder(definitionsService);
+ Rule trackParameterRule = new Rule(new Metadata(TEST_SCOPE,
"tracked-parameter-rule", "Tracked parameter rule", "A rule with tracked
parameter"));
+ Condition trackedCondition =
builder.condition("clickEventCondition").build();
+ trackedCondition.setParameter("tracked_properties_pageInfo_pagePath",
"/test-page.html");
+
trackedCondition.getConditionType().getMetadata().getSystemTags().add("trackedCondition");
+ trackParameterRule.setCondition(trackedCondition);
+ rulesService.setRule(trackParameterRule);
+ // Add rule that has a trackParameter condition that does not match
+ Rule unTrackParameterRule = new Rule(new Metadata(TEST_SCOPE,
"not-tracked-parameter-rule", "Not Tracked parameter rule", "A rule that has a
parameter not tracked"));
+ Condition unTrackedCondition =
builder.condition("clickEventCondition").build();
+
unTrackedCondition.setParameter("tracked_properties_pageInfo_pagePath",
"/test-page-that-does-not-exist.html");
+
unTrackedCondition.getConditionType().getMetadata().getSystemTags().add("trackedCondition");
+ unTrackParameterRule.setCondition(unTrackedCondition);
+ rulesService.setRule(unTrackParameterRule);
+ refreshPersistence();
+ rulesService.refreshRules();
+ // Check that the given event return the tracked condition
+ Profile profile = new Profile(UUID.randomUUID().toString());
+ Session session = new Session(UUID.randomUUID().toString(), profile,
new Date(), TEST_SCOPE);
+ Event viewEvent = generateViewEvent(session, profile);
+ Set<Condition> trackedConditions =
rulesService.getTrackedConditions(viewEvent.getTarget());
+ Assert.assertTrue(trackedConditions.contains(trackedCondition));
+ Assert.assertFalse(trackedConditions.contains(unTrackedCondition));
+ }
Review comment:
Test is good, but we need to clear the test data after the test
execution.
Either in a global @after method or inside a try/finally close.
Resource to be cleaned:
- the condition type
- the 2 rules
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]