sergehuber commented on a change in pull request #364:
URL: https://github.com/apache/unomi/pull/364#discussion_r752090150



##########
File path: itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
##########
@@ -358,4 +359,52 @@ public void testScoringPastEventRecalculation() throws 
Exception {
                 updatedProfile -> 
!updatedProfile.getScores().containsKey("past-event-scoring-test"),
                 1000, 20);
     }
+
+    @Test
+    public void testLinkedItems() throws Exception {
+
+        // create the past event condition
+        Condition pastEventCondition = new 
Condition(definitionsService.getConditionType("pastEventCondition"));
+        pastEventCondition.setParameter("minimumEventCount", 1);
+        pastEventCondition.setParameter("maximumEventCount", 2);
+
+        pastEventCondition.setParameter("fromDate", "2000-07-15T07:00:00Z");
+        pastEventCondition.setParameter("toDate", "2001-01-15T07:00:00Z");
+        ;
+        Condition pastEventEventCondition = new 
Condition(definitionsService.getConditionType("eventTypeCondition"));
+        pastEventEventCondition.setParameter("eventTypeId", "test-event-type");
+        pastEventCondition.setParameter("eventCondition", 
pastEventEventCondition);
+
+        // create the scoring
+        Metadata scoringMetadata = new Metadata("past-event-scoring-test");
+        Scoring scoring = new Scoring(scoringMetadata);
+        List<ScoringElement> scoringElements = new ArrayList<>();
+        ScoringElement scoringElement = new ScoringElement();
+        scoringElement.setCondition(pastEventCondition);
+        scoringElement.setValue(50);
+        scoringElements.add(scoringElement);
+        scoring.setElements(scoringElements);
+        segmentService.setScoringDefinition(scoring);
+        Thread.sleep(5000);
+        // Check linkedItems
+        List<Rule> rules = persistenceService.getAllItems(Rule.class);
+        Rule scoringRule = rules.stream().filter(rule -> 
rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey"))).findFirst().get();
+        Assert.assertEquals("Scoring linked Item should be one", 1, 
scoringRule.getLinkedItems().size());
+
+        // save the scoring once again
+        segmentService.setScoringDefinition(scoring);
+        Thread.sleep(5000);

Review comment:
       why not use refreshPersistence instead ?

##########
File path: itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
##########
@@ -358,4 +359,52 @@ public void testScoringPastEventRecalculation() throws 
Exception {
                 updatedProfile -> 
!updatedProfile.getScores().containsKey("past-event-scoring-test"),
                 1000, 20);
     }
+
+    @Test
+    public void testLinkedItems() throws Exception {
+
+        // create the past event condition
+        Condition pastEventCondition = new 
Condition(definitionsService.getConditionType("pastEventCondition"));
+        pastEventCondition.setParameter("minimumEventCount", 1);
+        pastEventCondition.setParameter("maximumEventCount", 2);
+
+        pastEventCondition.setParameter("fromDate", "2000-07-15T07:00:00Z");
+        pastEventCondition.setParameter("toDate", "2001-01-15T07:00:00Z");
+        ;
+        Condition pastEventEventCondition = new 
Condition(definitionsService.getConditionType("eventTypeCondition"));
+        pastEventEventCondition.setParameter("eventTypeId", "test-event-type");
+        pastEventCondition.setParameter("eventCondition", 
pastEventEventCondition);
+
+        // create the scoring
+        Metadata scoringMetadata = new Metadata("past-event-scoring-test");
+        Scoring scoring = new Scoring(scoringMetadata);
+        List<ScoringElement> scoringElements = new ArrayList<>();
+        ScoringElement scoringElement = new ScoringElement();
+        scoringElement.setCondition(pastEventCondition);
+        scoringElement.setValue(50);
+        scoringElements.add(scoringElement);
+        scoring.setElements(scoringElements);
+        segmentService.setScoringDefinition(scoring);
+        Thread.sleep(5000);
+        // Check linkedItems
+        List<Rule> rules = persistenceService.getAllItems(Rule.class);
+        Rule scoringRule = rules.stream().filter(rule -> 
rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey"))).findFirst().get();
+        Assert.assertEquals("Scoring linked Item should be one", 1, 
scoringRule.getLinkedItems().size());
+
+        // save the scoring once again
+        segmentService.setScoringDefinition(scoring);
+        Thread.sleep(5000);
+        // Check linkedItems
+        rules = persistenceService.getAllItems(Rule.class);
+        scoringRule = rules.stream().filter(rule -> 
rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey"))).findFirst().get();
+        Assert.assertEquals("Scoring linked Item should be one", 1, 
scoringRule.getLinkedItems().size());
+
+        // Remove scoring
+        segmentService.removeSegmentDefinition(scoring.getItemId(), true);
+        Thread.sleep(5000);

Review comment:
       Again, wouldn't refreshPersistence or keepTrying be better here ?




-- 
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]


Reply via email to