Search in sources :

Example 16 with IdmEntityEventDto

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()));
}
Also used : OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with IdmEntityEventDto

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);
    }
}
Also used : MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with IdmEntityEventDto

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);
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Mock(org.mockito.Mock) HashMap(java.util.HashMap) MockOwner(eu.bcvsolutions.idm.core.event.domain.MockOwner) ArrayList(java.util.ArrayList) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) InjectMocks(org.mockito.InjectMocks) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AbstractEntityEventProcessor) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) Mockito.verify(org.mockito.Mockito.verify) Serializable(java.io.Serializable) Matchers.any(org.mockito.Matchers.any) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) Assert(org.junit.Assert) PageImpl(org.springframework.data.domain.PageImpl) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) 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 19 with IdmEntityEventDto

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);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 20 with IdmEntityEventDto

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);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

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