TSK-61: Adding code-review issues and resolved failures on TaskIntegrationTests.

This commit is contained in:
Marcel Lengl 2017-12-11 09:12:34 +01:00
parent 134371f39a
commit a39814bf4b
8 changed files with 103 additions and 56 deletions

View File

@ -1,6 +1,7 @@
package pro.taskana;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -16,7 +17,6 @@ import pro.taskana.exceptions.ClassificationNotFoundException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.exceptions.WorkbasketNotFoundException;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.Task;
import pro.taskana.model.Workbasket;
@ -27,13 +27,16 @@ public class TaskanaRestTest {
@EJB
private TaskanaEjb taskanaEjb;
@Inject
private ClassificationService classificationService;
@GET
public Response startTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
Workbasket workbasket = new Workbasket();
workbasket.setName("wb");
taskanaEjb.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEjb.getClassificationService().createClassification(classification);
Task task = new Task();

View File

@ -1,7 +1,7 @@
package pro.taskana.exceptions;
/**
* This Exception will be thrown, when a classification does already exits,
* Thrown, when a classification does already exits,
* but wanted to create with same ID+domain.
*/
public class ClassificationAlreadyExistException extends NotFoundException {

View File

@ -1,8 +1,7 @@
package pro.taskana.exceptions;
/**
<<<<<<< HEAD
* This exception will be thrown if a specific task is not in the database.
* Thrown if a specific task is not in the database.
*/
@SuppressWarnings("serial")
public class ClassificationNotFoundException extends NotFoundException {

View File

@ -30,12 +30,10 @@ public class ClassificationServiceImpl implements ClassificationService {
public static final Date CURRENT_CLASSIFICATIONS_VALID_UNTIL = Date.valueOf("9999-12-31");
private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
private ClassificationMapper classificationMapper;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
public ClassificationServiceImpl(TaskanaEngine taskanaEngine, ClassificationMapper classificationMapper) {
super();
this.taskanaEngine = taskanaEngine;
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
this.classificationMapper = classificationMapper;
}
@ -222,7 +220,7 @@ public class ClassificationServiceImpl implements ClassificationService {
@Override
public ClassificationQuery createClassificationQuery() {
return new ClassificationQueryImpl(taskanaEngine);
return new ClassificationQueryImpl(taskanaEngineImpl);
}
@Override

View File

@ -26,7 +26,6 @@ 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.mappings.ObjectReferenceMapper;
import pro.taskana.model.mappings.TaskMapper;
@ -41,7 +40,6 @@ 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;
@ -113,9 +111,8 @@ public class TaskServiceImpl implements TaskService {
LOGGER.debug("entry to createTask(task = {})", task);
try {
taskanaEngineImpl.openConnection();
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
task.setWorkbasketId(wb.getId());
Classification classification = task.getClassification();
if (classification == null) {
throw new ClassificationNotFoundException(null);

View File

@ -98,7 +98,7 @@ public class SummaryServiceImplIntAutoCommitTest {
@Test(expected = WorkbasketNotFoundException.class)
public void shouldThrowWorkbasketNotFoundExceptionByNullParameter() throws WorkbasketNotFoundException {
List<TaskSummary> actualTaskSumamryResult = summaryServiceImp.getTaskSummariesByWorkbasketId(null);
summaryServiceImp.getTaskSummariesByWorkbasketId(null);
}
@Test(expected = WorkbasketNotFoundException.class)
@ -106,7 +106,7 @@ public class SummaryServiceImplIntAutoCommitTest {
Workbasket wb = new Workbasket();
wb.setName("wb");
workbasketServiceImpl.createWorkbasket(wb);
List<TaskSummary> actualTaskSumamryResult = summaryServiceImp.getTaskSummariesByWorkbasketId("1");
summaryServiceImp.getTaskSummariesByWorkbasketId("1");
}

View File

@ -16,6 +16,7 @@ import org.junit.Test;
import pro.taskana.Classification;
import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationService;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
@ -31,7 +32,6 @@ import pro.taskana.impl.TaskServiceImpl;
import pro.taskana.impl.TaskanaEngineImpl;
import pro.taskana.impl.configuration.DBCleaner;
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
import pro.taskana.model.ClassificationImpl;
import pro.taskana.model.Task;
import pro.taskana.model.TaskState;
import pro.taskana.model.Workbasket;
@ -47,6 +47,7 @@ public class TaskServiceImplIntAutocommitTest {
private TaskanaEngineConfiguration taskanaEngineConfiguration;
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private ClassificationService classificationService;
@BeforeClass
public static void resetDb() throws SQLException {
@ -64,6 +65,7 @@ public class TaskServiceImplIntAutocommitTest {
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
classificationService = taskanaEngine.getClassificationService();
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource, false);
}
@ -74,7 +76,7 @@ public class TaskServiceImplIntAutocommitTest {
Workbasket wb = new Workbasket();
wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();
@ -97,7 +99,7 @@ public class TaskServiceImplIntAutocommitTest {
Workbasket wb = new Workbasket();
wb.setName("sdf");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();
@ -118,7 +120,7 @@ public class TaskServiceImplIntAutocommitTest {
Workbasket wb = new Workbasket();
wb.setName("workbasket");
wb = taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();
@ -136,7 +138,7 @@ public class TaskServiceImplIntAutocommitTest {
Workbasket wb = new Workbasket();
wb.setName("workbasket");
taskanaEngine.getWorkbasketService().createWorkbasket(wb);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();

View File

@ -23,11 +23,11 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import pro.taskana.Classification;
import pro.taskana.ClassificationQuery;
import pro.taskana.ClassificationService;
import pro.taskana.ObjectReferenceQuery;
import pro.taskana.TaskanaEngine;
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
@ -65,6 +65,7 @@ public class TaskServiceImplIntExplicitTest {
private TaskanaEngine taskanaEngine;
private TaskanaEngineImpl taskanaEngineImpl;
private Subject subject;
private ClassificationService classificationService;
@BeforeClass
public static void resetDb() throws SQLException {
@ -80,6 +81,7 @@ public class TaskServiceImplIntExplicitTest {
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
classificationService = taskanaEngine.getClassificationService();
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
DBCleaner cleaner = new DBCleaner();
cleaner.clearDb(dataSource, false);
@ -103,6 +105,51 @@ public class TaskServiceImplIntExplicitTest {
}
}
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail() throws TaskNotFoundException {
try {
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
public Object run() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
do_testStartTransactionFail();
return null;
}
});
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause != null) {
Assert.assertTrue(cause instanceof TaskNotFoundException);
throw (TaskNotFoundException) cause;
}
}
}
public void do_testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
workbasket.setId("1"); // set id manually for authorization tests
Classification classification = classificationService.newClassification();
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();
task.setName("Unit Test Task");
task.setWorkbasketId(workbasket.getId());
task.setClassification(classification);
task = taskServiceImpl.createTask(task);
connection.commit();
taskServiceImpl.getTaskById(workbasket.getId());
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTaskById(workbasket.getId());
connection.commit();
}
@Test
public void testCreateTask() throws Throwable {
try {
@ -133,34 +180,6 @@ public class TaskServiceImplIntExplicitTest {
connection.commit();
}
@Ignore
@Test(expected = TaskNotFoundException.class)
public void testStartTransactionFail()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
// taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = (Classification) new ClassificationImpl();
workbasket.setId("1"); // set id manually for authorization tests
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();
task.setName("Unit Test Task");
task.setWorkbasketId(workbasket.getId());
task.setClassification(classification);
task = taskServiceImpl.createTask(task);
connection.commit();
taskServiceImpl.getTaskById(workbasket.getId());
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
taskServiceImpl2.getTaskById(workbasket.getId());
connection.commit();
}
@Test
public void testCreateTaskInTaskanaWithDefaultDb()
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
@ -175,7 +194,7 @@ public class TaskServiceImplIntExplicitTest {
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
workbasket.setName("workbasket99");
workbasketServiceImpl.createWorkbasket(workbasket);
classificationServiceImpl.createClassification(classification);
@ -192,13 +211,26 @@ public class TaskServiceImplIntExplicitTest {
te.setConnection(null);
}
@Ignore
@Test
public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
public void testCreateTaskWithPlannedAndName() throws Throwable {
try {
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, SQLException, ClassificationAlreadyExistException {
do_testCreateTaskWithPlannedAndName();
return null;
}
});
} catch (PrivilegedActionException e) {
throw e.getCause();
}
}
public void do_testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
classification.setCategory("MANUAL");
classification.setName("classification name");
classification.setServiceLevel("P1D");
@ -248,9 +280,25 @@ public class TaskServiceImplIntExplicitTest {
taskServiceImpl.createTask(test);
}
@Ignore
@Test(expected = ClassificationNotFoundException.class)
public void createManualTaskShouldThrowClassificationNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException, ClassificationAlreadyExistException {
public void createManualTaskShouldThrowClassificationNotFoundException() throws ClassificationNotFoundException {
try {
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
public Object run() throws NotAuthorizedException, SQLException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException {
do_createManualTaskShouldThrowClassificationNotFoundException();
return null;
}
});
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause != null) {
Assert.assertTrue(cause instanceof ClassificationNotFoundException);
throw (ClassificationNotFoundException) cause;
}
}
}
public void do_createManualTaskShouldThrowClassificationNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, SQLException, ClassificationAlreadyExistException {
Connection connection = dataSource.getConnection();
taskanaEngineImpl.setConnection(connection);
@ -280,7 +328,7 @@ public class TaskServiceImplIntExplicitTest {
Workbasket workbasket = new Workbasket();
workbasket.setName("workbasket");
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
workbasket.setId("1"); // set id manually for authorization tests
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
taskanaEngine.getClassificationService().createClassification(classification);
@ -315,7 +363,7 @@ public class TaskServiceImplIntExplicitTest {
workbasket.setId("1"); // set id manually for authorization tests
taskanaEngine.getWorkbasketService().createWorkbasket(workbasket);
Classification classification = (Classification) new ClassificationImpl();
Classification classification = classificationService.newClassification();
taskanaEngine.getClassificationService().createClassification(classification);
Task task = new Task();