Delegatee { @NotNull String[] syncAllUsers(boolean purge) { try { ResultMessages messages = new ResultMessages(); context.setKeepMissing(!purge) .setForceGroupSync(true) .setForceUserSync(true); Iterator<SyncedIdentity> it = handler.listIdentities(userMgr); List<SyncResult> results = new ArrayList<>(batchSize); while (it.hasNext()) { SyncedIdentity id = it.next(); if (isMyIDP(id)) { results = syncUser(id.getId(), false, results, messages); } } commit(messages, results, NO_BATCH_SIZE); return messages.getMessages(); } catch (RepositoryException e) { throw new IllegalStateException("Error retrieving users for syncing", e); } } private  Delegatee(@NotNull SyncHandler handler, @NotNull ExternalIdentityProvider idp,
                      @NotNull ContentSession systemSession, @NotNull SecurityProvider securityProvider, int batchSize);   }
@Test public void testSyncAllUsersBeforeSaveError() throws Exception { Root r = preventRootCommit(delegatee);; String[] result = delegatee.syncAllUsers(false); assertResultMessages(result, ImmutableMap.<String,String>of()); assertFalse(r.hasPendingChanges()); }
@Test public void testSyncAllUsersSaveError() throws Exception { sync(idp, ID_TEST_USER, false); sync(idp, TestIdentityProvider.ID_SECOND_USER, false); sync(new TestIdentityProvider.TestUser("third", idp.getName()), idp); sync(foreignIDP, TestIdentityProvider.ID_WILDCARD_USER, false); Root r = preventRootCommit(delegatee);; ImmutableMap<String, String> expected = ImmutableMap.<String, String>builder() .put(ID_TEST_USER, "ERR") .put("a", "ERR") .put("b", "ERR") .put("c", "ERR") .put(TestIdentityProvider.ID_SECOND_USER, "ERR") .put("secondGroup", "ERR") .put("third", "mis").build(); String[] result = delegatee.syncAllUsers(false); assertResultMessages(result, expected); assertFalse(r.hasPendingChanges()); }
@Test public void testSyncAllUsersPurgeSaveError() throws Exception { sync(idp, ID_TEST_USER, false); sync(idp, TestIdentityProvider.ID_SECOND_USER, false); sync(new TestIdentityProvider.TestUser("third", idp.getName()), idp); sync(foreignIDP, TestIdentityProvider.ID_WILDCARD_USER, false); Root r = preventRootCommit(delegatee);; ImmutableMap<String, String> expected = ImmutableMap.<String, String>builder() .put(ID_TEST_USER, "ERR") .put("a", "ERR") .put("b", "ERR") .put("c", "ERR") .put(TestIdentityProvider.ID_SECOND_USER, "ERR") .put("secondGroup", "ERR") .put("third", "ERR").build(); String[] result = delegatee.syncAllUsers(true); assertResultMessages(result, expected); assertFalse(r.hasPendingChanges()); }