Search in sources :

Example 26 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method testResurrectEventWithLoadedContent.

@Test
public void testResurrectEventWithLoadedContent() {
    IdmIdentityDto mockOwner = new IdmIdentityDto(UUID.randomUUID());
    IdmEntityEventDto entityEvent = new IdmEntityEventDto(UUID.randomUUID());
    entityEvent.setOwnerType(IdmIdentity.class.getCanonicalName());
    entityEvent.setOwnerId((UUID) mockOwner.getId());
    entityEvent.setEventType(CoreEventType.NOTIFY.name());
    // 
    when(lookupService.lookupDto(IdmIdentity.class, mockOwner.getId())).thenReturn(mockOwner);
    // 
    EntityEvent<Identifiable> event = eventManager.toEvent(entityEvent);
    // 
    Assert.assertEquals(mockOwner, event.getContent());
    Assert.assertEquals(CoreEventType.NOTIFY.name(), event.getType().name());
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) 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 27 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method testCreatedEventsHigherPriorityByDuplicate.

@Test
public void testCreatedEventsHigherPriorityByDuplicate() {
    List<IdmEntityEventDto> highEvents = new ArrayList<>();
    DateTime created = new DateTime();
    UUID ownerId = UUID.randomUUID();
    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(ownerId);
    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(4));
    normalEventTwo.setPriority(PriorityType.NORMAL);
    normalEventTwo.setOwnerId(ownerId);
    normalEvents.add(normalEventTwo);
    when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(normalEvents));
    // 
    List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
    // 
    // normalEventTwo (high now) - highEventOne - normalEventOne
    Assert.assertEquals(3, events.size());
    Assert.assertEquals(PriorityType.HIGH, events.get(0).getPriority());
    Assert.assertEquals(normalEventTwo.getId(), events.get(0).getId());
    Assert.assertEquals(highEventOne.getId(), events.get(1).getId());
    Assert.assertEquals(normalEventOne.getId(), events.get(2).getId());
}
Also used : ArrayList(java.util.ArrayList) UUID(java.util.UUID) 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 28 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method createEvents.

private Page<IdmEntityEventDto> createEvents(PriorityType priority, int count) {
    List<IdmEntityEventDto> events = new ArrayList<>();
    DateTime created = new DateTime().minusMillis(count);
    for (int i = 0; i < count; i++) {
        IdmEntityEventDto event = new IdmEntityEventDto();
        event.setCreated(created.plusMillis(count));
        event.setPriority(priority);
        event.setOwnerId(UUID.randomUUID());
        event.setEventType("custom");
        events.add(event);
    }
    // 
    return new PageImpl<>(events);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 29 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class IdmEntityEventFilterIntegrationTest method testFindByOwnerId.

@Test
@Transactional
public void testFindByOwnerId() {
    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.NORMAL);
    entityEventTwo = service.save(entityEventTwo);
    // 
    IdmEntityEventFilter filter = new IdmEntityEventFilter();
    filter.setOwnerId(ownerOneId);
    // 
    List<IdmEntityEventDto> events = service.find(filter, null).getContent();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(entityEventOne.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 30 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto in project CzechIdMng by bcvsolutions.

the class IdmEntityEventFilterIntegrationTest method testFindByParentId.

@Test
@Transactional
public void testFindByParentId() {
    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.setParent(entityEvent.getId());
    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.setParent(entityEventOne.getId());
    entityEventTwo = service.save(entityEventTwo);
    // 
    IdmEntityEventFilter filter = new IdmEntityEventFilter();
    filter.setOwnerType("mockType");
    filter.setParentId(entityEventTwo.getId());
    // 
    List<IdmEntityEventDto> events = service.find(filter, null).getContent();
    Assert.assertEquals(0, events.size());
    // 
    filter.setParentId(entityEvent.getId());
    events = service.find(filter, null).getContent();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(entityEventOne.getId(), events.get(0).getId());
    // 
    filter.setParentId(entityEventOne.getId());
    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)

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