TSK-87: Transfer Task, improved Integration-Tests, Updated CreateTask() with AlreadyExistException

This commit is contained in:
Marcel Lengl 2017-12-19 13:17:58 +01:00 committed by Holger Hagen
parent c0a5775a39
commit b6a75ed5e7
12 changed files with 644 additions and 160 deletions

3
lib/.gitignore vendored
View File

@ -23,3 +23,6 @@ nbbuild/
dist/ dist/
nbdist/ nbdist/
.nb-gradle/ .nb-gradle/
### DEV-TOOLS ###
.checkstyle

View File

@ -10,26 +10,29 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
@ApplicationScoped @ApplicationScoped
public class ExampleBootstrap { public class ExampleBootstrap {
@EJB @EJB
private TaskanaEjb taskanaEjb; private TaskanaEjb taskanaEjb;
@PostConstruct @PostConstruct
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidStateException, InvalidOwnerException { public void init(@Observes @Initialized(ApplicationScoped.class) Object init)
System.out.println("---------------------------> Start App"); throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException,
Task task = taskanaEjb.getTaskService().newTask(); ClassificationNotFoundException, InvalidStateException, InvalidOwnerException, TaskAlreadyExistException {
task = taskanaEjb.getTaskService().createTask(task); System.out.println("---------------------------> Start App");
System.out.println("---------------------------> Task started: " + task.getId()); Task task = taskanaEjb.getTaskService().newTask();
taskanaEjb.getTaskService().claim(task.getId()); task = taskanaEjb.getTaskService().createTask(task);
System.out.println( System.out.println("---------------------------> Task started: " + task.getId());
"---------------------------> Task claimed: " taskanaEjb.getTaskService().claim(task.getId());
+ taskanaEjb.getTaskService().getTaskById(task.getId()).getOwner()); System.out.println(
taskanaEjb.getTaskService().completeTask(task.getId()); "---------------------------> Task claimed: "
System.out.println("---------------------------> Task completed"); + taskanaEjb.getTaskService().getTaskById(task.getId()).getOwner());
} taskanaEjb.getTaskService().completeTask(task.getId());
System.out.println("---------------------------> Task completed");
}
} }

View File

@ -5,37 +5,39 @@ import javax.inject.Inject;
import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
@Stateless @Stateless
public class TaskanaEjb { public class TaskanaEjb {
@Inject @Inject
private TaskService taskService; private TaskService taskService;
@Inject @Inject
private ClassificationService classificationService; private ClassificationService classificationService;
@Inject @Inject
private WorkbasketService workbasketService; private WorkbasketService workbasketService;
public TaskService getTaskService() { public TaskService getTaskService() {
return taskService; return taskService;
} }
public ClassificationService getClassificationService() { public ClassificationService getClassificationService() {
return classificationService; return classificationService;
} }
public WorkbasketService getWorkbasketService() { public WorkbasketService getWorkbasketService() {
return workbasketService; return workbasketService;
} }
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException,
Task task = taskService.newTask(); ClassificationNotFoundException, TaskAlreadyExistException {
taskService.createTask(task); Task task = taskService.newTask();
System.out.println("---------------->" + task.getId()); taskService.createTask(task);
throw new RuntimeException(); System.out.println("---------------->" + task.getId());
} throw new RuntimeException();
}
} }

View File

@ -17,52 +17,55 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.Workbasket;
import pro.taskana.Task;
@Path("/test") @Path("/test")
public class TaskanaRestTest { public class TaskanaRestTest {
private static final Logger logger = LoggerFactory.getLogger(TaskanaRestTest.class); private static final Logger logger = LoggerFactory.getLogger(TaskanaRestTest.class);
@EJB @EJB
private TaskanaEjb taskanaEjb; private TaskanaEjb taskanaEjb;
@Inject
private ClassificationService classificationService;
@GET @Inject
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { private ClassificationService classificationService;
Workbasket workbasket = taskanaEjb.getWorkbasketService().newWorkbasket();;
workbasket.setName("wb");
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = classificationService.newClassification();
classification.setKey("TEST");
taskanaEjb.getClassificationService().createClassification(classification);
Task task = taskanaEjb.getTaskService().newTask(); @GET
task.setClassification(classification); public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException,
task.setWorkbasketId(workbasket.getId()); ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException {
Workbasket workbasket = taskanaEjb.getWorkbasketService().newWorkbasket();
;
workbasket.setName("wb");
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = classificationService.newClassification();
classification.setKey("TEST");
taskanaEjb.getClassificationService().createClassification(classification);
Task resultTask = taskanaEjb.getTaskService().createTask(task); Task task = taskanaEjb.getTaskService().newTask();
task.setClassification(classification);
task.setWorkbasketId(workbasket.getId());
logger.info(resultTask.getId() + ":" + resultTask.getOwner()); Task resultTask = taskanaEjb.getTaskService().createTask(task);
return Response.status(200).entity(resultTask.getId()).build();
}
@POST
public Response rollbackTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
taskanaEjb.triggerRollback();
return Response.status(204).build();
}
@DELETE logger.info(resultTask.getId() + ":" + resultTask.getOwner());
@Path("{id}") return Response.status(200).entity(resultTask.getId()).build();
public void completeTask(@PathParam("id") String id) throws TaskNotFoundException, InvalidOwnerException, InvalidStateException { }
logger.info(id);
taskanaEjb.getTaskService().completeTask(id, true); @POST
} public Response rollbackTask() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, TaskAlreadyExistException {
taskanaEjb.triggerRollback();
return Response.status(204).build();
}
@DELETE
@Path("{id}")
public void completeTask(@PathParam("id") String id)
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException {
logger.info(id);
taskanaEjb.getTaskService().completeTask(id, true);
}
} }

