You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by ta...@apache.org on 2021/04/01 14:41:11 UTC

[unomi] branch UNOMI-455-it created (now 06782e5)

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

taybou pushed a change to branch UNOMI-455-it
in repository https://gitbox.apache.org/repos/asf/unomi.git.


      at 06782e5  UNOMI-455 bump es maven plugin and fix IT

This branch includes the following new commits:

     new 06782e5  UNOMI-455 bump es maven plugin and fix IT

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[unomi] 01/01: UNOMI-455 bump es maven plugin and fix IT

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

taybou pushed a commit to branch UNOMI-455-it
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 06782e58a9c159061ef39a58b419c19a64fd55ad
Author: Taybou <be...@gmail.com>
AuthorDate: Thu Apr 1 12:45:22 2021 +0200

    UNOMI-455 bump es maven plugin and fix IT
---
 itests/pom.xml                                     |   2 +-
 .../apache/unomi/itests/IncrementInterestsIT.java  | 216 +++++++++------------
 2 files changed, 90 insertions(+), 128 deletions(-)

diff --git a/itests/pom.xml b/itests/pom.xml
index 4356471..c022536 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -169,7 +169,7 @@
                         <groupId>com.github.alexcojocaru</groupId>
                         <artifactId>elasticsearch-maven-plugin</artifactId>
                         <!-- REPLACE THE FOLLOWING WITH THE PLUGIN VERSION YOU NEED -->
