Search in sources :

Example 46 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class ClassificationServiceImplTest method testCreateClassificationInOwnDomainButExistingInRoot.

@Test
public void testCreateClassificationInOwnDomainButExistingInRoot() throws ClassificationAlreadyExistException, ClassificationNotFoundException, InterruptedException, NotAuthorizedException, DomainNotFoundException, InvalidArgumentException {
    Instant beforeTimestamp = Instant.now();
    Thread.sleep(10L);
    Classification classification = createDummyClassification();
    String domain = classification.getDomain();
    String key = classification.getKey();
    doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), classification.getDomain());
    doReturn(classification).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), "");
    doReturn(true).when(taskanaEngineImplMock).domainExists(any());
    classification = cutSpy.createClassification(classification);
    Thread.sleep(10L);
    verify(taskanaEngineImplMock, times(2)).openConnection();
    verify(classificationMapperMock, times(1)).findByKeyAndDomain(key, domain);
    verify(classificationMapperMock, times(1)).findByKeyAndDomain(key, "");
    verify(classificationMapperMock, times(1)).insert(any());
    verify(taskanaEngineImplMock, times(2)).returnConnection();
    verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any());
    verify(taskanaEngineImplMock, times(1)).domainExists(any());
    verifyNoMoreInteractions(classificationMapperMock, taskanaEngineImplMock, classificationQueryImplMock);
    Thread.sleep(15);
    assertThat(classification.getCreated().toString().substring(0, 10), equalTo(todaysDate));
    assertFalse(classification.getCreated().isAfter(Instant.now()));
    assertTrue(classification.getCreated().isAfter(beforeTimestamp));
    assertThat(classification.getDomain(), equalTo(domain));
    assertThat(classification.getKey(), equalTo(key));
}
Also used : Instant(java.time.Instant) Classification(pro.taskana.Classification) Test(org.junit.Test)

Example 47 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testTransferTaskToDestinationWorkbasketUsingSecurityTrue.

@Test
public void testTransferTaskToDestinationWorkbasketUsingSecurityTrue() throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, InvalidWorkbasketException, ClassificationNotFoundException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Workbasket destinationWorkbasket = createWorkbasket("2", "k2");
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "k1", dummyClassification);
    task.setRead(true);
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
    doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    doReturn(task).when(cutSpy).getTask(task.getId());
    doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
    doNothing().when(taskMapperMock).update(any());
    doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
    // doNothing().when(workbasketServiceMock).checkAuthorizationById(any(), WorkbasketAuthorization.TRANSFER);
    Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
    verify(taskanaEngineMock, times(1)).openConnection();
    verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
    verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId());
    verify(taskanaEngineMock, times(0)).getConfiguration();
    verify(taskanaEngineConfigurationMock, times(0)).isSecurityEnabled();
    verify(taskMapperMock, times(1)).update(any());
    verify(taskanaEngineMock, times(1)).returnConnection();
    verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
    assertThat(actualTask.isRead(), equalTo(false));
    assertThat(actualTask.getState(), equalTo(TaskState.READY));
    assertThat(actualTask.isTransferred(), equalTo(true));
    assertThat(actualTask.getWorkbasketKey(), equalTo(destinationWorkbasket.getKey()));
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) Workbasket(pro.taskana.Workbasket) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class TaskServiceImplTest method testGetTaskByIdWhereTaskDoesNotExist.

@Test(expected = TaskNotFoundException.class)
public void testGetTaskByIdWhereTaskDoesNotExist() throws Exception {
    Classification dummyClassification = createDummyClassification();
    Task task = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
    doThrow(TaskNotFoundException.class).when(taskMapperMock).findById(task.getId());
    try {
        cut.getTask(task.getId());
    } catch (Exception e) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(taskMapperMock, times(1)).findById(task.getId());
        verify(taskanaEngineMock, times(1)).returnConnection();
        verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock);
        throw e;
    }
}
Also used : Task(pro.taskana.Task) Classification(pro.taskana.Classification) ClassificationAlreadyExistException(pro.taskana.exceptions.ClassificationAlreadyExistException) SystemException(pro.taskana.exceptions.SystemException) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class CreateClassificationAccTest method testCreateRootClassification.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test
public void testCreateRootClassification() throws ClassificationAlreadyExistException, ClassificationNotFoundException, NotAuthorizedException, DomainNotFoundException, InvalidArgumentException {
    long amountOfClassificationsBefore = classificationService.createClassificationQuery().count();
    Classification classification = classificationService.newClassification("Key0", "", "TASK");
    classification.setIsValidInDomain(true);
    classification = classificationService.createClassification(classification);
    // check only 1 created
    long amountOfClassificationsAfter = classificationService.createClassificationQuery().count();
    assertThat(amountOfClassificationsAfter, equalTo(amountOfClassificationsBefore + 1));
    classification = classificationService.getClassification(classification.getId());
    assertNotNull(classification);
    assertNotNull(classification.getCreated());
    assertNotNull(classification.getModified());
    assertNotNull(classification.getId());
    assertThat(classification.getIsValidInDomain(), equalTo(false));
}
Also used : Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 50 with Classification

use of pro.taskana.Classification in project taskana by Taskana.

the class CreateClassificationAccTest method testCreateClassificationAlreadyExisting.

@WithAccessId(userName = "teamlead_1", groupNames = { "group_1", "businessadmin" })
@Test(expected = ClassificationAlreadyExistException.class)
public void testCreateClassificationAlreadyExisting() throws ClassificationAlreadyExistException, NotAuthorizedException, ClassificationNotFoundException, DomainNotFoundException, InvalidArgumentException {
    Classification classification = classificationService.newClassification("Key3", "", "TASK");
    classification = classificationService.createClassification(classification);
    classification = classificationService.createClassification(classification);
}
Also used : Classification(pro.taskana.Classification) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

Classification (pro.taskana.Classification)102 Test (org.junit.Test)88 Task (pro.taskana.Task)32 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 AbstractAccTest (acceptance.AbstractAccTest)23 WithAccessId (pro.taskana.security.WithAccessId)21 ClassificationSummary (pro.taskana.ClassificationSummary)20 Workbasket (pro.taskana.Workbasket)18 Connection (java.sql.Connection)14 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)14 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)13 TaskAlreadyExistException (pro.taskana.exceptions.TaskAlreadyExistException)11 ClassificationService (pro.taskana.ClassificationService)10 AttachmentPersistenceException (pro.taskana.exceptions.AttachmentPersistenceException)10 ConcurrencyException (pro.taskana.exceptions.ConcurrencyException)10 InvalidOwnerException (pro.taskana.exceptions.InvalidOwnerException)10 InvalidStateException (pro.taskana.exceptions.InvalidStateException)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)10 SystemException (pro.taskana.exceptions.SystemException)10