use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmEntityEventServiceIntegrationTest method testReferentialIntegrityLastChildIsDeleted.
@Transactional
public void testReferentialIntegrityLastChildIsDeleted() {
IdmEntityEventDto parentEvent = new IdmEntityEventDto();
parentEvent.setOwnerType("empty");
parentEvent.setEventType("empty");
parentEvent.setOwnerId(UUID.randomUUID());
parentEvent.setInstanceId("empty");
parentEvent.setResult(new OperationResultDto(OperationState.BLOCKED));
parentEvent.setPriority(PriorityType.NORMAL);
parentEvent = entityEventService.save(parentEvent);
//
IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
entityEventOne.setOwnerType("empty");
entityEventOne.setEventType("empty");
entityEventOne.setOwnerId(UUID.randomUUID());
entityEventOne.setInstanceId("empty");
entityEventOne.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventOne.setPriority(PriorityType.NORMAL);
entityEventOne.setParent(parentEvent.getId());
entityEventOne = entityEventService.save(entityEventOne);
//
IdmEntityEventDto entityEventTwo = new IdmEntityEventDto();
entityEventTwo.setOwnerType("empty");
entityEventTwo.setEventType("empty");
entityEventTwo.setOwnerId(UUID.randomUUID());
entityEventTwo.setInstanceId("empty");
entityEventTwo.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventTwo.setPriority(PriorityType.NORMAL);
entityEventTwo.setParent(parentEvent.getId());
entityEventTwo = entityEventService.save(entityEventTwo);
//
Assert.assertNotNull(parentEvent.getId());
Assert.assertNotNull(entityEventOne.getId());
Assert.assertNotNull(entityEventTwo.getId());
//
entityEventService.delete(entityEventTwo);
//
Assert.assertNotNull(entityEventService.get(parentEvent.getId()));
Assert.assertNotNull(entityEventService.get(entityEventOne.getId()));
Assert.assertNull(entityEventService.get(entityEventTwo.getId()));
//
entityEventService.delete(entityEventOne);
//
Assert.assertNull(entityEventService.get(parentEvent.getId()));
Assert.assertNull(entityEventService.get(entityEventOne.getId()));
Assert.assertNull(entityEventService.get(entityEventTwo.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testRemoveDuplicateEventsForTheSameOwner.
@Test
public void testRemoveDuplicateEventsForTheSameOwner() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
int count = 10;
//
// create events
MockOwner mockOwner = new MockOwner();
for (int i = 0; i < count; i++) {
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType(mockOwner.getClass().getCanonicalName());
entityEvent.setEventType("empty");
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setInstanceId(configurationService.getInstanceId());
entityEvent.setResult(new OperationResultDto(OperationState.CREATED));
entityEvent.setPriority(PriorityType.NORMAL);
events.add(entityEventService.save(entityEvent));
}
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType(MockOwner.class.getCanonicalName());
filter.setStates(Lists.newArrayList(OperationState.CREATED));
Assert.assertEquals(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
//
// execute
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// wait for executed events
helper.waitForResult(res -> {
return entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements() != 0;
}, 1000, Integer.MAX_VALUE);
//
// check what happened
filter.setStates(Lists.newArrayList(OperationState.EXECUTED));
Assert.assertEquals(1, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
// the last one
entityEventService.delete(events.get(9));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testCreatedEventsRemoveDuplicatesByProps.
@Test
public void testCreatedEventsRemoveDuplicatesByProps() {
List<IdmEntityEventDto> highEvents = new ArrayList<>();
DateTime created = new DateTime();
UUID ownerId = UUID.randomUUID();
IdmEntityEventDto highEventOne = new IdmEntityEventDto(UUID.randomUUID());
highEventOne.setCreated(created.minusMillis(21));
highEventOne.setPriority(PriorityType.HIGH);
highEventOne.setOwnerId(ownerId);
highEventOne.getProperties().put("one", "one");
highEvents.add(highEventOne);
IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
highEventTwo.setCreated(created.minusMillis(11));
highEventTwo.setPriority(PriorityType.HIGH);
highEventTwo.setOwnerId(ownerId);
highEventTwo.getProperties().put("one", "one");
highEvents.add(highEventTwo);
IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
highEventThree.setCreated(created.minusMillis(2));
highEventThree.setPriority(PriorityType.HIGH);
highEventThree.setOwnerId(ownerId);
highEventThree.getProperties().put("one", "oneU");
highEvents.add(highEventThree);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.HIGH), any())).thenReturn(new PageImpl<>(highEvents));
//
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(new ArrayList<>()));
//
List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
Assert.assertEquals(1, events.size());
Assert.assertTrue(events.stream().anyMatch(e -> e.getId().equals(highEventTwo.getId())));
verify(entityEventService).delete(highEventOne);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class EntityEventEndProcessor method process.
@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
IdmEntityEventDto entityEvent = event.getContent();
entityEvent = service.save(entityEvent);
event.setContent(entityEvent);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class EntityEventSaveProcessor method process.
@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
IdmEntityEventDto entity = event.getContent();
entity = service.saveInternal(entity);
event.setContent(entity);
//
return new DefaultEventResult<>(event, this);
}
Aggregations