This is an automated email from the ASF dual-hosted git repository.

shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new c69515f  UNOMI-398: Implement interests increments integration tests 
(#225)
c69515f is described below

commit c69515f527ae714e2d0662e264d806e80fb2b519
Author: anatol-sialitski <[email protected]>
AuthorDate: Tue Jan 5 16:33:12 2021 +0300

    UNOMI-398: Implement interests increments integration tests (#225)
---
 .../test/java/org/apache/unomi/itests/BasicIT.java |   2 +-
 .../apache/unomi/itests/IncrementInterestsIT.java  | 100 +++++++++++++++++++++
 .../META-INF/cxs/actions/incrementInterest.json    |   2 +-
 .../META-INF/cxs/rules/incrementInterest.json      |   1 -
 4 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java 
b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
index 0ae2feb..da0e715 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
@@ -73,7 +73,7 @@ public class BasicIT extends BaseIT {
     private static final String ITEM_ID_SITE = "/test/site";
     private static final String ITEM_TYPE_VISITOR = "VISITOR";
     private static final String ITEM_ID_PAGE_1 = "/test/site/page1";
-    private static final String ITEM_TYPE_PAGE = "page";
+    protected static final String ITEM_TYPE_PAGE = "page";
 
     private static final String FIRST_NAME = "firstName";
     private static final String LAST_NAME = "lastName";
diff --git 
a/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java 
b/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
index 9ebaa79..ba8ae25 100644
--- a/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
@@ -24,11 +24,18 @@ import java.util.UUID;
 
 import javax.inject.Inject;
 
+import org.apache.unomi.api.CustomItem;
 import org.apache.unomi.api.Event;
+import org.apache.unomi.api.Metadata;
 import org.apache.unomi.api.Profile;
 import org.apache.unomi.api.Topic;
+import org.apache.unomi.api.actions.Action;
+import org.apache.unomi.api.conditions.Condition;
+import org.apache.unomi.api.rules.Rule;
+import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.api.services.EventService;
 import org.apache.unomi.api.services.ProfileService;
+import org.apache.unomi.api.services.RulesService;
 import org.apache.unomi.api.services.TopicService;
 import org.junit.Assert;
 import org.junit.Test;
@@ -38,6 +45,10 @@ import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerSuite;
 import org.ops4j.pax.exam.util.Filter;
 
+import com.sun.tools.javac.util.List;
+
+import static org.apache.unomi.itests.BasicIT.ITEM_TYPE_PAGE;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerSuite.class)
 public class IncrementInterestsIT
@@ -56,6 +67,14 @@ public class IncrementInterestsIT
     @Filter(timeout = 600000)
     protected TopicService topicService;
 
+    @Inject
+    @Filter(timeout = 600000)
+    protected RulesService rulesService;
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected DefinitionsService definitionsService;
+
     @Test
     @SuppressWarnings("unchecked")
     public void test()
@@ -85,9 +104,90 @@ public class IncrementInterestsIT
                 Assert.assertEquals( 0.5, interests.get( topic.getTopicId() ), 
0.0 );
                 Assert.assertFalse( interests.containsKey( "unknown" ) );
             }
+            else
+            {
+                throw new IllegalStateException( "Profile was not updated" );
+            }
+        }
+        finally
+        {
+            topicService.delete( topic.getItemId() );
+            profileService.delete( profile.getItemId(), false );
+        }
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testAction()
+        throws InterruptedException
+    {
+        final Topic topic = createTopic( "topicId" );
+        final Profile profile = createProfile();
+
+        final Action incrementAction = new Action( 
definitionsService.getActionType( "incrementInterestAction" ) );
+        incrementAction.setParameter( "eventInterestProperty", 
"eventProperty::target.properties.interests" );
+
+        final Condition condition = new Condition( 
definitionsService.getConditionType( "eventTypeCondition" ) );
+        condition.setParameter( "eventTypeId", "view" );
+
+        final String itemId = UUID.randomUUID().toString();
+
+        final Metadata metadata = new Metadata();
+        metadata.setId( itemId );
+        metadata.setName( itemId );
+        metadata.setDescription( itemId );
+        metadata.setEnabled( true );
+        metadata.setScope( "systemscope" );
+
+        final Rule rule = new Rule();
+
+        rule.setCondition( condition );
+        rule.setActions( List.of( incrementAction ) );
+        rule.setMetadata( metadata );
+
+        rulesService.setRule( rule );
+
+        keepTrying( "Failed waiting for the creation of the rule for the 
IncrementInterestsIT test",
+                    () -> rulesService.getRule( rule.getItemId() ), 
Objects::nonNull, 1000, 100 );
+
+        final Map<String, Double> interestsAsMap = new HashMap<>();
+        interestsAsMap.put( topic.getTopicId(), 50.0 );
+        interestsAsMap.put( "unknown", 10.0 );
+
+        final Map<String, Object> properties = new HashMap<>();
+
+        properties.put( "interests", interestsAsMap );
+
+        final CustomItem item = new CustomItem( "page", ITEM_TYPE_PAGE );
+        item.setProperties( properties );
+
+        final Event event = new Event( "view", null, profile, null, null, 
item, new Date() );
+        event.setPersistent( false );
+
+        try
+        {
+            int eventCode = eventService.send( event );
+
+            if ( eventCode == EventService.PROFILE_UPDATED )
+            {
+                Profile updatedProfile = profileService.save( 
event.getProfile() );
+
+                refreshPersistence();
+
+                Map<String, Double> interests = (Map<String, Double>) 
updatedProfile.getProperty( "interests" );
+
+                Assert.assertEquals( 0.5, interests.get( topic.getTopicId() ), 
0.0 );
+                Assert.assertFalse( interests.containsKey( "unknown" ) );
+            }
+            else
+            {
+                throw new IllegalStateException( "Profile was not updated" );
+            }
         }
         finally
         {
+            rulesService.removeRule( rule.getItemId() );
+
             topicService.delete( topic.getItemId() );
             profileService.delete( profile.getItemId(), false );
         }
diff --git 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json
 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json
index a328eb0..0a036e0 100644
--- 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json
+++ 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json
@@ -12,7 +12,7 @@
   "parameters": [
     {
       "id": "eventInterestProperty",
-      "type": "properties",
+      "type": "string",
       "multivalued": false
     }
   ]
diff --git 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json
 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json
index ad002f3..f289aa3 100644
--- 
a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json
+++ 
b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json
@@ -14,7 +14,6 @@
     {
       "type": "incrementInterestAction",
       "parameterValues": {
-        "eventInterestProperty": "target.properties.interests"
       }
     }
   ]

Reply via email to