TSK-21: Conflicts resolved (merge)
This commit is contained in:
commit
f166b648ce
|
@ -8,6 +8,7 @@ import javax.enterprise.event.Observes;
|
||||||
|
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
|
@ -17,7 +18,7 @@ public class ExampleBootstrap {
|
||||||
private TaskanaEjb taskanaEjb;
|
private TaskanaEjb taskanaEjb;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException {
|
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
System.out.println("---------------------------> Start App");
|
System.out.println("---------------------------> Start App");
|
||||||
Task task = taskanaEjb.getTaskService().create(new Task());
|
Task task = taskanaEjb.getTaskService().create(new Task());
|
||||||
System.out.println("---------------------------> Task started: " + task.getId());
|
System.out.println("---------------------------> Task started: " + task.getId());
|
||||||
|
|
|
@ -4,6 +4,7 @@ import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
|
@ -16,7 +17,7 @@ public class TaskanaEjb {
|
||||||
return taskService;
|
return taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void triggerRollback() throws NotAuthorizedException {
|
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Task t = taskService.create(new Task());
|
Task t = taskService.create(new Task());
|
||||||
System.out.println("---------------->" + t.getId());
|
System.out.println("---------------->" + t.getId());
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
|
|
||||||
@Path("/test")
|
@Path("/test")
|
||||||
|
@ -23,14 +24,14 @@ public class TaskanaRestTest {
|
||||||
private TaskanaEjb taskanaEjb;
|
private TaskanaEjb taskanaEjb;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public Response startTask() throws NotAuthorizedException {
|
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Task result = taskanaEjb.getTaskService().create(new Task());
|
Task result = taskanaEjb.getTaskService().create(new Task());
|
||||||
logger.info(result.getId() + ":" + result.getOwner());
|
logger.info(result.getId() + ":" + result.getOwner());
|
||||||
return Response.status(200).entity(result.getId()).build();
|
return Response.status(200).entity(result.getId()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public Response rollbackTask() throws NotAuthorizedException {
|
public Response rollbackTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
taskanaEjb.triggerRollback();
|
taskanaEjb.triggerRollback();
|
||||||
return Response.status(204).build();
|
return Response.status(204).build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,19 @@ public interface TaskService {
|
||||||
* task id
|
* task id
|
||||||
* @param userName
|
* @param userName
|
||||||
* user who claims the task
|
* user who claims the task
|
||||||
|
* @return modified claimed Task
|
||||||
* @throws TaskNotFoundException
|
* @throws TaskNotFoundException
|
||||||
*/
|
*/
|
||||||
void claim(String id, String userName) throws TaskNotFoundException;
|
Task claim(String id, String userName) throws TaskNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set task to completed.
|
* Set task to completed.
|
||||||
* @param taskId
|
* @param taskId
|
||||||
* the task id
|
* the task id
|
||||||
|
* @return changed Task after update.
|
||||||
* @throws TaskNotFoundException
|
* @throws TaskNotFoundException
|
||||||
*/
|
*/
|
||||||
void complete(String taskId) throws TaskNotFoundException;
|
Task complete(String taskId) throws TaskNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a task by a task object.
|
* Create a task by a task object.
|
||||||
|
@ -39,7 +41,7 @@ public interface TaskService {
|
||||||
* @return the created task
|
* @return the created task
|
||||||
* @throws NotAuthorizedException
|
* @throws NotAuthorizedException
|
||||||
*/
|
*/
|
||||||
Task create(Task task) throws NotAuthorizedException;
|
Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the details of a task.
|
* Get the details of a task.
|
||||||
|
|
|
@ -51,10 +51,11 @@ public class TaskServiceImpl implements TaskService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void claim(String id, String userName) throws TaskNotFoundException {
|
public Task claim(String id, String userName) throws TaskNotFoundException {
|
||||||
|
Task task = null;
|
||||||
try {
|
try {
|
||||||
taskanaEngineImpl.openConnection();
|
taskanaEngineImpl.openConnection();
|
||||||
Task task = taskMapper.findById(id);
|
task = taskMapper.findById(id);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setOwner(userName);
|
task.setOwner(userName);
|
||||||
|
@ -69,13 +70,15 @@ public class TaskServiceImpl implements TaskService {
|
||||||
} finally {
|
} finally {
|
||||||
taskanaEngineImpl.returnConnection();
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(String id) throws TaskNotFoundException {
|
public Task complete(String id) throws TaskNotFoundException {
|
||||||
|
Task task = null;
|
||||||
try {
|
try {
|
||||||
taskanaEngineImpl.openConnection();
|
taskanaEngineImpl.openConnection();
|
||||||
Task task = taskMapper.findById(id);
|
task = taskMapper.findById(id);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setCompleted(now);
|
task.setCompleted(now);
|
||||||
|
@ -89,10 +92,11 @@ public class TaskServiceImpl implements TaskService {
|
||||||
} finally {
|
} finally {
|
||||||
taskanaEngineImpl.returnConnection();
|
taskanaEngineImpl.returnConnection();
|
||||||
}
|
}
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task create(Task task) throws NotAuthorizedException {
|
public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
try {
|
try {
|
||||||
taskanaEngineImpl.openConnection();
|
taskanaEngineImpl.openConnection();
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||||
|
|
|
@ -1,11 +1,24 @@
|
||||||
package pro.taskana.impl;
|
package pro.taskana.impl;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
|
import static org.hamcrest.core.IsNot.not;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -20,10 +33,13 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
|
import pro.taskana.model.DueWorkbasketCounter;
|
||||||
import pro.taskana.model.ObjectReference;
|
import pro.taskana.model.ObjectReference;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
import pro.taskana.model.TaskState;
|
import pro.taskana.model.TaskState;
|
||||||
|
import pro.taskana.model.TaskStateCounter;
|
||||||
import pro.taskana.model.Workbasket;
|
import pro.taskana.model.Workbasket;
|
||||||
|
import pro.taskana.model.WorkbasketAuthorization;
|
||||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||||
import pro.taskana.model.mappings.TaskMapper;
|
import pro.taskana.model.mappings.TaskMapper;
|
||||||
|
|
||||||
|
@ -35,29 +51,35 @@ import pro.taskana.model.mappings.TaskMapper;
|
||||||
public class TaskServiceImplTest {
|
public class TaskServiceImplTest {
|
||||||
|
|
||||||
private static final int SLEEP_TIME = 100;
|
private static final int SLEEP_TIME = 100;
|
||||||
@Mock
|
|
||||||
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
TaskServiceImpl taskServiceImpl;
|
private TaskServiceImpl cut;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngineImpl taskanaEngine;
|
private TaskanaEngineConfiguration taskanaEngineConfigurationMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TaskanaEngineImpl taskanaEngineImpl;
|
private TaskanaEngineImpl taskanaEngineMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TaskMapper taskMapper;
|
private TaskanaEngineImpl taskanaEngineImpl;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
ObjectReferenceMapper objectReferenceMapper;
|
private TaskMapper taskMapperMock;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
WorkbasketService workbasketService;
|
private ObjectReferenceMapper objectReferenceMapperMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private WorkbasketService workbasketServiceMock;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
Mockito.when(taskanaEngine.getWorkbasketService()).thenReturn(workbasketService);
|
doReturn(workbasketServiceMock).when(taskanaEngineMock).getWorkbasketService();
|
||||||
try {
|
try {
|
||||||
Mockito.doNothing().when(workbasketService).checkAuthorization(any(), any());
|
Mockito.doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||||
} catch (NotAuthorizedException e) {
|
} catch (NotAuthorizedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -66,144 +88,482 @@ public class TaskServiceImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateSimpleTask() throws NotAuthorizedException {
|
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Mockito.doNothing().when(taskMapper).insert(any());
|
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||||
Task task = new Task();
|
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||||
task.setName("Unit Test Task");
|
|
||||||
task.setWorkbasketId("1");
|
Task actualTask = cut.create(expectedTask);
|
||||||
task.setBusinessProcessId("BPI1");
|
|
||||||
task.setParentBusinessProcessId("PBPI1");
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
task = taskServiceImpl.create(task);
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
Assert.assertNull(task.getOwner());
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
Assert.assertNotNull(task.getCreated());
|
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||||
Assert.assertNotNull(task.getModified());
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
Assert.assertNull(task.getCompleted());
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
Assert.assertEquals(task.getWorkbasketId(), "1");
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
Assert.assertEquals(task.getBusinessProcessId(), "BPI1");
|
assertNull(actualTask.getOwner());
|
||||||
Assert.assertEquals(task.getParentBusinessProcessId(), "PBPI1");
|
assertNotNull(actualTask.getCreated());
|
||||||
Assert.assertEquals(task.getState(), TaskState.READY);
|
assertNotNull(actualTask.getModified());
|
||||||
|
assertNull(actualTask.getCompleted());
|
||||||
|
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||||
|
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||||
|
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClaim() throws Exception {
|
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
ObjectReference expectedObjectReference = new ObjectReference();
|
||||||
|
expectedObjectReference.setId("1");
|
||||||
|
expectedObjectReference.setType("DUMMY");
|
||||||
|
|
||||||
|
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||||
|
expectedTask.setPrimaryObjRef(new ObjectReference());
|
||||||
|
|
||||||
|
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||||
|
Mockito.doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(any());
|
||||||
|
|
||||||
|
Task actualTask = cut.create(expectedTask);
|
||||||
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
|
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
|
||||||
|
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
|
assertNull(actualTask.getOwner());
|
||||||
|
assertNotNull(actualTask.getCreated());
|
||||||
|
assertNotNull(actualTask.getModified());
|
||||||
|
assertNull(actualTask.getCompleted());
|
||||||
|
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||||
|
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||||
|
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||||
|
assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
|
ObjectReference expectedObjectReference = new ObjectReference();
|
||||||
|
expectedObjectReference.setId("1");
|
||||||
|
expectedObjectReference.setType("DUMMY");
|
||||||
|
|
||||||
|
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
|
||||||
|
expectedTask.setPrimaryObjRef(expectedObjectReference);
|
||||||
|
|
||||||
|
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||||
|
Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
|
||||||
|
Mockito.doReturn(null).when(objectReferenceMapperMock).findByObjectReference(any());
|
||||||
|
|
||||||
|
Task actualTask = cut.create(expectedTask);
|
||||||
|
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
|
||||||
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
|
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
|
||||||
|
verify(objectReferenceMapperMock, times(1)).insert(any());
|
||||||
|
verify(taskMapperMock, times(1)).insert(expectedTask);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
|
assertNull(actualTask.getOwner());
|
||||||
|
assertNotNull(actualTask.getCreated());
|
||||||
|
assertNotNull(actualTask.getModified());
|
||||||
|
assertNull(actualTask.getCompleted());
|
||||||
|
assertThat(actualTask.getWorkbasketId(), equalTo(expectedTask.getWorkbasketId()));
|
||||||
|
assertThat(actualTask.getName(), equalTo(expectedTask.getName()));
|
||||||
|
assertThat(actualTask.getState(), equalTo(TaskState.READY));
|
||||||
|
assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NotAuthorizedException.class)
|
||||||
|
public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
|
try {
|
||||||
|
Mockito.doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||||
|
Task task = new Task();
|
||||||
|
task.setWorkbasketId("1");
|
||||||
|
|
||||||
|
cut.create(task);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
|
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
|
try {
|
||||||
|
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||||
|
Task task = new Task();
|
||||||
|
task.setWorkbasketId("1");
|
||||||
|
|
||||||
|
cut.create(task);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClaimSuccessfulToOwner() throws Exception {
|
||||||
|
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||||
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
||||||
taskServiceImpl.claim(task.getId(), "John Does");
|
String expectedOwner = "John Does";
|
||||||
task = taskServiceImpl.getTaskById(task.getId());
|
|
||||||
Assert.assertEquals(task.getState(), TaskState.CLAIMED);
|
Task acturalTask = cut.claim(expectedTask.getId(), expectedOwner);
|
||||||
Assert.assertNotEquals(task.getCreated(), task.getModified());
|
|
||||||
Assert.assertNotNull(task.getClaimed());
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
Assert.assertEquals(task.getOwner(), "John Does");
|
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||||
|
verify(taskMapperMock, times(1)).update(any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
|
assertThat(acturalTask.getState(), equalTo(TaskState.CLAIMED));
|
||||||
|
assertThat(acturalTask.getCreated(), not(equalTo(expectedTask.getModified())));
|
||||||
|
assertThat(acturalTask.getClaimed(), not(equalTo(null)));
|
||||||
|
assertThat(acturalTask.getOwner(), equalTo(expectedOwner));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testClaimFailsWithNonExistingTaskId() throws TaskNotFoundException {
|
public void testClaimThrowinTaskNotFoundException() throws TaskNotFoundException {
|
||||||
taskServiceImpl.claim("test", "John Doe");
|
try {
|
||||||
|
Task expectedTask = null;
|
||||||
|
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(any());
|
||||||
|
|
||||||
|
cut.claim("1", "OWNER");
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).findById(any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComplete() throws Exception {
|
public void testCompleteTask() throws TaskNotFoundException, InterruptedException {
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task expectedTask = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
|
||||||
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
Thread.sleep(SLEEP_TIME); // to have different timestamps
|
||||||
taskServiceImpl.complete(task.getId());
|
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||||
task = taskServiceImpl.getTaskById(task.getId());
|
|
||||||
Assert.assertEquals(task.getState(), TaskState.COMPLETED);
|
Task actualTask = cut.complete(expectedTask.getId());
|
||||||
Assert.assertNotEquals(task.getCreated(), task.getModified());
|
|
||||||
Assert.assertNotNull(task.getCompleted());
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||||
|
verify(taskMapperMock, times(1)).update(any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
|
assertThat(actualTask.getState(), equalTo(TaskState.COMPLETED));
|
||||||
|
assertThat(actualTask.getCreated(), not(equalTo(expectedTask.getModified())));
|
||||||
|
assertThat(actualTask.getCompleted(), not(equalTo(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testCompleteFailsWithNonExistingTaskId() throws TaskNotFoundException {
|
public void testCompleteFailsWithNonExistingTaskId() throws TaskNotFoundException {
|
||||||
taskServiceImpl.complete("test");
|
String invalidTaskId = "";
|
||||||
|
try {
|
||||||
|
cut.complete(invalidTaskId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).findById(invalidTaskId);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransferTaskZuDestinationWorkbasket()
|
public void testTransferTaskToDestinationWorkbasketWithoutSecurity()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
Workbasket workbasket2 = createWorkbasket2();
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
Workbasket destinationWorkbasket = createWorkbasket("2");
|
||||||
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
final int workServiceMockCalls = 3;
|
||||||
|
task.setRead(true);
|
||||||
|
doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
|
||||||
|
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
|
||||||
|
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||||
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
|
doNothing().when(taskMapperMock).update(any());
|
||||||
|
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||||
|
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
|
||||||
Mockito.when(taskanaEngine.getWorkbasketService().getWorkbasket("2")).thenReturn(workbasket2);
|
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
|
||||||
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(workServiceMockCalls)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
verify(taskanaEngineMock, times(1)).getConfiguration();
|
||||||
|
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
|
||||||
|
verify(workbasketServiceMock, times(1)).getWorkbasket(destinationWorkbasket.getId());
|
||||||
|
verify(taskMapperMock, times(1)).update(any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
|
assertThat(actualTask.isRead(), equalTo(false));
|
||||||
|
assertThat(actualTask.isTransferred(), equalTo(true));
|
||||||
|
assertThat(actualTask.getWorkbasketId(), equalTo(destinationWorkbasket.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTransferTaskToDestinationWorkbasketUsingSecurityTrue()
|
||||||
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
Workbasket destinationWorkbasket = createWorkbasket("2");
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
task.setRead(true);
|
task.setRead(true);
|
||||||
|
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
|
||||||
|
doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
|
||||||
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
|
doNothing().when(taskMapperMock).update(any());
|
||||||
|
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||||
|
doNothing().when(workbasketServiceMock).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
|
||||||
// taskanaEngine.getConfiguration().isSecurityEnabled())
|
Task actualTask = cutSpy.transfer(task.getId(), destinationWorkbasket.getId());
|
||||||
Mockito.when(taskanaEngine.getConfiguration()).thenReturn(taskanaEngineConfiguration);
|
|
||||||
Mockito.when(taskanaEngineConfiguration.isSecurityEnabled()).thenReturn(false);
|
|
||||||
|
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
taskServiceImpl.transfer(task.getId(), "2");
|
verify(taskanaEngineMock, times(2)).getWorkbasketService();
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "2");
|
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasket.getId(), WorkbasketAuthorization.APPEND);
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
verify(taskanaEngineMock, times(1)).getConfiguration();
|
||||||
|
verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled();
|
||||||
|
verify(taskMapperMock, times(1)).update(any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
|
||||||
Assert.assertTrue(task.isTransferred());
|
assertThat(actualTask.isRead(), equalTo(false));
|
||||||
Assert.assertFalse(task.isRead());
|
assertThat(actualTask.isTransferred(), equalTo(true));
|
||||||
|
assertThat(actualTask.getWorkbasketId(), equalTo(destinationWorkbasket.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityDisabled()
|
public void testTransferDestinationWorkbasketDoesNotExist()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService)
|
|
||||||
.checkAuthorization(eq("invalidWorkbasketId"), any());
|
|
||||||
|
|
||||||
|
String destinationWorkbasketId = "2";
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
|
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
try {
|
||||||
taskServiceImpl.transfer(task.getId(), "invalidWorkbasketId");
|
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testTransferFailsIfDestinationWorkbasketDoesNotExist_withSecurityEnabled()
|
public void testTransferTaskDoesNotExist()
|
||||||
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketService).checkAuthorization(eq("invalidWorkbasketId"), any());
|
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||||
|
|
||||||
Assert.assertEquals(taskServiceImpl.getTaskById(task.getId()).getWorkbasketId(), "1");
|
try {
|
||||||
taskServiceImpl.transfer(task.getId(), "invalidWorkbasketId");
|
cutSpy.transfer(task.getId(), "2");
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NotAuthorizedException.class)
|
||||||
|
public void testTransferNotAuthorizationOnWorkbasketAppend()
|
||||||
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
|
String destinationWorkbasketId = "2";
|
||||||
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
|
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = NotAuthorizedException.class)
|
||||||
|
public void testTransferNotAuthorizationOnWorkbasketTransfer()
|
||||||
|
throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
|
String destinationWorkbasketId = "2";
|
||||||
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
|
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cutSpy.transfer(task.getId(), destinationWorkbasketId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineMock, times(2)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(destinationWorkbasketId, WorkbasketAuthorization.APPEND);
|
||||||
|
verify(workbasketServiceMock, times(1)).checkAuthorization(task.getId(), WorkbasketAuthorization.TRANSFER);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_setTheReadFlag_when_taskIsRead() throws TaskNotFoundException {
|
public void testGetTaskCountForState() {
|
||||||
createUnitTestTask("1", "Unit Test Task 1", "1");
|
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||||
|
List<TaskStateCounter> expectedResult = new ArrayList<>();
|
||||||
|
doReturn(expectedResult).when(taskMapperMock).getTaskCountForState(taskStates);
|
||||||
|
|
||||||
Task readTask = taskServiceImpl.setTaskRead("1", true);
|
List<TaskStateCounter> actualResult = cut.getTaskCountForState(taskStates);
|
||||||
Assert.assertTrue(readTask.isRead());
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).getTaskCountForState(taskStates);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
assertThat(actualResult, equalTo(expectedResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_InsertObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
public void testGetTaskCountForWorkbasketByDaysInPastAndState() {
|
||||||
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(null);
|
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||||
|
final long daysInPast = 10L;
|
||||||
|
final long expectedResult = 5L;
|
||||||
|
String workbasketId = "1";
|
||||||
|
doReturn(expectedResult).when(taskMapperMock).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
|
||||||
|
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
long actualResult = cut.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, daysInPast, taskStates);
|
||||||
ObjectReference primaryObjRef = new ObjectReference();
|
|
||||||
primaryObjRef.setSystem("Sol");
|
|
||||||
task.setPrimaryObjRef(primaryObjRef);
|
|
||||||
Task createdTask = taskServiceImpl.create(task);
|
|
||||||
|
|
||||||
Assert.assertNotNull(createdTask.getPrimaryObjRef());
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
Assert.assertNotNull(createdTask.getPrimaryObjRef().getId());
|
verify(taskMapperMock, times(1)).getTaskCountForWorkbasketByDaysInPastAndState(any(), any(), any());
|
||||||
Assert.assertEquals("Sol", createdTask.getPrimaryObjRef().getSystem());
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
assertThat(actualResult, equalTo(expectedResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_LinkObjectReference_when_TaskIsCreated() throws NotAuthorizedException {
|
public void testGetTaskCountByWorkbasketAndDaysInPastAndState() {
|
||||||
|
final long daysInPast = 10L;
|
||||||
|
List<TaskState> taskStates = Arrays.asList(TaskState.CLAIMED, TaskState.COMPLETED);
|
||||||
|
List<DueWorkbasketCounter> expectedResult = new ArrayList<>();
|
||||||
|
doReturn(expectedResult).when(taskMapperMock).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
|
||||||
|
|
||||||
|
List<DueWorkbasketCounter> actualResult = cut.getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast, taskStates);
|
||||||
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).getTaskCountByWorkbasketIdAndDaysInPastAndState(any(Date.class), any());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
assertThat(actualResult, equalTo(expectedResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetTaskReadWIthExistingTask() throws TaskNotFoundException {
|
||||||
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
ObjectReference primaryObjRef = new ObjectReference();
|
task.setModified(null);
|
||||||
primaryObjRef.setSystem("Sol");
|
doReturn(task).when(cutSpy).getTaskById(task.getId());
|
||||||
task.setPrimaryObjRef(primaryObjRef);
|
doNothing().when(taskMapperMock).update(task);
|
||||||
|
|
||||||
ObjectReference returnPrimaryObjRef = new ObjectReference();
|
Task actualTask = cutSpy.setTaskRead("1", true);
|
||||||
returnPrimaryObjRef.setId("1");
|
|
||||||
returnPrimaryObjRef.setSystem("Sol");
|
|
||||||
|
|
||||||
Mockito.when(objectReferenceMapper.findByObjectReference(any())).thenReturn(returnPrimaryObjRef);
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
Task createdTask = taskServiceImpl.create(task);
|
verify(taskMapperMock, times(1)).update(task);
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
assertThat(actualTask.getModified(), not(equalTo(null)));
|
||||||
|
assertThat(actualTask.isRead(), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertNotNull(createdTask.getPrimaryObjRef());
|
@Test(expected = TaskNotFoundException.class)
|
||||||
Assert.assertEquals("1", createdTask.getPrimaryObjRef().getId());
|
public void testSetTaskReadTaskNotBeFound() throws TaskNotFoundException {
|
||||||
Assert.assertEquals("Sol", createdTask.getPrimaryObjRef().getSystem());
|
TaskServiceImpl cutSpy = Mockito.spy(cut);
|
||||||
|
Task task = createUnitTestTask("1", "Unit Test Task 1", "1");
|
||||||
|
task.setModified(null);
|
||||||
|
doThrow(TaskNotFoundException.class).when(cutSpy).getTaskById(task.getId());
|
||||||
|
|
||||||
|
try {
|
||||||
|
cutSpy.setTaskRead("1", true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTaskByIdWithExistingTask() throws TaskNotFoundException {
|
||||||
|
Task expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1");
|
||||||
|
doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
|
||||||
|
|
||||||
|
Task actualTask = cut.getTaskById(expectedTask.getId());
|
||||||
|
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).findById(expectedTask.getId());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
assertThat(actualTask, equalTo(expectedTask));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = TaskNotFoundException.class)
|
||||||
|
public void testGetTaskByIdWhereTaskDoesNotExist() throws Exception {
|
||||||
|
Task task = createUnitTestTask("1", "DUMMY-TASK", "1");
|
||||||
|
doThrow(TaskNotFoundException.class).when(taskMapperMock).findById(task.getId());
|
||||||
|
|
||||||
|
try {
|
||||||
|
cut.getTaskById(task.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
|
verify(taskMapperMock, times(1)).findById(task.getId());
|
||||||
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task createUnitTestTask(String id, String name, String workbasketId) {
|
private Task createUnitTestTask(String id, String name, String workbasketId) {
|
||||||
|
@ -214,15 +574,13 @@ public class TaskServiceImplTest {
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
task.setCreated(now);
|
task.setCreated(now);
|
||||||
task.setModified(now);
|
task.setModified(now);
|
||||||
Mockito.when(taskMapper.findById(any())).thenReturn(task);
|
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Workbasket createWorkbasket2() {
|
private Workbasket createWorkbasket(String id) {
|
||||||
Workbasket workbasket2 = new Workbasket();
|
Workbasket workbasket = new Workbasket();
|
||||||
workbasket2.setId("2");
|
workbasket.setId(id);
|
||||||
workbasket2.setName("Workbasket 2");
|
workbasket.setName("Workbasket " + id);
|
||||||
return workbasket2;
|
return workbasket;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.impl.ClassificationQueryImpl;
|
import pro.taskana.impl.ClassificationQueryImpl;
|
||||||
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
||||||
import pro.taskana.impl.TaskServiceImpl;
|
import pro.taskana.impl.TaskServiceImpl;
|
||||||
|
@ -64,7 +65,8 @@ public class TaskServiceImplIntAutocommitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException,
|
||||||
|
WorkbasketNotFoundException, NotAuthorizedException {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
@ -80,7 +82,7 @@ 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 {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
@ -95,7 +97,7 @@ public class TaskServiceImplIntAutocommitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskInTaskanaWithDefaultDb()
|
public void testCreateTaskInTaskanaWithDefaultDb()
|
||||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
|
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
|
||||||
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||||
|
@ -111,7 +113,7 @@ public class TaskServiceImplIntAutocommitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
|
|
@ -23,6 +23,7 @@ import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.impl.ClassificationQueryImpl;
|
import pro.taskana.impl.ClassificationQueryImpl;
|
||||||
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
import pro.taskana.impl.ObjectReferenceQueryImpl;
|
||||||
import pro.taskana.impl.TaskServiceImpl;
|
import pro.taskana.impl.TaskServiceImpl;
|
||||||
|
@ -65,7 +66,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
taskanaEngineImpl.setConnection(connection);
|
taskanaEngineImpl.setConnection(connection);
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
|
@ -84,7 +85,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
|
|
||||||
@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 {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
taskanaEngineImpl.setConnection(connection);
|
taskanaEngineImpl.setConnection(connection);
|
||||||
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||||
|
@ -105,7 +106,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskInTaskanaWithDefaultDb()
|
public void testCreateTaskInTaskanaWithDefaultDb()
|
||||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
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();
|
||||||
|
@ -126,7 +127,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
|
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
taskanaEngineImpl.setConnection(connection);
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -17,7 +18,7 @@ public class ExampleBootstrap {
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void test() throws TaskNotFoundException, NotAuthorizedException {
|
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
System.out.println("---------------------------> Start App");
|
System.out.println("---------------------------> Start App");
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Spring example task");
|
task.setName("Spring example task");
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.model.Task;
|
import pro.taskana.model.Task;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -17,7 +18,7 @@ public class TaskanaComponent {
|
||||||
return taskService;
|
return taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void triggerRollback() throws NotAuthorizedException {
|
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException {
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setName("Unit Test Task");
|
task.setName("Unit Test Task");
|
||||||
task.setWorkbasketId("1");
|
task.setWorkbasketId("1");
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class TaskController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TaskFilter taskLogic;
|
private TaskFilter taskLogic;
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ public class TaskController {
|
||||||
}
|
}
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(taskLogic.inspectPrams(params));
|
return ResponseEntity.status(HttpStatus.OK).body(taskLogic.inspectPrams(params));
|
||||||
} catch (NotAuthorizedException e) {
|
} catch (NotAuthorizedException e) {
|
||||||
|
logger.error("Somthing went wrong whith the Authorisation, while getting all Tasks.", e);
|
||||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +57,7 @@ public class TaskController {
|
||||||
Task task = taskService.getTaskById(taskId);
|
Task task = taskService.getTaskById(taskId);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(task);
|
return ResponseEntity.status(HttpStatus.OK).body(task);
|
||||||
} catch (TaskNotFoundException e) {
|
} catch (TaskNotFoundException e) {
|
||||||
|
logger.error("The searched Task couldn´t be found or does not exist.", e);
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +70,7 @@ public class TaskController {
|
||||||
Task updatedTask = taskService.getTaskById(taskId);
|
Task updatedTask = taskService.getTaskById(taskId);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(updatedTask);
|
return ResponseEntity.status(HttpStatus.OK).body(updatedTask);
|
||||||
} catch (TaskNotFoundException e) {
|
} catch (TaskNotFoundException e) {
|
||||||
|
logger.error("The given Task coundn´t be found/claimd or does not Exist.", e);
|
||||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue