Search in sources :

Example 61 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class NeverEndingProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    // TODO Auto-generated method stub
    int counter = 0;
    while (wait && counter < 50) {
        // max wait is 15s
        try {
            counter++;
            Thread.sleep(300L);
        } catch (Exception ex) {
            throw new CoreException(ex);
        }
    }
    return null;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException)

Example 62 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method testNotContinueWithoutRequiresNew.

@Test
public void testNotContinueWithoutRequiresNew() throws Exception {
    List<IdmIdentityDto> identities = createTestIdentities(3);
    // 
    TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
    executor.dtos = identities;
    executor.continueOnException = false;
    executor.requireNewTransaction = false;
    String changeLastName = "last-name-update";
    executor.changeLastName = changeLastName;
    executor.exceptionOnItem = 2;
    // 
    try {
        getTransactionTemplate().execute(new TransactionCallback<Object>() {

            public Object doInTransaction(TransactionStatus transactionStatus) {
                longRunningTaskManager.execute(executor);
                // lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
                throw new CoreException("fail");
            }
        });
    } catch (Exception ex) {
    // nothing
    }
    // 
    IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
    Assert.assertEquals(3, taskDto.getCount().intValue());
    Assert.assertEquals(1, taskDto.getSuccessItemCount().intValue());
    Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
    // nothing committed
    for (IdmIdentityDto i : identities) {
        IdmIdentityDto identity = identityService.get(i);
        // 
        Assert.assertNotEquals(changeLastName, identity.getLastName());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TransactionStatus(org.springframework.transaction.TransactionStatus) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 63 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method testTransaction.

@Test
public void testTransaction() throws Exception {
    List<IdmIdentityDto> identities = createTestIdentities(3);
    String lastName = getHelper().createName();
    try {
        getTransactionTemplate().execute(new TransactionCallback<Object>() {

            public Object doInTransaction(TransactionStatus transactionStatus) {
                IdmIdentityDto identity = identities.get(0);
                identity.setLastName(lastName);
                identityService.save(identity);
                throw new CoreException("fail");
            }
        });
    } catch (Exception ex) {
    // nothing
    } finally {
        Assert.assertNotEquals(lastName, identityService.get(identities.get(0)).getLastName());
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TransactionStatus(org.springframework.transaction.TransactionStatus) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 64 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutorIntegrationTest method testContinueWithoutRequiresNew.

@Test
public void testContinueWithoutRequiresNew() throws Exception {
    List<IdmIdentityDto> identities = createTestIdentities(3);
    // 
    TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
    executor.dtos = identities;
    executor.continueOnException = true;
    executor.requireNewTransaction = false;
    String changeLastName = "last-name-update";
    executor.changeLastName = changeLastName;
    executor.exceptionOnItem = 2;
    // 
    try {
        getTransactionTemplate().execute(new TransactionCallback<Object>() {

            public Object doInTransaction(TransactionStatus transactionStatus) {
                longRunningTaskManager.execute(executor);
                // lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
                throw new CoreException("fail");
            }
        });
    } catch (Exception ex) {
    // nothing
    }
    // 
    Assert.assertNotNull(executor);
    Assert.assertNotNull(executor.getLongRunningTaskId());
    IdmLongRunningTaskDto taskDto = longRunningTaskManager.getLongRunningTask(executor);
    Assert.assertEquals(3, taskDto.getCount().intValue());
    Assert.assertEquals(2, taskDto.getSuccessItemCount().intValue());
    Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
    // nothing committed
    for (IdmIdentityDto i : identities) {
        IdmIdentityDto identity = identityService.get(i);
        // 
        Assert.assertNotEquals(changeLastName, identity.getLastName());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) TransactionStatus(org.springframework.transaction.TransactionStatus) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6