TSK-864: Refactor more exception handling for unit tests

This commit is contained in:
Benjamin Eckstein 2019-11-19 14:37:32 +01:00 committed by Holger Hagen
parent c81de3d08b
commit 2a2e510013
7 changed files with 263 additions and 355 deletions

View File

@ -1,10 +1,10 @@
package acceptance.task;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertAll;
import static pro.taskana.BaseQuery.SortDirection.ASCENDING;
import static pro.taskana.BaseQuery.SortDirection.DESCENDING;
import static pro.taskana.TaskQueryColumnName.A_CHANNEL;
@ -14,12 +14,10 @@ import static pro.taskana.TaskQueryColumnName.CLASSIFICATION_KEY;
import static pro.taskana.TaskQueryColumnName.OWNER;
import static pro.taskana.TaskQueryColumnName.STATE;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
@ -61,15 +59,10 @@ class QueryTasksAccTest extends AbstractAccTest {
@Test
void testQueryTaskValuesForEveryColumn() {
TaskService taskService = taskanaEngine.getTaskService();
List<String> notWorkingColumns = new ArrayList<>();
for (TaskQueryColumnName columnName : TaskQueryColumnName.values()) {
try {
taskService.createTaskQuery().listValues(columnName, ASCENDING);
} catch (PersistenceException p) {
notWorkingColumns.add(columnName.toString());
}
}
assertEquals(new ArrayList<>(), notWorkingColumns);
assertAll(() -> Arrays.stream(TaskQueryColumnName.values()).forEach(columnName ->
Assertions.assertDoesNotThrow(() -> taskService.createTaskQuery().listValues(columnName, ASCENDING),
"Column is not working " + columnName)
));
}
@WithAccessId(
@ -138,7 +131,7 @@ class QueryTasksAccTest extends AbstractAccTest {
TaskSummary previousSummary = null;
for (TaskSummary taskSummary : results) {
if (previousSummary != null) {
Assert.assertTrue(!previousSummary.getCreated().isAfter(taskSummary.getCreated()));
Assert.assertFalse(previousSummary.getCreated().isAfter(taskSummary.getCreated()));
}
previousSummary = taskSummary;
}
@ -183,8 +176,7 @@ class QueryTasksAccTest extends AbstractAccTest {
String[] ids = results.stream()
.map(TaskSummary::getName)
.collect(Collectors.toList())
.toArray(new String[0]);
.toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.nameIn(ids)
@ -206,8 +198,7 @@ class QueryTasksAccTest extends AbstractAccTest {
String[] ids = results.stream()
.map(t -> t.getClassificationSummary().getKey())
.collect(Collectors.toList())
.toArray(new String[0]);
.toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.classificationKeyIn(ids)
@ -296,9 +287,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("1", ids)
@ -327,9 +316,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("2", ids)
@ -358,9 +345,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("3", ids)
@ -389,9 +374,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("4", ids)
@ -420,9 +403,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("5", ids)
@ -451,9 +432,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("6", ids)
@ -497,9 +476,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
Assertions.assertThrows(InvalidArgumentException.class, () -> {
List<TaskSummary> result2 = taskService.createTaskQuery()
@ -530,9 +507,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("7", ids)
@ -561,9 +536,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("8", ids)
@ -592,9 +565,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("9", ids)
@ -623,9 +594,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.customAttributeIn("10", ids)
@ -654,9 +623,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("11", ids)
.list();
@ -684,9 +651,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("12", ids)
.list();
@ -714,9 +679,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("13", ids)
.list();
@ -744,9 +707,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("14", ids)
.list();
@ -774,9 +735,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("15", ids)
.list();
@ -804,9 +763,7 @@ class QueryTasksAccTest extends AbstractAccTest {
e.printStackTrace();
return "";
}
})
.collect(Collectors.toList())
.toArray(new String[0]);
}).toArray(String[]::new);
List<TaskSummary> results2 = taskService.createTaskQuery()
.customAttributeIn("16", ids)
.list();
@ -843,15 +800,15 @@ class QueryTasksAccTest extends AbstractAccTest {
engineProxy.openConnection();
List<TaskImpl> queryResult = mapper.selectTasksByCustomAttributeLike("%Property Value of Property_1339%");
assertTrue(queryResult.size() == 1);
assertEquals(1, queryResult.size());
Task retrievedTask = queryResult.get(0);
assertTrue(createdTask.getId().equals(retrievedTask.getId()));
assertEquals(createdTask.getId(), retrievedTask.getId());
// verify that the map is correctly retrieved from the database
Map<String, String> customAttributesFromDb = retrievedTask.getCustomAttributes();
assertNotNull(customAttributesFromDb);
assertTrue(customAttributesForCreate.equals(customAttributesFromDb));
assertEquals(customAttributesForCreate, customAttributesFromDb);
} finally {
engineProxy.returnConnection();
@ -1487,10 +1444,7 @@ class QueryTasksAccTest extends AbstractAccTest {
.list();
assertThat(results.size(), equalTo(10));
String[] ids = results.stream()
.map(TaskSummary::getTaskId)
.collect(Collectors.toList())
.toArray(new String[0]);
String[] ids = results.stream().map(TaskSummary::getTaskId).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.idIn(ids)
@ -1510,10 +1464,7 @@ class QueryTasksAccTest extends AbstractAccTest {
.list();
assertThat(results.size(), equalTo(10));
String[] ids = results.stream()
.map(TaskSummary::getTaskId)
.collect(Collectors.toList())
.toArray(new String[0]);
String[] ids = results.stream().map(TaskSummary::getTaskId).toArray(String[]::new);
List<TaskSummary> result2 = taskService.createTaskQuery()
.idIn(ids)

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
@ -54,13 +53,10 @@ class DeleteWorkbasketAccTest extends AbstractAccTest {
throws WorkbasketNotFoundException, NotAuthorizedException, InvalidArgumentException {
Workbasket wb = workbasketService.getWorkbasket("USER_2_2", "DOMAIN_A");
try {
Assertions.assertThrows(WorkbasketNotFoundException.class, () -> {
workbasketService.deleteWorkbasket(wb.getId());
workbasketService.getWorkbasket("USER_2_2", "DOMAIN_A");
fail("There should be no result for a deleted Workbasket.");
} catch (WorkbasketNotFoundException | WorkbasketInUseException e) {
// Workbasket is deleted
}
}, "There should be no result for a deleted Workbasket.");
}
@WithAccessId(userName = "elena")
@ -90,14 +86,11 @@ class DeleteWorkbasketAccTest extends AbstractAccTest {
int distTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001")
.size();
try {
Assertions.assertThrows(WorkbasketNotFoundException.class, () -> {
// WB deleted
workbasketService.deleteWorkbasket(wb.getId());
workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
fail("There should be no result for a deleted Workbasket.");
} catch (WorkbasketNotFoundException | WorkbasketInUseException e) {
// Workbasket is deleted
}
}, "There should be no result for a deleted Workbasket.");
int newDistTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001")
.size();
@ -112,20 +105,15 @@ class DeleteWorkbasketAccTest extends AbstractAccTest {
void testDeleteWorkbasketWithNullOrEmptyParam()
throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException {
// Test Null-Value
try {
workbasketService.deleteWorkbasket(null);
fail("delete() should have thrown an InvalidArgumentException, when the param ID is null.");
} catch (InvalidArgumentException e) {
// Nothing to do here
}
Assertions.assertThrows(InvalidArgumentException.class, () ->
workbasketService.deleteWorkbasket(null),
"delete() should have thrown an InvalidArgumentException, when the param ID is null.");
// Test EMPTY-Value
try {
workbasketService.deleteWorkbasket("");
fail("delete() should have thrown an InvalidArgumentException, when the param ID is EMPTY-String.");
} catch (InvalidArgumentException e) {
// Nothing to do here
}
Assertions.assertThrows(InvalidArgumentException.class, () ->
workbasketService.deleteWorkbasket(""),
"delete() should have thrown an InvalidArgumentException, when the param ID is EMPTY-String.");
}
@WithAccessId(
@ -182,13 +170,11 @@ class DeleteWorkbasketAccTest extends AbstractAccTest {
workbasketService.createWorkbasketAccessItem(accessItem);
List<WorkbasketAccessItem> accessItemsBefore = workbasketService.getWorkbasketAccessItems(wbId);
assertEquals(5, accessItemsBefore.size());
try {
Assertions.assertThrows(WorkbasketNotFoundException.class, () -> {
workbasketService.deleteWorkbasket(wbId);
workbasketService.getWorkbasket("WBI:100000000000000000000000000000000008");
fail("There should be no result for a deleted Workbasket.");
} catch (WorkbasketNotFoundException | WorkbasketInUseException e) {
// Workbasket is deleted
}
}, "There should be no result for a deleted Workbasket.");
List<WorkbasketAccessItem> accessItemsAfter = workbasketService.getWorkbasketAccessItems(wbId);
assertEquals(0, accessItemsAfter.size());

View File

@ -91,28 +91,15 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
String existingWb = "WBI:100000000000000000000000000000000001";
String nonExistingWb = "WBI:100000000000000000000000000000000xx1";
try {
workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000xx1");
assertTrue("This line of code should not be reached", false);
} catch (WorkbasketNotFoundException ex) {
// nothing to do
}
Assertions.assertThrows(WorkbasketNotFoundException.class, () ->
workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000xx1"));
try {
List<String> distributionTargets = new ArrayList<>(
Arrays.asList(nonExistingWb));
workbasketService.setDistributionTargets(existingWb, distributionTargets);
assertTrue("This line of code should not be reached", false);
} catch (WorkbasketNotFoundException ex) {
// nothing to do
}
Assertions.assertThrows(WorkbasketNotFoundException.class, () ->
workbasketService.setDistributionTargets(existingWb, new ArrayList<>(
Arrays.asList(nonExistingWb))));
try {
workbasketService.addDistributionTarget(existingWb, nonExistingWb);
assertTrue("This line of code should not be reached", false);
} catch (WorkbasketNotFoundException ex) {
// nothing to do
}
Assertions.assertThrows(WorkbasketNotFoundException.class, () ->
workbasketService.addDistributionTarget(existingWb, nonExistingWb));
int beforeCount = workbasketService.getDistributionTargets(existingWb).size();
workbasketService.removeDistributionTarget(existingWb, nonExistingWb);
@ -130,37 +117,21 @@ public class DistributionTargetsAccTest extends AbstractAccTest {
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
}
Assertions.assertThrows(NotAuthorizedException.class, () ->
workbasketService.getDistributionTargets(existingWb));
try {
Assertions.assertThrows(NotAuthorizedException.class, () ->
workbasketService.setDistributionTargets(existingWb, Arrays.asList("WBI:100000000000000000000000000000000002")));
Assertions.assertThrows(NotAuthorizedException.class, () ->
workbasketService.addDistributionTarget(existingWb,
"WBI:100000000000000000000000000000000002");
assertTrue("This line of code should not be reached", false);
} catch (NotAuthorizedException ex) {
// nothing to do
}
"WBI:100000000000000000000000000000000002"));
try {
Assertions.assertThrows(NotAuthorizedException.class, () ->
workbasketService.removeDistributionTarget(existingWb,
"WBI:100000000000000000000000000000000002");
assertTrue("This line of code should not be reached", false);
} catch (NotAuthorizedException ex) {
// nothing to do
}
"WBI:100000000000000000000000000000000002"));
}

View File

@ -5,13 +5,14 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -37,9 +38,9 @@ import pro.taskana.security.WithAccessId;
* Acceptance test for all "update workbasket" scenarios.
*/
@ExtendWith(JAASExtension.class)
public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
public UpdateWorkbasketAuthorizationsAccTest() {
UpdateWorkbasketAuthorizationsAccTest() {
super();
}
@ -47,7 +48,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testUpdateWorkbasketAccessItemSucceeds()
void testUpdateWorkbasketAccessItemSucceeds()
throws InvalidArgumentException, NotAuthorizedException, WorkbasketNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
WorkbasketAccessItem accessItem = workbasketService
@ -70,19 +71,20 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
.findFirst()
.orElse(null);
assertNotNull(updatedItem);
assertEquals("Rojas, Miguel", updatedItem.getAccessName());
assertEquals(false, updatedItem.isPermAppend());
assertEquals(true, updatedItem.isPermRead());
assertEquals(true, updatedItem.isPermCustom11());
assertEquals(true, updatedItem.isPermCustom1());
assertEquals(false, updatedItem.isPermCustom2());
assertFalse(updatedItem.isPermAppend());
assertTrue(updatedItem.isPermRead());
assertTrue(updatedItem.isPermCustom11());
assertTrue(updatedItem.isPermCustom1());
assertFalse(updatedItem.isPermCustom2());
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testUpdateWorkbasketAccessItemRejected()
void testUpdateWorkbasketAccessItemRejected()
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
WorkbasketAccessItem accessItem = workbasketService
@ -90,40 +92,36 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
accessItem.setPermAppend(true);
accessItem.setPermCustom11(true);
accessItem.setPermRead(true);
accessItem = workbasketService.createWorkbasketAccessItem(accessItem);
WorkbasketAccessItem accessItemCreated = workbasketService.createWorkbasketAccessItem(accessItem);
accessItem.setPermCustom1(true);
accessItem.setPermAppend(false);
((WorkbasketAccessItemImpl) accessItem).setAccessId("willi");
try {
workbasketService.updateWorkbasketAccessItem(accessItem);
fail("InvalidArgumentException was expected because access id was changed");
} catch (InvalidArgumentException ex) {
// nothing to do
}
accessItemCreated.setPermCustom1(true);
accessItemCreated.setPermAppend(false);
((WorkbasketAccessItemImpl) accessItemCreated).setAccessId("willi");
((WorkbasketAccessItemImpl) accessItem).setAccessId("user1");
accessItem = workbasketService.updateWorkbasketAccessItem(accessItem);
assertEquals(false, accessItem.isPermAppend());
assertEquals(true, accessItem.isPermRead());
assertEquals(true, accessItem.isPermCustom11());
assertEquals(true, accessItem.isPermCustom1());
assertEquals(false, accessItem.isPermCustom2());
Assertions.assertThrows(InvalidArgumentException.class, () ->
workbasketService.updateWorkbasketAccessItem(accessItemCreated),
"InvalidArgumentException was expected because access id was changed");
((WorkbasketAccessItemImpl) accessItem).setWorkbasketId("2");
try {
workbasketService.updateWorkbasketAccessItem(accessItem);
fail("InvalidArgumentException was expected because key was changed");
} catch (InvalidArgumentException ex) {
// nothing to do
}
((WorkbasketAccessItemImpl) accessItemCreated).setAccessId("user1");
WorkbasketAccessItem accessItemUpdated = workbasketService.updateWorkbasketAccessItem(accessItemCreated);
assertFalse(accessItemUpdated.isPermAppend());
assertTrue(accessItemUpdated.isPermRead());
assertTrue(accessItemUpdated.isPermCustom11());
assertTrue(accessItemUpdated.isPermCustom1());
assertFalse(accessItemUpdated.isPermCustom2());
((WorkbasketAccessItemImpl) accessItemUpdated).setWorkbasketId("2");
Assertions.assertThrows(InvalidArgumentException.class, () ->
workbasketService.updateWorkbasketAccessItem(accessItemUpdated),
"InvalidArgumentException was expected because key was changed");
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_2", "businessadmin"})
@Test
public void testUpdatedAccessItemLeadsToNotAuthorizedException()
void testUpdatedAccessItemLeadsToNotAuthorizedException()
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException,
ClassificationNotFoundException, TaskAlreadyExistException {
TaskService taskService = taskanaEngine.getTaskService();
@ -150,25 +148,21 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
.findFirst()
.orElse(null);
assertTrue(theAccessItem != null);
assertNotNull(theAccessItem);
theAccessItem.setPermOpen(false);
workbasketService.updateWorkbasketAccessItem(theAccessItem);
try {
Assertions.assertThrows(NotAuthorizedToQueryWorkbasketException.class, () ->
taskService.createTaskQuery()
.workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain))
.list();
fail("NotAuthorizedToQueryWorkbasketException was expected ");
} catch (NotAuthorizedToQueryWorkbasketException ignored) {
// nothing to do
}
.list());
}
@WithAccessId(
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testUpdatedAccessItemList() throws InvalidArgumentException, NotAuthorizedException {
void testUpdatedAccessItemList() throws InvalidArgumentException, NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
final String wbId = "WBI:100000000000000000000000000000000004";
List<WorkbasketAccessItem> accessItems = workbasketService
@ -209,7 +203,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testUpdatedAccessItemListToEmptyList() throws InvalidArgumentException, NotAuthorizedException {
void testUpdatedAccessItemListToEmptyList() throws InvalidArgumentException, NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
final String wbId = "WBI:100000000000000000000000000000000004";
List<WorkbasketAccessItem> accessItems = workbasketService
@ -229,7 +223,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testInsertAccessItemList() throws InvalidArgumentException, NotAuthorizedException {
void testInsertAccessItemList() throws InvalidArgumentException, NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
final String wbId = "WBI:100000000000000000000000000000000004";
List<WorkbasketAccessItem> accessItems = workbasketService
@ -254,7 +248,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
List<WorkbasketAccessItem> updatedAccessItems = workbasketService
.getWorkbasketAccessItems(wbId);
int countAfter = updatedAccessItems.size();
assertTrue((countBefore + 1) == countAfter);
assertEquals((countBefore + 1), countAfter);
item0 = updatedAccessItems.stream().filter(i -> i.getId().equals(updateId0)).findFirst().get();
assertFalse(item0.isPermAppend());
@ -268,12 +262,12 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"group_1", "businessadmin"})
@Test
public void testDeleteAccessItemForAccessItemId() throws NotAuthorizedException, InvalidArgumentException {
void testDeleteAccessItemForAccessItemId() throws NotAuthorizedException, InvalidArgumentException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
final String wbId = "WBI:100000000000000000000000000000000001";
List<WorkbasketAccessItem> originalList = workbasketService.getWorkbasketAccessItems(wbId);
List<String> originalIds = new ArrayList<String>();
List<String> originalIds = new ArrayList<>();
for (WorkbasketAccessItem a : originalList) {
originalIds.add(a.getId());
}
@ -300,7 +294,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"businessadmin"})
@Test
public void testDeleteAccessItemsForAccessId() throws NotAuthorizedException {
void testDeleteAccessItemsForAccessId() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
final String accessId = "group_1";
final long accessIdCountBefore = workbasketService
@ -321,7 +315,7 @@ public class UpdateWorkbasketAuthorizationsAccTest extends AbstractAccTest {
userName = "teamlead_1",
groupNames = {"businessadmin"})
@Test
public void testDeleteAccessItemsForAccessIdWithUnusedValuesThrowingNoException() throws NotAuthorizedException {
void testDeleteAccessItemsForAccessIdWithUnusedValuesThrowingNoException() throws NotAuthorizedException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
workbasketService.deleteWorkbasketAccessItemsForAccessId("");
workbasketService.deleteWorkbasketAccessItemsForAccessId(null);

View File

@ -4,7 +4,6 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.sql.Connection;
import java.sql.SQLException;
@ -22,6 +21,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
@ -106,16 +106,18 @@ public class ClassificationServiceImplIntExplicitTest {
assertThat(masterResult, not(equalTo(null)));
// invalid serviceLevel
try {
expectedClassification = (ClassificationImpl) this.createNewClassificationWithUniqueKey("", "TASK");
expectedClassification.setDomain(domain);
expectedClassification.setKey("");
expectedClassification.setServiceLevel("ASAP");
classificationService.createClassification(expectedClassification);
connection.commit();
fail("Should have thrown IllegalArgumentException, because ServiceLevel is invalid.");
} catch (InvalidArgumentException e) {
}
ClassificationImpl expectedClassificationCreated = (ClassificationImpl) this.createNewClassificationWithUniqueKey(
"", "TASK");
expectedClassificationCreated.setDomain(domain);
expectedClassificationCreated.setKey("");
expectedClassificationCreated.setServiceLevel("ASAP");
Assertions.assertThrows(InvalidArgumentException.class, () -> {
classificationService.createClassification(expectedClassificationCreated);
},
"Should have thrown IllegalArgumentException, because ServiceLevel is invalid.");
connection.commit();
}
@Test

View File

@ -3,7 +3,6 @@ package pro.taskana.impl.integration;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.sql.SQLException;
import java.util.List;
@ -12,9 +11,10 @@ import java.util.UUID;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
@ -52,7 +52,7 @@ import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.security.CurrentUserContext;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.JAASExtension;
import pro.taskana.security.WithAccessId;
/**
@ -60,8 +60,8 @@ import pro.taskana.security.WithAccessId;
*
* @author EH
*/
@RunWith(JAASRunner.class)
public class TaskServiceImplIntAutocommitTest {
@ExtendWith(JAASExtension.class)
class TaskServiceImplIntAutocommitTest {
private DataSource dataSource;
@ -77,8 +77,8 @@ public class TaskServiceImplIntAutocommitTest {
private WorkbasketService workbasketService;
@Before
public void setup() throws SQLException {
@BeforeEach
void setup() throws SQLException {
dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, false,
TaskanaEngineConfigurationTest.getSchemaName());
@ -94,7 +94,7 @@ public class TaskServiceImplIntAutocommitTest {
}
@Test
public void testStart() throws TaskNotFoundException,
void testStart() throws TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
@ -120,8 +120,8 @@ public class TaskServiceImplIntAutocommitTest {
Assert.assertNotNull(resultTask);
}
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail()
@Test
void testStartTransactionFail()
throws TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
@ -149,11 +149,12 @@ public class TaskServiceImplIntAutocommitTest {
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTask(wb.getId());
Assertions.assertThrows(TaskNotFoundException.class, () -> taskServiceImpl2.getTask(wb.getId()));
}
@Test
public void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException,
void should_ReturnList_when_BuilderIsUsed() throws NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException,
WorkbasketAlreadyExistException, DomainNotFoundException {
@ -190,7 +191,7 @@ public class TaskServiceImplIntAutocommitTest {
}
@Test
public void shouldTransferTaskToOtherWorkbasket()
void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException,
InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException,
@ -248,18 +249,19 @@ public class TaskServiceImplIntAutocommitTest {
assertThat(resultTask.getCreated(), equalTo(task.getCreated()));
}
@Test(expected = TaskNotFoundException.class)
public void shouldNotTransferAnyTask()
throws WorkbasketNotFoundException, NotAuthorizedException, TaskNotFoundException, InvalidStateException {
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1");
@Test
void shouldNotTransferAnyTask() {
Assertions.assertThrows(TaskNotFoundException.class, () ->
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1"));
}
@WithAccessId(userName = "User", groupNames = { "businessadmin" })
@WithAccessId(userName = "User", groupNames = {"businessadmin"})
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException, DomainNotFoundException, InvalidStateException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException, DomainNotFoundException {
final String user = CurrentUserContext.getUserid();
// Set up Security for this Test
@ -284,8 +286,8 @@ public class TaskServiceImplIntAutocommitTest {
wb.setDescription("Normal base WB");
wb.setOwner(user);
wb.setType(WorkbasketType.TOPIC);
wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
WorkbasketImpl wbCreated = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wbCreated, wbCreated.getOwner(), true, true, true, true);
WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("key77", "DOMAIN_A");
wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
@ -293,8 +295,8 @@ public class TaskServiceImplIntAutocommitTest {
wbNoAppend.setOwner(user);
wbNoAppend.setType(WorkbasketType.PERSONAL);
wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
WorkbasketImpl wbNoAppendCreated = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppendCreated, wbNoAppendCreated.getOwner(), true, true, false, true);
WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("k99", "DOMAIN_B");
wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
@ -305,47 +307,45 @@ public class TaskServiceImplIntAutocommitTest {
wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wb.getId());
TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wbCreated.getId());
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setOwner(user);
task.setClassificationKey(classification.getKey());
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = (TaskImpl) taskServiceImpl.createTask(task);
TaskImpl taskCreated = (TaskImpl) taskServiceImpl.createTask(task);
// Check failing with missing APPEND
try {
task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wbNoAppend.getId());
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
} catch (NotAuthorizedException e) {
if (!e.getMessage().contains("APPEND")) {
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
}
assertThat(task.isTransferred(), equalTo(false));
assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
assertThat(task.getWorkbasketKey(), equalTo(wb.getKey()));
}
NotAuthorizedException e = Assertions.assertThrows(NotAuthorizedException.class, () ->
taskServiceImpl.transfer(taskCreated.getId(), wbNoAppendCreated.getId()),
"Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
Assertions.assertTrue(e.getMessage().contains("APPEND"),
"Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
assertThat(taskCreated.isTransferred(), equalTo(false));
assertThat(taskCreated.getWorkbasketKey(), not(equalTo(wbNoAppendCreated.getKey())));
assertThat(taskCreated.getWorkbasketKey(), equalTo(wbCreated.getKey()));
// Check failing with missing TRANSFER
task.setId("");
task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
task.setWorkbasketKey(null);
task.setExternalId(IdGenerator.generateWithPrefix("TST"));
task = (TaskImpl) taskServiceImpl.createTask(task);
try {
task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wb.getId());
fail("Transfer Task should be FAILD, because there are no TRANSFER-Rights on current WB.");
} catch (NotAuthorizedException e) {
if (!e.getMessage().contains("TRANSFER")) {
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on current WB.");
}
assertThat(task.isTransferred(), equalTo(false));
assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
}
taskCreated.setId("");
taskCreated.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
taskCreated.setWorkbasketKey(null);
taskCreated.setExternalId(IdGenerator.generateWithPrefix("TST"));
TaskImpl taskCreated2 = (TaskImpl) taskServiceImpl.createTask(taskCreated);
e = Assertions.assertThrows(NotAuthorizedException.class, () ->
taskServiceImpl.transfer(taskCreated2.getId(), wbCreated.getId()),
"Transfer Task should be FAILED, because there are no TRANSFER-Rights on current WB.");
Assertions.assertTrue(e.getMessage().contains("TRANSFER"),
"Transfer Task should be FAILED, because there are no APPEND-Rights on current WB.");
assertThat(taskCreated2.isTransferred(), equalTo(false));
assertThat(taskCreated2.getWorkbasketKey(), not(equalTo(wbNoAppendCreated.getKey())));
}
@Test
public void testWithPrimaryObjectRef() throws TaskNotFoundException,
void testWithPrimaryObjectRef() throws TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {

View File

@ -3,7 +3,7 @@ package pro.taskana.impl.integration;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.sql.Connection;
@ -13,12 +13,13 @@ import java.util.UUID;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.Classification;
import pro.taskana.ClassificationService;
@ -57,7 +58,7 @@ import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.security.CurrentUserContext;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.JAASExtension;
import pro.taskana.security.WithAccessId;
/**
@ -65,8 +66,8 @@ import pro.taskana.security.WithAccessId;
*
* @author EH
*/
@RunWith(JAASRunner.class)
public class TaskServiceImplIntExplicitTest {
@ExtendWith(JAASExtension.class)
class TaskServiceImplIntExplicitTest {
private static DataSource dataSource;
@ -84,10 +85,10 @@ public class TaskServiceImplIntExplicitTest {
private static WorkbasketService workbasketService;
@BeforeClass
public static void setup() throws SQLException {
String userHomeDirectroy = System.getProperty("user.home");
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
@BeforeAll
static void setup() throws SQLException {
String userHomeDirectory = System.getProperty("user.home");
String propertiesFileName = userHomeDirectory + "/taskanaUnitTest.properties";
dataSource = new File(propertiesFileName).exists()
? TaskanaEngineConfigurationTest.createDataSourceFromProperties(propertiesFileName)
@ -105,14 +106,14 @@ public class TaskServiceImplIntExplicitTest {
creator.run();
}
@Before
public void resetDb() {
@BeforeEach
void resetDb() {
cleaner.clearDb(dataSource, false);
}
@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail()
@WithAccessId(userName = "Elena", groupNames = {"businessadmin"})
@Test
void testStartTransactionFail()
throws SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
@ -142,17 +143,18 @@ public class TaskServiceImplIntExplicitTest {
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = taskServiceImpl.createTask(task);
connection.commit();
task = taskServiceImpl.getTask(task.getId());
taskServiceImpl.getTask(task.getId());
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTask(workbasket.getId());
Assertions.assertThrows(TaskNotFoundException.class, () ->
taskServiceImpl2.getTask(workbasket.getId()));
connection.commit();
}
@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@WithAccessId(userName = "Elena", groupNames = {"businessadmin"})
@Test
public void testCreateTask()
void testCreateTask()
throws SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
@ -180,24 +182,26 @@ public class TaskServiceImplIntExplicitTest {
connection.commit();
}
@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test(expected = WorkbasketNotFoundException.class)
public void createTaskShouldThrowWorkbasketNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
@WithAccessId(userName = "Elena", groupNames = {"businessadmin"})
@Test
void createTaskShouldThrowWorkbasketNotFoundException()
throws NotAuthorizedException, SQLException,
ClassificationAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Task test = this.generateDummyTask();
((WorkbasketSummaryImpl) (test.getWorkbasketSummary())).setId("2");
taskServiceImpl.createTask(test);
Assertions.assertThrows(WorkbasketNotFoundException.class, () ->
taskServiceImpl.createTask(test));
}
@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test(expected = ClassificationNotFoundException.class)
public void createManualTaskShouldThrowClassificationNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException,
@WithAccessId(userName = "Elena", groupNames = {"businessadmin"})
@Test
void createManualTaskShouldThrowClassificationNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, SQLException,
ClassificationAlreadyExistException, InvalidWorkbasketException,
InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -216,12 +220,14 @@ public class TaskServiceImplIntExplicitTest {
Task task = this.generateDummyTask();
((TaskImpl) task).setWorkbasketSummary(wb.asSummary());
task.setClassificationKey(classification.getKey());
taskServiceImpl.createTask(task);
Assertions.assertThrows(ClassificationNotFoundException.class, () ->
taskServiceImpl.createTask(task));
}
@WithAccessId(userName = "Elena", groupNames = { "DummyGroup", "businessadmin" })
@WithAccessId(userName = "Elena", groupNames = {"DummyGroup", "businessadmin"})
@Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, SystemException,
WorkbasketAlreadyExistException, DomainNotFoundException {
@ -245,7 +251,7 @@ public class TaskServiceImplIntExplicitTest {
task.setName("Unit Test Task");
task.setClassificationKey(classification.getKey());
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = taskServiceImpl.createTask(task);
taskServiceImpl.createTask(task);
List<TaskSummary> results = taskServiceImpl.createTaskQuery()
.nameIn("bla", "test")
@ -267,9 +273,9 @@ public class TaskServiceImplIntExplicitTest {
connection.commit();
}
@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@WithAccessId(userName = "Elena", groupNames = {"businessadmin"})
@Test
public void shouldTransferTaskToOtherWorkbasket()
void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException,
SQLException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException,
@ -337,21 +343,22 @@ public class TaskServiceImplIntExplicitTest {
assertThat(resultTask.getCreated(), equalTo(task.getCreated()));
}
@Test(expected = TaskNotFoundException.class)
public void shouldNotTransferAnyTask()
throws WorkbasketNotFoundException, NotAuthorizedException, TaskNotFoundException, SQLException,
InvalidStateException {
@Test
void shouldNotTransferAnyTask()
throws SQLException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1");
Assertions.assertThrows(TaskNotFoundException.class, () ->
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1"));
}
@WithAccessId(userName = "User", groupNames = { "businessadmin" })
@WithAccessId(userName = "User", groupNames = {"businessadmin"})
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException, DomainNotFoundException, InvalidStateException {
TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException,
WorkbasketAlreadyExistException, DomainNotFoundException {
final String user = "User";
// Set up Security for this Test
@ -376,8 +383,8 @@ public class TaskServiceImplIntExplicitTest {
wb.setDescription("Normal base WB");
wb.setOwner(user);
wb.setType(WorkbasketType.GROUP);
wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
WorkbasketImpl wbCreated = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wbCreated, wbCreated.getOwner(), true, true, true, true);
WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoAppend", "DOMAIN_B");
wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
@ -385,8 +392,8 @@ public class TaskServiceImplIntExplicitTest {
wbNoAppend.setOwner(user);
wbNoAppend.setType(WorkbasketType.CLEARANCE);
wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
WorkbasketImpl wbNoAppendCreated = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppendCreated, wbNoAppendCreated.getOwner(), true, true, false, true);
WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoTransfer", "DOMAIN_A");
wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
@ -396,43 +403,40 @@ public class TaskServiceImplIntExplicitTest {
wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wb.getId());
TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wbCreated.getId());
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setOwner(user);
task.setClassificationKey(classification.getKey());
task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
task = (TaskImpl) taskServiceImpl.createTask(task);
TaskImpl taskCreated = (TaskImpl) taskServiceImpl.createTask(task);
// Check failing with missing APPEND
try {
task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wbNoAppend.getId());
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
} catch (NotAuthorizedException e) {
if (!e.getMessage().contains("APPEND")) {
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
}
assertThat(task.isTransferred(), equalTo(false));
assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
assertThat(task.getWorkbasketKey(), equalTo(wb.getKey()));
}
NotAuthorizedException e = Assertions.assertThrows(NotAuthorizedException.class,
() -> taskServiceImpl.transfer(taskCreated.getId(), wbNoAppendCreated.getId()),
"Transfer Task should be FAILED, because there are no APPEND-Rights on destination WB.");
assertTrue(e.getMessage().contains("APPEND"),
"Transfer Task should be FAILED, because there are no APPEND-Rights on destination WB.");
assertThat(taskCreated.isTransferred(), equalTo(false));
assertThat(taskCreated.getWorkbasketKey(), not(equalTo(wbNoAppendCreated.getKey())));
assertThat(taskCreated.getWorkbasketKey(), equalTo(wbCreated.getKey()));
// Check failing with missing TRANSFER
task.setId("");
task.setWorkbasketKey(wbNoTransfer.getKey());
task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
task.setExternalId(IdGenerator.generateWithPrefix("TST"));
task = (TaskImpl) taskServiceImpl.createTask(task);
try {
task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wb.getId());
fail("Transfer Task should be FAILD, because there are no TRANSFER-Rights on current WB.");
} catch (NotAuthorizedException e) {
if (!e.getMessage().contains("TRANSFER")) {
fail("Transfer Task should be FAILD, because there are no APPEND-Rights on current WB.");
}
assertThat(task.isTransferred(), equalTo(false));
assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
}
taskCreated.setId("");
taskCreated.setWorkbasketKey(wbNoTransfer.getKey());
taskCreated.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
taskCreated.setExternalId(IdGenerator.generateWithPrefix("TST"));
TaskImpl taskCreated2 = (TaskImpl) taskServiceImpl.createTask(taskCreated);
e = Assertions.assertThrows(NotAuthorizedException.class,
() -> taskServiceImpl.transfer(taskCreated2.getId(), wbCreated.getId()),
"Transfer Task should be FAILED, because there are no TRANSFER-Rights on current WB.");
assertTrue(e.getMessage().contains("TRANSFER"),
"Transfer Task should be FAILED, because there are no APPEND-Rights on current WB.");
assertThat(taskCreated2.isTransferred(), equalTo(false));
assertThat(taskCreated2.getWorkbasketKey(), not(equalTo(wbNoAppendCreated.getKey())));
}
private Task generateDummyTask()
@ -463,8 +467,8 @@ public class TaskServiceImplIntExplicitTest {
workbasketService.createWorkbasketAccessItem(accessItem);
}
@After
public void cleanUp() throws SQLException {
@AfterEach
void cleanUp() throws SQLException {
taskanaEngineImpl.setConnection(null);
}
}