-                        <version>6.16</version>
+                        <version>6.19</version>
                         <configuration>
                             <clusterName>contextElasticSearchITests</clusterName>
                             <transportPort>9500</transportPort>
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 85b63a0..ada4104 100644
--- a/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
@@ -33,7 +33,9 @@ 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.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.PaxExam;
@@ -45,10 +47,7 @@ import static org.apache.unomi.itests.BasicIT.ITEM_TYPE_PAGE;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerSuite.class)
-public class IncrementInterestsIT
-    extends BaseIT
-{
-
+public class IncrementInterestsIT extends BaseIT {
     @Inject
     @Filter(timeout = 600000)
     protected ProfileService profileService;
@@ -69,168 +68,131 @@ public class IncrementInterestsIT
     @Filter(timeout = 600000)
     protected DefinitionsService definitionsService;
 
-    @Test
-    @SuppressWarnings("unchecked")
-    public void test()
-        throws InterruptedException
-    {
-        final Topic topic = createTopic( "topicId" );
-        final Profile profile = createProfile();
-
-        final Map<String, Double> interestsAsMap = new HashMap<>();
-        interestsAsMap.put( topic.getTopicId(), 50.0 );
-        interestsAsMap.put( "unknown", 10.0 );
-
-        final Event event = createEvent( profile, interestsAsMap );
-
-        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
-        {
-            topicService.delete( topic.getItemId() );
-            profileService.delete( profile.getItemId(), false );
-        }
+    private Profile profile;
+    private Rule rule;
+    private Topic topic;
+
+    @Before
+    public void setup() throws Exception {
+        topic = createTopic("topicId");
+        profile = createProfile();
+        rule = new Rule();
+    }
+
+    @After
+    public void tearDown() {
+        rulesService.removeRule(rule.getItemId());
+        profileService.delete(profile.getItemId(), false);
     }
 
     @Test
-    @SuppressWarnings("unchecked")
-    public void testAction()
-        throws InterruptedException
-    {
-        final Topic topic = createTopic( "topicId" );
-        final Profile profile = createProfile();
+    public void test() throws InterruptedException {
+        Map<String, Double> interestsAsMap = new HashMap<>();
+        interestsAsMap.put(topic.getTopicId(), 50.0);
+        interestsAsMap.put("unknown", 10.0);
 
-        final Action incrementAction = new Action( definitionsService.getActionType( "incrementInterestAction" ) );
-        incrementAction.setParameter( "eventInterestProperty", "eventProperty::target.properties.interests" );
+        Event event = createEvent(profile, interestsAsMap);
 
-        final Condition condition = new Condition( definitionsService.getConditionType( "eventTypeCondition" ) );
-        condition.setParameter( "eventTypeId", "view" );
+        int eventCode = eventService.send(event);
 
-        final String itemId = UUID.randomUUID().toString();
+        if (eventCode == EventService.PROFILE_UPDATED) {
+            Profile updatedProfile = profileService.save(event.getProfile());
 
-        final Metadata metadata = new Metadata();
-        metadata.setId( itemId );
-        metadata.setName( itemId );
-        metadata.setDescription( itemId );
-        metadata.setEnabled( true );
-        metadata.setScope( "systemscope" );
+            Map<String, Double> interests = (Map<String, Double>) updatedProfile.getProperty("interests");
 
-        final Rule rule = new Rule();
+            Assert.assertEquals(0.5, interests.get(topic.getTopicId()), 0.0);
+            Assert.assertFalse(interests.containsKey("unknown"));
+        } else {
+            Assert.fail("Profile was not updated");
+        }
+    }
 
-        rule.setCondition( condition );
-        List<Action> actions = new ArrayList<>();
-        actions.add(incrementAction);
-        rule.setActions( actions );
-        rule.setMetadata( metadata );
+    @Test
+    public void testAction() throws InterruptedException {
+        Action incrementAction = new Action(definitionsService.getActionType("incrementInterestAction"));
+        incrementAction.setParameter("eventInterestProperty", "eventProperty::target.properties.interests");
 
-        rulesService.setRule( rule );
+        Condition condition = new Condition(definitionsService.getConditionType("eventTypeCondition"));
+        condition.setParameter("eventTypeId", "view");
 
-        keepTrying( "Failed waiting for the creation of the rule for the IncrementInterestsIT test",
-                    () -> rulesService.getRule( rule.getItemId() ), Objects::nonNull, 1000, 100 );
+        String itemId = UUID.randomUUID().toString();
 
-        final Map<String, Double> interestsAsMap = new HashMap<>();
-        interestsAsMap.put( topic.getTopicId(), 50.0 );
-        interestsAsMap.put( "unknown", 10.0 );
+        Metadata metadata = new Metadata();
+        metadata.setId(itemId);
+        metadata.setName(itemId);
+        metadata.setDescription(itemId);
+        metadata.setEnabled(true);
+        metadata.setScope("systemscope");
 
-        final Map<String, Object> properties = new HashMap<>();
+        rule.setCondition(condition);
+        List<Action> actions = new ArrayList<>();
+        actions.add(incrementAction);
+        rule.setActions(actions);
+        rule.setMetadata(metadata);
 
-        properties.put( "interests", interestsAsMap );
+        rulesService.setRule(rule);
+        refreshPersistence();
 
-        final CustomItem item = new CustomItem( "page", ITEM_TYPE_PAGE );
-        item.setProperties( properties );
+        Map<String, Double> interestsAsMap = new HashMap<>();
+        interestsAsMap.put(topic.getTopicId(), 50.0);
+        interestsAsMap.put("unknown", 10.0);
 
-        final Event event = new Event( "view", null, profile, null, null, item, new Date() );
-        event.setPersistent( false );
+        Map<String, Object> properties = new HashMap<>();
 
-        try
-        {
-            int eventCode = eventService.send( event );
+        properties.put("interests", interestsAsMap);
 
-            if ( eventCode == EventService.PROFILE_UPDATED )
-            {
-                Profile updatedProfile = profileService.save( event.getProfile() );
+        CustomItem item = new CustomItem("page", ITEM_TYPE_PAGE);
+        item.setProperties(properties);
 
-                refreshPersistence();
+        Event event = new Event("view", null, profile, null, null, item, new Date());
+        event.setPersistent(false);
 
-                Map<String, Double> interests = (Map<String, Double>) updatedProfile.getProperty( "interests" );
+        int eventCode = eventService.send(event);
 
-                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() );
+        if (eventCode == EventService.PROFILE_UPDATED) {
+            Profile updatedProfile = profileService.save(event.getProfile());
 
-            topicService.delete( topic.getItemId() );
-            profileService.delete( profile.getItemId(), false );
+            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");
         }
     }
 
-    private Event createEvent( Profile profile, Map<String, Double> interestsAsMap )
-    {
-        final Event event = new Event( "incrementInterest", null, profile, null, null, profile, new Date() );
+    private Event createEvent(Profile profile, Map<String, Double> interestsAsMap) {
+        Event event = new Event("incrementInterest", null, profile, null, null, profile, new Date());
 
-        event.setPersistent( false );
-        event.setProperty( "interests", interestsAsMap );
+        event.setPersistent(false);
+        event.setProperty("interests", interestsAsMap);
 
         return event;
     }
 
-    private Topic createTopic( final String topicId )
-        throws InterruptedException
-    {
-        final Topic topic = new Topic();
-
-        topic.setTopicId( topicId );
-        topic.setItemId( topicId );
-        topic.setName( "topicName" );
-        topic.setScope( "scope" );
+    private Topic createTopic(final String topicId) throws InterruptedException {
+        Topic topic = new Topic();
 
-        topicService.save( topic );
+        topic.setTopicId(topicId);
+        topic.setItemId(topicId);
+        topic.setName("topicName");
+        topic.setScope("scope");
 
-        keepTrying( "Failed waiting for the creation of the topic for the IncrementInterestsIT test",
-                    () -> topicService.load( topic.getItemId() ), Objects::nonNull, 1000, 100 );
+        topicService.save(topic);
+        refreshPersistence();
 
         return topic;
     }
 
-    private Profile createProfile()
-        throws InterruptedException
-    {
-        final Profile profile = new Profile( UUID.randomUUID().toString() );
+    private Profile createProfile() throws InterruptedException {
+        Profile profile = new Profile(UUID.randomUUID().toString());
 
-        profile.setProperty( "firstName", "FirstName" );
-        profile.setProperty( "lastName", "LastName" );
+        profile.setProperty("firstName", "FirstName");
+        profile.setProperty("lastName", "LastName");
 
-        profileService.save( profile );
-
-        keepTrying( "Failed waiting for the creation of the profile for the IncrementInterestsIT test",
-                    () -> profileService.load( profile.getItemId() ), Objects::nonNull, 1000, 100 );
+        profileService.save(profile);
+        refreshPersistence();
 
         return profile;
     }
-
 }