TSK-245: acceptance test for getting distribution sources.

This commit is contained in:
Holger Hagen 2018-02-05 16:34:49 +01:00 committed by Marcel Lengl
parent e6883a05c2
commit 4d24ff7c67
1 changed files with 36 additions and 18 deletions

View File

@ -1,5 +1,8 @@
package acceptance.workbasket; package acceptance.workbasket;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -8,7 +11,7 @@ import java.util.stream.Collectors;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -45,13 +48,13 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
List<WorkbasketSummary> retrievedDistributionTargets = workbasketService List<WorkbasketSummary> retrievedDistributionTargets = workbasketService
.getDistributionTargets(workbasketSummary.getId()); .getDistributionTargets(workbasketSummary.getId());
Assert.assertEquals(4, retrievedDistributionTargets.size()); assertEquals(4, retrievedDistributionTargets.size());
List<String> expectedTargetIds = new ArrayList<>( List<String> expectedTargetIds = new ArrayList<>(
Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003", Arrays.asList("WBI:100000000000000000000000000000000002", "WBI:100000000000000000000000000000000003",
"WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005")); "WBI:100000000000000000000000000000000004", "WBI:100000000000000000000000000000000005"));
for (WorkbasketSummary wbSummary : retrievedDistributionTargets) { 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 { try {
workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000xx1"); 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) { } catch (WorkbasketNotFoundException ex) {
// nothing to do // nothing to do
} }
@ -77,14 +80,14 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
List<String> distributionTargets = new ArrayList<>( List<String> distributionTargets = new ArrayList<>(
Arrays.asList(nonExistingWb)); Arrays.asList(nonExistingWb));
workbasketService.setDistributionTargets(existingWb, distributionTargets); 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) { } catch (WorkbasketNotFoundException ex) {
// nothing to do // nothing to do
} }
try { try {
workbasketService.addDistributionTarget(existingWb, nonExistingWb); 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) { } catch (WorkbasketNotFoundException ex) {
// nothing to do // nothing to do
} }
@ -93,7 +96,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
workbasketService.removeDistributionTarget(existingWb, nonExistingWb); workbasketService.removeDistributionTarget(existingWb, nonExistingWb);
int afterCount = workbasketService.getDistributionTargets(existingWb).size(); int afterCount = workbasketService.getDistributionTargets(existingWb).size();
Assert.assertEquals(afterCount, beforeCount); assertEquals(afterCount, beforeCount);
} }
@ -107,7 +110,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
try { try {
workbasketService.getDistributionTargets(existingWb); 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) { } catch (NotAuthorizedException ex) {
// nothing to do // nothing to do
} }
@ -116,7 +119,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
List<String> distributionTargets = new ArrayList<>( List<String> distributionTargets = new ArrayList<>(
Arrays.asList("WBI:100000000000000000000000000000000002")); Arrays.asList("WBI:100000000000000000000000000000000002"));
workbasketService.setDistributionTargets(existingWb, distributionTargets); 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) { } catch (NotAuthorizedException ex) {
// nothing to do // nothing to do
} }
@ -124,7 +127,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
try { try {
workbasketService.addDistributionTarget(existingWb, workbasketService.addDistributionTarget(existingWb,
"WBI:100000000000000000000000000000000002"); "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) { } catch (NotAuthorizedException ex) {
// nothing to do // nothing to do
} }
@ -132,7 +135,7 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
try { try {
workbasketService.removeDistributionTarget(existingWb, workbasketService.removeDistributionTarget(existingWb,
"WBI:100000000000000000000000000000000002"); "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) { } catch (NotAuthorizedException ex) {
// nothing to do // nothing to do
} }
@ -149,24 +152,24 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
Workbasket workbasket = workbasketService.getWorkbasketByKey("GPK_KSC_1"); Workbasket workbasket = workbasketService.getWorkbasketByKey("GPK_KSC_1");
List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasket.getId()); List<WorkbasketSummary> distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
Assert.assertEquals(4, distributionTargets.size()); assertEquals(4, distributionTargets.size());
// add a new distribution target // add a new distribution target
Workbasket newTarget = workbasketService.getWorkbasketByKey("GPK_B_KSC_2"); Workbasket newTarget = workbasketService.getWorkbasketByKey("GPK_B_KSC_2");
workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId()); workbasketService.addDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.getId()); distributionTargets = workbasketService.getDistributionTargets(workbasket.getId());
Assert.assertEquals(5, distributionTargets.size()); assertEquals(5, distributionTargets.size());
// remove the new target // remove the new target
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId()); workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.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? // remove the new target again Question: should this throw an exception?
workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId()); workbasketService.removeDistributionTarget(workbasket.getId(), newTarget.getId());
distributionTargets = workbasketService.getDistributionTargets(workbasket.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<WorkbasketSummary> initialDistributionTargets = workbasketService List<WorkbasketSummary> initialDistributionTargets = workbasketService
.getDistributionTargets(sourceWorkbasket.getId()); .getDistributionTargets(sourceWorkbasket.getId());
Assert.assertEquals(4, initialDistributionTargets.size()); assertEquals(4, initialDistributionTargets.size());
List<WorkbasketSummary> newDistributionTargets = workbasketService.createWorkbasketQuery() List<WorkbasketSummary> newDistributionTargets = workbasketService.createWorkbasketQuery()
.keyIn("USER_1_1", "GPK_B_KSC_1") .keyIn("USER_1_1", "GPK_B_KSC_1")
.list(); .list();
Assert.assertEquals(2, newDistributionTargets.size()); assertEquals(2, newDistributionTargets.size());
List<String> newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect( List<String> newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect(
Collectors.toList()); Collectors.toList());
workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds); workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds);
List<WorkbasketSummary> changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId()); List<WorkbasketSummary> changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
Assert.assertEquals(2, changedTargets.size()); assertEquals(2, changedTargets.size());
// reset DB to original state // reset DB to original state
resetDb(false); 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<WorkbasketSummary> distributionSources = workbasketService
// .getDistributionSources("WBI:100000000000000000000000000000000004");
//
// assertEquals(2, distributionSources.size());
}
@AfterClass @AfterClass
public static void cleanUpClass() { public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true); FileUtils.deleteRecursive("~/data", true);