Search in sources :

Example 46 with IdmScheduledTaskDto

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

the class PasswordExpiredTaskExecutorIntegrationTest method testNotSendMessageValidTillToday.

@Test
public void testNotSendMessageValidTillToday() {
    // prepare date
    IdmIdentityDto identity = getHelper().createIdentity();
    // 
    try {
        IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
        password.setValidTill(LocalDate.now());
        passwordService.save(password);
        // prepare task
        IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
        IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
        PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(new HashMap<>());
        // first process
        Boolean result = executor.process();
        Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
        // check
        Assert.assertTrue(result);
        Assert.assertTrue(logItems.getContent().stream().anyMatch(pi -> {
            return pi.getReferencedEntityId().equals(password.getId()) && pi.getOperationResult().getState() == OperationState.NOT_EXECUTED;
        }));
    } finally {
        identityService.delete(identity);
    }
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) HashMap(java.util.HashMap) Test(org.junit.Test) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) SchedulerTestUtils(eu.bcvsolutions.idm.test.api.utils.SchedulerTestUtils) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmPasswordService(eu.bcvsolutions.idm.core.api.service.IdmPasswordService) IdmProcessedTaskItemService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmProcessedTaskItemService) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) LocalDate(java.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmLongRunningTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmLongRunningTaskService) Assert(org.junit.Assert) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 47 with IdmScheduledTaskDto

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

the class PasswordExpiredTaskExecutorIntegrationTest method testNotSendMessageToDisabledIdentity.

@Test
public void testNotSendMessageToDisabledIdentity() {
    // prepare date
    IdmIdentityDto identity = getHelper().createIdentity();
    // 
    try {
        IdmPasswordDto preparedPassword = passwordService.findOneByIdentity(identity.getId());
        preparedPassword.setValidTill(LocalDate.now().minusDays(1));
        IdmPasswordDto password = passwordService.save(preparedPassword);
        // disable identity
        identity.setState(IdentityState.DISABLED_MANUALLY);
        identityService.save(identity);
        // prepare task
        IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
        IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
        PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(new HashMap<>());
        // first process
        Boolean result = executor.process();
        Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
        // check
        Assert.assertTrue(result);
        Assert.assertFalse(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
    } finally {
        identityService.delete(identity);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 48 with IdmScheduledTaskDto

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

the class PasswordExpirationWarningTaskExecutorIntegrationTest method testNotSendWarningMessageToDisabledIdentity.

@Test
public void testNotSendWarningMessageToDisabledIdentity() {
    // prepare date
    IdmIdentityDto identity = getHelper().createIdentity();
    // 
    try {
        IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
        password.setValidTill(LocalDate.now().plusDays(1));
        passwordService.save(password);
        // disable identity
        identity.setState(IdentityState.DISABLED_MANUALLY);
        identityService.save(identity);
        // prepare task
        IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
        IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpirationWarningTaskExecutor.class));
        PasswordExpirationWarningTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpirationWarningTaskExecutor());
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
        // first process
        Boolean result = executor.process();
        Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
        // check
        Assert.assertTrue(result);
        Assert.assertFalse(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
    } finally {
        identityService.delete(identity);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 49 with IdmScheduledTaskDto

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

the class AbstractSchedulableTaskExecutor method createIdmScheduledTask.

protected IdmScheduledTaskDto createIdmScheduledTask(String taskName) {
    IdmScheduledTaskDto t = new IdmScheduledTaskDto();
    t.setQuartzTaskName(taskName);
    return scheduledTaskService.save(t);
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)

Example 50 with IdmScheduledTaskDto

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

the class AbstractSchedulableTaskExecutor method getScheduledTask.

private IdmScheduledTaskDto getScheduledTask(JobExecutionContext context) {
    String taskName = context.getJobDetail().getKey().getName();
    IdmScheduledTaskDto dto = scheduledTaskService.findByQuartzTaskName(taskName);
    return dto == null ? createIdmScheduledTask(taskName) : dto;
}
Also used : IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)

Aggregations

IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)63 Test (org.junit.Test)50 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)46 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)40 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)24 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)18 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)9 UUID (java.util.UUID)9 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)8 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)7 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)7 Pageable (org.springframework.data.domain.Pageable)5 LocalDate (org.joda.time.LocalDate)4 PageImpl (org.springframework.data.domain.PageImpl)4 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)3 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)2 SchedulableTaskExecutor (eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor)2