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

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


The following commit(s) were added to 
refs/heads/eventCollectorSessionProfileHandling by this push:
     new 9e3a4740a UNOMI-628, UNOMI-629: provide additional tests on profile 
aliases
9e3a4740a is described below

commit 9e3a4740ad6a85b95bd3de63db782a8677b79d97
Author: Kevan <[email protected]>
AuthorDate: Tue Aug 9 10:37:50 2022 +0200

    UNOMI-628, UNOMI-629: provide additional tests on profile aliases
---
 .../fetchers/profile/ProfileDataFetcher.java       |  2 -
 .../org/apache/unomi/itests/ProfileServiceIT.java  | 53 ++++++++++++++++++++--
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/fetchers/profile/ProfileDataFetcher.java
 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/fetchers/profile/ProfileDataFetcher.java
index 000006581..6a8bf0b39 100644
--- 
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/fetchers/profile/ProfileDataFetcher.java
+++ 
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/fetchers/profile/ProfileDataFetcher.java
@@ -53,8 +53,6 @@ public class ProfileDataFetcher extends 
BaseDataFetcher<CDPProfile> {
 
             profile = profileService.save(profile);
 
-            profileService.addAliasToProfile(profile.getItemId(), 
profile.getItemId(), profileIDInput.getClient().getId());
-
             return new CDPProfile(profile);
         }
 
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 f6e58c048..c85a83a59 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -16,13 +16,13 @@
  */
 package org.apache.unomi.itests;
 
-import org.apache.unomi.api.PartialList;
-import org.apache.unomi.api.Profile;
-import org.apache.unomi.api.ProfileAlias;
+import org.apache.unomi.api.*;
 import org.apache.unomi.api.query.Query;
 import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.api.services.ProfileService;
 import org.apache.unomi.persistence.spi.PersistenceService;
+import org.apache.unomi.schema.api.JsonSchemaWrapper;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -63,6 +63,11 @@ public class ProfileServiceIT extends BaseIT {
         TestUtils.removeAllProfiles(definitionsService, persistenceService);
     }
 
+    @After
+    public void tearDown() throws InterruptedException {
+        removeItems(Profile.class, ProfileAlias.class);
+    }
+
     @Test
     public void testProfileDelete() throws Exception {
         Profile profile = new Profile();
@@ -219,6 +224,46 @@ public class ProfileServiceIT extends BaseIT {
         }
     }
 
-    // todo test alias cannot be created on profile itself
+    @Test
+    public void testAliasCannotBeCreatedOnSameProfile() throws Exception {
+        String profileID = UUID.randomUUID().toString();
+        Profile profile = new Profile();
+        profile.setItemId(profileID);
+        profileService.save(profile);
 
+        keepTrying("Profile " + profileID + " not found in the required time", 
() -> profileService.load(profileID), Objects::nonNull,
+                DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+        try {
+            profileService.addAliasToProfile(profileID, profileID, 
"defaultClientId");
+            fail("It should not be possible to create an Alias on the same 
profile ID");
+        } catch (Exception e) {
+            // do nothing, it's expected
+        }
+    }
+
+    @Test
+    public void testAliasCannotBeCreatedInCaseAlreadyExists() throws Exception 
{
+        String profileID = UUID.randomUUID().toString();
+        String alias = UUID.randomUUID().toString();
+        Profile profile = new Profile();
+        profile.setItemId(profileID);
+        profileService.save(profile);
+
+        keepTrying("Profile " + profileID + " not found in the required time", 
() -> profileService.load(profileID), Objects::nonNull,
+                DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+        profileService.addAliasToProfile(profileID, alias, "defaultClientId");
+
+        keepTrying("Profile " + profileID + " not found in the required time", 
() -> profileService.load(alias), Objects::nonNull,
+                DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
+
+        String otherProfileId = UUID.randomUUID().toString();
+        try {
+            profileService.addAliasToProfile(otherProfileId, alias, 
"defaultClientId");
+            fail("It should not be possible to create an Alias when an alias 
already exists with same ID");
+        } catch (Exception e) {
+            // do nothing, it's expected
+        }
+    }
 }

Reply via email to