use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class AbstractFormValueUnitTest method testDateValueAsDate.
@Test
public void testDateValueAsDate() {
IdmFormValueDto formValue = new IdmFormValueDto();
formValue.setPersistentType(PersistentType.DATETIME);
DateTime current = new DateTime();
formValue.setValue(current.toDate());
assertEquals(current, formValue.getValue());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method testCreateForm.
@Test
@Transactional
public void testCreateForm() {
Codeable owner = helper.createIdentity();
IdmFormAttributeDto attribute = createDefinition();
IdmFormValueDto formValue = new IdmFormValueDto(attribute);
formValue.setValue("testOne");
IdmFormDto formOne = new IdmFormDto();
formOne.setName("test");
formOne.setFormDefinition(attribute.getFormDefinition());
formOne.setValues(Lists.newArrayList(formValue));
formOne.setOwnerCode(owner.getCode());
//
commonFormService.saveForm(owner, formOne);
formOne = commonFormService.getForms(owner).get(0);
//
Assert.assertNotNull(formOne.getId());
Assert.assertEquals(owner.getCode(), formOne.getOwnerCode());
Assert.assertEquals(lookupService.lookupEntity(owner.getClass(), owner.getId()).getClass().getCanonicalName(), formOne.getOwnerType());
Assert.assertEquals(owner.getId(), formOne.getOwnerId());
Assert.assertEquals(formValue.getValue(), formOne.getValues().get(0).getValue());
//
commonFormService.deleteForms(owner);
Assert.assertTrue(commonFormService.getForms(owner).isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testMultipleValues.
/**
* Test multi values order and removal
*/
@Test
public void testMultipleValues() {
FormableEntity owner = createTestOwner("test3");
//
// create definition with multi parameter
IdmFormAttributeDto multiAttribite = new IdmFormAttributeDto();
String multiAttributeName = "name_" + System.currentTimeMillis();
multiAttribite.setCode(multiAttributeName);
multiAttribite.setName(multiAttribite.getCode());
multiAttribite.setPersistentType(PersistentType.TEXT);
multiAttribite.setMultiple(true);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v3", Lists.newArrayList(multiAttribite));
multiAttribite = formDefinitionOne.getMappedAttributeByCode(multiAttribite.getCode());
//
// fill values
IdmFormValueDto value1 = new IdmFormValueDto(multiAttribite);
value1.setValue(FORM_VALUE_ONE);
value1.setSeq((short) 0);
IdmFormValueDto value2 = new IdmFormValueDto(multiAttribite);
value2.setValue(FORM_VALUE_TWO);
value2.setSeq((short) 1);
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1, value2));
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
// check order
assertEquals(2, m.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, (m.get(multiAttributeName).get(0)).getValue());
assertEquals(FORM_VALUE_TWO, (m.get(multiAttributeName).get(1)).getValue());
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
// check delete unsaved multiple values
m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
assertEquals(1, m.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, m.get(multiAttributeName).get(0).getValue());
// checks value map
Map<String, ? extends List<Serializable>> v = formService.getFormInstance(owner, formDefinitionOne).toPersistentValueMap();
assertEquals(1, v.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, v.get(multiAttributeName).get(0));
//
identityService.deleteById(owner.getId());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testSaveValuesByOwnerId.
@Test
public void testSaveValuesByOwnerId() {
FormableEntity owner = createTestOwner("test8");
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PHONE);
// save value
List<IdmFormValueDto> attributeValues = formService.saveValues((UUID) owner.getId(), owner.getClass(), attribute, Lists.newArrayList(FORM_VALUE_ONE));
assertEquals(1, attributeValues.size());
assertEquals(FORM_VALUE_ONE, attributeValues.get(0).getValue());
List<IdmFormValueDto> getValues = formService.getValues((UUID) owner.getId(), owner.getClass(), attribute);
assertEquals(1, getValues.size());
assertEquals(FORM_VALUE_ONE, ((IdmFormValueDto) getValues.get(0)).getValue());
//
identityService.deleteById(owner.getId());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFillFormValues.
@Test
public void testFillFormValues() {
FormableEntity owner = createTestOwner("test1");
//
// create definition one
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode("name_" + System.currentTimeMillis());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v1", Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
// create definition two
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setCode("name_" + System.currentTimeMillis());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v2", Lists.newArrayList(attributeDefinitionTwo));
attributeDefinitionTwo = formDefinitionTwo.getMappedAttributeByCode(attributeDefinitionTwo.getCode());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue(FORM_VALUE_ONE);
IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
value2.setValue(FORM_VALUE_TWO);
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
formService.saveValues(owner, formDefinitionTwo, Lists.newArrayList(value2));
assertEquals(FORM_VALUE_ONE, formService.getValues(owner, formDefinitionOne).get(0).getStringValue());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
//
// create second owner
FormableEntity owner2 = createTestOwner("test2");
assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
identityService.deleteById(owner2.getId());
assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
formService.deleteValues(owner, formDefinitionOne);
assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
identityService.deleteById(owner.getId());
assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
assertEquals(0, formService.getValues(owner, formDefinitionTwo).size());
}
Aggregations