use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testPersistChildEventAutomatically.
/**
* Child event has to be persisted automatically, when parent event is persisted
*/
@Test
@Transactional
public void testPersistChildEventAutomatically() {
MockOwner mockOwner = new MockOwner();
//
// root
IdmEntityEventDto eventDto = manager.prepareEvent(mockOwner, null);
eventDto.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
eventDto.setEventType(CoreEventType.CREATE.name());
eventDto.setPriority(PriorityType.HIGH);
final IdmEntityEventDto rootEventDto = manager.saveEvent(eventDto);
//
// child
CoreEvent<MockOwner> childEvent = new CoreEvent<MockOwner>(CoreEventType.CREATE, mockOwner);
//
// process - sync
manager.process(childEvent, manager.toEvent(rootEventDto));
//
// two event should be persisted
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(manager.getOwnerType(mockOwner));
filter.setOwnerId(mockOwner.getId());
List<IdmEntityEventDto> content = entityEventService.find(filter, null).getContent();
Assert.assertEquals(2, content.size());
Assert.assertTrue(content.stream().allMatch(e -> e.getResult().getState() == OperationState.EXECUTED));
Assert.assertTrue(content.stream().anyMatch(e -> e.getRootId() == null));
Assert.assertTrue(content.stream().anyMatch(e -> rootEventDto.getId().equals(e.getRootId()) && e.getEventType().equals(CoreEventType.CREATE.name())));
// check child event
IdmEntityEventDto childEventDto = content.stream().filter(e -> rootEventDto.getId().equals(e.getRootId()) && e.getEventType().equals(CoreEventType.CREATE.name())).findFirst().get();
Assert.assertEquals(rootEventDto.getId(), childEventDto.getParent());
Assert.assertEquals(rootEventDto.getPriority(), childEventDto.getPriority());
Assert.assertEquals(rootEventDto.getEventType(), childEventDto.getParentEventType());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testAcceptedException.
@Test
public void testAcceptedException() {
try {
getHelper().enableAsynchronousProcessing();
//
IdmEntityEventDto event = new IdmEntityEventDto();
AcceptedContent content = new AcceptedContent();
content.setId(UUID.randomUUID());
event.setContent(content);
event.setOwnerId(content.getId());
event.setOwnerType(manager.getOwnerType(content));
event = manager.saveEvent(event);
manager.executeEvent(event);
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerId(content.getId());
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
//
// wait for execute event
getHelper().waitForResult(res -> {
return entityEventService.find(filter, PageRequest.of(0, 1)).getContent().isEmpty();
}, 500, 20);
//
event = manager.getEvent(event.getId());
Assert.assertEquals(OperationState.EXECUTED, event.getResult().getState());
Assert.assertEquals(CoreResultCode.ACCEPTED.name(), event.getResult().getCode());
//
// check state is executed too
IdmEntityStateFilter stateFilter = new IdmEntityStateFilter();
stateFilter.setEventId(event.getId());
List<IdmEntityStateDto> states = entityStateManager.findStates(content, null).getContent();
Assert.assertFalse(states.isEmpty());
Assert.assertTrue(states.stream().allMatch(s -> s.getResult().getState() == OperationState.EXECUTED && s.getResult().getCode().equals(CoreResultCode.ACCEPTED.name())));
} finally {
getHelper().disableAsynchronousProcessing();
}
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testMinMaxStringValidation.
@Test
public void testMinMaxStringValidation() {
// prepare form definition a test saving form values
IdmFormAttributeDto attributeShortText = new IdmFormAttributeDto();
String attributeShortTextCode = getHelper().createName();
attributeShortText.setCode(attributeShortTextCode);
attributeShortText.setName(attributeShortTextCode);
attributeShortText.setPersistentType(PersistentType.SHORTTEXT);
attributeShortText.setMin(new BigDecimal("3"));
attributeShortText.setMax(new BigDecimal("5"));
IdmFormAttributeDto attributeText = new IdmFormAttributeDto();
String attributeTextCode = getHelper().createName();
attributeText.setCode(attributeTextCode);
attributeText.setName(attributeTextCode);
attributeText.setPersistentType(PersistentType.TEXT);
attributeText.setMin(new BigDecimal("6"));
attributeText.setMax(new BigDecimal("8"));
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeShortText, attributeText));
attributeShortText = formDefinitionOne.getMappedAttributeByCode(attributeShortText.getCode());
attributeText = formDefinitionOne.getMappedAttributeByCode(attributeText.getCode());
//
IdmFormValueDto valueShortText = new IdmFormValueDto(attributeShortText);
IdmFormValueDto valueText = new IdmFormValueDto(attributeText);
//
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(formDefinitionOne);
formInstance.setValues(Lists.newArrayList(valueShortText, valueText));
//
List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
//
Assert.assertTrue(validationErrors.isEmpty());
//
valueShortText.setShortTextValue("xx");
valueText.setStringValue("xxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(2, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMinValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("3")) && e.getAttributeCode().equals(attributeShortTextCode)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMinValue().equals(new BigDecimal("6")) && e.getAttributeCode().equals(attributeTextCode)));
//
valueShortText.setShortTextValue("xxxxxx");
valueText.setStringValue("xxxxxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertEquals(2, validationErrors.size());
Assert.assertTrue(validationErrors.stream().allMatch(e -> e.getMaxValue() != null));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("5")) && e.getAttributeCode().equals(attributeShortTextCode)));
Assert.assertTrue(validationErrors.stream().anyMatch(e -> e.getMaxValue().equals(new BigDecimal("8")) && e.getAttributeCode().equals(attributeTextCode)));
//
valueShortText.setShortTextValue("xxxxx");
valueText.setStringValue("xxxxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
//
valueShortText.setShortTextValue("xxx");
valueText.setStringValue("xxxxxx");
//
validationErrors = formService.validate(formInstance);
Assert.assertTrue(validationErrors.isEmpty());
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testGetAttributes.
@Test
public void testGetAttributes() {
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
IdmFormDefinitionDto definitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
IdmFormAttributeDto attributeOther = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
IdmFormDefinitionDto definitionOther = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(attributeOther));
Assert.assertEquals(CoreModuleDescriptor.MODULE_ID, definitionOther.getModule());
//
List<IdmFormAttributeDto> results = formService.getAttributes(definitionOne);
//
Assert.assertTrue(results.stream().anyMatch(a -> a.getCode().equals(attributeOne.getCode())));
Assert.assertTrue(results.stream().anyMatch(a -> a.getCode().equals(attributeTwo.getCode())));
Assert.assertFalse(results.stream().anyMatch(a -> a.getCode().equals(attributeOther.getCode())));
//
results = formService.getAttributes(definitionOther);
//
Assert.assertFalse(results.stream().anyMatch(a -> a.getCode().equals(attributeOne.getCode())));
Assert.assertFalse(results.stream().anyMatch(a -> a.getCode().equals(attributeTwo.getCode())));
Assert.assertTrue(results.stream().anyMatch(a -> a.getCode().equals(attributeOther.getCode())));
}
use of org.junit.Assert.assertTrue in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testGetDefinitions.
@Test
public void testGetDefinitions() {
IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
//
IdmFormDefinitionDto definitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), null);
IdmFormDefinitionDto definitionTwo = formService.createDefinition(owner.getClass(), getHelper().createName(), null);
IdmFormDefinitionDto definitionOther = formService.createDefinition(IdmRole.class, getHelper().createName(), null);
//
List<IdmFormDefinitionDto> results = formService.getDefinitions(IdmIdentity.class);
//
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionOne.getId())));
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionTwo.getId())));
Assert.assertFalse(results.stream().anyMatch(d -> d.getId().equals(definitionOther.getId())));
//
results = formService.getDefinitions(owner.getClass());
//
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionOne.getId())));
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionTwo.getId())));
Assert.assertFalse(results.stream().anyMatch(d -> d.getId().equals(definitionOther.getId())));
//
results = formService.getDefinitions(owner);
//
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionOne.getId())));
Assert.assertTrue(results.stream().anyMatch(d -> d.getId().equals(definitionTwo.getId())));
Assert.assertFalse(results.stream().anyMatch(d -> d.getId().equals(definitionOther.getId())));
}
Aggregations