Search in sources :

Example 11 with IdmEntityEventDto

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());
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IdmEntityEventDto

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)));
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) List(java.util.List) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) Lists(com.google.common.collect.Lists) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) UUID(java.util.UUID) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with IdmEntityEventDto

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"));
}
Also used : MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 14 with IdmEntityEventDto

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());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 15 with IdmEntityEventDto

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());
}
Also used : ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)35 Test (org.junit.Test)21 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)15 Transactional (org.springframework.transaction.annotation.Transactional)13 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 UUID (java.util.UUID)12 ArrayList (java.util.ArrayList)11 DateTime (org.joda.time.DateTime)10 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)9 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)9 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)5 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 PageRequest (org.springframework.data.domain.PageRequest)4 Lists (com.google.common.collect.Lists)3 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 MockOwner (eu.bcvsolutions.idm.core.event.domain.MockOwner)3