14
14
import java .util .Date ;
15
15
import java .util .HashMap ;
16
16
import java .util .List ;
17
- import java .util .Map ;
18
17
import java .util .Optional ;
19
18
import java .util .Set ;
20
19
import java .util .stream .Collectors ;
39
38
import pl .edu .icm .unity .base .identity .IdentityParam ;
40
39
import pl .edu .icm .unity .base .identity .IllegalIdentityValueException ;
41
40
import pl .edu .icm .unity .base .verifiable .VerifiableEmail ;
42
- import pl .edu .icm .unity .engine .api .EntityManagement ;
43
41
import pl .edu .icm .unity .engine .api .GroupsManagement ;
44
42
import pl .edu .icm .unity .engine .api .bulk .BulkGroupQueryService ;
45
43
import pl .edu .icm .unity .engine .api .bulk .EntityInGroupData ;
46
44
import pl .edu .icm .unity .engine .api .entity .EntityWithContactInfo ;
45
+ import pl .edu .icm .unity .engine .api .identity .EntityResolver ;
47
46
import pl .edu .icm .unity .engine .attribute .AttributesHelper ;
47
+ import pl .edu .icm .unity .engine .credential .EntityCredentialsHelper ;
48
48
import pl .edu .icm .unity .stdext .attr .VerifiableEmailAttribute ;
49
49
import pl .edu .icm .unity .stdext .identity .EmailIdentity ;
50
50
import pl .edu .icm .unity .stdext .utils .ContactEmailMetadataProvider ;
51
51
import pl .edu .icm .unity .store .api .AttributeDAO ;
52
+ import pl .edu .icm .unity .store .api .EntityDAO ;
52
53
import pl .edu .icm .unity .store .api .IdentityDAO ;
54
+ import pl .edu .icm .unity .store .api .MembershipDAO ;
53
55
import pl .edu .icm .unity .store .types .StoredAttribute ;
54
56
55
57
public class ExistingUserFinderTest
@@ -58,10 +60,13 @@ public class ExistingUserFinderTest
58
60
private BulkGroupQueryService bulkService = mock (BulkGroupQueryService .class );
59
61
private AttributesHelper attrHelper = mock (AttributesHelper .class );
60
62
private GroupsManagement groupsManagement = mock (GroupsManagement .class );
61
- private EntityManagement entityManagement = mock (EntityManagement .class );
62
63
private IdentityDAO identityDAO = mock (IdentityDAO .class );
63
64
private AttributeDAO attributeDAO = mock (AttributeDAO .class );
64
-
65
+ private EntityDAO entityDAO = mock (EntityDAO .class );
66
+ private EntityResolver idResolver = mock (EntityResolver .class );
67
+ private EntityCredentialsHelper credentialsHelper = mock (EntityCredentialsHelper .class );
68
+ private IdentityHelper identityHelper = mock (IdentityHelper .class );
69
+ private MembershipDAO membershipDAO = mock (MembershipDAO .class );
65
70
66
71
67
72
@ Test
@@ -70,7 +75,7 @@ public void shouldFindByIdentityCaseInsensitive() throws EngineException
70
75
EntityInGroupData entityData =
new EntityInGroupData (
createEmailEntity (
"[email protected] " ,
13 ),
null ,
null ,
71
76
null , null , null );
72
77
when (bulkService .getMembershipInfo (any ())).thenReturn (ImmutableMap .of (13l , entityData ));
73
- ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , entityManagement , identityDAO , attributeDAO );
78
+ ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , identityDAO , attributeDAO , entityDAO , idResolver , credentialsHelper , identityHelper , membershipDAO );
74
79
75
80
Set <
Entity >
entityIdByContactAddress =
userFinder .
getEntitiesIdsByContactAddress (
"[email protected] " );
76
81
@@ -86,7 +91,7 @@ public void shouldFindByAttributeCaseInsensitive() throws EngineException
86
91
when (bulkService .getMembershipInfo (any ())).thenReturn (ImmutableMap .of (13l , entityData ));
87
92
when (attrHelper .getFirstVerifiableAttributeValueFilteredByMeta (eq (ContactEmailMetadataProvider .NAME ), any ()))
88
93
.thenReturn (Optional .of (VerifiableEmail .fromJsonString (emailAttr .getValues ().get (0 ))));
89
- ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , entityManagement , identityDAO , attributeDAO );
94
+ ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , identityDAO , attributeDAO , entityDAO , idResolver , credentialsHelper , identityHelper , membershipDAO );
90
95
91
96
Set <
Entity >
entityIdByContactAddress =
userFinder .
getEntitiesIdsByContactAddress (
"[email protected] " );
92
97
@@ -109,7 +114,7 @@ public void shouldFindAllEntitiesWithGivenEmail() throws EngineException
109
114
eq (Arrays .asList (emailAttr ))))
110
115
.thenReturn (Optional .of (VerifiableEmail .fromJsonString (emailAttr .getValues ().get (0 ))));
111
116
112
- ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , entityManagement , identityDAO , attributeDAO );
117
+ ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , identityDAO , attributeDAO , entityDAO , idResolver , credentialsHelper , identityHelper , membershipDAO );
113
118
Set <
Entity >
entityIdByContactAddress =
userFinder .
getEntitiesIdsByContactAddress (
"[email protected] " );
114
119
assertThat (entityIdByContactAddress .size ()).isEqualTo (2 );
115
120
assertThat (entityIdByContactAddress .stream ().map (e -> e .getId ()).collect (Collectors .toSet ())).contains (14L , 13L );
@@ -138,12 +143,18 @@ public void shouldFindAllEntitiesWithGivenEmailRespectOnlyDirectAttributes() thr
138
143
139
144
when (
identityDAO .
getIdByTypeAndValues (
EmailIdentity .
ID ,
List .
of (
"[email protected] " ))).
thenReturn (
Set .
of (
14L ));
140
145
when (attributeDAO .getAttributesOfGroupMembers (List .of (ContactEmailMetadataProvider .NAME ), List .of ("/" ))).thenReturn (List .of (new StoredAttribute (emailAttr , 13L )));
141
- when (entityManagement .getEntity (new EntityParam (13L ))).thenReturn (entityWithEmailAttrData );
142
- when (entityManagement .getEntity (new EntityParam (14L ))).thenReturn (entityWithIdEmailData );
143
- when (entityManagement .getGroups (new EntityParam (14L ))).thenReturn (Map .of ("/" , new GroupMembership ("/" , 14L , new Date ()), "/B" , new GroupMembership ("/B" , 14L , new Date ())));
144
- when (entityManagement .getGroups (new EntityParam (13L ))).thenReturn (Map .of ("/" , new GroupMembership ("/" , 13L , new Date ()), "/A" , new GroupMembership ("/A" , 14L , new Date ())));
145
-
146
- ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , entityManagement , identityDAO , attributeDAO );
146
+
147
+ when (idResolver .getEntityId (new EntityParam (13L ))).thenReturn (13L );
148
+ when (entityDAO .getByKey (13L )).thenReturn (entityWithEmailAttrData .getEntityInformation ());
149
+ when (identityHelper .getIdentitiesForEntity (13L , null )).thenReturn (entityWithEmailAttrData .getIdentities ());
150
+ when (membershipDAO .getEntityMembership (13L )).thenReturn (List .of (new GroupMembership ("/" , 13L , new Date ()), new GroupMembership ("/A" , 13L , new Date ())));
151
+
152
+ when (idResolver .getEntityId (new EntityParam (14L ))).thenReturn (14L );
153
+ when (entityDAO .getByKey (14L )).thenReturn (entityWithIdEmailData .getEntityInformation ());
154
+ when (identityHelper .getIdentitiesForEntity (14L , null )).thenReturn (entityWithIdEmailData .getIdentities ());
155
+ when (membershipDAO .getEntityMembership (14L )).thenReturn (List .of (new GroupMembership ("/" , 14L , new Date ()), new GroupMembership ("/B" , 14L , new Date ())));
156
+
157
+ ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , identityDAO , attributeDAO , entityDAO , idResolver , credentialsHelper , identityHelper , membershipDAO );
147
158
Set <
EntityWithContactInfo >
entityIdByContactAddress =
userFinder .
getEntitiesIdsByContactAddressesWithDirectAttributeCheck (
Set .
of (
"[email protected] " ));
148
159
assertThat (entityIdByContactAddress .stream ().map (e -> e .entity .getId ()).collect (Collectors .toSet ())).contains (14L , 13L );
149
160
assertThat (entityIdByContactAddress .stream ().filter (e -> e .entity .getId ().equals (13l )).findFirst ().get ().groups ).containsExactlyElementsOf (Set .of ("/A" , "/" ));
@@ -160,14 +171,17 @@ public void shouldFindAllEntitiesWithGivenEmailRespectOnlyEmailIdentity() throws
160
171
when (attrHelper .getAttributeTypeWithSingeltonMetadata (ContactEmailMetadataProvider .NAME )).thenReturn (null );
161
172
162
173
when (
identityDAO .
getIdByTypeAndValues (
EmailIdentity .
ID ,
List .
of (
"[email protected] " ,
"[email protected] " ))).
thenReturn (
Set .
of (
14L ,
15L ));
163
- when (entityManagement .getEntity (new EntityParam (14L ))).thenReturn (entityWithIdEmailData1 );
164
- when (entityManagement .getGroups (new EntityParam (14L ))).thenReturn (Map .of ("/" , new GroupMembership ("/" , 15L , new Date ()), "/B" , new GroupMembership ("/B" , 14L , new Date ())));
165
- when (entityManagement .getEntity (new EntityParam (15L ))).thenReturn (entityWithIdEmailData2 );
166
- when (entityManagement .getGroups (new EntityParam (15L ))).thenReturn (Map .of ("/" , new GroupMembership ("/" , 15L , new Date ()), "/C" , new GroupMembership ("/C" , 14L , new Date ())));
167
-
174
+ when (idResolver .getEntityId (new EntityParam (14L ))).thenReturn (14L );
175
+ when (entityDAO .getByKey (14L )).thenReturn (entityWithIdEmailData1 .getEntityInformation ());
176
+ when (identityHelper .getIdentitiesForEntity (14L , null )).thenReturn (entityWithIdEmailData1 .getIdentities ());
177
+ when (membershipDAO .getEntityMembership (14L )).thenReturn (List .of (new GroupMembership ("/" , 14L , new Date ()), new GroupMembership ("/B" , 14L , new Date ())));
168
178
179
+ when (idResolver .getEntityId (new EntityParam (15L ))).thenReturn (15L );
180
+ when (entityDAO .getByKey (15L )).thenReturn (entityWithIdEmailData2 .getEntityInformation ());
181
+ when (identityHelper .getIdentitiesForEntity (15L , null )).thenReturn (entityWithIdEmailData2 .getIdentities ());
182
+ when (membershipDAO .getEntityMembership (15L )).thenReturn (List .of (new GroupMembership ("/" , 15L , new Date ()), new GroupMembership ("/C" , 15L , new Date ())));
169
183
170
- ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , entityManagement , identityDAO , attributeDAO );
184
+ ExistingUserFinder userFinder = new ExistingUserFinder (bulkService , attrHelper , groupsManagement , identityDAO , attributeDAO , entityDAO , idResolver , credentialsHelper , identityHelper , membershipDAO );
171
185
Set <
EntityWithContactInfo >
entityIdByContactAddress =
userFinder .
getEntitiesIdsByContactAddressesWithDirectAttributeCheck (
Set .
of (
"[email protected] " ,
"[email protected] " ));
172
186
173
187
assertThat (entityIdByContactAddress .stream ().map (e -> e .entity .getId ()).collect (Collectors .toSet ())).contains (14L , 15L );
0 commit comments