Search in sources :

Example 31 with Workbasket

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

the class WorkbasketServiceImplTest method testCreateWorkbasket_WithoutDistibutionTargets.

@Test
public void testCreateWorkbasket_WithoutDistibutionTargets() throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
    doNothing().when(workbasketMapperMock).insert(expectedWb);
    doReturn(expectedWb).when(workbasketMapperMock).findById(any());
    doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration();
    doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
    doReturn(true).when(taskanaEngineImplMock).domainExists(any());
    Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
    cutSpy.setDistributionTargets(expectedWb.getId(), null);
    verify(taskanaEngineImplMock, times(3)).openConnection();
    verify(taskanaEngineImplMock, times(1)).getConfiguration();
    verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
    verify(workbasketMapperMock, times(1)).insert(expectedWb);
    verify(workbasketMapperMock, times(1)).findByKeyAndDomain(any(), any());
    verify(workbasketMapperMock, times(2)).findById(expectedWb.getId());
    verify(workbasketMapperMock, times(1)).update(any());
    verify(taskanaEngineImplMock, times(3)).returnConnection();
    verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any());
    verify(taskanaEngineImplMock, times(1)).isUserInRole(any());
    verify(taskanaEngineImplMock, times(1)).domainExists(any());
    verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any());
    verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, distributionTargetMapperMock, taskanaEngineImplMock, taskanaEngineConfigurationMock);
    assertThat(actualWb.getId(), not(equalTo(null)));
    assertThat(actualWb.getId(), startsWith("WBI"));
    assertThat(actualWb.getCreated(), not(equalTo(null)));
    assertThat(actualWb.getModified(), not(equalTo(null)));
}
Also used : Workbasket(pro.taskana.Workbasket) Test(org.junit.Test)

Example 32 with Workbasket

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

the class TaskServiceImplIntExplicitTest method createManualTaskShouldThrowClassificationNotFoundException.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test(expected = ClassificationNotFoundException.class)
public void createManualTaskShouldThrowClassificationNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    generateSampleAccessItems();
    Workbasket wb = workbasketService.newWorkbasket("WB NR.1", "DOMAIN_A");
    wb.setName("dummy-WB");
    wb.setType(WorkbasketType.PERSONAL);
    wb = workbasketService.createWorkbasket(wb);
    this.createWorkbasketWithSecurity(wb, CurrentUserContext.getUserid(), true, true, true, false);
    Classification classification = classificationService.newClassification(UUID.randomUUID().toString(), wb.getDomain(), // not persisted,
    "t1");
    // not found.
    classification.setName("not persisted - so not found.");
    Task task = this.generateDummyTask();
    ((TaskImpl) task).setWorkbasketKey(wb.getKey());
    task.setClassificationKey(classification.getKey());
    taskServiceImpl.createTask(task);
}
Also used : Task(pro.taskana.Task) TaskImpl(pro.taskana.impl.TaskImpl) Classification(pro.taskana.Classification) Connection(java.sql.Connection) Workbasket(pro.taskana.Workbasket) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 33 with Workbasket

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

the class TaskServiceImplIntExplicitTest method testCreateTaskInTaskanaWithDefaultDb.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testCreateTaskInTaskanaWithDefaultDb() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(ds, false);
    TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
    TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
    Connection connection = ds.getConnection();
    te.setConnection(connection);
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
    WorkbasketServiceImpl workBasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService();
    ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
    Workbasket workbasket = workbasketService.newWorkbasket("K99", "DOMAIN_A");
    workbasket.setName("workbasket");
    workbasket.setName("workbasket99");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket = workBasketServiceImpl.createWorkbasket(workbasket);
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    classification = classificationServiceImpl.createClassification(classification);
    Task task = taskServiceImpl.newTask(workbasket.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task.addAttachment(null);
    task = taskServiceImpl.createTask(task);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
    connection.commit();
    te.setConnection(null);
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Task(pro.taskana.Task) ClassificationServiceImpl(pro.taskana.impl.ClassificationServiceImpl) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) WorkbasketServiceImpl(pro.taskana.impl.WorkbasketServiceImpl) DBCleaner(pro.taskana.impl.configuration.DBCleaner) Workbasket(pro.taskana.Workbasket) DataSource(javax.sql.DataSource) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 34 with Workbasket

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

