DefaultSyncContext implements SyncContext { @Nullable protected Value createValue(@Nullable Object v) throws RepositoryException { if (v == null) { return null; } else if (v instanceof Boolean) { return valueFactory.createValue((Boolean) v); } else if (v instanceof Byte || v instanceof Short || v instanceof Integer || v instanceof Long) { return valueFactory.createValue(((Number) v).longValue()); } else if (v instanceof Float || v instanceof Double) { return valueFactory.createValue(((Number) v).doubleValue()); } else if (v instanceof BigDecimal) { return valueFactory.createValue((BigDecimal) v); } else if (v instanceof Calendar) { return valueFactory.createValue((Calendar) v); } else if (v instanceof Date) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) v); return valueFactory.createValue(cal); } else if (v instanceof byte[]) { Binary bin = valueFactory.createBinary(new ByteArrayInputStream((byte[])v)); return valueFactory.createValue(bin); } else if (v instanceof Binary) { return valueFactory.createValue((Binary) v); } else if (v instanceof InputStream) { return valueFactory.createValue((InputStream) v); } else if (v instanceof char[]) { return valueFactory.createValue(new String((char[]) v)); } else { return valueFactory.createValue(String.valueOf(v)); } } 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 testCreateValueNull() throws Exception { assertNull(syncCtx.createValue(null)); }
@Test public void testCreateValueString() throws Exception { Value v = syncCtx.createValue("s"); assertNotNull(v); assertEquals(PropertyType.STRING, v.getType()); assertEquals("s", v.getString()); v = syncCtx.createValue(new char[] {'s'}); assertNotNull(v); assertEquals(PropertyType.STRING, v.getType()); assertEquals("s", v.getString()); Object o = new TestIdentityProvider.ForeignExternalUser(); v = syncCtx.createValue(o); assertNotNull(v); assertEquals(PropertyType.STRING, v.getType()); assertEquals(o.toString(), v.getString()); }
@Test public void testCreateValueBoolean() throws Exception { Value v = syncCtx.createValue(true); assertNotNull(v); assertEquals(PropertyType.BOOLEAN, v.getType()); assertEquals(true, v.getBoolean()); }
@Test public void testCreateValueLong() throws Exception { Value v = syncCtx.createValue(Long.MAX_VALUE); assertNotNull(v); assertEquals(PropertyType.LONG, v.getType()); assertEquals(Long.MAX_VALUE, v.getLong()); v = syncCtx.createValue(23); assertNotNull(v); assertEquals(PropertyType.LONG, v.getType()); assertEquals(23, v.getLong()); v = syncCtx.createValue(Short.MIN_VALUE); assertNotNull(v); assertEquals(PropertyType.LONG, v.getType()); assertEquals(Short.MIN_VALUE, v.getLong()); v = syncCtx.createValue(Byte.MAX_VALUE); assertNotNull(v); assertEquals(PropertyType.LONG, v.getType()); assertEquals(Byte.MAX_VALUE, v.getLong()); }
@Test public void testCreateValueDouble() throws Exception { Value v = syncCtx.createValue(1.1); assertNotNull(v); assertEquals(PropertyType.DOUBLE, v.getType()); assertEquals(1.1, v.getDouble(), 0); v = syncCtx.createValue(Float.NaN); assertNotNull(v); assertEquals(PropertyType.DOUBLE, v.getType()); assertEquals(Float.NaN, v.getDouble(), 0); }
@Test public void testCreateValueDate() throws Exception { Date d = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(d); Value v = syncCtx.createValue(cal); assertNotNull(v); assertEquals(PropertyType.DATE, v.getType()); Value v2 = syncCtx.createValue(d); assertNotNull(v2); assertEquals(PropertyType.DATE, v2.getType()); assertEquals(v, v2); }
@Test public void testCreateValueDecimal() throws Exception { BigDecimal dec = new BigDecimal(123); Value v = syncCtx.createValue(dec); assertNotNull(v); assertEquals(PropertyType.DECIMAL, v.getType()); assertEquals(dec, v.getDecimal()); }
@Test public void testCreateValueFromBytesArray() throws Exception { byte[] bytes = new byte[]{'a', 'b'}; ByteArrayInputStream is = new ByteArrayInputStream(bytes); Binary binary = valueFactory.createBinary(is); Value v = syncCtx.createValue(bytes); assertNotNull(v); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(binary, v.getBinary()); }
@Test public void testCreateValueFromBinary() throws Exception { byte[] bytes = new byte[]{'a', 'b'}; ByteArrayInputStream is = new ByteArrayInputStream(bytes); Binary binary = valueFactory.createBinary(is); Value v = syncCtx.createValue(binary); assertNotNull(v); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(binary, v.getBinary()); }
@Test public void testCreateValueFromInputStream() throws Exception { byte[] bytes = new byte[]{'a', 'b'}; ByteArrayInputStream is = new ByteArrayInputStream(bytes); Binary binary = valueFactory.createBinary(is); Value v = syncCtx.createValue(is); assertNotNull(v); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(binary, v.getBinary()); }