auth.setProperty(relPath, createValues((Collection) obj)); } else if (obj instanceof byte[] || obj instanceof char[]) { auth.setProperty(relPath, createValue(obj)); } else if (obj instanceof Object[]) { auth.setProperty(relPath, createValues(Arrays.asList((Object[]) obj))); } else { auth.setProperty(relPath, createValue(obj));
@Test public void testCreateValuesEmptyCollection() throws Exception { Value[] vs = syncCtx.createValues(ImmutableList.of()); assertNotNull(vs); assertEquals(0, vs.length); }
@Test public void testCreateValuesSkipsNull() throws Exception { List<String> strings = Lists.newArrayList("s", null, null, "t"); Value[] vs = syncCtx.createValues(strings); assertNotNull(vs); assertEquals(2, vs.length); }
@Test public void testSyncProperties() throws Exception { ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER); Authorizable a = syncCtx.createUser(externalUser); // create exact mapping Map<String, String> mapping = new HashMap<>(); Map<String, ?> extProps = externalUser.getProperties(); for (String propName : extProps.keySet()) { mapping.put(propName, propName); } syncCtx.syncProperties(externalUser, a, mapping); for (String propName : extProps.keySet()) { assertTrue(a.hasProperty(propName)); Object obj = extProps.get(propName); Value[] vs = a.getProperty(propName); if (vs.length == 1) { assertEquals(syncCtx.createValue(obj), a.getProperty(propName)[0]); } else { Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj)); assertArrayEquals(expected, a.getProperty(propName)); } } }
@Test public void testSyncPropertiesRemapped() throws Exception { ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_SECOND_USER); Authorizable a = syncCtx.createUser(externalUser); // create exact mapping Map<String, String> mapping = new HashMap<>(); Map<String, ?> extProps = externalUser.getProperties(); for (String propName : extProps.keySet()) { mapping.put("a/"+propName, propName); } syncCtx.syncProperties(externalUser, a, mapping); for (String propName : extProps.keySet()) { String relPath = "a/" + propName; assertTrue(a.hasProperty(relPath)); Object obj = extProps.get(propName); Value[] vs = a.getProperty(relPath); if (vs.length == 1) { assertEquals(syncCtx.createValue(obj), a.getProperty(relPath)[0]); } else { Value[] expected = (obj instanceof Collection) ? syncCtx.createValues((Collection) obj) : syncCtx.createValues(Arrays.asList((Object[]) obj)); assertArrayEquals(expected, a.getProperty(relPath)); } } }