the class TaskServiceImplIntExplicitTest method shouldTransferTaskToOtherWorkbasket.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void shouldTransferTaskToOtherWorkbasket() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException, SQLException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    Workbasket sourceWB;
    Workbasket destinationWB;
    WorkbasketImpl wb;
    ClassificationImpl classification;
    TaskImpl task;
    Task resultTask;
    final int sleepTime = 100;
    final String user = CurrentUserContext.getUserid();
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    // Source Workbasket
    wb = (WorkbasketImpl) workbasketService.newWorkbasket("sourceWbKey", "DOMAIN_A");
    wb.setName("Basic-Workbasket");
    wb.setDescription("Just used as base WB for Task here");
    wb.setOwner(user);
    wb.setType(WorkbasketType.PERSONAL);
    sourceWB = workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(wb, wb.getOwner(), false, false, false, false);
    createWorkbasketWithSecurity(sourceWB, sourceWB.getOwner(), true, true, true, true);
    // Destination Workbasket
    wb = (WorkbasketImpl) workbasketService.newWorkbasket("wb2Key", "DOMAIN_A");
    wb.setName("Desination-WorkBasket");
    wb.setDescription("Destination WB where Task should be transfered to");
    wb.setOwner(user);
    wb.setType(WorkbasketType.TOPIC);
    destinationWB = workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(destinationWB, destinationWB.getOwner(), false, true, true, true);
    // Classification required for Task
    classification = (ClassificationImpl) classificationService.newClassification("KEY", "DOMAIN_A", "TASK");
    classification.setCategory("EXTERNAL");
    classification.setName("Transfert-Task Classification");
    classificationService.createClassification(classification);
    // Task which should be transfered
    task = (TaskImpl) taskServiceImpl.newTask(sourceWB.getId());
    task.setName("Task Name");
    task.setDescription("Task used for transfer Test");
    task.setRead(true);
    task.setTransferred(false);
    task.setModified(null);
    task.setClassificationKey("KEY");
    task.setOwner(user);
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    // Sleep for modification-timestamp
    Thread.sleep(sleepTime);
    connection.commit();
    resultTask = taskServiceImpl.transfer(task.getId(), destinationWB.getId());
    connection.commit();
    assertThat(resultTask.isRead(), equalTo(false));
    assertThat(resultTask.isTransferred(), equalTo(true));
    assertThat(resultTask.getWorkbasketKey(), equalTo(destinationWB.getKey()));
    assertThat(resultTask.getModified(), not(equalTo(null)));
    assertThat(resultTask.getModified(), not(equalTo(task.getModified())));
    assertThat(resultTask.getCreated(), not(equalTo(null)));
    assertThat(resultTask.getCreated(), equalTo(task.getCreated()));
}
Also used : Task(pro.taskana.Task) TaskImpl(pro.taskana.impl.TaskImpl) Connection(java.sql.Connection) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) Workbasket(pro.taskana.Workbasket) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 35 with Workbasket

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

the class WorkbasketServiceImplIntExplicitTest method testUpdateWorkbasket.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testUpdateWorkbasket() throws Exception {
    Connection connection = dataSource.getConnection();
    taskanaEngineImpl.setConnection(connection);
    workBasketService = taskanaEngine.getWorkbasketService();
    String id0 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket0 = createTestWorkbasket(id0, "key0", "DOMAIN_A", "Superbasket", WorkbasketType.GROUP);
    workbasket0 = workBasketService.createWorkbasket(workbasket0);
    createWorkbasketWithSecurity(workbasket0, "Elena", true, true, false, false);
    String id1 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket1 = createTestWorkbasket(id1, "key1", "DOMAIN_A", "Megabasket", WorkbasketType.GROUP);
    workbasket1 = workBasketService.createWorkbasket(workbasket1);
    createWorkbasketWithSecurity(workbasket1, "Elena", true, true, false, false);
    String id2 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket2 = createTestWorkbasket(id2, "key2", "DOMAIN_A", "Hyperbasket", WorkbasketType.GROUP);
    workbasket2 = workBasketService.createWorkbasket(workbasket2);
    createWorkbasketWithSecurity(workbasket2, "Elena", true, true, false, false);
    List<String> distTargets = new ArrayList<>(Arrays.asList(workbasket0.getId(), workbasket1.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), distTargets);
    String id3 = IdGenerator.generateWithPrefix("TWB");
    Workbasket workbasket3 = createTestWorkbasket(id3, "key3", "DOMAIN_A", "hm ... irgend ein basket", WorkbasketType.GROUP);
    workbasket3 = workBasketService.createWorkbasket(workbasket3);
    createWorkbasketWithSecurity(workbasket3, "Elena", true, true, false, false);
    List<String> newDistTargets = new ArrayList<>(Arrays.asList(workbasket3.getId()));
    Thread.sleep(SLEEP_TIME);
    workBasketService.setDistributionTargets(workbasket2.getId(), newDistTargets);
    Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
    List<WorkbasketSummary> distributionTargets = workBasketService.getDistributionTargets(foundBasket.getId());
    Assert.assertEquals(1, distributionTargets.size());
    Assert.assertEquals(workbasket3.getId(), distributionTargets.get(0).getId());
    Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(), workBasketService.getWorkbasket(id2).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(), workBasketService.getWorkbasket(id1).getModified());
    Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(), workBasketService.getWorkbasket(id3).getModified());
    connection.commit();
}
Also used : Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

Workbasket (pro.taskana.Workbasket)62 Test (org.junit.Test)47 WithAccessId (pro.taskana.security.WithAccessId)23 AbstractAccTest (acceptance.AbstractAccTest)18 Task (pro.taskana.Task)18 Classification (pro.taskana.Classification)17 WorkbasketService (pro.taskana.WorkbasketService)13 ArrayList (java.util.ArrayList)11 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)10 WorkbasketSummary (pro.taskana.WorkbasketSummary)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)7 Attachment (pro.taskana.Attachment)6 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)6 Instant (java.time.Instant)5 Transactional (org.springframework.transaction.annotation.Transactional)5 WorkbasketResource (pro.taskana.rest.resource.WorkbasketResource)5 Connection (java.sql.Connection)4