}
@Test
public void testAddSeveralSocialWorkspaceMembers() throws Exception {
assertEquals(0, ImportEventListener.getMemberAddedCount());
SocialWorkspace socialWorkspace = createSocialWorkspace("Social workspace for test");
assertTrue(socialWorkspace.isMembersNotificationEnabled());
String userAlreadyMember1Email = "userAlreadyMember1@mail.net";
DocumentModel userAlreadyMember1 = createUserForTest(
userAlreadyMember1Email, "userAlreadyMember1");
socialWorkspace.addMember(userManager.getPrincipal(userAlreadyMember1.getId()));
assertEquals(2, ImportEventListener.getMemberAddedCount());
socialWorkspace.getDocument().putContextData(ScopeType.REQUEST,
"memberNotificationDisabled", true);
assertFalse(socialWorkspace.isMembersNotificationEnabled());
DocumentModel userAlreadyMember2 = createUserForTest(
"userAlreadyMember2@mail.net", "userAlreadyMember2");
socialWorkspace.addMember(userManager.getPrincipal(userAlreadyMember2.getId()));
assertEquals(2, ImportEventListener.getMemberAddedCount());
socialWorkspace.getDocument().putContextData(ScopeType.REQUEST,
"memberNotificationDisabled", false);
DocumentModel fulltextEmailUser1 = createUserForTest(
"fulltextEmailUser1@mail.net", "fulltextEmailUser1");
String userNewMember1Email = "userNewMember1@mail.net";
createUserForTest(userNewMember1Email, "userNewMember1");
createUserForTest("userNewMember2@mail.net", "userNewMember2");
String nonExsitingUser1Email = "nonExistingUser1@mail.net";
List<String> emails = Arrays.asList(userAlreadyMember1Email,
"userAlreadyMember2@mail.net", "userNewMember1@mail.net",
"userNewMember2@mail.net", nonExsitingUser1Email,
"nonExistingUser2@mail.net", fulltextEmailUser1.getId());
Framework.getLocalService(EventService.class).waitForAsyncCompletion();
List<String> addedUsers = socialWorkspaceService.addSocialWorkspaceMembers(
socialWorkspace, emails);
assertEquals(3, socialWorkspace.getMembers().size());
assertTrue(socialWorkspace.isAdministratorOrMember(userManager.getPrincipal("userAlreadyMember1")));
assertEquals(3, addedUsers.size());
assertEquals(5, ImportEventListener.getMemberAddedCount());
assertEquals(3, ImportEventListener.getLastPrincipalsCount());
assertFalse(addedUsers.contains(userAlreadyMember1Email));
assertFalse(addedUsers.contains(nonExsitingUser1Email));