use of eu.bcvsolutions.idm.core.event.domain.MockOwner in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testResurrectEventWithPersistedContent.
@Test
public void testResurrectEventWithPersistedContent() {
IdmEntityEventDto entityEvent = new IdmEntityEventDto(UUID.randomUUID());
MockOwner mockOwner = new MockOwner();
entityEvent.setOwnerType(eventManager.getOwnerType(mockOwner.getClass()));
entityEvent.setOwnerId((UUID) mockOwner.getId());
entityEvent.setContent(mockOwner);
entityEvent.setPriority(PriorityType.NORMAL);
entityEvent.setExecuteDate(new DateTime());
entityEvent.setEventType(CoreEventType.NOTIFY.name());
entityEvent.getProperties().put("one", "one");
entityEvent.setParentEventType(CoreEventType.UPDATE.name());
//
EntityEvent<Identifiable> event = eventManager.toEvent(entityEvent);
//
Assert.assertEquals(mockOwner, event.getContent());
Assert.assertEquals(CoreEventType.NOTIFY.name(), event.getType().name());
Assert.assertEquals(entityEvent.getId(), event.getProperties().get(EntityEventManager.EVENT_PROPERTY_EVENT_ID));
Assert.assertEquals(entityEvent.getPriority(), event.getProperties().get(EntityEventManager.EVENT_PROPERTY_PRIORITY));
Assert.assertEquals(entityEvent.getExecuteDate(), event.getProperties().get(EntityEventManager.EVENT_PROPERTY_EXECUTE_DATE));
Assert.assertEquals(CoreEventType.UPDATE.name(), event.getProperties().get(EntityEventManager.EVENT_PROPERTY_PARENT_EVENT_TYPE));
Assert.assertEquals("one", event.getProperties().get("one"));
}
use of eu.bcvsolutions.idm.core.event.domain.MockOwner 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.event.domain.MockOwner in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testMultiThreadEventProcessing.
@Test
public void testMultiThreadEventProcessing() {
List<IdmEntityEventDto> events = new ArrayList<>();
try {
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.disable(EntityEventDeleteExecutedProcessor.class);
// 15s
int count = 250;
// create events
for (int i = 0; i < count; i++) {
MockOwner mockOwner = new MockOwner();
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(count, entityEventService.find(filter, new PageRequest(0, 1)).getTotalElements());
} finally {
events.forEach(e -> entityEventService.delete(e));
helper.setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
helper.enable(EntityEventDeleteExecutedProcessor.class);
}
}
Aggregations