Search in sources :

Example 71 with WorkbasketService

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

the class DistributionTargetsAccTest method testGetDistributionTargetsSucceeds.

@WithAccessId(userName = "user_1_1", groupNames = { "teamlead_1" })
@Test
public void testGetDistributionTargetsSucceeds() throws NotAuthorizedException, WorkbasketNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    WorkbasketSummary workbasketSummary = workbasketService.createWorkbasketQuery().keyIn("GPK_KSC").single();
    List<WorkbasketSummary> retrievedDistributionTargets = workbasketService.getDistributionTargets(workbasketSummary.getKey(), workbasketSummary.getDomain());
    assertEquals(4, retrievedDistributionTargets.size());
    List<String> expectedTargetIds = new ArrayList<>(Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003", "WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005"));
    for (WorkbasketSummary wbSummary : retrievedDistributionTargets) {
        assertTrue(expectedTargetIds.contains(wbSummary.getId()));
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 72 with WorkbasketService

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

the class DistributionTargetsAccTest method testDistributionTargetCallsFailWithNotAuthorizedException.

@WithAccessId(userName = "user_3_1", groupNames = { "group_1" })
@Test
public void testDistributionTargetCallsFailWithNotAuthorizedException() throws NotAuthorizedException, WorkbasketNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    String existingWb = "WBI:100000000000000000000000000000000001";
    try {
        workbasketService.getDistributionTargets(existingWb);
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        List<String> distributionTargets = new ArrayList<>(Arrays.asList("WBI:100000000000000000000000000000000002"));
        workbasketService.setDistributionTargets(existingWb, distributionTargets);
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        workbasketService.addDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002");
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        workbasketService.removeDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002");
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 73 with WorkbasketService

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

the class DistributionTargetsAccTest method testAddAndRemoveDistributionTargets.

@WithAccessId(userName = "user_2_2", groupNames = { "group_1", "group_2", "businessadmin" })
@Test
public void testAddAndRemoveDistributionTargets() throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket workbasket = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
    List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
    assertEquals(4, distributionTargets.size());
    // add a new distribution target
    Workbasket newTarget = workbasketService.getWorkbasket("GPK_B_KSC_2", "DOMAIN_B");
    workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId());
    distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
    assertEquals(5, distributionTargets.size());
    // remove the new target
    workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
    distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
    assertEquals(4, distributionTargets.size());
    // remove the new target again Question: should this throw an exception?
    workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
    distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
    assertEquals(4, distributionTargets.size());
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 74 with WorkbasketService

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

the class DistributionTargetsAccTest method testSetDistributionTargets.

@WithAccessId(userName = "user_2_2", groupNames = { "group_1", "group_2", "businessadmin" })
@Test
public void testSetDistributionTargets() throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket sourceWorkbasket = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
    List<WorkbasketSummary> initialDistributionTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
    assertEquals(4, initialDistributionTargets.size());
    List<WorkbasketSummary> newDistributionTargets = workbasketService.createWorkbasketQuery().keyIn("USER_1_1", "GPK_B_KSC_1").list();
    assertEquals(2, newDistributionTargets.size());
    List<String> newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect(Collectors.toList());
    workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds);
    List<WorkbasketSummary> changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
    assertEquals(2, changedTargets.size());
    // reset DB to original state
    resetDb(false);
}
Also used : Arrays(java.util.Arrays) WithAccessId(pro.taskana.security.WithAccessId) RunWith(org.junit.runner.RunWith) AbstractAccTest(acceptance.AbstractAccTest) Assert.assertTrue(org.junit.Assert.assertTrue) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) Test(org.junit.Test) WorkbasketService(pro.taskana.WorkbasketService) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SQLException(java.sql.SQLException) List(java.util.List) Workbasket(pro.taskana.Workbasket) JAASRunner(pro.taskana.security.JAASRunner) WorkbasketSummary(pro.taskana.WorkbasketSummary) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 75 with WorkbasketService

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

the class DistributionTargetsAccTest method testGetDistributionTargetsSucceedsById.

@WithAccessId(userName = "user_1_1", groupNames = { "teamlead_1" })
@Test
public void testGetDistributionTargetsSucceedsById() throws NotAuthorizedException, WorkbasketNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    WorkbasketSummary workbasketSummary = workbasketService.createWorkbasketQuery().keyIn("GPK_KSC").single();
    List<WorkbasketSummary> retrievedDistributionTargets = workbasketService.getDistributionTargets(workbasketSummary.getId());
    assertEquals(4, retrievedDistributionTargets.size());
    List<String> expectedTargetIds = new ArrayList<>(Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003", "WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005"));
    for (WorkbasketSummary wbSummary : retrievedDistributionTargets) {
        assertTrue(expectedTargetIds.contains(wbSummary.getId()));
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

AbstractAccTest (acceptance.AbstractAccTest)84 Test (org.junit.Test)84 WorkbasketService (pro.taskana.WorkbasketService)84 WithAccessId (pro.taskana.security.WithAccessId)78 WorkbasketSummary (pro.taskana.WorkbasketSummary)52 Workbasket (pro.taskana.Workbasket)12 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)11 ArrayList (java.util.ArrayList)8 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)7 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)5 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)5 SQLException (java.sql.SQLException)4 Task (pro.taskana.Task)4 TaskService (pro.taskana.TaskService)4 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)4 List (java.util.List)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Assert.fail (org.junit.Assert.fail)3 Ignore (org.junit.Ignore)3 RunWith (org.junit.runner.RunWith)3