Repository: incubator-unomi
Updated Branches:
  refs/heads/master 5d7a1cd35 -> 7c7462018


UNOMI-129 : Add integration tests to validate functionality of profile property 
update event


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/7c746201
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/7c746201
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/7c746201

Branch: refs/heads/master
Commit: 7c74620182be7c8454489a87014bb5154cdd5a9e
Parents: 5d7a1cd
Author: Abdelkader Midani <[email protected]>
Authored: Thu Oct 12 18:30:51 2017 +0200
Committer: Abdelkader Midani <[email protected]>
Committed: Thu Oct 12 18:30:51 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/unomi/itests/AllITs.java    |   3 +-
 .../itests/ProfilePropertiesUpdateActionIT.java | 114 +++++++++++++++++++
 .../apache/unomi/itests/ProfileServiceIT.java   |   2 +-
 .../actions/UpdateProfilePropertiesAction.java  |   3 +-
 4 files changed, 119 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7c746201/itests/src/test/java/org/apache/unomi/itests/AllITs.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/AllITs.java 
b/itests/src/test/java/org/apache/unomi/itests/AllITs.java
index f3bd042..38e57e0 100644
--- a/itests/src/test/java/org/apache/unomi/itests/AllITs.java
+++ b/itests/src/test/java/org/apache/unomi/itests/AllITs.java
@@ -39,7 +39,8 @@ import org.junit.runners.Suite.SuiteClasses;
         ProfileImportSurfersDeleteIT.class,
         ProfileImportRankingIT.class,
         ProfileImportActorsIT.class,
-        ProfileExportIT.class
+        ProfileExportIT.class,
+        ProfilePropertiesUpdateActionIT.class
     })
 public class AllITs {
 }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7c746201/itests/src/test/java/org/apache/unomi/itests/ProfilePropertiesUpdateActionIT.java
----------------------------------------------------------------------
diff --git 
a/itests/src/test/java/org/apache/unomi/itests/ProfilePropertiesUpdateActionIT.java
 
