dgriffon commented on a change in pull request #363:
URL: https://github.com/apache/unomi/pull/363#discussion_r751957805



##########
File path: itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
##########
@@ -358,4 +360,100 @@ public void testScoringPastEventRecalculation() throws 
Exception {
                 updatedProfile -> 
!updatedProfile.getScores().containsKey("past-event-scoring-test"),
                 1000, 20);
     }
+
+
+    @Test
+    public void testScoringRecalculation() throws Exception {
+        // create Profile
+        Profile profile = new Profile();
+        profile.setItemId("test_profile_id");
+        profileService.save(profile);
+        persistenceService.refreshIndex(Profile.class, null); // wait for 
profile to be full persisted and index
+
+        Date timestampEventInRange = new 
SimpleDateFormat("yyyy-MM-dd").parse("2000-10-30");
+        // 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);
+
+        // Send 2 events that match the scoring plan.
+        Event testEvent = new Event("test-event-type", null, profile, null, 
null, profile, timestampEventInRange);
+        testEvent.setPersistent(true);
+        eventService.send(testEvent);
+        refreshPersistence();
+        // 2nd event
+        testEvent = new Event("test-event-type", null, testEvent.getProfile(), 
null, null, testEvent.getProfile(), timestampEventInRange);
+        eventService.send(testEvent);
+        refreshPersistence();
+
+        // insure the profile is engaged;
+        try {
+            Assert.assertTrue("Profile should have 2 events in the scoring",  
(Long) ((Map) 
testEvent.getProfile().getSystemProperties().get("pastEvents")).get(pastEventCondition.getParameterValues().get("generatedPropertyKey"))
 == 2);

Review comment:
       We have another test that is validating the engaged profiles, I wanted 
to focus that test to what it is supposed to test. 




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