use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class IdmEntityEventFilterIntegrationTest method testFindByPriority.
@Test
@Transactional
public void testFindByPriority() {
UUID ownerOneId = UUID.randomUUID();
IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
entityEventOne.setOwnerType("mockType");
entityEventOne.setEventType("mockEvent");
entityEventOne.setOwnerId(ownerOneId);
entityEventOne.setInstanceId("mockInstance");
entityEventOne.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventOne.setPriority(PriorityType.NORMAL);
entityEventOne = service.save(entityEventOne);
//
UUID ownerTwoId = UUID.randomUUID();
IdmEntityEventDto entityEventTwo = new IdmEntityEventDto();
entityEventTwo.setOwnerType("mockType");
entityEventTwo.setEventType("mockEvent");
entityEventTwo.setOwnerId(ownerTwoId);
entityEventTwo.setInstanceId("mockInstance");
entityEventTwo.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventTwo.setPriority(PriorityType.HIGH);
entityEventTwo = service.save(entityEventTwo);
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType("mockType");
filter.setPriority(PriorityType.NORMAL);
//
List<IdmEntityEventDto> events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventOne.getId(), events.get(0).getId());
//
filter.setPriority(PriorityType.HIGH);
events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventTwo.getId(), events.get(0).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class IdmEntityEventFilterIntegrationTest method testFindByStates.
@Test
@Transactional
public void testFindByStates() {
UUID ownerId = UUID.randomUUID();
IdmEntityEventDto entityEvent = new IdmEntityEventDto();
entityEvent.setOwnerType("mockType");
entityEvent.setEventType("mockEvent");
entityEvent.setOwnerId(ownerId);
entityEvent.setInstanceId("mockInstance");
entityEvent.setResult(new OperationResultDto(OperationState.CANCELED));
entityEvent.setPriority(PriorityType.NORMAL);
entityEvent = service.save(entityEvent);
//
UUID ownerOneId = UUID.randomUUID();
IdmEntityEventDto entityEventOne = new IdmEntityEventDto();
entityEventOne.setOwnerType("mockType");
entityEventOne.setEventType("mockEvent");
entityEventOne.setOwnerId(ownerOneId);
entityEventOne.setInstanceId("mockInstance");
entityEventOne.setResult(new OperationResultDto(OperationState.BLOCKED));
entityEventOne.setPriority(PriorityType.NORMAL);
entityEventOne = service.save(entityEventOne);
//
UUID ownerTwoId = UUID.randomUUID();
IdmEntityEventDto entityEventTwo = new IdmEntityEventDto();
entityEventTwo.setOwnerType("mockType");
entityEventTwo.setEventType("mockEvent");
entityEventTwo.setOwnerId(ownerTwoId);
entityEventTwo.setInstanceId("mockInstance");
entityEventTwo.setResult(new OperationResultDto(OperationState.EXCEPTION));
entityEventTwo.setPriority(PriorityType.NORMAL);
entityEventTwo = service.save(entityEventTwo);
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerType("mockType");
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
//
List<IdmEntityEventDto> events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventOne.getId(), events.get(0).getId());
//
filter.setStates(Lists.newArrayList(OperationState.EXCEPTION));
//
events = service.find(filter, null).getContent();
Assert.assertEquals(1, events.size());
Assert.assertEquals(entityEventTwo.getId(), events.get(0).getId());
//
filter.setStates(Lists.newArrayList(OperationState.EXCEPTION, OperationState.BLOCKED));
//
events = service.find(filter, null).getContent();
Assert.assertEquals(2, events.size());
Assert.assertTrue(events.stream().anyMatch(e -> e.getOwnerId().equals(ownerOneId)));
Assert.assertTrue(events.stream().anyMatch(e -> e.getOwnerId().equals(ownerTwoId)));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto 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.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testSetAdditionalPrioritiesForEvent.
@Test
public void testSetAdditionalPrioritiesForEvent() {
when(eventConfiguration.getAsynchronousInstanceId()).thenReturn("mockInstance");
//
DateTime executeDate = new DateTime();
IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
Map<String, Serializable> props = new HashMap<>();
props.put(EntityEventManager.EVENT_PROPERTY_EXECUTE_DATE, executeDate);
props.put(EntityEventManager.EVENT_PROPERTY_PRIORITY, PriorityType.HIGH);
//
IdmEntityEventDto entityEvent = eventManager.createEvent(identity, new CoreEvent<>(CoreEventType.CREATE, identity, props));
//
Assert.assertEquals("mockInstance", entityEvent.getInstanceId());
Assert.assertEquals(executeDate, entityEvent.getExecuteDate());
Assert.assertEquals(PriorityType.HIGH, entityEvent.getPriority());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerUnitTest method testCreatedEventsSortByCreatedAndPriority.
@Test
public void testCreatedEventsSortByCreatedAndPriority() {
List<IdmEntityEventDto> highEvents = new ArrayList<>();
DateTime created = new DateTime();
IdmEntityEventDto highEventOne = new IdmEntityEventDto(UUID.randomUUID());
highEventOne.setCreated(created.minusMillis(11));
highEventOne.setPriority(PriorityType.HIGH);
highEventOne.setOwnerId(UUID.randomUUID());
highEvents.add(highEventOne);
IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
highEventTwo.setCreated(created.minusMillis(21));
highEventTwo.setPriority(PriorityType.HIGH);
highEventTwo.setOwnerId(UUID.randomUUID());
highEvents.add(highEventTwo);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.HIGH), any())).thenReturn(new PageImpl<>(highEvents));
//
List<IdmEntityEventDto> normalEvents = new ArrayList<>();
IdmEntityEventDto normalEventOne = new IdmEntityEventDto(UUID.randomUUID());
normalEventOne.setCreated(created.minusMillis(18));
normalEventOne.setPriority(PriorityType.NORMAL);
normalEventOne.setOwnerId(UUID.randomUUID());
normalEvents.add(normalEventOne);
IdmEntityEventDto normalEventTwo = new IdmEntityEventDto(UUID.randomUUID());
normalEventTwo.setCreated(created.minusMillis(40));
normalEventTwo.setPriority(PriorityType.NORMAL);
normalEventTwo.setOwnerId(UUID.randomUUID());
normalEvents.add(normalEventTwo);
when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(normalEvents));
//
List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
//
// highEventTwo - highEventOne - normalEventTwo - normalEventOne
Assert.assertEquals(4, events.size());
Assert.assertEquals(highEventTwo.getId(), events.get(0).getId());
Assert.assertEquals(highEventOne.getId(), events.get(1).getId());
Assert.assertEquals(normalEventTwo.getId(), events.get(2).getId());
Assert.assertEquals(normalEventOne.getId(), events.get(3).getId());
}
Aggregations