b/itests/src/test/java/org/apache/unomi/itests/ProfilePropertiesUpdateActionIT.java
new file mode 100644
index 0000000..b89666a
--- /dev/null
+++ 
b/itests/src/test/java/org/apache/unomi/itests/ProfilePropertiesUpdateActionIT.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package org.apache.unomi.itests;
+
+import org.apache.unomi.api.Event;
+import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.services.EventService;
+import org.apache.unomi.api.services.ProfileService;
+import 
org.apache.unomi.plugins.baseplugin.actions.UpdateProfilePropertiesAction;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by amidani on 12/10/2017.
+ */
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class ProfilePropertiesUpdateActionIT extends BaseIT {
+
+    private final static Logger LOGGER = 
LoggerFactory.getLogger(ProfilePropertiesUpdateActionIT.class);
+    private final static String PROFILE_TARGET_TEST_ID = 
"profile-target-event";
+    private final static String PROFILE_TEST_ID = "profile-to-update-by-event";
+
+    @Inject
+    protected ProfileService profileService;
+
+    @Inject
+    protected EventService eventService;
+
+    @Before
+    public void setUp() throws IOException {
+        Profile profile = new Profile();
+        profile.setItemId(PROFILE_TEST_ID);
+        profileService.save(profile);
+        LOGGER.info("Profile saved with ID [{}].", profile.getItemId());
+
+        Profile profileTarget = new Profile();
+        profileTarget.setItemId(PROFILE_TARGET_TEST_ID);
+        profileService.save(profileTarget);
+        LOGGER.info("Profile saved with ID [{}].", profileTarget.getItemId());
+    }
+
+    @Test
+    public void testUpdateProperties_CurrentProfile() {
+        Profile profile = profileService.load(PROFILE_TARGET_TEST_ID);
+        Assert.assertNull(profile.getProperty("firstName"));
+
+        Event updateProfileProperties = new Event("updateProfileProperties", 
null, profile, null, null, profile, new Date());
+        updateProfileProperties.setPersistent(false);
+
+        Map<String, Object> propertyToUpdate = new HashMap<>();
+        propertyToUpdate.put("properties.firstName", "UPDATED FIRST NAME 
CURRENT PROFILE");
+
+        
updateProfileProperties.setProperty(UpdateProfilePropertiesAction.PROPS_TO_UPDATE,
 propertyToUpdate);
+        int changes = eventService.send(updateProfileProperties);
+
+        LOGGER.info("Changes of the event : {}", changes);
+
+        Assert.assertTrue(changes > 0);
+    }
+
+    @Test
+    public void testUpdateProperties_NotCurrentProfile() {
+
+        Profile profile = profileService.load(PROFILE_TARGET_TEST_ID);
+        Profile profileToUpdate = profileService.load(PROFILE_TEST_ID);
+        Assert.assertNull(profileToUpdate.getProperty("firstName"));
+
+        Event updateProfileProperties = new Event("updateProfileProperties", 
null, profile, null, null, profile, new Date());
+        updateProfileProperties.setPersistent(false);
+
+        Map<String, Object> propertyToUpdate = new HashMap<>();
+        propertyToUpdate.put("properties.firstName", "UPDATED FIRST NAME");
+
+        
updateProfileProperties.setProperty(UpdateProfilePropertiesAction.PROPS_TO_UPDATE,
 propertyToUpdate);
+        
updateProfileProperties.setProperty(UpdateProfilePropertiesAction.PROFILE_TARGET_ID_KEY,
 PROFILE_TEST_ID);
+        int changes = eventService.send(updateProfileProperties);
+
+        LOGGER.info("Changes of the event : {}", changes);
+
+        profileToUpdate = profileService.load(PROFILE_TEST_ID);
+        Assert.assertEquals(profileToUpdate.getProperty("firstName"), "UPDATED 
FIRST NAME");
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7c746201/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java 
b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index c23e5ea..f2acbf9 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -35,7 +35,7 @@ import javax.inject.Inject;
 @ExamReactorStrategy(PerSuite.class)
 public class ProfileServiceIT extends BaseIT {
 
-    private final static Logger LOGGER = 
LoggerFactory.getLogger(SegmentIT.class);
+    private final static Logger LOGGER = 
LoggerFactory.getLogger(ProfileServiceIT.class);
     private final static String TEST_PROFILE_ID = "test-profile-id";
     @Inject
     protected ProfileService profileService;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/7c746201/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java
----------------------------------------------------------------------
diff --git 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java
 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java
index 919c996..d39eb0f 100644
--- 
a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java
+++ 
b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/UpdateProfilePropertiesAction.java
@@ -40,6 +40,7 @@ public class UpdateProfilePropertiesAction implements 
ActionExecutor {
     public static final String PROPS_TO_ADD = "propertiesToAdd";
     public static final String PROPS_TO_UPDATE = "propertiesToUpdate";
     public static final String PROPS_TO_DELETE = "propertiesToDelete";
+    public static final String PROFILE_TARGET_ID_KEY = "targetProfileId";
     Logger logger = 
LoggerFactory.getLogger(UpdateProfilePropertiesAction.class.getName());
 
     private ProfileService profileService;
@@ -49,7 +50,7 @@ public class UpdateProfilePropertiesAction implements 
ActionExecutor {
 
         Profile target = event.getProfile();
 
-        String targetProfileId = (String) event.getProperty("targetProfileId");
+        String targetProfileId = (String) 
event.getProperty(PROFILE_TARGET_ID_KEY);
         if (StringUtils.isNotBlank(targetProfileId) && event.getProfile() != 
null && !targetProfileId.equals(event.getProfile().getItemId())) {
             target = profileService.load(targetProfileId);
             if (target == null) {

Reply via email to