Taybou commented on a change in pull request #277:
URL: https://github.com/apache/unomi/pull/277#discussion_r606250338



##########
File path: 
itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java
##########
@@ -69,168 +68,131 @@
     @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();

Review comment:
       it's removed here: 
https://github.com/apache/unomi/pull/277/files#diff-f06e946def04bc51838d479376e9f0b4f2b074c4a5e01093ec712e327762f90dR84




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to