From 4d24ff7c67684384313f6bf0a38e9daa49b98270 Mon Sep 17 00:00:00 2001 From: Holger Hagen <19706592+holgerhagen@users.noreply.github.com> Date: Mon, 5 Feb 2018 16:34:49 +0100 Subject: [PATCH] TSK-245: acceptance test for getting distribution sources. --- .../DistributionTargetsAccTest.java | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/taskana-core/src/test/java/acceptance/workbasket/DistributionTargetsAccTest.java b/lib/taskana-core/src/test/java/acceptance/workbasket/DistributionTargetsAccTest.java index 658944352..881cd2101 100644 --- a/lib/taskana-core/src/test/java/acceptance/workbasket/DistributionTargetsAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/workbasket/DistributionTargetsAccTest.java @@ -1,5 +1,8 @@ package acceptance.workbasket; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -8,7 +11,7 @@ import java.util.stream.Collectors; import org.h2.store.fs.FileUtils; import org.junit.AfterClass; -import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,13 +48,13 @@ public class DistributionTargetsAccTest extends AbstractAccTest { List retrievedDistributionTargets = workbasketService .getDistributionTargets(workbasketSummary.getId()); - Assert.assertEquals(4, retrievedDistributionTargets.size()); + assertEquals(4, retrievedDistributionTargets.size()); List expectedTargetIds = new ArrayList<>( Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003", "WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005")); for (WorkbasketSummary wbSummary : retrievedDistributionTargets) { - Assert.assertTrue(expectedTargetIds.contains(wbSummary.getId())); + assertTrue(expectedTargetIds.contains(wbSummary.getId())); } } @@ -68,7 +71,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { try { workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000xx1"); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (WorkbasketNotFoundException ex) { // nothing to do } @@ -77,14 +80,14 @@ public class DistributionTargetsAccTest extends AbstractAccTest { List distributionTargets = new ArrayList<>( Arrays.asList(nonExistingWb)); workbasketService.setDistributionTargets(existingWb, distributionTargets); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (WorkbasketNotFoundException ex) { // nothing to do } try { workbasketService.addDistributionTarget(existingWb, nonExistingWb); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (WorkbasketNotFoundException ex) { // nothing to do } @@ -93,7 +96,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { workbasketService.removeDistributionTarget(existingWb, nonExistingWb); int afterCount = workbasketService.getDistributionTargets(existingWb).size(); - Assert.assertEquals(afterCount, beforeCount); + assertEquals(afterCount, beforeCount); } @@ -107,7 +110,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { try { workbasketService.getDistributionTargets(existingWb); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (NotAuthorizedException ex) { // nothing to do } @@ -116,7 +119,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { List distributionTargets = new ArrayList<>( Arrays.asList("WBI:100000000000000000000000000000000002")); workbasketService.setDistributionTargets(existingWb, distributionTargets); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (NotAuthorizedException ex) { // nothing to do } @@ -124,7 +127,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { try { workbasketService.addDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002"); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (NotAuthorizedException ex) { // nothing to do } @@ -132,7 +135,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest { try { workbasketService.removeDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002"); - Assert.assertTrue("This line of code should not be reached", false); + assertTrue("This line of code should not be reached", false); } catch (NotAuthorizedException ex) { // nothing to do } @@ -149,24 +152,24 @@ public class DistributionTargetsAccTest extends AbstractAccTest { Workbasket workbasket = workbasketService.getWorkbasketByKey("GPK_KSC_1"); List distributionTargets = workbasketService.getDistributionTargets(workbasket.getId()); - Assert.assertEquals(4, distributionTargets.size()); + assertEquals(4, distributionTargets.size()); // add a new distribution target Workbasket newTarget = workbasketService.getWorkbasketByKey("GPK_B_KSC_2"); workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId()); distributionTargets = workbasketService.getDistributionTargets(workbasket.getId()); - Assert.assertEquals(5, distributionTargets.size()); + assertEquals(5, distributionTargets.size()); // remove the new target workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId()); distributionTargets = workbasketService.getDistributionTargets(workbasket.getId()); - Assert.assertEquals(4, distributionTargets.size()); + 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()); - Assert.assertEquals(4, distributionTargets.size()); + assertEquals(4, distributionTargets.size()); } @@ -182,25 +185,40 @@ public class DistributionTargetsAccTest extends AbstractAccTest { List initialDistributionTargets = workbasketService .getDistributionTargets(sourceWorkbasket.getId()); - Assert.assertEquals(4, initialDistributionTargets.size()); + assertEquals(4, initialDistributionTargets.size()); List newDistributionTargets = workbasketService.createWorkbasketQuery() .keyIn("USER_1_1", "GPK_B_KSC_1") .list(); - Assert.assertEquals(2, newDistributionTargets.size()); + assertEquals(2, newDistributionTargets.size()); List newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect( Collectors.toList()); workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds); List changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId()); - Assert.assertEquals(2, changedTargets.size()); + assertEquals(2, changedTargets.size()); // reset DB to original state resetDb(false); } + @Ignore + @WithAccessId( + userName = "user_2_2", + groupNames = {"group_1", "group_2"}) + @Test + public void testQueryWorkbasketsWhereGivenWorkbasketIsDistributionTarget() + throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException { + // WorkbasketService workbasketService = taskanaEngine.getWorkbasketService(); + // + // List distributionSources = workbasketService + // .getDistributionSources("WBI:100000000000000000000000000000000004"); + // + // assertEquals(2, distributionSources.size()); + } + @AfterClass public static void cleanUpClass() { FileUtils.deleteRecursive("~/data", true);