use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testFindOwnersByDateAttributeValue.
@Test
public void testFindOwnersByDateAttributeValue() {
Identifiable owner = getHelper().createIdentity((GuardedString) null);
Identifiable ownerTwo = getHelper().createIdentity((GuardedString) null);
IdmFormDefinitionDto formDefinition = formService.getDefinition(owner.getClass());
IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME);
// save values
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
ZonedDateTime tomorrow = now.plusDays(1).truncatedTo(ChronoUnit.MILLIS);
formService.saveValues(owner, attribute, Lists.newArrayList(now));
formService.saveValues(ownerTwo, attribute, Lists.newArrayList(tomorrow));
//
Page<? extends Identifiable> owners = formService.findOwners(owner.getClass(), InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME, now, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(owner.getId(), owners.getContent().get(0).getId());
//
owners = formService.findOwners(owner.getClass(), InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME, tomorrow, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(ownerTwo.getId(), owners.getContent().get(0).getId());
//
identityService.deleteById(owner.getId());
identityService.deleteById(ownerTwo.getId());
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testOwnerWithoutId.
@Test(expected = IllegalArgumentException.class)
public void testOwnerWithoutId() {
// unpersisted identity
Identifiable owner = new IdmIdentity();
formService.getValues(owner);
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testMoveValueIntoOtherOwner.
@Test
public void testMoveValueIntoOtherOwner() {
Identifiable ownerOne = getHelper().createIdentity((GuardedString) null);
Identifiable ownerTwo = getHelper().createIdentity((GuardedString) null);
//
// create definition with attribute
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
attribute.setCode(attributeName);
attribute.setName(attribute.getCode());
attribute.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
// fill values
List<IdmFormValueDto> savedValueOne = formService.saveValues(ownerOne, attribute, Lists.newArrayList(FORM_VALUE_ONE));
List<IdmFormValueDto> savedValueTwo = formService.saveValues(ownerTwo, formDefinitionOne, savedValueOne);
List<IdmFormValueDto> getValueOne = formService.getValues(ownerOne, attribute);
// both values should be saved
Assert.assertEquals(1, getValueOne.size());
Assert.assertEquals(1, savedValueTwo.size());
Assert.assertNotEquals(getValueOne.get(0).getId(), savedValueTwo.get(0).getId());
//
// prevent to move value for original owner
List<IdmFormValueDto> getValueAfterMoveOne = formService.getValues(ownerOne, attribute);
Assert.assertEquals(1, getValueAfterMoveOne.size());
Assert.assertEquals(getValueOne.get(0).getId(), getValueAfterMoveOne.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testFillFormValues.
@Test
public void testFillFormValues() {
Identifiable owner = getHelper().createIdentity((GuardedString) null);
//
// create definition one
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
// create definition two
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setCode(getHelper().createName());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), 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
Identifiable owner2 = getHelper().createIdentity((GuardedString) null);
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());
// TODO: remove this test? - not exists entity has to be given
assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner2.getId()), 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(new IdmIdentity((UUID) owner.getId()), formDefinitionOne).size());
assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner.getId()), formDefinitionTwo).size());
}
use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManagerIntegrationTest method testUpdateAttachment.
@Test
public void testUpdateAttachment() {
Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
String contentOne = "test data 1";
IdmAttachmentDto attachment = prepareAttachment(contentOne);
attachment = attachmentManager.saveAttachment(owner, attachment);
//
String updatedContent = "update";
attachment.setInputData(IOUtils.toInputStream(updatedContent));
attachment.setDescription(updatedContent);
attachment = attachmentManager.updateAttachment(attachment);
//
List<IdmAttachmentDto> attachments = attachmentManager.getAttachmentVersions(attachment.getId());
//
Assert.assertEquals(1, attachments.size());
IdmAttachmentDto createdAttachment = attachments.get(0);
Assert.assertEquals(attachment.getName(), createdAttachment.getName());
Assert.assertEquals(attachment.getMimetype(), createdAttachment.getMimetype());
Assert.assertEquals(owner.getClass().getCanonicalName(), createdAttachment.getOwnerType());
Assert.assertEquals(owner.getId(), createdAttachment.getOwnerId());
Assert.assertNotNull(createdAttachment.getContentId());
Assert.assertNotNull(createdAttachment.getContentPath());
Assert.assertNull(createdAttachment.getParent());
Assert.assertNull(createdAttachment.getNextVersion());
Assert.assertEquals(Integer.valueOf(1), createdAttachment.getVersionNumber());
Assert.assertEquals("1.0", createdAttachment.getVersionLabel());
Assert.assertEquals(AttachableEntity.DEFAULT_ENCODING, createdAttachment.getEncoding());
Assert.assertEquals(Long.valueOf(updatedContent.getBytes(AttachableEntity.DEFAULT_CHARSET).length), createdAttachment.getFilesize());
Assert.assertEquals(updatedContent, createdAttachment.getDescription());
//
attachmentManager.deleteAttachment(attachment);
//
Assert.assertEquals(0, attachmentManager.getAttachmentVersions(attachment.getId()).size());
}
Aggregations