/**
* @see http://code.google.com/p/syncope/issues/detail?id=42
*/
@Test
public void issue42() {
USchema userId = schemaDAO.find("userId", USchema.class);
Set<SchemaMapping> beforeUserIdMappings = new HashSet<SchemaMapping>();
for (SchemaMapping mapping : resourceDAO.findAllMappings()) {
if (userId.getName().equals(SchemaMappingUtil.getIntAttrName(mapping, IntMappingType.UserSchema))) {
beforeUserIdMappings.add(mapping);
}
}
SchemaMappingTO schemaMappingTO = new SchemaMappingTO();
schemaMappingTO.setIntAttrName("userId");
schemaMappingTO.setIntMappingType(IntMappingType.UserSchema);
schemaMappingTO.setExtAttrName("campo1");
schemaMappingTO.setAccountid(true);
schemaMappingTO.setPassword(false);
schemaMappingTO.setMandatoryCondition("false");
List<SchemaMappingTO> schemaMappingTOs = new ArrayList<SchemaMappingTO>();
schemaMappingTOs.add(schemaMappingTO);
ResourceTO resourceTO = new ResourceTO();
resourceTO.setName("resource-issue42");
resourceTO.setConnectorId(100L);
resourceTO.setMappings(schemaMappingTOs);
resourceTO.setPropagationMode(PropagationMode.ONE_PHASE);
resourceTO.setForceMandatoryConstraint(true);
ExternalResource resource = resourceDataBinder.create(resourceTO);
resource = resourceDAO.save(resource);
resourceDAO.flush();
ExternalResource actual = resourceDAO.find("resource-issue42");
assertNotNull(actual);
assertEquals(resource, actual);
userId = schemaDAO.find("userId", USchema.class);
Set<SchemaMapping> afterUserIdMappings = new HashSet<SchemaMapping>();
for (SchemaMapping mapping : resourceDAO.findAllMappings()) {
if (userId.getName().equals(SchemaMappingUtil.getIntAttrName(mapping, IntMappingType.UserSchema))) {
afterUserIdMappings.add(mapping);
}
}
assertEquals(beforeUserIdMappings.size(), afterUserIdMappings.size() - 1);