Merge pull request #48 from BVier/master

TSK-64: Refactor createManualTask to createTask
This commit is contained in:
Holger Hagen 2017-12-07 14:26:40 +01:00 committed by GitHub
commit 8572ecc3d1
15 changed files with 337 additions and 293 deletions

View File

@ -1,16 +1,17 @@
package pro.taskana; package pro.taskana;
import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.Task;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized; import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes; import javax.enterprise.event.Observes;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.Task;
@ApplicationScoped @ApplicationScoped
public class ExampleBootstrap { public class ExampleBootstrap {
@ -18,9 +19,9 @@ public class ExampleBootstrap {
private TaskanaEjb taskanaEjb; private TaskanaEjb taskanaEjb;
@PostConstruct @PostConstruct
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { public void init(@Observes @Initialized(ApplicationScoped.class) Object init) throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
System.out.println("---------------------------> Start App"); System.out.println("---------------------------> Start App");
Task task = taskanaEjb.getTaskService().create(new Task()); Task task = taskanaEjb.getTaskService().createTask(new Task());
System.out.println("---------------------------> Task started: " + task.getId()); System.out.println("---------------------------> Task started: " + task.getId());
taskanaEjb.getTaskService().claim(task.getId(), "John Doe"); taskanaEjb.getTaskService().claim(task.getId(), "John Doe");
System.out.println( System.out.println(

View File

@ -1,9 +1,8 @@
package pro.taskana; package pro.taskana;
import java.io.IOException; import org.slf4j.Logger;
import java.io.InputStream; import org.slf4j.LoggerFactory;
import java.sql.SQLException; import pro.taskana.configuration.TaskanaEngineConfiguration;
import java.util.Properties;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
@ -13,10 +12,10 @@ import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.IOException;
import org.slf4j.Logger; import java.io.InputStream;
import org.slf4j.LoggerFactory; import java.sql.SQLException;
import pro.taskana.configuration.TaskanaEngineConfiguration; import java.util.Properties;
@ApplicationScoped @ApplicationScoped
public class TaskanaProducers { public class TaskanaProducers {
@ -61,4 +60,16 @@ public class TaskanaProducers {
return taskanaEngine.getTaskService(); return taskanaEngine.getTaskService();
} }
@ApplicationScoped
@Produces
public ClassificationService generateClassificationService() {
return taskanaEngine.getClassificationService();
}
@ApplicationScoped
@Produces
public WorkbasketService generateWorkbasketService() {
return taskanaEngine.getWorkbasketService();
}
} }

View File

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

View File

@ -1,19 +1,18 @@
package pro.taskana; package pro.taskana;
import javax.ejb.EJB;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pro.taskana.exceptions.ClassificationNotFoundException;
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.Classification;
import pro.taskana.model.Task; import pro.taskana.model.Task;
import pro.taskana.model.Workbasket;
import javax.ejb.EJB;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@Path("/test") @Path("/test")
public class TaskanaRestTest { public class TaskanaRestTest {
@ -24,14 +23,25 @@ public class TaskanaRestTest {
private TaskanaEjb taskanaEjb; private TaskanaEjb taskanaEjb;
@GET @GET
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException { public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Task result = taskanaEjb.getTaskService().create(new Task()); Workbasket workbasket = new Workbasket();
workbasket.setName("wb");
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = new Classification();
taskanaEjb.getClassificationService().addClassification(classification);
Task task = new Task();
task.setClassification(classification);
task.setWorkbasketId(workbasket.getId());
Task result = taskanaEjb.getTaskService().createTask(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, WorkbasketNotFoundException { public Response rollbackTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
taskanaEjb.triggerRollback(); taskanaEjb.triggerRollback();
return Response.status(204).build(); return Response.status(204).build();
} }

View File

@ -4,11 +4,12 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
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.*; import pro.taskana.model.DueWorkbasketCounter;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.TaskStateCounter;
import java.sql.Timestamp;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* The Task Service manages all operations on tasks. * The Task Service manages all operations on tasks.
@ -41,21 +42,8 @@ public interface TaskService {
* @return the created task * @return the created task
* @throws NotAuthorizedException * @throws NotAuthorizedException
*/ */
Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException; Task createTask(Task task) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException;
/**
* Create a task manually by filling the fields.
* @param workbasketId not null
* @param classificationId not null
* @param domain
* @param planned
* @param name
* @param description
* @param primaryObjectReference
* @param customAttributes
* @return
*/
Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name, String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException;
/** /**
* Get the details of a task. * Get the details of a task.
* @param taskId * @param taskId

View File

@ -1,5 +1,7 @@
package pro.taskana.impl; package pro.taskana.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationService; import pro.taskana.ClassificationService;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
@ -16,9 +18,6 @@ import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* This is the implementation of ClassificationService. * This is the implementation of ClassificationService.
*/ */
@ -170,6 +169,9 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override @Override
public Classification getClassification(String id, String domain) throws ClassificationNotFoundException { public Classification getClassification(String id, String domain) throws ClassificationNotFoundException {
if (id == null) {
throw new ClassificationNotFoundException(null);
}
LOGGER.debug("entry to getClassification(id = {}, domain = {})", id, domain); LOGGER.debug("entry to getClassification(id = {}, domain = {})", id, domain);
Classification result = null; Classification result = null;
try { try {

View File

@ -1,17 +1,7 @@
package pro.taskana.impl; package pro.taskana.impl;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import pro.taskana.TaskQuery; import pro.taskana.TaskQuery;
import pro.taskana.TaskService; import pro.taskana.TaskService;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
@ -21,16 +11,18 @@ 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;
import pro.taskana.impl.util.LoggerUtils; import pro.taskana.impl.util.LoggerUtils;
import pro.taskana.model.Classification; import pro.taskana.model.*;
import pro.taskana.model.DueWorkbasketCounter;
import pro.taskana.model.ObjectReference;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.TaskStateCounter;
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;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/** /**
* This is the implementation of TaskService. * This is the implementation of TaskService.
*/ */
@ -109,66 +101,31 @@ public class TaskServiceImpl implements TaskService {
} }
@Override @Override
public Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException { public Task createTask(Task task) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
LOGGER.debug("entry to create(task = {})", task); LOGGER.debug("entry to createTask(task = {})", task);
try { try {
taskanaEngineImpl.openConnection(); taskanaEngineImpl.openConnection();
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND); taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
Classification classification = task.getClassification();
if (classification == null) {
throw new ClassificationNotFoundException(null);
}
taskanaEngine.getClassificationService().getClassification(classification.getId(), "");
standardSettings(task); standardSettings(task);
this.taskMapper.insert(task); this.taskMapper.insert(task);
LOGGER.debug("Method create() created Task '{}'.", task.getId()); LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
return task; return task;
} finally { } finally {
taskanaEngineImpl.returnConnection(); taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from create(task = {})"); LOGGER.debug("exit from createTask(task = {})");
} }
} }
@Override
public Task createManualTask(String workbasketId, String classificationId, String domain, Timestamp planned, String name,
String description, ObjectReference primaryObjectReference, Map<String, Object> customAttributes) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to createManualTask(workbasketId = {}, classificationId = {}, domain = {}, planned = {}, name = {},"
+ " description = {}, primaryObjectReference = {}, customAttributes = {})", workbasketId, classificationId, domain, planned, name,
description, primaryObjectReference, LoggerUtils.mapToString(customAttributes));
}
try {
taskanaEngineImpl.openConnection();
taskanaEngine.getWorkbasketService().checkAuthorization(workbasketId, WorkbasketAuthorization.APPEND);
taskanaEngine.getWorkbasketService().getWorkbasket(workbasketId);
Classification classification = taskanaEngine.getClassificationService().getClassification(classificationId, domain);
if (!TYPE_MANUAL.equals(classification.getCategory())) {
throw new NotAuthorizedException("You're not allowed to add a task manually to a '" + classification.getCategory() + "'- Classification!");
}
Task task = new Task();
task.setWorkbasketId(workbasketId);
task.setClassification(classification);
task.setPlanned(planned);
task.setPrimaryObjRef(primaryObjectReference);
task.setCustomAttributes(customAttributes);
task.setName(name);
task.setDescription(description);
this.standardSettings(task);
this.setCustomAttributes(task);
this.taskMapper.insert(task);
LOGGER.debug("Method create() created Task '{}'.", task.getId());
return task;
} finally {
taskanaEngineImpl.returnConnection();
LOGGER.debug("exit from create()");
}
}
@Override @Override
public Task getTaskById(String id) throws TaskNotFoundException { public Task getTaskById(String id) throws TaskNotFoundException {
LOGGER.debug("entry to getTaskById(id = {})", id); LOGGER.debug("entry to getTaskById(id = {})", id);
@ -382,34 +339,4 @@ public class TaskServiceImpl implements TaskService {
task.setPrimaryObjRef(objectReference); task.setPrimaryObjRef(objectReference);
} }
} }
private void setCustomAttributes(Task task) {
if (task.getCustomAttributes() != null) {
for (String custom : task.getCustomAttributes().keySet()) {
if (task.getCustom1() == null) {
task.setCustom1(custom);
} else if (task.getCustom2() == null) {
task.setCustom2(custom);
} else if (task.getCustom3() == null) {
task.setCustom3(custom);
} else if (task.getCustom4() == null) {
task.setCustom4(custom);
} else if (task.getCustom5() == null) {
task.setCustom5(custom);
} else if (task.getCustom6() == null) {
task.setCustom6(custom);
} else if (task.getCustom7() == null) {
task.setCustom7(custom);
} else if (task.getCustom8() == null) {
task.setCustom8(custom);
} else if (task.getCustom9() == null) {
task.setCustom9(custom);
} else if (task.getCustom10() == null) {
task.setCustom10(custom);
} else {
break;
}
}
}
}
} }

View File

@ -13,6 +13,7 @@ import pro.taskana.model.Classification;
import pro.taskana.model.mappings.ClassificationMapper; import pro.taskana.model.mappings.ClassificationMapper;
import java.sql.Date; import java.sql.Date;
import java.sql.SQLException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -87,6 +88,22 @@ public class ClassificationServiceImplTest {
Assert.assertEquals(classification2.getValidUntil(), classification3.getValidUntil()); Assert.assertEquals(classification2.getValidUntil(), classification3.getValidUntil());
} }
@Test
public void testGetClassification() throws ClassificationNotFoundException, SQLException {
doNothing().when(classificationMapper).insert(any());
doNothing().when(taskanaEngineImpl).openConnection();
doNothing().when(taskanaEngineImpl).returnConnection();
Classification classification = new Classification();
classification.setDomain("domain");
classificationService.addClassification(classification);
doReturn(classification).when(classificationMapper).findByIdAndDomain(any(), any(), any());
Classification test = classificationService.getClassification(classification.getId(), "domain");
Assert.assertEquals("domain", test.getDomain());
}
@Test @Test
public void testFindAllClassifications() throws NotAuthorizedException { public void testFindAllClassifications() throws NotAuthorizedException {
doNothing().when(classificationMapper).insert(any()); doNothing().when(classificationMapper).insert(any());

View File

@ -80,19 +80,25 @@ public class TaskServiceImplTest {
} }
@Test @Test
public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException { public void testCreateSimpleTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Mockito.doNothing().when(taskMapperMock).insert(any()); Mockito.doNothing().when(taskMapperMock).insert(any());
Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1"); Task expectedTask = createUnitTestTask("1", "DUMMYTASK", "1");
Task actualTask = cut.create(expectedTask); Task actualTask = cut.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService(); verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskMapperMock, times(1)).insert(expectedTask); verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verify(classificationServiceMock, times(1)).addClassification(any());
verify(classificationServiceMock, times(1)).getClassification(any(), any());
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
assertNull(actualTask.getOwner()); assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated()); assertNotNull(actualTask.getCreated());
assertNotNull(actualTask.getModified()); assertNotNull(actualTask.getModified());
@ -103,7 +109,7 @@ public class TaskServiceImplTest {
} }
@Test @Test
public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException { public void testCreateSimpleTaskWithObjectReference() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
@ -114,16 +120,22 @@ public class TaskServiceImplTest {
Mockito.doNothing().when(taskMapperMock).insert(any()); Mockito.doNothing().when(taskMapperMock).insert(any());
Mockito.doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(any()); Mockito.doReturn(expectedObjectReference).when(objectReferenceMapperMock).findByObjectReference(any());
Task actualTask = cut.create(expectedTask); Task actualTask = cut.createTask(expectedTask);
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService(); verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any()); verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
verify(taskMapperMock, times(1)).insert(expectedTask); verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verify(classificationServiceMock, times(1)).addClassification(any());
verify(classificationServiceMock, times(1)).getClassification(any(),
any());
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
assertNull(actualTask.getOwner()); assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated()); assertNotNull(actualTask.getCreated());
@ -136,7 +148,7 @@ public class TaskServiceImplTest {
} }
@Test @Test
public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException { public void testCreateSimpleTaskWithObjectReferenceIsNull() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
@ -148,18 +160,23 @@ public class TaskServiceImplTest {
Mockito.doNothing().when(objectReferenceMapperMock).insert(any()); Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
Mockito.doReturn(null).when(objectReferenceMapperMock).findByObjectReference(any()); Mockito.doReturn(null).when(objectReferenceMapperMock).findByObjectReference(any());
Task actualTask = cut.create(expectedTask); Task actualTask = cut.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(taskanaEngineMock, times(1)).getWorkbasketService(); verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(taskanaEngineMock, times(1)).getClassificationService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(classificationServiceMock, times(1)).addClassification(any());
verify(classificationServiceMock, times(1)).getClassification(any(), any());
verify(objectReferenceMapperMock, times(1)).findByObjectReference(any()); verify(objectReferenceMapperMock, times(1)).findByObjectReference(any());
verify(objectReferenceMapperMock, times(1)).insert(any()); verify(objectReferenceMapperMock, times(1)).insert(any());
verify(taskMapperMock, times(1)).insert(expectedTask); verify(taskMapperMock, times(1)).insert(expectedTask);
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
assertNull(actualTask.getOwner()); assertNull(actualTask.getOwner());
assertNotNull(actualTask.getCreated()); assertNotNull(actualTask.getCreated());
@ -172,7 +189,7 @@ public class TaskServiceImplTest {
} }
@Test @Test
public void testCreateManualTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public void testCreateTaskWithPlanned() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
ObjectReference expectedObjectReference = new ObjectReference(); ObjectReference expectedObjectReference = new ObjectReference();
expectedObjectReference.setId("1"); expectedObjectReference.setId("1");
expectedObjectReference.setType("DUMMY"); expectedObjectReference.setType("DUMMY");
@ -185,40 +202,55 @@ public class TaskServiceImplTest {
Mockito.doNothing().when(taskMapperMock).insert(any()); Mockito.doNothing().when(taskMapperMock).insert(any());
Mockito.doNothing().when(objectReferenceMapperMock).insert(any()); Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
Task manualTask = cut.createManualTask("workbasketId", "classification", "domain", null, null, "simply awesome task", expectedObjectReference, null); Task test = new Task();
test.setWorkbasketId("workbasketId");
test.setClassification(classification);
test.setPrimaryObjRef(expectedObjectReference);
test.setDescription("simply awesome task");
Task manualTask2 = cut.createManualTask("workbasketId", "classification", "domain", Timestamp.valueOf(LocalDateTime.now().minusHours(1)), "Task2", "simply awesome task", expectedObjectReference, null); cut.createTask(test);
Task test2 = new Task();
test2.setWorkbasketId("workbasketId");
test2.setClassification(classification);
test2.setPrimaryObjRef(expectedObjectReference);
test2.setPlanned(Timestamp.valueOf(LocalDateTime.now().minusHours(1)));
test2.setName("Task2");
cut.createTask(test2);
verify(taskanaEngineImpl, times(2)).openConnection(); verify(taskanaEngineImpl, times(2)).openConnection();
verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService(); verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService();
verify(taskanaEngineMock, times(2)).getClassificationService(); verify(taskanaEngineMock, times(2)).getClassificationService();
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(classificationServiceMock, times(2)).getClassification(any(), any());
verify(objectReferenceMapperMock, times(2)).findByObjectReference(any()); verify(objectReferenceMapperMock, times(2)).findByObjectReference(any());
verify(objectReferenceMapperMock, times(2)).insert(any()); verify(objectReferenceMapperMock, times(2)).insert(any());
verify(taskMapperMock, times(1)).insert(manualTask); verify(taskMapperMock, times(1)).insert(test);
verify(taskMapperMock, times(1)).insert(manualTask2); verify(taskMapperMock, times(1)).insert(test2);
verify(taskanaEngineImpl, times(2)).returnConnection(); verify(taskanaEngineImpl, times(2)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
assertNull(manualTask.getOwner()); assertNull(test.getOwner());
assertNotNull(manualTask.getCreated()); assertNotNull(test.getCreated());
assertNotNull(manualTask.getModified()); assertNotNull(test.getModified());
assertNull(manualTask.getCompleted()); assertNull(test.getCompleted());
assertNull(manualTask.getDue()); assertNull(test.getDue());
assertThat(manualTask.getWorkbasketId(), equalTo(manualTask2.getWorkbasketId())); assertThat(test.getWorkbasketId(), equalTo(test2.getWorkbasketId()));
assertThat(manualTask.getName(), equalTo(classification.getName())); assertThat(test.getName(), equalTo(classification.getName()));
assertThat(manualTask.getState(), equalTo(TaskState.READY)); assertThat(test.getState(), equalTo(TaskState.READY));
assertThat(manualTask.getPrimaryObjRef(), equalTo(expectedObjectReference)); assertThat(test.getPrimaryObjRef(), equalTo(expectedObjectReference));
assertThat(manualTask.getName(), not(manualTask2.getName())); assertThat(test.getName(), not(test2.getName()));
assertThat(manualTask.getPlanned(), not(manualTask2.getPlanned())); assertThat(test.getPlanned(), not(test2.getPlanned()));
assertThat(manualTask2.getPlanned(), not(manualTask2.getCreated())); assertThat(test2.getPlanned(), not(test2.getCreated()));
} }
@Test(expected = NotAuthorizedException.class) @Test(expected = NotAuthorizedException.class)
public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException { public void testCreateThrowingAuthorizedOnWorkbasket() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
try { try {
Mockito.doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(any(), any()); Mockito.doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
Task task = new Task(); Task task = new Task();
@ -226,33 +258,36 @@ public class TaskServiceImplTest {
task.setBusinessProcessId("BPI1"); task.setBusinessProcessId("BPI1");
task.setParentBusinessProcessId("PBPI1"); task.setParentBusinessProcessId("PBPI1");
cut.create(task); cut.createTask(task);
} catch (Exception e) { } catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService(); verify(taskanaEngineMock, times(2)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
throw e; throw e;
} }
} }
@Test(expected = WorkbasketNotFoundException.class) @Test(expected = WorkbasketNotFoundException.class)
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException { public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
try { try {
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(any(), any()); Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
Task task = new Task(); Task task = new Task();
task.setWorkbasketId("1"); task.setWorkbasketId("1");
cut.create(task); cut.createTask(task);
} catch (Exception e) { } catch (Exception e) {
verify(taskanaEngineImpl, times(1)).openConnection(); verify(taskanaEngineImpl, times(1)).openConnection();
verify(taskanaEngineMock, times(1)).getWorkbasketService(); verify(taskanaEngineMock, times(1)).getWorkbasketService();
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any()); verify(workbasketServiceMock, times(1)).getWorkbasket(any());
verify(taskanaEngineImpl, times(1)).returnConnection(); verify(taskanaEngineImpl, times(1)).returnConnection();
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
classificationServiceMock);
throw e; throw e;
} }
} }
@ -614,6 +649,9 @@ 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);
Classification classification = new Classification();
classificationServiceMock.addClassification(classification);
task.setClassification(classification);
return task; return task;
} }

