Merge pull request #45 from BVier/master2
TSK-15: Create a manual task in a given Workbasket
This commit is contained in:
commit
ed0703cd9a
|
@ -1,5 +1,6 @@
|
|||
package pro.taskana;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
|
@ -31,7 +32,7 @@ public interface ClassificationService {
|
|||
* @param domain
|
||||
* @return If exist: domain-specific classification, else default classification
|
||||
*/
|
||||
Classification getClassification(String id, String domain);
|
||||
Classification getClassification(String id, String domain) throws ClassificationNotFoundException;
|
||||
|
||||
/**
|
||||
* Insert a new Classification.
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.model.DueWorkbasketCounter;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.TaskStateCounter;
|
||||
import pro.taskana.model.*;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Task Service manages all operations on tasks.
|
||||
|
@ -43,6 +43,19 @@ public interface TaskService {
|
|||
*/
|
||||
Task create(Task task) throws NotAuthorizedException, WorkbasketNotFoundException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param taskId
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package pro.taskana.exceptions;
|
||||
|
||||
/**
|
||||
* This exception will be thrown if a specific task is not in the database.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ClassificationNotFoundException extends NotFoundException {
|
||||
|
||||
public ClassificationNotFoundException(String id) {
|
||||
super("Classification '" + id + "' not found");
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package pro.taskana.impl;
|
|||
import pro.taskana.ClassificationQuery;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.model.Classification;
|
||||
|
@ -80,13 +81,9 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
taskanaEngineImpl.openConnection();
|
||||
this.setDefaultValues(classification);
|
||||
|
||||
Classification oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
||||
|
||||
if (oldClassification == null) {
|
||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
classificationMapper.insert(classification);
|
||||
} else {
|
||||
Classification oldClassification = null;
|
||||
try {
|
||||
oldClassification = this.getClassification(classification.getId(), classification.getDomain());
|
||||
|
||||
// ! If you update an classification twice the same day,
|
||||
// the older version is valid from today until yesterday.
|
||||
|
@ -98,8 +95,11 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
classificationMapper.update(oldClassification);
|
||||
classificationMapper.insert(classification);
|
||||
}
|
||||
} catch (ClassificationNotFoundException e) {
|
||||
classification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||
classification.setCreated(Date.valueOf(LocalDate.now()));
|
||||
classificationMapper.insert(classification);
|
||||
}
|
||||
return;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
}
|
||||
|
@ -142,15 +142,18 @@ public class ClassificationServiceImpl implements ClassificationService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Classification getClassification(String id, String domain) {
|
||||
public Classification getClassification(String id, String domain) throws ClassificationNotFoundException {
|
||||
try {
|
||||
taskanaEngineImpl.openConnection();
|
||||
Classification classification = classificationMapper.findByIdAndDomain(id, domain, CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
if (classification == null) {
|
||||
return classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
} else {
|
||||
return classification;
|
||||
classification = classificationMapper.findByIdAndDomain(id, "", CURRENT_CLASSIFICATIONS_VALID_UNTIL);
|
||||
}
|
||||
if (classification == null) {
|
||||
throw new ClassificationNotFoundException(id);
|
||||
}
|
||||
return classification;
|
||||
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
}
|
||||
|
|
|
@ -1,31 +1,28 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.TaskQuery;
|
||||
import pro.taskana.TaskService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
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.*;
|
||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This is the implementation of TaskService.
|
||||
*/
|
||||
|
@ -36,6 +33,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
private static final String ID_PREFIX_OBJECTR_EFERENCE = "ORI";
|
||||
private static final String ID_PREFIX_TASK = "TKI";
|
||||
private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI";
|
||||
private static final String TYPE_MANUAL = "MANUAL";
|
||||
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
@ -102,29 +100,43 @@ public class TaskServiceImpl implements TaskService {
|
|||
taskanaEngineImpl.openConnection();
|
||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
||||
task.setState(TaskState.READY);
|
||||
task.setCreated(now);
|
||||
task.setModified(now);
|
||||
task.setRead(false);
|
||||
task.setTransferred(false);
|
||||
standardSettings(task);
|
||||
|
||||
// if no business process id is provided, a unique id is created.
|
||||
if (task.getBusinessProcessId() == null) {
|
||||
task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
|
||||
this.taskMapper.insert(task);
|
||||
|
||||
LOGGER.debug("Task '{}' created.", task.getId());
|
||||
return task;
|
||||
} finally {
|
||||
taskanaEngineImpl.returnConnection();
|
||||
}
|
||||
}
|
||||
|
||||
// insert ObjectReference if needed.
|
||||
if (task.getPrimaryObjRef() != null) {
|
||||
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||
if (objectReference == null) {
|
||||
objectReference = task.getPrimaryObjRef();
|
||||
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
||||
this.objectReferenceMapper.insert(objectReference);
|
||||
}
|
||||
task.setPrimaryObjRef(objectReference);
|
||||
@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 {
|
||||
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("Task '{}' created.", task.getId());
|
||||
|
@ -249,4 +261,86 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
return (resultList == null) ? new ArrayList<>() : resultList;
|
||||
}
|
||||
|
||||
private void standardSettings(Task task) {
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
|
||||
task.setState(TaskState.READY);
|
||||
task.setCreated(now);
|
||||
task.setModified(now);
|
||||
task.setRead(false);
|
||||
task.setTransferred(false);
|
||||
|
||||
if (task.getPlanned() == null) {
|
||||
task.setPlanned(now);
|
||||
}
|
||||
|
||||
// if no business process id is provided, a unique id is created.
|
||||
if (task.getBusinessProcessId() == null) {
|
||||
task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
|
||||
}
|
||||
|
||||
// insert Classification specifications if Classification is given.
|
||||
Classification classification = task.getClassification();
|
||||
if (classification != null) {
|
||||
if (classification.getServiceLevel() != null) {
|
||||
Duration serviceLevel = Duration.parse(task.getClassification().getServiceLevel());
|
||||
LocalDateTime due = task.getPlanned().toLocalDateTime().plus(serviceLevel);
|
||||
task.setDue(Timestamp.valueOf(due));
|
||||
}
|
||||
|
||||
if (task.getName() == null) {
|
||||
task.setName(classification.getName());
|
||||
}
|
||||
|
||||
if (task.getDescription() == null) {
|
||||
task.setDescription(classification.getDescription());
|
||||
}
|
||||
|
||||
if (task.getPriority() == 0) {
|
||||
task.setPriority(classification.getPriority());
|
||||
}
|
||||
}
|
||||
|
||||
// insert ObjectReference if needed.
|
||||
if (task.getPrimaryObjRef() != null) {
|
||||
ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||
if (objectReference == null) {
|
||||
objectReference = task.getPrimaryObjRef();
|
||||
objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE));
|
||||
this.objectReferenceMapper.insert(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -20,11 +7,19 @@ import org.mockito.InjectMocks;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.model.Classification;
|
||||
import pro.taskana.model.mappings.ClassificationMapper;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit Test for ClassificationServiceImpl.
|
||||
* @author EH
|
||||
|
@ -43,7 +38,7 @@ public class ClassificationServiceImplTest {
|
|||
TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
@Test
|
||||
public void testAddClassification() {
|
||||
public void testAddClassification() throws ClassificationNotFoundException {
|
||||
doNothing().when(classificationMapper).insert(any());
|
||||
|
||||
Classification classification = new Classification();
|
||||
|
|
|
@ -1,24 +1,5 @@
|
|||
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.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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -27,22 +8,30 @@ import org.mockito.Mock;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.WorkbasketService;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
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.Workbasket;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
import pro.taskana.model.*;
|
||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||
import pro.taskana.model.mappings.TaskMapper;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Unit Test for TaskServiceImpl.
|
||||
* @author EH
|
||||
|
@ -73,11 +62,14 @@ public class TaskServiceImplTest {
|
|||
@Mock
|
||||
private WorkbasketService workbasketServiceMock;
|
||||
|
||||
@Mock
|
||||
private ClassificationService classificationServiceMock;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
doReturn(workbasketServiceMock).when(taskanaEngineMock).getWorkbasketService();
|
||||
doReturn(classificationServiceMock).when(taskanaEngineMock).getClassificationService();
|
||||
try {
|
||||
Mockito.doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
|
||||
} catch (NotAuthorizedException e) {
|
||||
|
@ -179,12 +171,60 @@ public class TaskServiceImplTest {
|
|||
assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateManualTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
ObjectReference expectedObjectReference = new ObjectReference();
|
||||
expectedObjectReference.setId("1");
|
||||
expectedObjectReference.setType("DUMMY");
|
||||
|
||||
Classification classification = new Classification();
|
||||
classification.setName("Name");
|
||||
classification.setCategory("MANUAL");
|
||||
|
||||
Mockito.doReturn(classification).when(classificationServiceMock).getClassification(any(), any());
|
||||
Mockito.doNothing().when(taskMapperMock).insert(any());
|
||||
Mockito.doNothing().when(objectReferenceMapperMock).insert(any());
|
||||
|
||||
Task manualTask = cut.createManualTask("workbasketId", "classification", "domain", null, null, "simply awesome task", expectedObjectReference, null);
|
||||
|
||||
Task manualTask2 = cut.createManualTask("workbasketId", "classification", "domain", Timestamp.valueOf(LocalDateTime.now().minusHours(1)), "Task2", "simply awesome task", expectedObjectReference, null);
|
||||
|
||||
verify(taskanaEngineImpl, times(2)).openConnection();
|
||||
verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService();
|
||||
verify(taskanaEngineMock, times(2)).getClassificationService();
|
||||
verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any());
|
||||
verify(workbasketServiceMock, times(2)).getWorkbasket(any());
|
||||
verify(objectReferenceMapperMock, times(2)).findByObjectReference(any());
|
||||
verify(objectReferenceMapperMock, times(2)).insert(any());
|
||||
verify(taskMapperMock, times(1)).insert(manualTask);
|
||||
verify(taskMapperMock, times(1)).insert(manualTask2);
|
||||
verify(taskanaEngineImpl, times(2)).returnConnection();
|
||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock);
|
||||
|
||||
assertNull(manualTask.getOwner());
|
||||
assertNotNull(manualTask.getCreated());
|
||||
assertNotNull(manualTask.getModified());
|
||||
assertNull(manualTask.getCompleted());
|
||||
assertNull(manualTask.getDue());
|
||||
assertThat(manualTask.getWorkbasketId(), equalTo(manualTask2.getWorkbasketId()));
|
||||
assertThat(manualTask.getName(), equalTo(classification.getName()));
|
||||
assertThat(manualTask.getState(), equalTo(TaskState.READY));
|
||||
assertThat(manualTask.getPrimaryObjRef(), equalTo(expectedObjectReference));
|
||||
assertThat(manualTask.getName(), not(manualTask2.getName()));
|
||||
assertThat(manualTask.getPlanned(), not(manualTask2.getPlanned()));
|
||||
assertThat(manualTask2.getPlanned(), not(manualTask2.getCreated()));
|
||||
|
||||
}
|
||||
|
||||
@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");
|
||||
task.setBusinessProcessId("BPI1");
|
||||
task.setParentBusinessProcessId("PBPI1");
|
||||
|
||||
cut.create(task);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,31 +1,26 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.*;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Integration Test for ClassificationServiceImpl with connection management mode AUTOCOMMIT.
|
||||
* @author EH
|
||||
|
@ -59,7 +54,7 @@ public class ClassificationServiceImplIntAutoCommitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertClassification() {
|
||||
public void testInsertClassification() throws ClassificationNotFoundException {
|
||||
Classification classification = new Classification();
|
||||
classificationService.addClassification(classification);
|
||||
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.*;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
|
@ -7,27 +22,6 @@ import java.sql.SQLException;
|
|||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.h2.store.fs.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.model.Classification;
|
||||
|
||||
/**
|
||||
* Integration Test for ClassificationServiceImpl with connection management mode EXPLICIT.
|
||||
* @author BBR
|
||||
|
@ -62,7 +56,7 @@ public class ClassificationServiceImplIntExplicitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertClassification() throws SQLException {
|
||||
public void testInsertClassification() throws SQLException, ClassificationNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
|
|
|
@ -1,26 +1,13 @@
|
|||
package pro.taskana.impl.integration;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
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.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.*;
|
||||
import pro.taskana.ClassificationQuery;
|
||||
import pro.taskana.ObjectReferenceQuery;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||
|
@ -31,8 +18,18 @@ import pro.taskana.impl.TaskanaEngineImpl;
|
|||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import pro.taskana.impl.util.IdGenerator;
|
||||
import pro.taskana.model.Task;
|
||||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.*;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
|
||||
|
@ -126,6 +123,87 @@ public class TaskServiceImplIntExplicitTest {
|
|||
te.setConnection(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateManualTask() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("workbasket1");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
Classification classification = new Classification();
|
||||
classification.setDomain("domain");
|
||||
classification.setCategory("MANUAL");
|
||||
classification.setName("classification name");
|
||||
classification.setServiceLevel("P1D");
|
||||
taskanaEngine.getClassificationService().addClassification(classification);
|
||||
|
||||
ObjectReference objectReference = new ObjectReference();
|
||||
objectReference.setCompany("Novatec");
|
||||
objectReference.setSystem("System");
|
||||
objectReference.setSystemInstance("2");
|
||||
objectReference.setValue("4444");
|
||||
objectReference.setType("type");
|
||||
|
||||
Task test = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", null, "Name", null, objectReference, null);
|
||||
|
||||
Assert.assertEquals(test.getPlanned(), test.getCreated());
|
||||
Assert.assertNotNull(test.getDue());
|
||||
|
||||
Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
|
||||
Map<String, Object> customs = new HashMap<String, Object>();
|
||||
customs.put("Daimler", "Tons of money. And cars. And gold.");
|
||||
customs.put("Audi", 2);
|
||||
|
||||
Task test2 = taskServiceImpl.createManualTask(workbasket.getId(), classification.getId(), "domain", tomorrow, "Name2", "desc", objectReference, customs);
|
||||
|
||||
Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId());
|
||||
Assert.assertTrue(test.getDue().before(test2.getDue()));
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void createManualTaskShouldThrowWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException {
|
||||
Connection connection = dataSource.getConnection();
|
||||
taskanaEngineImpl.setConnection(connection);
|
||||
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setName("wb");
|
||||
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
|
||||
|
||||
taskServiceImpl.createManualTask("1", "classification", "domain", null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test(expected = ClassificationNotFoundException.class)
|
||||
public void createManualTaskShouldThrowClassificationNotFoundException() 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", "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
|
||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue