use of eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testFindFormInstances.
@Test
public void testFindFormInstances() {
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
attributeOne = formDefinition.getMappedAttributeByCode(attributeOne.getCode());
attributeTwo = formDefinition.getMappedAttributeByCode(attributeTwo.getCode());
// create owner
IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
// fill values
IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
valueOne.setValue(FORM_VALUE_ONE);
IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
valueTwo.setValue(FORM_VALUE_TWO);
owner.getEavs().add(new IdmFormInstanceDto(owner, formDefinition, Lists.newArrayList(valueOne, valueTwo)));
identityService.save(owner);
//
// find saved values without filter
Map<String, List<IdmFormValueDto>> m = formService.findFormInstance(owner, formDefinition, null).toValueMap();
Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeOne.getCode()).get(0)).getValue());
Assert.assertEquals(FORM_VALUE_TWO, (m.get(attributeTwo.getCode()).get(0)).getValue());
//
m = formService.findFormInstances(owner, null).stream().filter(fi -> fi.getFormDefinition().equals(formDefinition)).findFirst().get().toValueMap();
Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeOne.getCode()).get(0)).getValue());
Assert.assertEquals(FORM_VALUE_TWO, (m.get(attributeTwo.getCode()).get(0)).getValue());
//
// find saved values with filter
DefaultFormableFilter filter = new DefaultFormableFilter();
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(attributeOne.getId());
filter.setFormDefinitionAttributes(Lists.newArrayList(attributes));
List<IdmFormValueDto> values = formService.findFormInstances(owner, filter).get(0).getValues();
Assert.assertEquals(1, values.size());
Assert.assertEquals(FORM_VALUE_ONE, values.get(0).getValue());
}
Aggregations