DefaultSyncContext implements SyncContext { @Nullable public static DefaultSyncedIdentity createSyncedIdentity(@Nullable Authorizable auth) throws RepositoryException { if (auth == null) { return null; } ExternalIdentityRef ref = getIdentityRef(auth); Value[] lmValues = auth.getProperty(REP_LAST_SYNCED); long lastModified = -1; if (lmValues != null && lmValues.length > 0) { lastModified = lmValues[0].getLong(); } return new DefaultSyncedIdentity(auth.getID(), ref, auth.isGroup(), lastModified); } DefaultSyncContext(@NotNull DefaultSyncConfig config, @NotNull ExternalIdentityProvider idp, @NotNull UserManager userManager, @NotNull ValueFactory valueFactory); @Nullable static DefaultSyncedIdentity createSyncedIdentity(@Nullable Authorizable auth); @Nullable static ExternalIdentityRef getIdentityRef(@Nullable Authorizable auth); static String joinPaths(String... paths); @Override void close(); @Override boolean isKeepMissing(); @NotNull @Override SyncContext setKeepMissing(boolean keepMissing); @Override boolean isForceUserSync(); @NotNull @Override SyncContext setForceUserSync(boolean forceUserSync); @Override boolean isForceGroupSync(); @Override @NotNull SyncContext setForceGroupSync(boolean forceGroupSync); @NotNull @Override SyncResult sync(@NotNull ExternalIdentity identity); @NotNull @Override SyncResult sync(@NotNull String id); static final String REP_EXTERNAL_ID; static final String REP_LAST_SYNCED; }
@Test public void testCreateSyncedIdentityNull() throws Exception { assertNull(DefaultSyncContext.createSyncedIdentity(null)); }
@Test public void testCreateSyncedIdentityLocalGroup() throws Exception { Group gr = createTestGroup(); SyncedIdentity si = DefaultSyncContext.createSyncedIdentity(gr); assertNotNull(si); assertEquals(gr.getID(), si.getId()); assertNull(si.getExternalIdRef()); assertTrue(si.isGroup()); assertEquals(-1, si.lastSynced()); }
@Test public void testCreateSyncedIdentityLocalUser() throws Exception { User u = getTestUser(); SyncedIdentity si = DefaultSyncContext.createSyncedIdentity(u); assertNotNull(si); assertEquals(u.getID(), si.getId()); assertNull(si.getExternalIdRef()); assertFalse(si.isGroup()); assertEquals(-1, si.lastSynced()); }
@Test public void testCreateSyncedIdentityEmptyLastSyncedProperty() throws Exception { Group gr = createTestGroup(); gr.setProperty(DefaultSyncContext.REP_LAST_SYNCED, new Value[0]); SyncedIdentity si = DefaultSyncContext.createSyncedIdentity(gr); assertNotNull(si); assertEquals(-1, si.lastSynced()); }