use of eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testSaveEavWithOwner.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testSaveEavWithOwner() {
List<FormableDto> owners = new ArrayList<>();
// implemented authorization policies for eav attributes
owners.add(getHelper().createIdentity((GuardedString) null));
// without authorization policies for eav attributes
owners.add(getHelper().createRole());
//
owners.forEach(owner -> {
//
// create definition with parameter
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
attribute.setCode(attributeName);
attribute.setName(attributeName);
attribute.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(owner.getClass().getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
// fill values
IdmFormValueDto value = new IdmFormValueDto(attribute);
value.setValue(FORM_VALUE_ONE);
owner.getEavs().add(new IdmFormInstanceDto(owner, formDefinitionOne, Lists.newArrayList(value)));
owner = (FormableDto) ((AbstractFormableService) lookupService.getDtoService(owner.getClass())).save(owner);
// check form instance values were saved
owner.getEavs().forEach(formInstance -> {
Assert.assertFalse(formInstance.getValues().isEmpty());
formInstance.getValues().forEach(formValue -> {
Assert.assertNotNull(formValue.getId());
Assert.assertNotNull(formValue.getCreated());
});
});
//
// load saved
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
Assert.assertEquals(1, m.get(attributeName).size());
Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeName).get(0)).getValue());
});
}
Aggregations