View File

@ -6,6 +6,7 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.TaskState; import pro.taskana.model.TaskState;
@ -83,11 +84,13 @@ public interface TaskService {
throws TaskNotFoundException, InvalidOwnerException, InvalidStateException; throws TaskNotFoundException, InvalidOwnerException, InvalidStateException;
/** /**
* Create and persist a task. * Persists a not persisted Task which does not exist already.
* *
* @param taskToCreate * @param taskToCreate
* the transient task object to be persisted * the transient task object to be persisted
* @return the created and persisted task * @return the created and persisted task
* @throws TaskAlreadyExistException
* when the Task does already exist.
* @throws NotAuthorizedException * @throws NotAuthorizedException
* thrown if the current user is not authorized to create that task * thrown if the current user is not authorized to create that task
* @throws WorkbasketNotFoundException * @throws WorkbasketNotFoundException
@ -96,7 +99,8 @@ public interface TaskService {
* thrown if the {@link Classification} referenced by the task is not found * thrown if the {@link Classification} referenced by the task is not found
*/ */
Task createTask(Task taskToCreate) Task createTask(Task taskToCreate)
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException; throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException;
/** /**
* Get the details of a task by Id. * Get the details of a task by Id.
@ -176,6 +180,7 @@ public interface TaskService {
/** /**
* Returns a not persisted instance of {@link Task}. * Returns a not persisted instance of {@link Task}.
*
* @return task - with default values * @return task - with default values
*/ */
Task newTask(); Task newTask();

View File

@ -0,0 +1,14 @@
package pro.taskana.exceptions;
/**
* Thrown when a Task is going to be created, but a Task with the same ID does already exist. The Task ID should be
* unique.
*/
public class TaskAlreadyExistException extends TaskanaException {
public TaskAlreadyExistException(String id) {
super(id);
}
private static final long serialVersionUID = 1L;
}

View File

@ -19,6 +19,7 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.util.IdGenerator; import pro.taskana.impl.util.IdGenerator;
@ -153,10 +154,17 @@ public class TaskServiceImpl implements TaskService {
@Override @Override
public Task createTask(Task taskToCreate) public Task createTask(Task taskToCreate)
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException {
LOGGER.debug("entry to createTask(task = {})", taskToCreate); LOGGER.debug("entry to createTask(task = {})", taskToCreate);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
try {
this.getTaskById(taskToCreate.getId());
throw new TaskAlreadyExistException(taskToCreate.getId());
} catch (TaskNotFoundException ex) {
LOGGER.debug("Task {} can´t be be found, so it can be created.", taskToCreate.getId());
}
TaskImpl task = (TaskImpl) taskToCreate; TaskImpl task = (TaskImpl) taskToCreate;
workbasketService.getWorkbasket(task.getWorkbasketId()); workbasketService.getWorkbasket(task.getWorkbasketId());
workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); workbasketService.checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
@ -164,7 +172,8 @@ public class TaskServiceImpl implements TaskService {
if (classification == null) { if (classification == null) {
throw new ClassificationNotFoundException(null); throw new ClassificationNotFoundException(null);
} }
taskanaEngine.getClassificationService().getClassification(classification.getKey(), classification.getDomain()); taskanaEngine.getClassificationService().getClassification(classification.getKey(),
classification.getDomain());
standardSettings(task); standardSettings(task);
@ -269,7 +278,7 @@ public class TaskServiceImpl implements TaskService {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
workbasketService.checkAuthorization(workbasketId, WorkbasketAuthorization.READ); workbasketService.checkAuthorization(workbasketId, WorkbasketAuthorization.READ);
List<TaskImpl> tasks = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState); List<TaskImpl> tasks = taskMapper.findTasksByWorkbasketIdAndState(workbasketId, taskState);
tasks.stream().forEach(t -> results.add((Task) t)); tasks.stream().forEach(t -> results.add(t));
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {

View File

@ -41,6 +41,7 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.ClassificationImpl; import pro.taskana.model.ClassificationImpl;
@ -105,18 +106,21 @@ public class TaskServiceImplTest {
@Test @Test
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException, public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException { ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException,
Mockito.doNothing().when(taskMapperMock).insert(any()); TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1"); TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
WorkbasketImpl wb = new WorkbasketImpl(); WorkbasketImpl wb = new WorkbasketImpl();
wb.setId("1"); wb.setId("1");
wb.setName("workbasket"); wb.setName("workbasket");
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId()); doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
doNothing().when(taskMapperMock).insert(any()); doNothing().when(taskMapperMock).insert(expectedTask);
Task actualTask = cut.createTask(expectedTask); Task actualTask = cutSpy.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any()); verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskanaEngineMock, times(1)).getClassificationService(); verify(taskanaEngineMock, times(1)).getClassificationService();
@ -138,7 +142,9 @@ public class TaskServiceImplTest {
@Test @Test
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException, public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException,
ClassificationNotFoundException, ClassificationAlreadyExistException { ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException,
TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
@ -148,17 +154,21 @@ public class TaskServiceImplTest {
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", wb.getId()); TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", wb.getId());
expectedTask.setPrimaryObjRef(expectedObjectReference); expectedTask.setPrimaryObjRef(expectedObjectReference);
Classification classification = expectedTask.getClassification(); Classification classification = expectedTask.getClassification();
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId()); doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(expectedObjectReference); doReturn(expectedObjectReference).when(objectReferenceMapperMock)
.findByObjectReference(expectedObjectReference);
doNothing().when(taskMapperMock).insert(expectedTask); doNothing().when(taskMapperMock).insert(expectedTask);
Task actualTask = cut.createTask(expectedTask); Task actualTask = cutSpy.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getId()); verify(workbasketServiceMock, times(1)).getWorkbasket(wb.getId());
verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketAuthorization.APPEND); verify(workbasketServiceMock, times(1)).checkAuthorization(wb.getId(), WorkbasketAuthorization.APPEND);
verify(taskanaEngineMock, times(1)).getClassificationService(); verify(taskanaEngineMock, times(1)).getClassificationService();
verify(classificationServiceMock, times(1)).getClassification(classification.getKey(), classification.getDomain()); verify(classificationServiceMock, times(1)).getClassification(classification.getKey(),
classification.getDomain());
verify(objectReferenceMapperMock, times(1)).findByObjectReference(expectedObjectReference); verify(objectReferenceMapperMock, times(1)).findByObjectReference(expectedObjectReference);
verify(taskMapperMock, times(1)).insert(expectedTask); verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
@ -177,7 +187,9 @@ public class TaskServiceImplTest {
@Test @Test
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException, TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
@ -188,19 +200,24 @@ public class TaskServiceImplTest {
TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1"); TaskImpl expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
expectedTask.setPrimaryObjRef(expectedObjectReference); expectedTask.setPrimaryObjRef(expectedObjectReference);
Classification classification = expectedTask.getClassification(); Classification classification = expectedTask.getClassification();
doReturn(classification).when(classificationServiceMock).getClassification(classification.getKey(), classification.getDomain()); doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(expectedTask.getId());
doReturn(classification).when(classificationServiceMock).getClassification(classification.getKey(),
classification.getDomain());
doNothing().when(taskMapperMock).insert(expectedTask); doNothing().when(taskMapperMock).insert(expectedTask);
doNothing().when(objectReferenceMapperMock).insert(expectedObjectReference); doNothing().when(objectReferenceMapperMock).insert(expectedObjectReference);
doReturn(null).when(objectReferenceMapperMock).findByObjectReference(expectedTask.getPrimaryObjRef()); doReturn(null).when(objectReferenceMapperMock).findByObjectReference(expectedTask.getPrimaryObjRef());
Task actualTask = cut.createTask(expectedTask); Task actualTask = cutSpy.createTask(expectedTask);
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(any());
verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketId()); verify(workbasketServiceMock, times(1)).getWorkbasket(expectedTask.getWorkbasketId());
verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketId(), WorkbasketAuthorization.APPEND); verify(workbasketServiceMock, times(1)).checkAuthorization(expectedTask.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
verify(taskanaEngineMock, times(1)).getClassificationService(); verify(taskanaEngineMock, times(1)).getClassificationService();
verify(classificationServiceMock, times(1)).getClassification(classification.getKey(), classification.getDomain()); verify(classificationServiceMock, times(1)).getClassification(classification.getKey(),
classification.getDomain());
verify(objectReferenceMapperMock, times(1)).findByObjectReference(expectedObjectReference); verify(objectReferenceMapperMock, times(1)).findByObjectReference(expectedObjectReference);
verify(objectReferenceMapperMock, times(1)).insert(expectedObjectReference); verify(objectReferenceMapperMock, times(1)).insert(expectedObjectReference);
verify(taskMapperMock, times(1)).insert(expectedTask); verify(taskMapperMock, times(1)).insert(expectedTask);
@ -220,11 +237,13 @@ public class TaskServiceImplTest {
@Test @Test
public void testCreateTaskWithPlanned() public void testCreateTaskWithPlanned()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException, TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
Classification classification = (Classification) new ClassificationImpl(); Classification classification = new ClassificationImpl();
classification.setName("Name"); classification.setName("Name");
classification.setCategory("MANUAL"); classification.setCategory("MANUAL");
WorkbasketImpl wb = new WorkbasketImpl(); WorkbasketImpl wb = new WorkbasketImpl();
@ -235,12 +254,15 @@ public class TaskServiceImplTest {
task.setClassification(classification); task.setClassification(classification);
task.setPrimaryObjRef(expectedObjectReference); task.setPrimaryObjRef(expectedObjectReference);
task.setDescription("simply awesome task"); task.setDescription("simply awesome task");
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId()); doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
doReturn(classification).when(classificationServiceMock).getClassification(classification.getKey(), classification.getDomain()); doReturn(classification).when(classificationServiceMock).getClassification(classification.getKey(),
doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(expectedObjectReference); classification.getDomain());
doReturn(expectedObjectReference).when(objectReferenceMapperMock)
.findByObjectReference(expectedObjectReference);
doNothing().when(taskMapperMock).insert(task); doNothing().when(taskMapperMock).insert(task);
cut.createTask(task); cutSpy.createTask(task);
TaskImpl task2 = new TaskImpl(); TaskImpl task2 = new TaskImpl();
task2.setWorkbasketId(wb.getId()); task2.setWorkbasketId(wb.getId());
@ -249,9 +271,10 @@ public class TaskServiceImplTest {
task2.setPlanned(Timestamp.valueOf(LocalDateTime.now().minusHours(1))); task2.setPlanned(Timestamp.valueOf(LocalDateTime.now().minusHours(1)));
task2.setName("Task2"); task2.setName("Task2");
cut.createTask(task2); cutSpy.createTask(task2);
verify(taskanaEngineImpl, times(2)).openConnection(); verify(taskanaEngineImpl, times(2)).openConnection();
verify(cutSpy, times(2)).getTaskById(any());
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(2)).getWorkbasket(any()); verify(workbasketServiceMock, times(2)).getWorkbasket(any());
verify(taskanaEngineMock, times(2)).getClassificationService(); verify(taskanaEngineMock, times(2)).getClassificationService();
@ -278,17 +301,43 @@ public class TaskServiceImplTest {
assertThat(task2.getPlanned(), not(task2.getCreated())); assertThat(task2.getPlanned(), not(task2.getCreated()));
} }
@Test(expected = TaskAlreadyExistException.class)
public void testCreateTaskThrowingAlreadyExistException() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, TaskAlreadyExistException, TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
TaskImpl task = createUnitTestTask("12", "Task Name", "1");
doReturn(task).when(cutSpy).getTaskById(task.getId());
try {
cutSpy.createTask(task);
} catch (TaskAlreadyExistException ex) {
verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
throw ex;
}
}
@Test(expected = NotAuthorizedException.class) @Test(expected = NotAuthorizedException.class)
public void testCreateThrowingAuthorizedOnWorkbasket() public void testCreateThrowingAuthorizedOnWorkbasket()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException, TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
TaskImpl task = createUnitTestTask("1", "dummyTask", "1"); TaskImpl task = createUnitTestTask("1", "dummyTask", "1");
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
try { try {
cut.createTask(task); cutSpy.createTask(task);
} catch (NotAuthorizedException e) { } catch (NotAuthorizedException e) {
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId()); verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); verify(workbasketServiceMock, times(1)).checkAuthorization(task.getWorkbasketId(),
WorkbasketAuthorization.APPEND);
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
@ -298,13 +347,18 @@ public class TaskServiceImplTest {
} }
@Test(expected = WorkbasketNotFoundException.class) @Test(expected = WorkbasketNotFoundException.class)
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public void testCreateThrowsWorkbasketNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
TaskAlreadyExistException, TaskNotFoundException {
TaskServiceImpl cutSpy = Mockito.spy(cut);
TaskImpl task = createUnitTestTask("1", "dumma-task", "1"); TaskImpl task = createUnitTestTask("1", "dumma-task", "1");
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any()); doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
try { try {
cut.createTask(task); cutSpy.createTask(task);
} catch (WorkbasketNotFoundException e) { } catch (WorkbasketNotFoundException e) {
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(cutSpy, times(1)).getTaskById(task.getId());
verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId()); verify(workbasketServiceMock, times(1)).getWorkbasket(task.getWorkbasketId());
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,

View File

@ -1,12 +1,15 @@
package pro.taskana.impl.integration; package pro.taskana.impl.integration;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -17,6 +20,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import pro.taskana.Classification; import pro.taskana.Classification;
import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationQuery;
@ -31,6 +35,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ClassificationQueryImpl; import pro.taskana.impl.ClassificationQueryImpl;
@ -41,14 +46,21 @@ import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.WorkbasketImpl; import pro.taskana.impl.WorkbasketImpl;
import pro.taskana.impl.configuration.DBCleaner; import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest; import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.impl.util.IdGenerator;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.TaskState; import pro.taskana.model.TaskState;
import pro.taskana.model.TaskSummary; import pro.taskana.model.TaskSummary;
import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.security.CurrentUserContext;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
/** /**
* Integration Test for TaskServiceImpl transactions with connection management mode AUTOCOMMIT. * Integration Test for TaskServiceImpl transactions with connection management mode AUTOCOMMIT.
* *
* @author EH * @author EH
*/ */
@RunWith(JAASRunner.class)
public class TaskServiceImplIntAutocommitTest { public class TaskServiceImplIntAutocommitTest {
private DataSource dataSource; private DataSource dataSource;
@ -90,7 +102,7 @@ public class TaskServiceImplIntAutocommitTest {
@Test @Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException,
ClassificationAlreadyExistException { ClassificationAlreadyExistException, TaskAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket(); Workbasket wb = workbasketService.newWorkbasket();
wb.setName("workbasket"); wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb); taskanaEngine.getWorkbasketService().createWorkbasket(wb);
@ -115,7 +127,8 @@ public class TaskServiceImplIntAutocommitTest {
@Test(expected = TaskNotFoundException.class) @Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket(); Workbasket wb = workbasketService.newWorkbasket();
wb.setName("sdf"); wb.setName("sdf");
taskanaEngine.getWorkbasketService().createWorkbasket(wb); taskanaEngine.getWorkbasketService().createWorkbasket(wb);
@ -138,7 +151,8 @@ public class TaskServiceImplIntAutocommitTest {
@Test @Test
public void testCreateTaskInTaskanaWithDefaultDb() public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket(); Workbasket wb = workbasketService.newWorkbasket();
wb.setName("workbasket"); wb.setName("workbasket");
wb = taskanaEngine.getWorkbasketService().createWorkbasket(wb); wb = taskanaEngine.getWorkbasketService().createWorkbasket(wb);
@ -158,7 +172,8 @@ public class TaskServiceImplIntAutocommitTest {
@Test @Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Workbasket wb = workbasketService.newWorkbasket(); Workbasket wb = workbasketService.newWorkbasket();
wb.setName("workbasket"); wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb); taskanaEngine.getWorkbasketService().createWorkbasket(wb);
@ -206,7 +221,6 @@ public class TaskServiceImplIntAutocommitTest {
@Test @Test
public void shouldReturnTaskSummaryListWithValues() throws Exception { public void shouldReturnTaskSummaryListWithValues() throws Exception {
Workbasket dummyWorkbasket = workbasketService.newWorkbasket(); Workbasket dummyWorkbasket = workbasketService.newWorkbasket();
dummyWorkbasket.setName("Dummy-Basket"); dummyWorkbasket.setName("Dummy-Basket");
dummyWorkbasket = workbasketService.createWorkbasket(dummyWorkbasket); dummyWorkbasket = workbasketService.createWorkbasket(dummyWorkbasket);
@ -254,6 +268,163 @@ public class TaskServiceImplIntAutocommitTest {
taskServiceImpl.getTaskSummariesByWorkbasketId(wb.getId()); taskServiceImpl.getTaskSummariesByWorkbasketId(wb.getId());
} }
@Test
public void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException {
Workbasket sourceWB;
Workbasket destinationWB;
WorkbasketImpl wb;
ClassificationImpl classification;
TaskImpl task;
Task resultTask;
final int sleepTime = 100;
// Source Workbasket
wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setName("Basic-Workbasket");
wb.setDescription("Just used as base WB for Task here");
wb.setOwner("The Tester ID");
sourceWB = workbasketService.createWorkbasket(wb);
// Destination Workbasket
wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setName("Desination-WorkBasket");
wb.setDescription("Destination WB where Task should be transfered to");
wb.setOwner("The Tester ID");
destinationWB = workbasketService.createWorkbasket(wb);
// Classification required for Task
classification = (ClassificationImpl) classificationService.newClassification();
classification.setCategory("Test Classification");
classification.setDomain("test-domain");
classification.setName("Transfert-Task Classification");
classification.setKey("KEY");
classificationService.createClassification(classification);
// Task which should be transfered
task = (TaskImpl) taskServiceImpl.newTask();
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setWorkbasketId(sourceWB.getId());
task.setRead(true);
task.setTransferred(false);
task.setModified(null);
task.setClassification(classification);
task = (TaskImpl) taskServiceImpl.createTask(task);
Thread.sleep(sleepTime); // Sleep for modification-timestamp
resultTask = taskServiceImpl.transfer(task.getId(), destinationWB.getId());
assertThat(resultTask.isRead(), equalTo(false));
assertThat(resultTask.isTransferred(), equalTo(true));
assertThat(resultTask.getWorkbasketId(), equalTo(destinationWB.getId()));
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()));
}
@Test(expected = TaskNotFoundException.class)
public void shouldNotTransferAnyTask()
throws WorkbasketNotFoundException, NotAuthorizedException, TaskNotFoundException {
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1");
}
@WithAccessId(userName = "User")
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException {
final String user = CurrentUserContext.getUserid();
// Set up Security for this Test
dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, true);
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
classificationService = taskanaEngine.getClassificationService();
workbasketService = taskanaEngine.getWorkbasketService();
ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification();
classification.setCategory("Test Classification");
classification.setDomain("test-domain");
classification.setName("Transfert-Task Classification");
classification.setKey("KEY");
classificationService.createClassification(classification);
WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setName("BASE WB");
wb.setDescription("Normal base WB");
wb.setOwner(user);
wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket();
wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
wbNoAppend.setOwner(user);
wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket();
wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
wbNoTransfer.setOwner(user);
wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
TaskImpl task = (TaskImpl) taskServiceImpl.newTask();
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setWorkbasketId(wb.getId());
task.setOwner(user);
task.setClassification(classification);
task = (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.getWorkbasketId(), not(equalTo(wbNoAppend.getId())));
assertThat(task.getWorkbasketId(), equalTo(wb.getId()));
}
// Check failing with missing TRANSFER
task.setId(UUID.randomUUID().toString());
task.setWorkbasketId(wbNoTransfer.getId());
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.getWorkbasketId(), not(equalTo(wbNoAppend.getId())));
}
}
private void createWorkbasketWithSecurity(Workbasket wb, String accessId, boolean permOpen,
boolean permRead, boolean permAppend, boolean permTransfer) {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketId(wb.getId());
accessItem.setAccessId(accessId);
accessItem.setPermOpen(permOpen);
accessItem.setPermRead(permRead);
accessItem.setPermAppend(permAppend);
accessItem.setPermTransfer(permTransfer);
workbasketService.createWorkbasketAuthorization(accessItem);
}
@AfterClass @AfterClass
public static void cleanUpClass() { public static void cleanUpClass() {
FileUtils.deleteRecursive("~/data", true); FileUtils.deleteRecursive("~/data", true);

View File

@ -1,11 +1,17 @@
package pro.taskana.impl.integration; 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.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -32,11 +38,13 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationAlreadyExistException; import pro.taskana.exceptions.ClassificationAlreadyExistException;
import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.impl.ClassificationQueryImpl; import pro.taskana.impl.ClassificationQueryImpl;
import pro.taskana.impl.ClassificationServiceImpl; import pro.taskana.impl.ClassificationServiceImpl;
import pro.taskana.impl.ObjectReferenceQueryImpl; import pro.taskana.impl.ObjectReferenceQueryImpl;
import pro.taskana.impl.TaskImpl;
import pro.taskana.impl.TaskServiceImpl; import pro.taskana.impl.TaskServiceImpl;
import pro.taskana.impl.TaskanaEngineImpl; import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.WorkbasketImpl; import pro.taskana.impl.WorkbasketImpl;
@ -48,23 +56,31 @@ import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.ObjectReference; import pro.taskana.model.ObjectReference;
import pro.taskana.model.TaskState; import pro.taskana.model.TaskState;
import pro.taskana.model.WorkbasketAccessItem; import pro.taskana.model.WorkbasketAccessItem;
import pro.taskana.security.CurrentUserContext;
import pro.taskana.security.JAASRunner; import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId; import pro.taskana.security.WithAccessId;
/** /**
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT. * Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
*
* @author EH * @author EH
*/ */
@RunWith(JAASRunner.class) @RunWith(JAASRunner.class)
public class TaskServiceImplIntExplicitTest { public class TaskServiceImplIntExplicitTest {
private DataSource dataSource; private DataSource dataSource;
private TaskServiceImpl taskServiceImpl; private TaskServiceImpl taskServiceImpl;
private TaskanaEngineConfiguration taskanaEngineConfiguration; private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine; private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl; private TaskanaEngineImpl taskanaEngineImpl;
private ClassificationService classificationService; private ClassificationService classificationService;
private WorkbasketService workBasketService;
private WorkbasketService workbasketService;
@BeforeClass @BeforeClass
public static void resetDb() throws SQLException { public static void resetDb() throws SQLException {
@ -82,7 +98,7 @@ public class TaskServiceImplIntExplicitTest {
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine; taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
classificationService = taskanaEngine.getClassificationService(); classificationService = taskanaEngine.getClassificationService();
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT); taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
workBasketService = taskanaEngine.getWorkbasketService(); workbasketService = taskanaEngine.getWorkbasketService();
DBCleaner cleaner = new DBCleaner(); DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource, false); cleaner.clearDb(dataSource, false);
} }
@ -90,13 +106,15 @@ public class TaskServiceImplIntExplicitTest {
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@Test(expected = TaskNotFoundException.class) @Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
generateSampleAccessItems(); generateSampleAccessItems();
WorkbasketImpl workbasket = (WorkbasketImpl) workBasketService.newWorkbasket(); WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket();
workbasket.setName("workbasket"); workbasket.setName("workbasket");
workbasket.setId("1"); // set id manually for authorization tests workbasket.setId("1"); // set id manually for authorization tests
Classification classification = classificationService.newClassification(); Classification classification = classificationService.newClassification();
@ -120,7 +138,10 @@ public class TaskServiceImplIntExplicitTest {
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@Test @Test
public void testCreateTask() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { public void testCreateTask()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
@ -140,22 +161,24 @@ public class TaskServiceImplIntExplicitTest {
@Test @Test
public void testCreateTaskInTaskanaWithDefaultDb() public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource(); DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false); TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine(); TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
Connection connection = ds.getConnection(); Connection connection = ds.getConnection();
te.setConnection(connection); te.setConnection(connection);
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService(); TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
WorkbasketServiceImpl workbasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService(); WorkbasketServiceImpl workBasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService();
ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService(); ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
Workbasket workbasket = workBasketService.newWorkbasket(); Workbasket workbasket = workbasketService.newWorkbasket();
workbasket.setName("workbasket"); workbasket.setName("workbasket");
Classification classification = classificationService.newClassification(); Classification classification = classificationService.newClassification();
classification.setKey("TEST"); classification.setKey("TEST");
workbasket.setName("workbasket99"); workbasket.setName("workbasket99");
workbasketServiceImpl.createWorkbasket(workbasket); workBasketServiceImpl.createWorkbasket(workbasket);
classificationServiceImpl.createClassification(classification); classificationServiceImpl.createClassification(classification);
Task task = taskServiceImpl.newTask(); Task task = taskServiceImpl.newTask();
@ -172,7 +195,9 @@ public class TaskServiceImplIntExplicitTest {
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@Test @Test
public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
@ -221,7 +246,9 @@ public class TaskServiceImplIntExplicitTest {
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@Test(expected = WorkbasketNotFoundException.class) @Test(expected = WorkbasketNotFoundException.class)
public void createTaskShouldThrowWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException, ClassificationAlreadyExistException { public void createTaskShouldThrowWorkbasketNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
@ -234,7 +261,9 @@ public class TaskServiceImplIntExplicitTest {
@WithAccessId(userName = "Elena") @WithAccessId(userName = "Elena")
@Test(expected = ClassificationNotFoundException.class) @Test(expected = ClassificationNotFoundException.class)
public void createManualTaskShouldThrowClassificationNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException, ClassificationAlreadyExistException { public void createManualTaskShouldThrowClassificationNotFoundException()
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException,
ClassificationAlreadyExistException, TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
@ -245,15 +274,17 @@ public class TaskServiceImplIntExplicitTest {
taskServiceImpl.createTask(test); taskServiceImpl.createTask(test);
} }
@WithAccessId(userName = "Elena", groupNames = {"DummyGroup"}) @WithAccessId(userName = "Elena", groupNames = { "DummyGroup" })
@Test @Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException { public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException,
WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException,
TaskAlreadyExistException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
generateSampleAccessItems(); generateSampleAccessItems();
WorkbasketImpl workbasket = (WorkbasketImpl) workBasketService.newWorkbasket(); WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket();
workbasket.setName("workbasket"); workbasket.setName("workbasket");
Classification classification = classificationService.newClassification(); Classification classification = classificationService.newClassification();
classification.setKey("TEST"); classification.setKey("TEST");
@ -269,24 +300,196 @@ public class TaskServiceImplIntExplicitTest {
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine; TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl) ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl)
.parentClassificationKey("pId1", "pId2").category("cat1", "cat2").type("oneType").name("1Name", "name2") .parentClassificationKey("pId1", "pId2")
.descriptionLike("my desc").priority(1, 2, 1).serviceLevel("me", "and", "you"); .category("cat1", "cat2")
.type("oneType")
.name("1Name", "name2")
.descriptionLike("my desc")
.priority(1, 2, 1)
.serviceLevel("me", "and", "you");
ObjectReferenceQuery objectReferenceQuery = new ObjectReferenceQueryImpl(taskanaEngineImpl) ObjectReferenceQuery objectReferenceQuery = new ObjectReferenceQueryImpl(taskanaEngineImpl)
.company("first comp", "sonstwo gmbh").system("sys").type("type1", "type2") .company("first comp", "sonstwo gmbh")
.systemInstance("sysInst1", "sysInst2").value("val1", "val2", "val3"); .system("sys")
.type("type1", "type2")
.systemInstance("sysInst1", "sysInst2")
.value("val1", "val2", "val3");
List<Task> results = taskServiceImpl.createTaskQuery().name("bla", "test").descriptionLike("test") List<Task> results = taskServiceImpl.createTaskQuery()
.priority(1, 2, 2).state(TaskState.CLAIMED).workbasketId("1", "2") .name("bla", "test")
.owner("test", "test2", "bla").customFields("test").classification(classificationQuery) .descriptionLike("test")
.objectReference(objectReferenceQuery).list(); .priority(1, 2, 2)
.state(TaskState.CLAIMED)
.workbasketId("1", "2")
.owner("test", "test2", "bla")
.customFields("test")
.classification(classificationQuery)
.objectReference(objectReferenceQuery)
.list();
Assert.assertEquals(0, results.size()); Assert.assertEquals(0, results.size());
connection.commit(); connection.commit();
} }
@WithAccessId(userName = "Elena")
@Test
public void shouldTransferTaskToOtherWorkbasket()
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
ClassificationAlreadyExistException, TaskNotFoundException, InterruptedException, TaskAlreadyExistException,
SQLException {
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();
wb.setName("Basic-Workbasket");
wb.setDescription("Just used as base WB for Task here");
wb.setOwner(user);
sourceWB = workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), false, false, false, false);
createWorkbasketWithSecurity(sourceWB, sourceWB.getOwner(), false, false, true, true);
// Destination Workbasket
wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setName("Desination-WorkBasket");
wb.setDescription("Destination WB where Task should be transfered to");
wb.setOwner(user);
destinationWB = workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(destinationWB, destinationWB.getOwner(), false, false, true, true);
// Classification required for Task
classification = (ClassificationImpl) classificationService.newClassification();
classification.setCategory("Test Classification");
classification.setDomain("test-domain");
classification.setName("Transfert-Task Classification");
classification.setKey("KEY");
classificationService.createClassification(classification);
// Task which should be transfered
task = (TaskImpl) taskServiceImpl.newTask();
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setWorkbasketId(sourceWB.getId());
task.setRead(true);
task.setTransferred(false);
task.setModified(null);
task.setClassification(classification);
task.setOwner(user);
task = (TaskImpl) taskServiceImpl.createTask(task);
Thread.sleep(sleepTime); // Sleep for modification-timestamp
connection.commit();
resultTask = taskServiceImpl.transfer(task.getId(), destinationWB.getId());
connection.commit();
assertThat(resultTask.isRead(), equalTo(false));
assertThat(resultTask.isTransferred(), equalTo(true));
assertThat(resultTask.getWorkbasketId(), equalTo(destinationWB.getId()));
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()));
}
@Test(expected = TaskNotFoundException.class)
public void shouldNotTransferAnyTask()
throws WorkbasketNotFoundException, NotAuthorizedException, TaskNotFoundException, SQLException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
taskServiceImpl.transfer(UUID.randomUUID() + "_X", "1");
}
@WithAccessId(userName = "User")
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException,
ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException,
TaskNotFoundException, TaskAlreadyExistException {
final String user = "User";
// Set up Security for this Test
dataSource = TaskanaEngineConfigurationTest.getDataSource();
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, true);
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
classificationService = taskanaEngine.getClassificationService();
workbasketService = taskanaEngine.getWorkbasketService();
ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification();
classification.setCategory("Test Classification");
classification.setDomain("test-domain");
classification.setName("Transfert-Task Classification");
classification.setKey("KEY");
classificationService.createClassification(classification);
WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket();
wb.setName("BASE WB");
wb.setDescription("Normal base WB");
wb.setOwner(user);
wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket();
wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
wbNoAppend.setOwner(user);
wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket();
wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
wbNoTransfer.setOwner(user);
wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
TaskImpl task = (TaskImpl) taskServiceImpl.newTask();
task.setName("Task Name");
task.setDescription("Task used for transfer Test");
task.setWorkbasketId(wb.getId());
task.setOwner(user);
task.setClassification(classification);
task = (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.getWorkbasketId(), not(equalTo(wbNoAppend.getId())));
assertThat(task.getWorkbasketId(), equalTo(wb.getId()));
}
// Check failing with missing TRANSFER
task.setId(UUID.randomUUID().toString());
task.setWorkbasketId(wbNoTransfer.getId());
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.getWorkbasketId(), not(equalTo(wbNoAppend.getId())));
}
}
private Task generateDummyTask() throws ClassificationAlreadyExistException { private Task generateDummyTask() throws ClassificationAlreadyExistException {
WorkbasketImpl workbasket = (WorkbasketImpl) workBasketService.newWorkbasket(); WorkbasketImpl workbasket = (WorkbasketImpl) workbasketService.newWorkbasket();
workbasket.setName("wb"); workbasket.setName("wb");
workbasket.setId("1"); // set id manually for authorization tests workbasket.setId("1"); // set id manually for authorization tests
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket); taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
@ -308,14 +511,27 @@ public class TaskServiceImplIntExplicitTest {
accessItem.setAccessId("Elena"); accessItem.setAccessId("Elena");
accessItem.setPermAppend(true); accessItem.setPermAppend(true);
accessItem.setPermOpen(true); accessItem.setPermOpen(true);
workBasketService.createWorkbasketAuthorization(accessItem); workbasketService.createWorkbasketAuthorization(accessItem);
WorkbasketAccessItem accessItem2 = new WorkbasketAccessItem(); WorkbasketAccessItem accessItem2 = new WorkbasketAccessItem();
accessItem2.setId(IdGenerator.generateWithPrefix("WAI")); accessItem2.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem2.setWorkbasketId("2"); accessItem2.setWorkbasketId("2");
accessItem2.setAccessId("DummyGroup"); accessItem2.setAccessId("DummyGroup");
accessItem2.setPermOpen(true); accessItem2.setPermOpen(true);
workBasketService.createWorkbasketAuthorization(accessItem2); workbasketService.createWorkbasketAuthorization(accessItem2);
}
private void createWorkbasketWithSecurity(Workbasket wb, String accessId, boolean permOpen,
boolean permRead, boolean permAppend, boolean permTransfer) {
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
accessItem.setId(IdGenerator.generateWithPrefix("WAI"));
accessItem.setWorkbasketId(wb.getId());
accessItem.setAccessId(accessId);
accessItem.setPermOpen(permOpen);
accessItem.setPermRead(permRead);
accessItem.setPermAppend(permAppend);
accessItem.setPermTransfer(permTransfer);
workbasketService.createWorkbasketAuthorization(accessItem);
} }
@After @After

View File

@ -10,6 +10,7 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.InvalidOwnerException; import pro.taskana.exceptions.InvalidOwnerException;
import pro.taskana.exceptions.InvalidStateException; import pro.taskana.exceptions.InvalidStateException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.TaskNotFoundException; import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
@ -17,22 +18,23 @@ import pro.taskana.exceptions.WorkbasketNotFoundException;
@Transactional @Transactional
public class ExampleBootstrap { public class ExampleBootstrap {
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
@PostConstruct @PostConstruct
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, InvalidStateException, InvalidOwnerException { public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException,
System.out.println("---------------------------> Start App"); ClassificationNotFoundException, InvalidStateException, InvalidOwnerException, TaskAlreadyExistException {
Task task = taskService.newTask(); System.out.println("---------------------------> Start App");
task.setName("Spring example task"); Task task = taskService.newTask();
task.setWorkbasketId("1"); task.setName("Spring example task");
task = taskService.createTask(task); task.setWorkbasketId("1");
System.out.println("---------------------------> Task started: " + task.getId()); task = taskService.createTask(task);
taskService.claim(task.getId()); System.out.println("---------------------------> Task started: " + task.getId());
System.out.println( taskService.claim(task.getId());
"---------------------------> Task claimed: " + taskService.getTaskById(task.getId()).getOwner()); System.out.println(
taskService.completeTask(task.getId(), true); "---------------------------> Task claimed: " + taskService.getTaskById(task.getId()).getOwner());
System.out.println("---------------------------> Task completed"); taskService.completeTask(task.getId(), true);
} System.out.println("---------------------------> Task completed");
}
} }

View File

@ -6,24 +6,26 @@ import org.springframework.transaction.annotation.Transactional;
import pro.taskana.exceptions.ClassificationNotFoundException; import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskAlreadyExistException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
@Component @Component
@Transactional @Transactional
public class TaskanaComponent { public class TaskanaComponent {
@Autowired @Autowired
TaskService taskService; TaskService taskService;
public TaskService getTaskService() { public TaskService getTaskService() {
return taskService; return taskService;
} }
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException,
Task task = taskService.newTask(); ClassificationNotFoundException, TaskAlreadyExistException {
task.setName("Unit Test Task"); Task task = taskService.newTask();
task.setWorkbasketId("1"); task.setName("Unit Test Task");
task = taskService.createTask(task); task.setWorkbasketId("1");
throw new RuntimeException(); task = taskService.createTask(task);
} throw new RuntimeException();
}
} }