Search in sources :

Example 46 with IdmLongRunningTaskDto

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

the class DefaultIdmProcessedTaskItemDtoServiceTest method testCreateItem.

@Test
public void testCreateItem() {
    IdmScheduledTaskDto d = helper.createSchedulableTask();
    IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
    IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
    // 
    IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(item).getId());
    // 
    assertNotNull(retrieved);
    assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType());
    assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId());
    assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 47 with IdmLongRunningTaskDto

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

the class DefaultIdmProcessedTaskItemDtoServiceTest method createLongRunningTask.

public IdmLongRunningTaskDto createLongRunningTask(IdmScheduledTaskDto d) {
    IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
    lrt.setTaskDescription("task description");
    lrt.setResult(new OperationResult.Builder(OperationState.CREATED).build());
    lrt.setInstanceId("test instance");
    lrt.setScheduledTask(d.getId());
    lrt.setTaskType(TestSchedulableTask.class.getCanonicalName());
    return longrunningService.saveInternal(lrt);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)

Example 48 with IdmLongRunningTaskDto

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

the class DefaultIdmProcessedTaskItemDtoServiceTest method testImmutable.

@Test
public void testImmutable() {
    IdmScheduledTaskDto d = helper.createSchedulableTask();
    IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
    IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
    IdmProcessedTaskItemDto saved = service.get(service.saveInternal(item).getId());
    // set fields to new value
    saved.setReferencedDtoType(IdmIdentityContractDto.class.getCanonicalName());
    saved.setReferencedEntityId(UUID.randomUUID());
    saved.setLongRunningTask(this.createLongRunningTask(d).getId());
    // 
    IdmProcessedTaskItemDto retrieved = service.get(service.saveInternal(saved).getId());
    // fields must not update
    assertEquals(item.getLongRunningTask(), retrieved.getLongRunningTask());
    assertEquals(item.getReferencedDtoType(), retrieved.getReferencedDtoType());
    assertEquals(item.getReferencedEntityId(), retrieved.getReferencedEntityId());
    // 
    assertNotEquals(item.getLongRunningTask(), saved.getLongRunningTask());
    assertNotEquals(item.getReferencedDtoType(), saved.getReferencedDtoType());
    assertNotEquals(item.getReferencedEntityId(), saved.getReferencedEntityId());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 49 with IdmLongRunningTaskDto

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

the class DefaultIdmProcessedTaskItemDtoServiceTest method testItemTypeReference.

@Test
public void testItemTypeReference() {
    IdmScheduledTaskDto d = helper.createSchedulableTask();
    IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
    IdmProcessedTaskItemDto item = helper.prepareProcessedItem(lrt);
    // 
    try {
        item.setScheduledTaskQueueOwner(d.getId());
        service.get(service.saveInternal(item).getId());
        fail("Both log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
    // 
    try {
        item.setScheduledTaskQueueOwner(null);
        item.setLongRunningTask(null);
        service.get(service.saveInternal(item).getId());
        fail("Empty log and queue association is forbidden.");
    } catch (CoreException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 50 with IdmLongRunningTaskDto

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

the class DefaultLongRunningTaskManagerIntegrationTest method testInterruptRunningTask.

@Test
public void testInterruptRunningTask() throws InterruptedException, ExecutionException {
    String result = "TEST_SUCCESS_05";
    Long count = 100L;
    LongRunningTaskExecutor<String> taskExecutor = new TestStopableLongRunningTaskExecutor(result, count);
    // 
    manager.execute(taskExecutor);
    // 
    Function<String, Boolean> continueFunction = res -> {
        return !manager.getLongRunningTask(taskExecutor).isRunning();
    };
    helper.waitForResult(continueFunction);
    // 
    IdmLongRunningTaskDto longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
    assertEquals(OperationState.RUNNING, longRunningTask.getResult().getState());
    assertEquals(count, longRunningTask.getCount());
    assertTrue(longRunningTask.isRunning());
    // 
    assertTrue(manager.interrupt(taskExecutor.getLongRunningTaskId()));
    // 
    longRunningTask = service.get(taskExecutor.getLongRunningTaskId());
    assertNotEquals(OperationState.RUNNING, longRunningTask.getResult().getState());
    assertEquals(count, longRunningTask.getCount());
    assertNotEquals(count, longRunningTask.getCounter());
    assertFalse(longRunningTask.isRunning());
}
Also used : TestTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.TestTaskExecutor) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) Function(java.util.function.Function) DefaultLongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultLongRunningTaskManager) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) ConcurrentExecutionException(eu.bcvsolutions.idm.core.scheduler.api.exception.ConcurrentExecutionException) AbstractLongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractLongRunningTaskExecutor) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) Before(org.junit.Before) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) LongRunningTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskExecutor) ApplicationContext(org.springframework.context.ApplicationContext) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertNull(org.junit.Assert.assertNull) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)56 Test (org.junit.Test)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)14 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)13 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)7 LocalDate (org.joda.time.LocalDate)6 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)4 UUID (java.util.UUID)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3