Enable JUnit tests to run on DB2
This commit is contained in:
parent
683a65dc5c
commit
aac8abdcad
|
@ -42,6 +42,12 @@
|
|||
<version>1.4.194</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ibm.db2.jcc</groupId>
|
||||
<artifactId>db2jcc4</artifactId>
|
||||
<version>11.1.1.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
|
@ -93,4 +99,15 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!--
|
||||
this repository is needed to fetch com.ibm.db2.jcc
|
||||
-->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>camunda public</id>
|
||||
<name>camunda</name>
|
||||
<url>https://app.camunda.com/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -18,6 +18,7 @@ public class TaskanaEngineConfiguration {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfiguration.class);
|
||||
|
||||
private static final String USER_NAME = "sa";
|
||||
private static final String USER_PASSWORD = "sa";
|
||||
private static final String JDBC_H2_MEM_TASKANA = "jdbc:h2:mem:taskana";
|
||||
private static final String H2_DRIVER = "org.h2.Driver";
|
||||
|
@ -57,7 +58,7 @@ public class TaskanaEngineConfiguration {
|
|||
public DataSource createDefaultDataSource() {
|
||||
LOGGER.warn("No datasource is provided. A inmemory db is used: "
|
||||
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
|
||||
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_PASSWORD, USER_PASSWORD);
|
||||
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ public interface QueryMapper {
|
|||
+ "<if test='classificationQuery.category != null'>AND c.CATEGORY IN(<foreach item='item' collection='classificationQuery.category' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='classificationQuery.type != null'>AND c.TYPE IN(<foreach item='item' collection='classificationQuery.type' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='classificationQuery.domain != null'>AND c.DOMAIN IN(<foreach item='item' collection='classificationQuery.domain' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='classificationQuery.validInDomain != null'>AND c.VALID_IN_DOMAIN like #{classificationQuery.validInDomain}</if> "
|
||||
+ "<if test='classificationQuery.validInDomain != null'>AND c.VALID_IN_DOMAIN = #{classificationQuery.validInDomain}</if> "
|
||||
+ "<if test='classificationQuery.created != null'>AND c.CREATED IN(<foreach item='item' collection='classificationQuery.created' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='classificationQuery.name != null'>AND c.NAME IN(<foreach item='item' collection='classificationQuery.name' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='classificationQuery.description != null'>AND c.DESCRIPTION like #{classificationQuery.description}</if> "
|
||||
|
@ -102,7 +102,7 @@ public interface QueryMapper {
|
|||
+ "<if test='category != null'>AND CATEGORY IN(<foreach item='item' collection='category' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='type != null'>AND TYPE IN(<foreach item='item' collection='type' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='domain != null'>AND DOMAIN IN(<foreach item='item' collection='domain' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='validInDomain != null'>AND VALID_IN_DOMAIN like #{validInDomain}</if> "
|
||||
+ "<if test='validInDomain != null'>AND VALID_IN_DOMAIN = #{validInDomain}</if> "
|
||||
+ "<if test='created != null'>AND CREATED IN(<foreach item='item' collection='created' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='name != null'>AND NAME IN(<foreach item='item' collection='name' separator=',' >#{item}</foreach>)</if> "
|
||||
+ "<if test='description != null'>AND DESCRIPTION like #{description}</if> "
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package org.taskana.impl.configuration;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.ibatis.jdbc.ScriptRunner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.taskana.configuration.DbScriptRunner;
|
||||
|
||||
/**
|
||||
* This class cleans the complete database. Only to be used in Unittest
|
||||
*/
|
||||
public class DBCleaner {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DbScriptRunner.class);
|
||||
private static final String DB_CLEAR_SCRIPT = "/sql/clear-db.sql";
|
||||
|
||||
private StringWriter outWriter = new StringWriter();
|
||||
private PrintWriter logWriter = new PrintWriter(outWriter);
|
||||
private StringWriter errorWriter = new StringWriter();
|
||||
private PrintWriter errorLogWriter = new PrintWriter(errorWriter);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the db.
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void clearDb(DataSource dataSource) throws SQLException {
|
||||
ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
|
||||
LOGGER.debug(dataSource.getConnection().getMetaData().toString());
|
||||
|
||||
runner.setStopOnError(true);
|
||||
runner.setLogWriter(logWriter);
|
||||
runner.setErrorLogWriter(errorLogWriter);
|
||||
|
||||
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_CLEAR_SCRIPT)));
|
||||
|
||||
runner.closeConnection();
|
||||
|
||||
LOGGER.debug(outWriter.toString());
|
||||
if (!errorWriter.toString().trim().isEmpty()) {
|
||||
LOGGER.error(errorWriter.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,13 +1,22 @@
|
|||
package org.taskana.impl.configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.taskana.TaskanaEngine;
|
||||
import org.taskana.configuration.TaskanaEngineConfiguration;
|
||||
/**
|
||||
|
@ -15,17 +24,114 @@ import org.taskana.configuration.TaskanaEngineConfiguration;
|
|||
* @author EH
|
||||
*/
|
||||
public class TaskanaEngineConfigurationTest {
|
||||
private static DataSource dataSource = null;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskanaEngineConfigurationTest.class);
|
||||
|
||||
@Test
|
||||
public void testCreateTaskEngine() throws FileNotFoundException, SQLException, LoginException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:mem:workbasket-test-db");
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
DataSource ds = getDataSource();
|
||||
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
|
||||
|
||||
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
|
||||
|
||||
Assert.assertNotNull(te);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the Datasource used for Junit test.
|
||||
* If the file {user.home}/taskanaUnitTest.properties is present, the Datasource is created according to the
|
||||
* properties jdbcDriver, jdbcUrl, dbUserName and dbPassword.
|
||||
* Assuming, the database has the name tskdb, a sample properties file for DB2 looks as follows:
|
||||
*
|
||||
* jdbcDriver=com.ibm.db2.jcc.DB2Driver
|
||||
* jdbcUrl=jdbc:db2://localhost:50000/tskdb
|
||||
* dbUserName=db2user
|
||||
* dbPassword=db2password
|
||||
*
|
||||
* If any of these properties is missing, or the file doesn't exist, the default Datasource for h2 in-memory db is created.
|
||||
*
|
||||
* @return dataSource for unit test
|
||||
*/
|
||||
public static DataSource getDataSource() {
|
||||
if (dataSource == null) {
|
||||
String userHomeDirectroy = System.getProperty("user.home");
|
||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
||||
File f = new File(propertiesFileName);
|
||||
if (f.exists() && !f.isDirectory()) {
|
||||
dataSource = createDataSourceFromProperties(propertiesFileName);
|
||||
} else {
|
||||
dataSource = createDefaultDataSource();
|
||||
}
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* create Default Datasource for in-memory database.
|
||||
* @return
|
||||
*/
|
||||
private static DataSource createDefaultDataSource() {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:mem:taskana");
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
return ds;
|
||||
}
|
||||
|
||||
/**
|
||||
* create data source from properties file.
|
||||
* @param propertiesFileName
|
||||
* @return
|
||||
*/
|
||||
private static DataSource createDataSourceFromProperties(String propertiesFileName) {
|
||||
DataSource ds = null;
|
||||
try (InputStream input = new FileInputStream(propertiesFileName)) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(input);
|
||||
boolean propertiesFileIsComplete = true;
|
||||
String warningMessage = "";
|
||||
String jdbcDriver = prop.getProperty("jdbcDriver");
|
||||
if (jdbcDriver == null || jdbcDriver.length() == 0) {
|
||||
propertiesFileIsComplete = false;
|
||||
warningMessage += ", jdbcDriver property missing";
|
||||
}
|
||||
String jdbcUrl = prop.getProperty("jdbcUrl");
|
||||
if (jdbcUrl == null || jdbcUrl.length() == 0) {
|
||||
propertiesFileIsComplete = false;
|
||||
warningMessage += ", jdbcUrl property missing";
|
||||
}
|
||||
String dbUserName = prop.getProperty("dbUserName");
|
||||
if (dbUserName == null || dbUserName.length() == 0) {
|
||||
propertiesFileIsComplete = false;
|
||||
warningMessage += ", dbUserName property missing";
|
||||
}
|
||||
String dbPassword = prop.getProperty("dbPassword");
|
||||
if (dbPassword == null || dbPassword.length() == 0) {
|
||||
propertiesFileIsComplete = false;
|
||||
warningMessage += ", dbPassword property missing";
|
||||
}
|
||||
|
||||
if (propertiesFileIsComplete) {
|
||||
ds = new UnpooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver,
|
||||
jdbcUrl, dbUserName, dbPassword);
|
||||
} else {
|
||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||
LOGGER.warn("Using default Datasource for Test");
|
||||
ds = createDefaultDataSource();
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
package org.taskana.impl.integration;
|
||||
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
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.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -10,33 +19,34 @@ import org.taskana.ClassificationService;
|
|||
import org.taskana.TaskanaEngine;
|
||||
import org.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import org.taskana.exceptions.NotAuthorizedException;
|
||||
import org.taskana.impl.TaskanaEngineImpl;
|
||||
import org.taskana.impl.configuration.DBCleaner;
|
||||
import org.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import org.taskana.model.Classification;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Integration Test for ClassificationServiceImpl.
|
||||
* @author EH
|
||||
*/
|
||||
public class ClassificationServiceImplIntTest {
|
||||
static int counter = 0;
|
||||
|
||||
private DataSource dataSource;
|
||||
private ClassificationService classificationService;
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:mem:test-db-classification" + counter++);
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
|
||||
|
||||
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
|
||||
classificationService = te.getClassificationService();
|
||||
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
classificationService = taskanaEngine.getClassificationService();
|
||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -252,8 +262,14 @@ public class ClassificationServiceImplIntTest {
|
|||
Assert.assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
taskanaEngineImpl.closeSession();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
public static void cleanUpClass() {
|
||||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
package org.taskana.impl.integration;
|
||||
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
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.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.taskana.TaskanaEngine;
|
||||
import org.taskana.configuration.TaskanaEngineConfiguration;
|
||||
|
@ -11,69 +19,70 @@ import org.taskana.exceptions.NotAuthorizedException;
|
|||
import org.taskana.exceptions.TaskNotFoundException;
|
||||
import org.taskana.impl.TaskServiceImpl;
|
||||
import org.taskana.impl.TaskanaEngineImpl;
|
||||
import org.taskana.impl.configuration.DBCleaner;
|
||||
import org.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import org.taskana.impl.persistence.ClassificationQueryImpl;
|
||||
import org.taskana.impl.persistence.ObjectReferenceQueryImpl;
|
||||
import org.taskana.impl.util.IdGenerator;
|
||||
import org.taskana.model.Task;
|
||||
import org.taskana.model.TaskState;
|
||||
import org.taskana.persistence.ClassificationQuery;
|
||||
import org.taskana.persistence.ObjectReferenceQuery;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Integration Test for TaskServiceImpl transactions.
|
||||
* @author EH
|
||||
*/
|
||||
public class TaskServiceImplTransactionTest {
|
||||
|
||||
private DataSource dataSource;
|
||||
private TaskServiceImpl taskServiceImpl;
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
|
||||
@Before
|
||||
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, false);
|
||||
|
||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStart() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:~/data/test-db-taskservice-int1");
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, true, false);
|
||||
|
||||
TaskanaEngineImpl te = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
task.setWorkbasketId(id1);
|
||||
task = taskServiceImpl.create(task);
|
||||
te.closeSession();
|
||||
taskanaEngineImpl.getSession().commit(); // needed so that the change is visible in the other session
|
||||
|
||||
TaskanaEngine te2 = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
||||
Task resultTask = taskServiceImpl2.getTaskById(task.getId());
|
||||
|
||||
Assert.assertNotNull(resultTask);
|
||||
}
|
||||
|
||||
@Test(expected = TaskNotFoundException.class)
|
||||
public void testStartTransactionFail()
|
||||
throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:~/data/test-db-taskservice-trans2");
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
|
||||
|
||||
TaskanaEngineImpl te = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
task.setWorkbasketId("id1");
|
||||
task = taskServiceImpl.create(task);
|
||||
taskServiceImpl.getTaskById("1");
|
||||
te.closeSession();
|
||||
taskServiceImpl.getTaskById(id1);
|
||||
|
||||
TaskanaEngineImpl te2 = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl2 = (TaskServiceImpl) te2.getTaskService();
|
||||
taskServiceImpl2.getTaskById("1");
|
||||
taskServiceImpl2.getTaskById(id1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,7 +94,8 @@ public class TaskServiceImplTransactionTest {
|
|||
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
task.setWorkbasketId(id1);
|
||||
task = taskServiceImpl.create(task);
|
||||
|
||||
Assert.assertNotNull(task);
|
||||
|
@ -94,25 +104,19 @@ public class TaskServiceImplTransactionTest {
|
|||
|
||||
@Test
|
||||
public void should_ReturnList_when_BuilderIsUsed() throws SQLException, NotAuthorizedException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:~/data/test-db-taskservice-int2");
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, true, false);
|
||||
|
||||
TaskanaEngineImpl te = (TaskanaEngineImpl) taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
|
||||
|
||||
Task task = new Task();
|
||||
task.setName("Unit Test Task");
|
||||
task.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
task.setWorkbasketId(id1);
|
||||
task = taskServiceImpl.create(task);
|
||||
|
||||
ClassificationQuery classificationQuery = new ClassificationQueryImpl(te).tenantId("asdasdasd")
|
||||
TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
ClassificationQuery classificationQuery = new ClassificationQueryImpl(taskanaEngineImpl).tenantId("asdasdasd")
|
||||
.parentClassification("pId1", "pId2").category("cat1", "cat2").type("oneType").name("1Name", "name2")
|
||||
.descriptionLike("my desc").priority(1, 2, 1).serviceLevel("me", "and", "you");
|
||||
|
||||
ObjectReferenceQuery objectReferenceQuery = new ObjectReferenceQueryImpl(te).tenantId("tenant1")
|
||||
ObjectReferenceQuery objectReferenceQuery = new ObjectReferenceQueryImpl(taskanaEngineImpl).tenantId("tenant1")
|
||||
.company("first comp", "sonstwo gmbh").system("sys").type("type1", "type2")
|
||||
.systemInstance("sysInst1", "sysInst2").value("val1", "val2", "val3");
|
||||
|
||||
|
@ -125,8 +129,13 @@ public class TaskServiceImplTransactionTest {
|
|||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
taskanaEngineImpl.closeSession();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
public static void cleanUpClass() {
|
||||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
package org.taskana.impl.integration;
|
||||
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
@ -11,15 +19,13 @@ import org.taskana.WorkbasketService;
|
|||
import org.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import org.taskana.exceptions.NotAuthorizedException;
|
||||
import org.taskana.exceptions.WorkbasketNotFoundException;
|
||||
import org.taskana.impl.TaskanaEngineImpl;
|
||||
import org.taskana.impl.configuration.DBCleaner;
|
||||
import org.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
import org.taskana.impl.util.IdGenerator;
|
||||
import org.taskana.model.Workbasket;
|
||||
import org.taskana.model.WorkbasketAccessItem;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Integration Test for workbasketServiceImpl.
|
||||
|
@ -30,160 +36,185 @@ public class WorkbasketServiceImplIntTest {
|
|||
private static final int SLEEP_TIME = 100;
|
||||
private static final int THREE = 3;
|
||||
|
||||
WorkbasketService workbasketServiceImpl;
|
||||
static int counter = 0;
|
||||
|
||||
private DataSource dataSource;
|
||||
private TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||
private TaskanaEngine taskanaEngine;
|
||||
private TaskanaEngineImpl taskanaEngineImpl;
|
||||
private WorkbasketService workBasketService;
|
||||
|
||||
@Before
|
||||
public void setup() throws FileNotFoundException, SQLException, LoginException {
|
||||
JdbcDataSource ds = new JdbcDataSource();
|
||||
ds.setURL("jdbc:h2:mem:test-db-workbasket" + counter++);
|
||||
ds.setPassword("sa");
|
||||
ds.setUser("sa");
|
||||
TaskanaEngineConfiguration taskEngineConfiguration = new TaskanaEngineConfiguration(ds, false);
|
||||
|
||||
TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();
|
||||
workbasketServiceImpl = te.getWorkbasketService();
|
||||
dataSource = TaskanaEngineConfigurationTest.getDataSource();
|
||||
taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
|
||||
taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
workBasketService = taskanaEngine.getWorkbasketService();
|
||||
DBCleaner cleaner = new DBCleaner();
|
||||
cleaner.clearDb(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertWorkbasket() throws NotAuthorizedException {
|
||||
int before = workbasketServiceImpl.getWorkbaskets().size();
|
||||
int before = workBasketService.getWorkbaskets().size();
|
||||
Workbasket workbasket = new Workbasket();
|
||||
workbasket.setId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket.setId(id1);
|
||||
workbasket.setName("Megabasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket);
|
||||
Assert.assertEquals(before + 1, workbasketServiceImpl.getWorkbaskets().size());
|
||||
workBasketService.createWorkbasket(workbasket);
|
||||
Assert.assertEquals(before + 1, workBasketService.getWorkbaskets().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectAllWorkbaskets() throws NotAuthorizedException {
|
||||
int before = workbasketServiceImpl.getWorkbaskets().size();
|
||||
int before = workBasketService.getWorkbaskets().size();
|
||||
Workbasket workbasket0 = new Workbasket();
|
||||
workbasket0.setId("0");
|
||||
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket0.setId(id0);
|
||||
workbasket0.setName("Superbasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket0);
|
||||
workBasketService.createWorkbasket(workbasket0);
|
||||
Workbasket workbasket1 = new Workbasket();
|
||||
workbasket1.setId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket1.setId(id1);
|
||||
workbasket1.setName("Megabasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket1);
|
||||
workBasketService.createWorkbasket(workbasket1);
|
||||
Workbasket workbasket2 = new Workbasket();
|
||||
workbasket2.setId("2");
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket2.setId(id2);
|
||||
workbasket2.setName("Hyperbasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket2);
|
||||
Assert.assertEquals(before + THREE, workbasketServiceImpl.getWorkbaskets().size());
|
||||
workBasketService.createWorkbasket(workbasket2);
|
||||
Assert.assertEquals(before + THREE, workBasketService.getWorkbaskets().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectWorkbasket() throws WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Workbasket workbasket0 = new Workbasket();
|
||||
workbasket0.setId("0");
|
||||
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket0.setId(id0);
|
||||
workbasket0.setName("Superbasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket0);
|
||||
workBasketService.createWorkbasket(workbasket0);
|
||||
Workbasket workbasket1 = new Workbasket();
|
||||
workbasket1.setId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket1.setId(id1);
|
||||
workbasket1.setName("Megabasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket1);
|
||||
workBasketService.createWorkbasket(workbasket1);
|
||||
Workbasket workbasket2 = new Workbasket();
|
||||
workbasket2.setId("2");
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket2.setId(id2);
|
||||
workbasket2.setName("Hyperbasket");
|
||||
workbasketServiceImpl.createWorkbasket(workbasket2);
|
||||
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
|
||||
Assert.assertEquals("2", foundWorkbasket.getId());
|
||||
workBasketService.createWorkbasket(workbasket2);
|
||||
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
|
||||
Assert.assertEquals(id2, foundWorkbasket.getId());
|
||||
}
|
||||
|
||||
@Test(expected = WorkbasketNotFoundException.class)
|
||||
public void testGetWorkbasketFail() throws WorkbasketNotFoundException {
|
||||
workbasketServiceImpl.getWorkbasket("fail");
|
||||
workBasketService.getWorkbasket("fail");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectWorkbasketWithDistribution() throws WorkbasketNotFoundException, NotAuthorizedException {
|
||||
Workbasket workbasket0 = new Workbasket();
|
||||
workbasket0.setId("0");
|
||||
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket0.setId(id0);
|
||||
workbasket0.setName("Superbasket");
|
||||
Workbasket workbasket1 = new Workbasket();
|
||||
workbasket1.setId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket1.setId(id1);
|
||||
workbasket1.setName("Megabasket");
|
||||
Workbasket workbasket2 = new Workbasket();
|
||||
workbasket2.setId("2");
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket2.setId(id2);
|
||||
workbasket2.setName("Hyperbasket");
|
||||
workbasket2.setDistributionTargets(new ArrayList<>());
|
||||
workbasket2.getDistributionTargets().add(workbasket0);
|
||||
workbasket2.getDistributionTargets().add(workbasket1);
|
||||
workbasketServiceImpl.createWorkbasket(workbasket2);
|
||||
Workbasket foundWorkbasket = workbasketServiceImpl.getWorkbasket("2");
|
||||
Assert.assertEquals("2", foundWorkbasket.getId());
|
||||
workBasketService.createWorkbasket(workbasket2);
|
||||
Workbasket foundWorkbasket = workBasketService.getWorkbasket(id2);
|
||||
Assert.assertEquals(id2, foundWorkbasket.getId());
|
||||
Assert.assertEquals(2, foundWorkbasket.getDistributionTargets().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWorkbasket() throws Exception {
|
||||
Workbasket workbasket0 = new Workbasket();
|
||||
workbasket0.setId("0");
|
||||
String id0 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket0.setId(id0);
|
||||
workbasket0.setName("Superbasket");
|
||||
Workbasket workbasket1 = new Workbasket();
|
||||
workbasket1.setId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket1.setId(id1);
|
||||
workbasket1.setName("Megabasket");
|
||||
Workbasket workbasket2 = new Workbasket();
|
||||
workbasket2.setId("2");
|
||||
String id2 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket2.setId(id2);
|
||||
workbasket2.setName("Hyperbasket");
|
||||
workbasket2.getDistributionTargets().add(workbasket0);
|
||||
workbasket2.getDistributionTargets().add(workbasket1);
|
||||
workbasketServiceImpl.createWorkbasket(workbasket2);
|
||||
workBasketService.createWorkbasket(workbasket2);
|
||||
|
||||
Workbasket workbasket3 = new Workbasket();
|
||||
workbasket3.setId("3");
|
||||
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket3.setId(id3);
|
||||
workbasket3.setName("hm ... irgend ein basket");
|
||||
workbasket2.getDistributionTargets().clear();
|
||||
workbasket2.getDistributionTargets().add(workbasket3);
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
workbasketServiceImpl.updateWorkbasket(workbasket2);
|
||||
workBasketService.updateWorkbasket(workbasket2);
|
||||
|
||||
Workbasket foundBasket = workbasketServiceImpl.getWorkbasket(workbasket2.getId());
|
||||
Workbasket foundBasket = workBasketService.getWorkbasket(workbasket2.getId());
|
||||
|
||||
List<Workbasket> distributionTargets = foundBasket.getDistributionTargets();
|
||||
Assert.assertEquals(1, distributionTargets.size());
|
||||
Assert.assertEquals("3", distributionTargets.get(0).getId());
|
||||
Assert.assertNotEquals(workbasketServiceImpl.getWorkbasket("2").getCreated(),
|
||||
workbasketServiceImpl.getWorkbasket("2").getModified());
|
||||
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("1").getCreated(),
|
||||
workbasketServiceImpl.getWorkbasket("1").getModified());
|
||||
Assert.assertEquals(workbasketServiceImpl.getWorkbasket("3").getCreated(),
|
||||
workbasketServiceImpl.getWorkbasket("3").getModified());
|
||||
Assert.assertEquals(id3, distributionTargets.get(0).getId());
|
||||
Assert.assertNotEquals(workBasketService.getWorkbasket(id2).getCreated(),
|
||||
workBasketService.getWorkbasket(id2).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id1).getCreated(),
|
||||
workBasketService.getWorkbasket(id1).getModified());
|
||||
Assert.assertEquals(workBasketService.getWorkbasket(id3).getCreated(),
|
||||
workBasketService.getWorkbasket(id3).getModified());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertWorkbasketAccessUser() throws NotAuthorizedException {
|
||||
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
|
||||
accessItem.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
accessItem.setWorkbasketId(id1);
|
||||
accessItem.setUserId("Arthur Dent");
|
||||
accessItem.setOpen(true);
|
||||
accessItem.setRead(true);
|
||||
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
|
||||
workBasketService.createWorkbasketAuthorization(accessItem);
|
||||
|
||||
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
|
||||
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWorkbasketAccessUser() throws NotAuthorizedException {
|
||||
WorkbasketAccessItem accessItem = new WorkbasketAccessItem();
|
||||
accessItem.setWorkbasketId("1");
|
||||
String id1 = IdGenerator.generateWithPrefix("TWB");
|
||||
accessItem.setWorkbasketId(id1);
|
||||
accessItem.setUserId("Arthur Dent");
|
||||
accessItem.setOpen(true);
|
||||
accessItem.setRead(true);
|
||||
workbasketServiceImpl.createWorkbasketAuthorization(accessItem);
|
||||
workBasketService.createWorkbasketAuthorization(accessItem);
|
||||
|
||||
Assert.assertEquals(1, workbasketServiceImpl.getAllAuthorizations().size());
|
||||
Assert.assertEquals(1, workBasketService.getAllAuthorizations().size());
|
||||
|
||||
accessItem.setUserId("Zaphod Beeblebrox");
|
||||
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
|
||||
workBasketService.updateWorkbasketAuthorization(accessItem);
|
||||
|
||||
Assert.assertEquals("Zaphod Beeblebrox",
|
||||
workbasketServiceImpl.getWorkbasketAuthorization(accessItem.getId()).getUserId());
|
||||
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getUserId());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
taskanaEngineImpl.closeSession();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
public static void cleanUpClass() {
|
||||
FileUtils.deleteRecursive("~/data", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
DELETE FROM TASK;
|
||||
DELETE FROM WORKBASKET;
|
||||
DELETE FROM DISTRIBUTION_TARGETS;
|
||||
DELETE FROM CLASSIFICATION;
|
||||
DELETE FROM WORKBASKET_ACCESS_LIST;
|
||||
DELETE FROM OBJECT_REFERENCE;
|
||||
COMMIT;
|
Loading…
Reference in New Issue