SyncMBeanImpl implements SynchronizationMBean { @NotNull @Override public String[] purgeOrphanedUsers() { Delegatee delegatee = getDelegatee(); try { return delegatee.purgeOrphanedUsers(); } finally { delegatee.close(); } } SyncMBeanImpl(@NotNull ContentRepository repository, @NotNull SecurityProvider securityProvider,
                         @NotNull SyncManager syncManager, @NotNull String syncName,
                         @NotNull ExternalIdentityProviderManager idpManager, @NotNull String idpName); @NotNull @Override String getSyncHandlerName(); @NotNull @Override String getIDPName(); @NotNull @Override String[] syncUsers(@NotNull String[] userIds, boolean purge); @NotNull @Override String[] syncAllUsers(boolean purge); @NotNull @Override String[] syncExternalUsers(@NotNull String[] externalIds); @NotNull @Override String[] syncAllExternalUsers(); @NotNull @Override String[] listOrphanedUsers(); @NotNull @Override String[] purgeOrphanedUsers();  }
@Test public void testPurgeOrphanedUsers() throws Exception { syncMBean.syncAllExternalUsers(); sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); String[] result = syncMBean.purgeOrphanedUsers(); assertResultMessages(result, ImmutableMap.of("thirdUser", "del", "g", "del")); UserManager userManager = getUserManager(); assertNull(userManager.getAuthorizable("thirdUser")); assertNull(userManager.getAuthorizable("g")); }
@Test public void testPurgeOrphanedUsersForeign() throws Exception { sync(foreignIDP, "a", true); sync(foreignIDP, TestIdentityProvider.ID_TEST_USER, false); String[] result = syncMBean.purgeOrphanedUsers(); assertEquals(0, result.length); }
@Test public void testPurgeOrphanedUsersException() throws Exception { User u = getUserManager().createUser(TestIdentityProvider.ID_EXCEPTION, null); u.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, getValueFactory().createValue(new ExternalIdentityRef(TestIdentityProvider.ID_EXCEPTION, idp.getName()).getString())); root.commit(); String[] result = syncMBean.purgeOrphanedUsers(); assertEquals(0, result.length); }
@Test public void testPurgeOrphanedUsersThrowingHandler() throws Exception { sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); String[] result = createThrowingSyncMBean(false).purgeOrphanedUsers(); assertEquals(0, result.length); UserManager userManager = getUserManager(); assertNotNull(userManager.getAuthorizable("thirdUser")); assertNotNull(userManager.getAuthorizable("g")); }
@Test public void testPurgeOrphanedUsersThrowingHandler2() throws Exception { sync(new TestIdentityProvider.TestUser("thirdUser", idp.getName()), idp); sync(new TestIdentityProvider.TestGroup("g", idp.getName()), idp); String[] result = createThrowingSyncMBean(true).purgeOrphanedUsers(); assertResultMessages(result, ImmutableMap.of("thirdUser", "ERR", "g", "ERR")); UserManager userManager = getUserManager(); assertNotNull(userManager.getAuthorizable("thirdUser")); assertNotNull(userManager.getAuthorizable("g")); }