View File

@ -127,7 +127,7 @@ public class SummaryServiceImplIntAutoCommitTest {
dummyTask.setName("Dummy-Task"); dummyTask.setName("Dummy-Task");
dummyTask.setClassification(dummyClassification); dummyTask.setClassification(dummyClassification);
dummyTask.setWorkbasketId(dummyWorkbasket.getId()); dummyTask.setWorkbasketId(dummyWorkbasket.getId());
dummyTask = taskServiceImpl.create(dummyTask); dummyTask = taskServiceImpl.createTask(dummyTask);
} }
@AfterClass @AfterClass

View File

@ -1,24 +1,13 @@
package pro.taskana.impl.integration; package pro.taskana.impl.integration;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.List;
import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.junit.AfterClass; import org.junit.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import pro.taskana.ClassificationQuery; import pro.taskana.ClassificationQuery;
import pro.taskana.ObjectReferenceQuery; import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine; import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode; import pro.taskana.TaskanaEngine.ConnectionManagementMode;
import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.ClassificationNotFoundException;
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;
@ -28,9 +17,16 @@ import pro.taskana.impl.TaskServiceImpl;
import pro.taskana.impl.TaskanaEngineImpl; import pro.taskana.impl.TaskanaEngineImpl;
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.Classification;
import pro.taskana.model.Task; import pro.taskana.model.Task;
import pro.taskana.model.TaskState; import pro.taskana.model.TaskState;
import pro.taskana.model.Workbasket;
import javax.security.auth.login.LoginException;
import javax.sql.DataSource;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.List;
/** /**
* Integration Test for TaskServiceImpl transactions with connection management mode AUTOCOMMIT. * Integration Test for TaskServiceImpl transactions with connection management mode AUTOCOMMIT.
@ -66,12 +62,19 @@ public class TaskServiceImplIntAutocommitTest {
@Test @Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException,
WorkbasketNotFoundException, NotAuthorizedException { WorkbasketNotFoundException, NotAuthorizedException, ClassificationNotFoundException {
Workbasket wb = new Workbasket();
wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(wb.getId());
task.setWorkbasketId(id1); task.setClassification(classification);
task = taskServiceImpl.create(task);
task = taskServiceImpl.createTask(task);
//skanaEngineImpl.getSqlSession().commit(); // needed so that the change is visible in the other session //skanaEngineImpl.getSqlSession().commit(); // needed so that the change is visible in the other session
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine(); TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
@ -82,43 +85,61 @@ public class TaskServiceImplIntAutocommitTest {
@Test(expected = TaskNotFoundException.class) @Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Workbasket wb = new Workbasket();
wb.setName("sdf");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(wb.getId());
task.setWorkbasketId("id1"); task.setClassification(classification);
task = taskServiceImpl.create(task); taskServiceImpl.createTask(task);
taskServiceImpl.getTaskById(id1); taskServiceImpl.getTaskById(task.getId());
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine(); TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService(); TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTaskById(id1); taskServiceImpl2.getTaskById(wb.getId());
} }
@Test @Test
public void testCreateTaskInTaskanaWithDefaultDb() public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
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();
Workbasket wb = new Workbasket();
wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(wb.getId());
task.setWorkbasketId(id1); task.setClassification(classification);
task = taskServiceImpl.create(task); task = taskServiceImpl.createTask(task);
Assert.assertNotNull(task); Assert.assertNotNull(task);
Assert.assertNotNull(task.getId()); Assert.assertNotNull(task.getId());
} }
@Test @Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException { public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Workbasket wb = new Workbasket();
wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(wb.getId());
task.setWorkbasketId(id1); task.setClassification(classification);
task = taskServiceImpl.create(task); taskServiceImpl.createTask(task);
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine; TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl) ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl)

View File

@ -11,13 +11,9 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
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.impl.ClassificationQueryImpl; import pro.taskana.impl.*;
import pro.taskana.impl.ObjectReferenceQueryImpl;
import pro.taskana.impl.TaskServiceImpl;
import pro.taskana.impl.TaskanaEngineImpl;
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.*; import pro.taskana.model.*;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
@ -27,9 +23,7 @@ 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.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT. * Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
@ -63,14 +57,12 @@ public class TaskServiceImplIntExplicitTest {
} }
@Test @Test
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
Task task = new Task();
task.setName("Unit Test Task"); Task task = this.generateDummyTask();
String id1 = IdGenerator.generateWithPrefix("TWB"); task = taskServiceImpl.createTask(task);
task.setWorkbasketId(id1);
task = taskServiceImpl.create(task);
connection.commit(); // needed so that the change is visible in the other session connection.commit(); // needed so that the change is visible in the other session
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine(); TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
@ -82,40 +74,54 @@ public class TaskServiceImplIntExplicitTest {
@Test(expected = TaskNotFoundException.class) @Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService(); // taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = new Classification();
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(workbasket.getId());
task.setWorkbasketId("id1"); task.setClassification(classification);
task = taskServiceImpl.create(task); task = taskServiceImpl.createTask(task);
connection.commit(); connection.commit();
taskServiceImpl.getTaskById(id1); taskServiceImpl.getTaskById(workbasket.getId());
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine(); TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService(); TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTaskById(id1); taskServiceImpl2.getTaskById(workbasket.getId());
connection.commit(); connection.commit();
} }
@Test @Test
public void testCreateTaskInTaskanaWithDefaultDb() public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
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();
ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = new Classification();
workbasketServiceImpl.createWorkbasket(workbasket);
classificationServiceImpl.addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(workbasket.getId());
task.setWorkbasketId(id1); task.setClassification(classification);
task = taskServiceImpl.create(task); task = taskServiceImpl.createTask(task);
Assert.assertNotNull(task); Assert.assertNotNull(task);
Assert.assertNotNull(task.getId()); Assert.assertNotNull(task.getId());
@ -124,16 +130,11 @@ public class TaskServiceImplIntExplicitTest {
} }
@Test @Test
public void testCreateManualTask() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket1");
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = new Classification(); Classification classification = new Classification();
classification.setDomain("domain");
classification.setCategory("MANUAL"); classification.setCategory("MANUAL");
classification.setName("classification name"); classification.setName("classification name");
classification.setServiceLevel("P1D"); classification.setServiceLevel("P1D");
@ -146,32 +147,41 @@ public class TaskServiceImplIntExplicitTest {
objectReference.setValue("4444"); objectReference.setValue("4444");
objectReference.setType("type"); objectReference.setType("type");
Task test = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", null, "Name", null, objectReference, null); Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
Assert.assertEquals(test.getPlanned(), test.getCreated()); Task test = this.generateDummyTask();
test.setClassification(classification);
test.setName("Name");
test.setPrimaryObjRef(objectReference);
test.setPlanned(tomorrow);
test = taskServiceImpl.createTask(test);
Assert.assertNotEquals(test.getPlanned(), test.getCreated());
Assert.assertNotNull(test.getDue()); Assert.assertNotNull(test.getDue());
Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1)); Task test2 = new Task();
Map<String, Object> customs = new HashMap<String, Object>(); test2.setWorkbasketId(test.getWorkbasketId());
customs.put("Daimler", "Tons of money. And cars. And gold."); test2.setClassification(classification);
customs.put("Audi", 2); test2.setPrimaryObjRef(objectReference);
test2.setDescription("desc");
taskServiceImpl.createTask(test2);
Task test2 = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", tomorrow, "Name2", "desc", objectReference, customs); Assert.assertEquals(test2.getPlanned(), test2.getCreated());
Assert.assertTrue(test2.getName().equals(classification.getName()));
Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId()); Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId());
Assert.assertTrue(test.getDue().before(test2.getDue())); Assert.assertTrue(test.getDue().after(test2.getDue()));
Assert.assertFalse(test.getName().equals(test2.getName()));
} }
@Test(expected = WorkbasketNotFoundException.class) @Test(expected = WorkbasketNotFoundException.class)
public void createManualTaskShouldThrowWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException { public void createTaskShouldThrowWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
Workbasket workbasket = new Workbasket(); Task test = this.generateDummyTask();
workbasket.setName("wb"); test.setWorkbasketId("1");
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket); taskServiceImpl.createTask(test);
taskServiceImpl.createManualTask("1", "classification", "domain", null, null, null, null, null);
} }
@Test(expected = ClassificationNotFoundException.class) @Test(expected = ClassificationNotFoundException.class)
@ -179,41 +189,28 @@ public class TaskServiceImplIntExplicitTest {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
Workbasket workbasket = new Workbasket(); Task test = this.generateDummyTask();
workbasket.setName("wb"); test.setClassification(new Classification());
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket); taskServiceImpl.createTask(test);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
taskServiceImpl.createManualTask(workbasket.getId(), "classification", "domain", null, null, null, null, null);
}
@Test(expected = NotAuthorizedException.class)
public void createManualTaskShouldThrowNotAuthorizedException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Workbasket workbasket = new Workbasket();
workbasket.setName("wb");
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", null, null, null, null, null);
} }
@Test @Test
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException { public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Connection connection = dataSource.getConnection(); Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection); taskanaEngineImpl.setConnection(connection);
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = new Classification();
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
String id1 = IdGenerator.generateWithPrefix("TWB"); task.setWorkbasketId(workbasket.getId());
task.setWorkbasketId(id1); task.setClassification(classification);
task = taskServiceImpl.create(task); task = taskServiceImpl.createTask(task);
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine; TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl) ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl)
@ -233,6 +230,20 @@ public class TaskServiceImplIntExplicitTest {
connection.commit(); connection.commit();
} }
private Task generateDummyTask() {
Workbasket workbasket = new Workbasket();
workbasket.setName("wb");
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = new Classification();
taskanaEngine.getClassificationService().addClassification(classification);
Task task = new Task();
task.setWorkbasketId(workbasket.getId());
task.setClassification(classification);
return task;
}
@After @After
public void cleanUp() { public void cleanUp() {
taskanaEngineImpl.setConnection(null); taskanaEngineImpl.setConnection(null);

View File

@ -1,15 +1,16 @@
package pro.taskana; package pro.taskana;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; 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.ClassificationNotFoundException;
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.Task; import pro.taskana.model.Task;
import javax.annotation.PostConstruct;
@Component @Component
@Transactional @Transactional
public class ExampleBootstrap { public class ExampleBootstrap {
@ -18,12 +19,12 @@ public class ExampleBootstrap {
private TaskService taskService; private TaskService taskService;
@PostConstruct @PostConstruct
public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException { public void test() throws TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
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");
task.setWorkbasketId("1"); task.setWorkbasketId("1");
task = taskService.create(task); task = taskService.createTask(task);
System.out.println("---------------------------> Task started: " + task.getId()); System.out.println("---------------------------> Task started: " + task.getId());
taskService.claim(task.getId(), "John Doe"); taskService.claim(task.getId(), "John Doe");
System.out.println( System.out.println(

View File

@ -3,8 +3,10 @@ package pro.taskana;
import org.springframework.beans.factory.annotation.Autowired; 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.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException; import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.WorkbasketNotFoundException; import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.Classification;
import pro.taskana.model.Task; import pro.taskana.model.Task;
@Component @Component
@ -18,11 +20,11 @@ public class TaskanaComponent {
return taskService; return taskService;
} }
public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException { public void triggerRollback() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
Task task = new Task(); Task task = new Task();
task.setName("Unit Test Task"); task.setName("Unit Test Task");
task.setWorkbasketId("1"); task.setWorkbasketId("1");
task = taskService.create(task); task = taskService.createTask(task);
throw new RuntimeException(); throw new RuntimeException();
} }
} }

View File

@ -106,7 +106,7 @@ public class TaskController {
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Task> createTask(@RequestBody Task task) { public ResponseEntity<Task> createTask(@RequestBody Task task) {
try { try {
Task createdTask = taskService.create(task); Task createdTask = taskService.createTask(task);
return ResponseEntity.status(HttpStatus.CREATED).body(createdTask); return ResponseEntity.status(HttpStatus.CREATED).body(createdTask);
} catch (Exception e) { } catch (Exception e) {
logger.error("Something went wrong: ", e); logger.error("Something went wrong: ", e);