Search in sources :

Example 21 with IdmEntityEventDto

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

the class EntityEventStartProcessor method process.

@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
    IdmEntityEventDto entity = event.getContent();
    // 
    entity = entityEventManager.saveResult(entity.getId(), new OperationResultDto.Builder(OperationState.RUNNING).build());
    event.setContent(entity);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 22 with IdmEntityEventDto

use of eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto 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);
    }
}
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 23 with IdmEntityEventDto

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

the class DefaultEntityEventManagerUnitTest method testResurrectEventWithDeletedContent.

@Test(expected = EventContentDeletedException.class)
public void testResurrectEventWithDeletedContent() {
    IdmEntityEventDto entityEvent = new IdmEntityEventDto(UUID.randomUUID());
    entityEvent.setOwnerType(IdmIdentity.class.getCanonicalName());
    entityEvent.setOwnerId(UUID.randomUUID());
    entityEvent.setEventType(CoreEventType.NOTIFY.name());
    // 
    when(lookupService.lookupDto(IdmIdentity.class, entityEvent.getOwnerId())).thenReturn(null);
    // 
    eventManager.toEvent(entityEvent);
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 24 with IdmEntityEventDto

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

the class DefaultEntityEventManagerUnitTest method testCreatedEventsDistinctByOwner.

@Test
public void testCreatedEventsDistinctByOwner() {
    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(ownerId);
    highEvents.add(highEventOne);
    IdmEntityEventDto highEventTwo = new IdmEntityEventDto(UUID.randomUUID());
    highEventTwo.setCreated(created.minusMillis(21));
    highEventTwo.setPriority(PriorityType.HIGH);
    highEventTwo.setOwnerId(ownerId);
    highEvents.add(highEventTwo);
    IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
    highEventThree.setCreated(created.minusMillis(2));
    highEventThree.setPriority(PriorityType.HIGH);
    highEventThree.setOwnerId(ownerId);
    highEvents.add(highEventThree);
    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(ownerId);
    normalEvents.add(normalEventOne);
    IdmEntityEventDto normalEventTwo = new IdmEntityEventDto(UUID.randomUUID());
    normalEventTwo.setCreated(created.minusMillis(1));
    normalEventTwo.setPriority(PriorityType.NORMAL);
    normalEventTwo.setOwnerId(ownerId);
    normalEvents.add(normalEventTwo);
    IdmEntityEventDto normalEventThree = new IdmEntityEventDto(UUID.randomUUID());
    normalEventThree.setCreated(created.minusMillis(3));
    normalEventThree.setPriority(PriorityType.NORMAL);
    normalEventThree.setOwnerId(ownerId);
    normalEvents.add(normalEventThree);
    when(entityEventService.findToExecute(any(), any(DateTime.class), eq(PriorityType.NORMAL), any())).thenReturn(new PageImpl<>(normalEvents));
    // 
    List<IdmEntityEventDto> events = eventManager.getCreatedEvents("instance");
    // 
    // normalEventTwo (high now)
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(PriorityType.HIGH, events.get(0).getPriority());
    Assert.assertEquals(normalEventTwo.getId(), events.get(0).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 25 with IdmEntityEventDto

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

the class DefaultEntityEventManagerUnitTest method testCreatedEventsRemoveOlderDuplicates.

@Test
public void testCreatedEventsRemoveOlderDuplicates() {
    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);
    IdmEntityEventDto highEventThree = new IdmEntityEventDto(UUID.randomUUID());
    highEventThree.setCreated(created.minusMillis(2));
    highEventThree.setPriority(PriorityType.HIGH);
    highEventThree.setOwnerId(ownerId);
    highEvents.add(highEventThree);
    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(1));
    normalEventTwo.setPriority(PriorityType.NORMAL);
    normalEventTwo.setOwnerId(ownerId);
    normalEvents.add(normalEventTwo);
    IdmEntityEventDto normalEventThree = new IdmEntityEventDto(UUID.randomUUID());
    normalEventThree.setCreated(created.minusMillis(2));
    normalEventThree.setPriority(PriorityType.NORMAL);
    normalEventThree.setOwnerId(ownerId);
    normalEvents.add(normalEventThree);
    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)

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