1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.social.core.manager;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.HashMap;
22 import java.util.List;
23
24 import org.apache.commons.lang.StringEscapeUtils;
25 import org.exoplatform.commons.utils.ListAccess;
26 import org.exoplatform.services.organization.User;
27 import org.exoplatform.services.organization.UserHandler;
28 import org.exoplatform.services.security.ConversationState;
29 import org.exoplatform.services.security.IdentityRegistry;
30 import org.exoplatform.social.core.activity.model.ExoSocialActivity;
31 import org.exoplatform.social.core.identity.SpaceMemberFilterListAccess.Type;
32 import org.exoplatform.social.core.identity.model.Identity;
33 import org.exoplatform.social.core.identity.model.Profile;
34 import org.exoplatform.social.core.identity.provider.Application;
35 import org.exoplatform.social.core.identity.provider.FakeIdentityProvider;
36 import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
37 import org.exoplatform.social.core.identity.provider.SpaceIdentityProvider;
38 import org.exoplatform.social.core.profile.ProfileFilter;
39 import org.exoplatform.social.core.space.SpaceUtils;
40 import org.exoplatform.social.core.space.impl.DefaultSpaceApplicationHandler;
41 import org.exoplatform.social.core.space.model.Space;
42 import org.exoplatform.social.core.space.spi.SpaceService;
43 import org.exoplatform.social.core.storage.ActivityStorageException;
44 import org.exoplatform.social.core.test.AbstractCoreTest;
45 import org.junit.FixMethodOrder;
46 import org.junit.runners.MethodSorters;
47
48
49
50
51
52
53
54
55
56 @FixMethodOrder(MethodSorters.JVM)
57 public class IdentityManagerTest extends AbstractCoreTest {
58
59 private IdentityManager identityManager;
60
61 private List<Space> tearDownSpaceList;
62 private List<Identity> tearDownIdentityList;
63
64 private ActivityManager activityManager;
65 private SpaceService spaceService;
66 private UserHandler userHandler;
67
68 public void setUp() throws Exception {
69 super.setUp();
70 identityManager = (IdentityManager) getContainer().getComponentInstanceOfType(IdentityManager.class);
71 assertNotNull(identityManager);
72
73 spaceService = (SpaceService) getContainer().getComponentInstanceOfType(SpaceService.class);
74 assertNotNull(spaceService);
75
76 activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class);
77 assertNotNull(activityManager);
78
79 userHandler = SpaceUtils.getOrganizationService().getUserHandler();
80
81 tearDownIdentityList = new ArrayList<Identity>();
82 tearDownSpaceList = new ArrayList<Space>();
83 org.exoplatform.services.security.Identity identity = getService(IdentityRegistry.class).getIdentity("root");
84 ConversationState.setCurrent(new ConversationState(identity));
85 }
86
87 public void tearDown() throws Exception {
88 for (Identity identity : tearDownIdentityList) {
89 identityManager.deleteIdentity(identity);
90 }
91 for (Space space : tearDownSpaceList) {
92 Identity spaceIdentity = identityManager.getOrCreateIdentity(SpaceIdentityProvider.NAME, space.getPrettyName(), false);
93 if (spaceIdentity != null) {
94 identityManager.deleteIdentity(spaceIdentity);
95 }
96 spaceService.deleteSpace(space);
97 }
98 super.tearDown();
99 }
100
101
102
103
104
105 public void testRegisterIdentityProviders() {
106
107 assert true;
108 }
109
110
111
112
113 public void testSaveIdentity() {
114 Identity tobeSavedIdentity = new Identity(OrganizationIdentityProvider.NAME, "identity1");
115 identityManager.saveIdentity(tobeSavedIdentity);
116
117 assertNotNull(tobeSavedIdentity.getId());
118
119
120
121
122
123
124
125
126
127
128
129 tearDownIdentityList.add(tobeSavedIdentity);
130 }
131
132
133
134
135 public void testGetIdentityById() {
136 final String username = "root";
137 Identity foundIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username,
138 true);
139
140
141 {
142 Identity gotIdentity = identityManager.getIdentity(foundIdentity.getId(), true);
143
144 assertNotNull(gotIdentity);
145 assertEquals(foundIdentity.getId(), gotIdentity.getId());
146 assertEquals("gotIdentity.getProviderId() must return: " + OrganizationIdentityProvider.NAME,
147 OrganizationIdentityProvider.NAME,
148 gotIdentity.getProviderId());
149 assertEquals("gotIdentity.getRemoteId() must return: " + username,
150 username,
151 gotIdentity.getRemoteId());
152
153
154 assertNotNull("gotIdentity.getProfile().getId() must not return: null",
155 gotIdentity.getProfile().getId());
156
157 assertNotNull("gotIdentity.getProfile().getProperty(Profile.FIRST_NAME) must not be null", gotIdentity.getProfile().getProperty(Profile.FIRST_NAME));
158 assertFalse("gotIdentity.getProfile().getFullName().isEmpty() must be false", gotIdentity.getProfile().getFullName().isEmpty());
159
160
161 }
162
163
164
165 {
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 }
193
194 tearDownIdentityList.add(identityManager.getIdentity(foundIdentity.getId(), false));
195 }
196
197
198
199
200
201 public void testGetSpaceMembers() throws Exception {
202
203 Identity demoIdentity = populateIdentity("demo");
204 Identity johnIdentity = populateIdentity("john");
205 Identity maryIdentity = populateIdentity("mary");
206 int number = 0;
207 Space space = new Space();
208 space.setDisplayName("my space " + number);
209 space.setPrettyName(space.getDisplayName());
210 space.setRegistration(Space.OPEN);
211 space.setDescription("add new space " + number);
212 space.setType(DefaultSpaceApplicationHandler.NAME);
213 space.setVisibility(Space.PUBLIC);
214 space.setRegistration(Space.VALIDATION);
215 space.setPriority(Space.INTERMEDIATE_PRIORITY);
216 space.setGroupId("/space/space" + number);
217 space.setUrl(space.getPrettyName());
218 String[] spaceManagers = new String[] {demoIdentity.getRemoteId()};
219 String[] members = new String[] {demoIdentity.getRemoteId()};
220 String[] invitedUsers = new String[] {};
221 String[] pendingUsers = new String[] {};
222 space.setInvitedUsers(invitedUsers);
223 space.setPendingUsers(pendingUsers);
224 space.setManagers(spaceManagers);
225 space.setMembers(members);
226
227 space = this.createSpaceNonInitApps(space, demoIdentity.getRemoteId(), null);
228
229 Space savedSpace = spaceService.getSpaceByDisplayName(space.getDisplayName());
230 assertNotNull("savedSpace must not be null", savedSpace);
231
232
233 spaceService.addMember(savedSpace, johnIdentity.getRemoteId());
234 spaceService.addMember(savedSpace, maryIdentity.getRemoteId());
235
236 {
237 ProfileFilter profileFilter = new ProfileFilter();
238 ListAccess<Identity> spaceMembers = identityManager.getSpaceIdentityByProfileFilter(savedSpace, profileFilter, Type.MEMBER, true);
239 assertEquals(3, spaceMembers.getSize());
240 }
241
242
243 spaceService.removeMember(savedSpace, johnIdentity.getRemoteId());
244 {
245 ProfileFilter profileFilter = new ProfileFilter();
246 ListAccess<Identity> got = identityManager.getSpaceIdentityByProfileFilter(savedSpace, profileFilter, Type.MEMBER, true);
247 assertEquals(2, got.getSize());
248 }
249
250
251 tearDownSpaceList.add(savedSpace);
252
253 }
254
255
256
257
258 public void testGetIdentityByIdWithLoadProfile() {
259
260 final String username = "root";
261 Identity tobeSavedIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username,
262 true);
263
264 {
265 Identity gotIdentity = identityManager.getIdentity(tobeSavedIdentity.getId(), false);
266
267 assertNotNull(gotIdentity);
268 assertEquals(tobeSavedIdentity.getId(), gotIdentity.getId());
269 assertEquals("gotIdentity.getProviderId() must return: " + OrganizationIdentityProvider.NAME,
270 OrganizationIdentityProvider.NAME,
271 gotIdentity.getProviderId());
272 assertEquals("gotIdentity.getRemoteId() must return: " + username,
273 username,
274 gotIdentity.getRemoteId());
275
276
277
278
279 }
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 tearDownIdentityList.add(identityManager.getIdentity(tobeSavedIdentity.getId(), false));
306
307 }
308
309
310
311
312 public void testDeleteIdentity() {
313 final String username = "demo";
314 Identity tobeSavedIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username,
315 false);
316
317 assertNotNull("tobeSavedIdentity.getId() must not be null", tobeSavedIdentity.getId());
318
319 assertNotNull("tobeSavedIdentity.getProfile().getId() must not be null",
320 tobeSavedIdentity.getProfile().getId());
321
322 identityManager.deleteIdentity(tobeSavedIdentity);
323
324
325
326 Identity gotIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
327 assertNotNull("gotIdentity must not be null because " + username + " is in organizationService",
328 gotIdentity);
329 assertNotNull("gotIdentity.getId() must not be null", gotIdentity.getId());
330
331
332 tearDownIdentityList.add(gotIdentity);
333 }
334
335
336
337
338 public void testDisabledIdentity() throws Exception {
339 final String username = "demo";
340 Identity disabledIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
341 userHandler.setEnabled(username, false, true);
342 identityManager.processEnabledIdentity(username, false);
343
344 disabledIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
345
346 assertFalse(disabledIdentity.isDeleted());
347 assertFalse(disabledIdentity.isEnable());
348
349 identityManager.deleteIdentity(disabledIdentity);
350 }
351
352
353
354
355 public void testEnabledIdentity() throws Exception {
356 final String username = "demo";
357 Identity enbledIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
358
359 userHandler.setEnabled(username, false, true);
360 identityManager.processEnabledIdentity(username, false);
361
362 enbledIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
363
364
365 userHandler.setEnabled(username, true, true);
366 identityManager.processEnabledIdentity(username, true);
367
368
369 enbledIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username, false);
370 assertFalse(enbledIdentity.isDeleted());
371 assertTrue(enbledIdentity.isEnable());
372
373
374 identityManager.deleteIdentity(enbledIdentity);
375 }
376
377
378
379
380
381 public void testAddIdentityProvider() {
382
383 assert true;
384 }
385
386
387
388
389 public void testGetOrCreateIdentity() {
390 final String username1 = "john";
391 final String username2 = "root";
392 Identity gotIdentity1;
393 Identity gotIdentity2;
394
395 {
396 gotIdentity1 = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
397 username1, true);
398
399 Profile profile1 = gotIdentity1.getProfile();
400
401
402 assertNotNull("gotIdentity1.getId() must not be null", gotIdentity1.getId());
403 assertNotNull("profile1.getId() must not be null", profile1.getId());
404 assertNotNull("profile1.getProperty(Profile.FIRST_NAME) must not be null", profile1.getProperty(Profile.FIRST_NAME));
405 assertNotNull("profile1.getProperty(Profile.LAST_NAME must not be null", profile1.getProperty(Profile.LAST_NAME));
406 assertFalse("profile1.getFullName().isEmpty() must return false", profile1.getFullName().isEmpty());
407
408 assertNotNull("gotIdentity1.getId() must not be null", gotIdentity1.getId());
409 Identity regotIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username1, true);
410
411 assertNotNull("regotIdentity.getId() must not be null", regotIdentity.getId());
412 assertNotNull("regotIdentity.getProfile().getId() must not be null", regotIdentity.getProfile().getId());
413
414 }
415
416
417 {
418 gotIdentity2 = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
419 username2,
420 false);
421 assertNotNull("gotIdentity2.getId() must not be null", gotIdentity2.getId());
422
423 assertNotNull("gotIdentity2.getProfile().getId() must not be null", gotIdentity2.getProfile()
424 .getId());
425 }
426
427 ActivityManager activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class);
428
429 assertEquals("activityManager.getActivities(gotIdentity1).size() must be 0", 0, activityManager.getActivities(gotIdentity1).size());
430 assertEquals("activityManager.getActivities(gotIdentity2).size() must be 0", 0, activityManager.getActivities(gotIdentity2).size());
431
432
433
434
435
436
437
438
439
440
441
442
443
444 tearDownIdentityList.add(identityManager.getIdentity(gotIdentity1.getId()));
445 tearDownIdentityList.add(identityManager.getIdentity(gotIdentity2.getId()));
446 }
447
448
449
450
451 public void testGetProfile() throws Exception {
452 Identity identity = populateIdentity("root");
453 assertNotNull("Identity must not be null.", identity);
454 assertNull("Profile status must be not loaded yet.", identity.getProfile().getId());
455 Profile profile = identityManager.getProfile(identity);
456 assertNotNull("Profile must not be null.", profile);
457 assertNotNull("Profile status must be loaded.", identity.getProfile().getId());
458
459 FakeIdentityProvider fakeIdentityProvider = (FakeIdentityProvider) getContainer().getComponentInstanceOfType(FakeIdentityProvider.class);
460
461 Application application = new Application();
462 application.setId("externalApp");
463 application.setName("External Application");
464 application.setDescription("external application identity");
465 application.setUrl("http://google.com/");
466 application.setIcon("http://google.com/logo.png");
467
468 Identity appIdentity = fakeIdentityProvider.createIdentity(application);
469 fakeIdentityProvider.addApplication(application);
470
471 appIdentity = identityManager.getOrCreateIdentity(FakeIdentityProvider.NAME, appIdentity.getRemoteId(), true);
472 assertNotNull("Identity must be create", appIdentity);
473
474 Profile profile1 = appIdentity.getProfile();
475
476 assertEquals("http://google.com/", profile1.getUrl());
477 assertEquals("http://google.com/logo.png", profile1.getAvatarUrl());
478
479 Identity appIdentityRecheck = identityManager.getOrCreateIdentity(FakeIdentityProvider.NAME, appIdentity.getRemoteId(), true);
480 Profile appProfileRecheck = appIdentityRecheck.getProfile();
481
482 assertEquals("http://google.com/", appProfileRecheck.getUrl());
483 assertEquals("http://google.com/logo.png", appProfileRecheck.getAvatarUrl());
484 }
485
486
487
488
489 public void testGetIdentitiesByProfileFilter() throws Exception {
490 String providerId = OrganizationIdentityProvider.NAME;
491 populateIdentities(5, true);
492
493 ProfileFilter pf = new ProfileFilter();
494 ListAccess<Identity> idsListAccess = null;
495 {
496
497 pf.setFirstCharacterOfName('F');
498 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
499 assertNotNull(idsListAccess);
500 assertEquals(0, idsListAccess.getSize());
501 pf.setFirstCharacterOfName('L');
502 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
503 assertNotNull(idsListAccess);
504 assertEquals(5, idsListAccess.getSize());
505
506
507 pf.setFirstCharacterOfName('\u0000');
508 pf.setName("FirstName");
509 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
510 assertNotNull(idsListAccess);
511 assertEquals(5, idsListAccess.getSize());
512
513
514 pf.setName("FirstName1");
515 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
516 assertNotNull(idsListAccess);
517 assertEquals(1, idsListAccess.getSize());
518
519
520 pf.setName("");
521 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
522 assertNotNull(idsListAccess);
523 assertEquals(5, idsListAccess.getSize());
524
525
526 pf.setViewerIdentity(identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "username1"));
527 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
528 assertNotNull(idsListAccess);
529 assertEquals(4, idsListAccess.getSize());
530 pf.setViewerIdentity(null);
531
532
533 pf.setName("*");
534 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
535 assertNotNull(idsListAccess);
536 assertEquals(5, idsListAccess.getSize());
537
538
539 pf.setName("n%me");
540 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
541 assertNotNull(idsListAccess);
542 assertEquals(5, idsListAccess.getSize());
543
544
545 pf.setName("n*me");
546 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
547 assertNotNull(idsListAccess);
548 assertEquals(5, idsListAccess.getSize());
549
550
551 pf.setName("%me");
552 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
553 assertNotNull(idsListAccess);
554 assertEquals(5, idsListAccess.getSize());
555
556
557 pf.setName("%name%");
558 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
559 assertNotNull(idsListAccess);
560 assertEquals(5, idsListAccess.getSize());
561
562
563 pf.setName("n%me");
564 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
565 assertNotNull(idsListAccess);
566 assertEquals(5, idsListAccess.getSize());
567
568
569 pf.setName("fir%n%me");
570 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
571 assertNotNull(idsListAccess);
572 assertEquals(5, idsListAccess.getSize());
573
574
575 pf.setName("noname");
576 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
577 assertNotNull(idsListAccess);
578 assertEquals(0, idsListAccess.getSize());
579 }
580
581 {
582 pf.setName("");
583 pf.setPosition("dev");
584 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
585 assertNotNull(idsListAccess);
586 assertEquals(5, idsListAccess.getSize());
587
588
589 pf.setPosition("d%v");
590 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
591 assertNotNull(idsListAccess);
592 assertEquals(5, idsListAccess.getSize());
593
594
595 pf.setPosition("test");
596 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
597 assertNotNull(idsListAccess);
598 assertEquals(0, idsListAccess.getSize());
599 }
600
601 {
602 pf.setPosition("");
603 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
604 assertNotNull(idsListAccess);
605 assertEquals(5, idsListAccess.getSize());
606 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
607 assertNotNull(idsListAccess);
608 }
609
610 {
611 pf.setName("n**me%");
612 pf.setPosition("*%");
613 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
614 assertNotNull(idsListAccess);
615 assertEquals(5, idsListAccess.getSize());
616
617
618 pf.setName("noname");
619 pf.setPosition("*%");
620 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
621 assertNotNull(idsListAccess);
622 assertEquals(0, idsListAccess.getSize());
623 }
624
625
626 {
627 ProfileFilter profileFilter = new ProfileFilter();
628 ListAccess<Identity> identityListAccess = identityManager.getIdentitiesByProfileFilter("organization", profileFilter, false);
629 assertEquals(5, identityListAccess.getSize());
630
631
632 Identity testIdentity = populateIdentity("test", false);
633 identityListAccess = identityManager.getIdentitiesByProfileFilter("organization", profileFilter, false);
634 assertEquals(6, identityListAccess.getSize());
635
636
637 identityManager.deleteIdentity(testIdentity);
638 identityListAccess = identityManager.getIdentitiesByProfileFilter("organization", profileFilter, false);
639 assertEquals(5, identityListAccess.getSize());
640 }
641
642
643 {
644 Identity excludeIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "username1", false);
645 List<Identity> excludedIdentities = new ArrayList<Identity>();
646 excludedIdentities.add(excludeIdentity);
647 ProfileFilter profileFilter = new ProfileFilter();
648 profileFilter.setExcludedIdentityList(excludedIdentities);
649 ListAccess<Identity> identityListAccess = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, profileFilter, false);
650 assertEquals(4, identityListAccess.getSize());
651 Identity[] identityArray = identityListAccess.load(0, 3);
652 assertEquals(3, identityArray.length);
653 }
654 }
655
656 public void testGetIdentitiesWithSpecialCharacters() throws Exception {
657 Identity identity = new Identity(OrganizationIdentityProvider.NAME, "username1");
658 identityManager.saveIdentity(identity);
659 Profile profile = new Profile(identity);
660 profile.setProperty(Profile.USERNAME, "username1");
661 profile.setProperty(Profile.FIRST_NAME, "FirstName");
662 profile.setProperty(Profile.LAST_NAME, "LastName");
663 profile.setProperty(Profile.FULL_NAME, "FirstName LastName");
664 profile.setProperty(Profile.POSITION, StringEscapeUtils.escapeHtml("A&d"));
665 profile.setProperty(Profile.GENDER, "male");
666 identityManager.saveProfile(profile);
667 identity.setProfile(profile);
668 tearDownIdentityList.add(identity);
669
670 ProfileFilter pf = new ProfileFilter();
671 pf.setPosition("A&d");
672 ListAccess<Identity> identityListAccess = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, pf, false);
673 assertEquals(1, identityListAccess.getSize());
674 assertEquals(1, identityListAccess.load(0, 10).length);
675
676 profile.setProperty(Profile.POSITION, StringEscapeUtils.escapeHtml("!@#$%^&*()"));
677 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT));
678 identityManager.updateProfile(profile);
679
680 pf.setPosition("!@#$%^&*()");
681 identityListAccess = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, pf, false);
682 assertEquals(1, identityListAccess.getSize());
683 assertEquals(1, identityListAccess.load(0, 10).length);
684
685
686 HashMap<String, Object> uiMap = new HashMap<String, Object>();
687 ArrayList<HashMap<String, Object>> experiences = new ArrayList<HashMap<String, Object>>();
688 uiMap.put(Profile.EXPERIENCES_SKILLS, StringEscapeUtils.escapeHtml("!@#$%^&*()"));
689 experiences.add(uiMap);
690 profile.setProperty(Profile.EXPERIENCES, experiences);
691 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.EXPERIENCES));
692 identityManager.updateProfile(profile);
693
694 pf = new ProfileFilter();
695 pf.setSkills("!@#$%^&*()");
696 identityListAccess = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, pf, false);
697 assertEquals(1, identityListAccess.getSize());
698
699
700 uiMap = new HashMap<String, Object>();
701 experiences = new ArrayList<HashMap<String, Object>>();
702 uiMap.put(Profile.EXPERIENCES_SKILLS, StringEscapeUtils.escapeHtml("sale & marketing"));
703 experiences.add(uiMap);
704 profile.setProperty(Profile.EXPERIENCES, experiences);
705 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.EXPERIENCES));
706 identityManager.updateProfile(profile);
707
708 pf = new ProfileFilter();
709 pf.setSkills("sale & marketing");
710 identityListAccess = identityManager.getIdentitiesByProfileFilter(OrganizationIdentityProvider.NAME, pf, false);
711 assertEquals(1, identityListAccess.getSize());
712 }
713
714
715
716
717 public void testOrderOfGetIdentitiesByProfileFilter() throws Exception {
718
719 String providerId = "organization";
720 String[] FirstNameList = {"John","Bob","Alain"};
721 String[] LastNameList = {"Smith","Dupond","Dupond"};
722 for (int i = 0; i < 3; i++) {
723 String remoteId = "username" + i;
724 Identity identity = new Identity(providerId, remoteId);
725 identityManager.saveIdentity(identity);
726 Profile profile = new Profile(identity);
727 profile.setProperty(Profile.FIRST_NAME, FirstNameList[i]);
728 profile.setProperty(Profile.LAST_NAME, LastNameList[i]);
729 profile.setProperty(Profile.FULL_NAME, FirstNameList[i] + " " + LastNameList[i]);
730 profile.setProperty(Profile.POSITION, "developer");
731 profile.setProperty(Profile.GENDER, "male");
732
733 identityManager.saveProfile(profile);
734 identity.setProfile(profile);
735 tearDownIdentityList.add(identity);
736 }
737
738 ProfileFilter pf = new ProfileFilter();
739 ListAccess<Identity> idsListAccess = null;
740
741 pf.setFirstCharacterOfName('D');
742 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
743 assertNotNull(idsListAccess);
744 assertEquals(2, idsListAccess.getSize());
745 assertEquals("Alain Dupond", idsListAccess.load(0, 20)[0].getProfile().getFullName());
746 assertEquals("Bob Dupond", idsListAccess.load(0, 20)[1].getProfile().getFullName());
747
748 pf = new ProfileFilter();
749 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
750 assertNotNull(idsListAccess);
751 assertEquals(3, idsListAccess.getSize());
752 assertEquals("Alain Dupond", idsListAccess.load(0, 20)[0].getProfile().getFullName());
753 assertEquals("Bob Dupond", idsListAccess.load(0, 20)[1].getProfile().getFullName());
754 assertEquals("John Smith", idsListAccess.load(0, 20)[2].getProfile().getFullName());
755
756
757 Identity[] identityArray = idsListAccess.load(0, 2);
758 assertEquals(tearDownIdentityList.get(2).getId(), identityArray[0].getId());
759
760 }
761
762
763
764
765 public void testUpdateIdentity() throws Exception {
766 Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root", true);
767 assertNotNull("Identity must not be null", identity);
768 assertEquals("Identity status must be " + identity.isDeleted(), false, identity.isDeleted());
769 identity.setDeleted(true);
770 identityManager.updateIdentity(identity);
771 Identity updatedIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root", false);
772 assertEquals("Identity status must be " + updatedIdentity.isDeleted(), true, updatedIdentity.isDeleted());
773 tearDownIdentityList.add(identity);
774 }
775
776
777
778
779 public void testUpdateProfile() throws Exception {
780 Identity rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root");
781 Profile profile = rootIdentity.getProfile();
782 profile.setProperty(Profile.POSITION, "CEO");
783 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT));
784 identityManager.updateProfile(profile);
785
786 Identity identityUpdated = identityManager.getOrCreateIdentity(rootIdentity.getProviderId(), rootIdentity.getRemoteId(), false);
787 assertEquals("CEO", identityUpdated.getProfile().getProperty(Profile.POSITION));
788
789 end();
790 begin();
791
792 List<ExoSocialActivity> rootActivityList = activityManager.getActivities(rootIdentity);
793
794 tearDownIdentityList.add(rootIdentity);
795 }
796
797 public void testUpdateProfileActivity() throws Exception {
798 Identity rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root", false);
799 Profile profile = rootIdentity.getProfile();
800 profile.setProperty(Profile.POSITION, "CEO");
801 assertEquals(0, profile.getListUpdateTypes().size());
802 identityManager.updateProfile(profile);
803 assertEquals(0, profile.getListUpdateTypes().size());
804
805 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT));
806 assertEquals(1, profile.getListUpdateTypes().size());
807
808 Identity identityUpdated = identityManager.getOrCreateIdentity(rootIdentity.getProviderId(), rootIdentity.getRemoteId(), false);
809 assertEquals("CEO", identityUpdated.getProfile().getProperty(Profile.POSITION));
810
811 end();
812 begin();
813
814 List<ExoSocialActivity> rootActivityList = activityManager.getActivities(rootIdentity);
815
816 tearDownIdentityList.add(rootIdentity);
817 }
818
819
820
821
822
823 private void populateData() {
824 populateIdentities(5, true);
825 }
826
827
828
829
830
831 private void populateData(String remoteId) {
832 String providerId = "organization";
833 Identity identity = new Identity(providerId, remoteId);
834 identityManager.saveIdentity(identity);
835 Profile profile = new Profile(identity);
836 profile.setProperty(Profile.FIRST_NAME, "FirstName " + remoteId);
837 profile.setProperty(Profile.LAST_NAME, "LastName" + remoteId);
838 profile.setProperty(Profile.FULL_NAME, "FirstName " + remoteId + " " + "LastName" + remoteId);
839 profile.setProperty(Profile.POSITION, "developer");
840 profile.setProperty(Profile.GENDER, "male");
841
842 identityManager.saveProfile(profile);
843 identity.setProfile(profile);
844 tearDownIdentityList.add(identity);
845 }
846
847
848
849
850
851
852
853
854 private void populateIdentities(int numberOfItems, boolean addedToTearDownList) {
855 String providerId = "organization";
856 for (int i = 0; i < numberOfItems; i++) {
857 String remoteId = "username" + i;
858 Identity identity = new Identity(providerId, remoteId);
859 identityManager.saveIdentity(identity);
860 Profile profile = new Profile(identity);
861 profile.setProperty(Profile.FIRST_NAME, "FirstName" + i);
862 profile.setProperty(Profile.LAST_NAME, "LastName" + i);
863 profile.setProperty(Profile.FULL_NAME, "FirstName" + i + " " + "LastName" + i);
864 profile.setProperty(Profile.POSITION, "developer");
865 profile.setProperty(Profile.GENDER, "male");
866
867 identityManager.saveProfile(profile);
868 identity.setProfile(profile);
869 if (addedToTearDownList) {
870 tearDownIdentityList.add(identity);
871 }
872 }
873 }
874
875
876
877
878
879
880
881 private Identity populateIdentity(String remoteId) {
882 return populateIdentity(remoteId, true);
883 }
884
885 private Identity populateIdentity(String remoteId, boolean addedToTearDownList) {
886 String providerId = "organization";
887 Identity identity = new Identity(providerId, remoteId);
888 identityManager.saveIdentity(identity);
889
890 Profile profile = new Profile(identity);
891 profile.setProperty(Profile.FIRST_NAME, remoteId);
892 profile.setProperty(Profile.LAST_NAME, "gtn");
893 profile.setProperty(Profile.FULL_NAME, remoteId + " " + "gtn");
894 profile.setProperty(Profile.POSITION, "developer");
895 profile.setProperty(Profile.GENDER, "male");
896
897 identityManager.saveProfile(profile);
898
899 if (addedToTearDownList) {
900 tearDownIdentityList.add(identity);
901 }
902 return identity;
903 }
904
905
906
907
908 public void testGetIdentitiesByProfileFilterWithProviderId() {
909
910 assert true;
911 }
912
913
914
915
916 public void testGetIdentitiesByProfileFilterWithoutProviderId() {
917
918 assert true;
919 }
920
921
922
923
924 public void testGetIdentitiesFilterByAlphabetWithProviderId() {
925
926 assert true;
927 }
928
929
930
931
932 public void testGetIdentitiesFilterByAlphaBetWihthoutProviderId() {
933
934
935 assert true;
936 }
937
938
939
940
941 public void testIdentityExisted() {
942
943 {
944 String remoteId = "notfound";
945 String providerId = OrganizationIdentityProvider.NAME;
946 final boolean existed = identityManager.identityExisted(providerId, remoteId);
947 assertFalse(existed);
948 }
949
950
951 {
952
953
954
955
956
957
958 String remoteId = "root";
959 String providerId = OrganizationIdentityProvider.NAME;
960 final boolean existed = identityManager.identityExisted(providerId, remoteId);
961 assertTrue(existed);
962 }
963
964 }
965
966
967
968
969 public void testUpdateAvatar() {
970 assert true;
971 }
972
973
974
975
976 public void testUpdateBasicInfo() {
977 assert true;
978 }
979
980
981
982
983 public void testUpdateContactSection() {
984 assert true;
985 }
986
987
988
989
990 public void testUpdateExperienceSection() {
991 assert true;
992 }
993
994
995
996
997 public void testUpdateHeaderSection() {
998 assert true;
999 }
1000
1001
1002
1003
1004 public void testGetIdentities() {
1005 assert true;
1006 }
1007
1008
1009
1010
1011 public void testGetIdentitiesWithLoadProfile() {
1012 assert true;
1013 }
1014
1015
1016
1017
1018 public void testRegisterProfileListener() {
1019 assert true;
1020 }
1021
1022
1023
1024
1025 public void testUnregisterProfileListener() {
1026 assert true;
1027 }
1028
1029
1030
1031
1032 public void testAddProfileListener() {
1033 assert true;
1034 }
1035
1036
1037
1038
1039 public void testCacheManagement() throws ActivityStorageException {
1040 Identity rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
1041 "root");
1042 Identity johnIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
1043 "john");
1044
1045
1046
1047
1048
1049
1050
1051 Profile rootProfile = rootIdentity.getProfile();
1052 Profile johnProfile = johnIdentity.getProfile();
1053
1054
1055
1056 final String newFirstName = "New First Name";
1057
1058 rootProfile.setProperty(Profile.FIRST_NAME, newFirstName);
1059 identityManager.saveProfile(rootProfile);
1060 Identity gotRootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
1061 "root",
1062 true);
1063 assertNotNull("gotRootIdentity.getId() must not be null", gotRootIdentity.getId());
1064 assertEquals("gotRootIdentity.getProfile().getProperty(Profile.FIRST_NAME) must be updated: "
1065 + newFirstName, newFirstName, gotRootIdentity.getProfile().getProperty(Profile.FIRST_NAME));
1066
1067 try {
1068 johnProfile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.AVATAR));
1069 identityManager.updateAvatar(johnProfile);
1070 } catch (Exception e1) {
1071 assert false : "can't update avatar" + e1 ;
1072 }
1073
1074 Identity gotJohnIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,
1075 "john");
1076 tearDownIdentityList.add(johnIdentity);
1077 tearDownIdentityList.add(rootIdentity);
1078
1079
1080 ActivityManager activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class);
1081
1082 end();
1083 begin();
1084
1085 List<ExoSocialActivity> johnActivityList = activityManager.getActivities(gotJohnIdentity, 0, 10);
1086 assertEquals("johnActivityList.size() must be 1", 1, johnActivityList.size());
1087 }
1088
1089 public void testGetIdentitiesByName() throws Exception {
1090 User user = userHandler.createUserInstance("alex");
1091 user.setFirstName("");
1092 user.setLastName("");
1093 user.setEmail("");
1094 userHandler.createUser(user, true);
1095 User found = userHandler.findUserByName("alex");
1096 assertNotNull(found);
1097 String providerId = OrganizationIdentityProvider.NAME;
1098
1099 Identity identity = new Identity(providerId, "alex");
1100 identityManager.saveIdentity(identity);
1101 Profile profile = new Profile(identity);
1102 profile.setProperty(Profile.USERNAME, "alex");
1103 profile.setProperty(Profile.FIRST_NAME, "Mary");
1104 profile.setProperty(Profile.LAST_NAME, "Williams");
1105 profile.setProperty(Profile.FULL_NAME, "Mary " + "Williams");
1106 profile.setProperty(Profile.POSITION, "developer");
1107 profile.setProperty(Profile.GENDER, "female");
1108 identityManager.saveProfile(profile);
1109 identity.setProfile(profile);
1110 tearDownIdentityList.add(identity);
1111
1112
1113 ProfileFilter pf = new ProfileFilter();
1114
1115
1116 pf.setName("Mary");
1117 ListAccess<Identity> idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
1118 assertEquals(1, idsListAccess.getSize());
1119 pf.setName("Williams");
1120 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
1121 assertEquals(1, idsListAccess.getSize());
1122 pf.setName("Mary Williams");
1123 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
1124 assertEquals(1, idsListAccess.getSize());
1125
1126
1127 profile.setProperty(Profile.FIRST_NAME, "Mary-James");
1128 profile.setProperty(Profile.FULL_NAME, "Mary-James Williams");
1129 profile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT));
1130 identityManager.updateProfile(profile);
1131 Identity alex = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "alex", true);
1132 assertEquals("Mary-James Williams", alex.getProfile().getFullName());
1133
1134 pf.setName("Mary-James Williams");
1135 idsListAccess = identityManager.getIdentitiesByProfileFilter(providerId, pf, false);
1136 assertEquals(1, idsListAccess.getSize());
1137
1138
1139 List<ExoSocialActivity> activities = activityManager.getActivitiesWithListAccess(identity).loadAsList(0, 20);
1140 for (ExoSocialActivity act : activities) {
1141 List<ExoSocialActivity> comments = activityManager.getCommentsWithListAccess(act).loadAsList(0, 20);
1142 for (ExoSocialActivity cmt : comments) {
1143 activityManager.deleteComment(act, cmt);
1144 }
1145 activityManager.deleteActivity(act);
1146 }
1147 userHandler.removeUser(user.getUserName(), false);
1148 }
1149 }