Search in sources :

Example 1 with MockOwner

use of eu.bcvsolutions.idm.core.event.domain.MockOwner 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 2 with MockOwner

use of eu.bcvsolutions.idm.core.event.domain.MockOwner 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 3 with MockOwner

use of eu.bcvsolutions.idm.core.event.domain.MockOwner 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)

Aggregations

IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 MockOwner (eu.bcvsolutions.idm.core.event.domain.MockOwner)3 Test (org.junit.Test)3 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)2 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 ArrayList (java.util.ArrayList)2 PageRequest (org.springframework.data.domain.PageRequest)2 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)1 DateTime (org.joda.time.DateTime)1