TSK-987: Fix some problems reported by spotbugs
This commit is contained in:
parent
6c8fb69f60
commit
c92190ca70
|
@ -45,7 +45,7 @@ public class DbSchemaCreator {
|
||||||
runner.setLogWriter(logWriter);
|
runner.setLogWriter(logWriter);
|
||||||
runner.setErrorLogWriter(errorLogWriter);
|
runner.setErrorLogWriter(errorLogWriter);
|
||||||
|
|
||||||
InputStream resourceAsStream = this.getClass().getResourceAsStream(DB_SCHEMA);
|
InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(DB_SCHEMA);
|
||||||
BufferedReader reader =
|
BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
||||||
runner.runScript(getSqlWithSchemaNameParsed(reader));
|
runner.runScript(getSqlWithSchemaNameParsed(reader));
|
||||||
|
|
|
@ -639,8 +639,8 @@ public class HistoryQueryImpl implements HistoryQuery {
|
||||||
private HistoryQueryImpl addOrderCriteria(String columnName, SortDirection sortDirection) {
|
private HistoryQueryImpl addOrderCriteria(String columnName, SortDirection sortDirection) {
|
||||||
String orderByDirection =
|
String orderByDirection =
|
||||||
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
||||||
orderBy.add(columnName.toString() + orderByDirection);
|
orderBy.add(columnName + orderByDirection);
|
||||||
orderColumns.add(columnName.toString());
|
orderColumns.add(columnName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
||||||
|
@ -25,12 +26,9 @@ public class AbstractAccTest {
|
||||||
private static final int POOL_TIME_TO_WAIT = 50;
|
private static final int POOL_TIME_TO_WAIT = 50;
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:DeclarationOrder")
|
@SuppressWarnings("checkstyle:DeclarationOrder")
|
||||||
public static SimpleHistoryServiceImpl historyService;
|
private static SimpleHistoryServiceImpl historyService;
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:DeclarationOrder")
|
private static DataSource dataSource;
|
||||||
protected static TaskanaEngineConfiguration taskanaEngineConfiguration;
|
|
||||||
|
|
||||||
private static DataSource dataSource = null;
|
|
||||||
private static String schemaName = null;
|
private static String schemaName = null;
|
||||||
|
|
||||||
protected AbstractAccTest() {
|
protected AbstractAccTest() {
|
||||||
|
@ -44,7 +42,8 @@ public class AbstractAccTest {
|
||||||
|
|
||||||
public static void resetDb(String schemaName) throws SQLException {
|
public static void resetDb(String schemaName) throws SQLException {
|
||||||
DataSource dataSource = getDataSource();
|
DataSource dataSource = getDataSource();
|
||||||
taskanaEngineConfiguration =
|
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration =
|
||||||
new TaskanaEngineConfiguration(
|
new TaskanaEngineConfiguration(
|
||||||
dataSource,
|
dataSource,
|
||||||
false,
|
false,
|
||||||
|
@ -57,19 +56,7 @@ public class AbstractAccTest {
|
||||||
writer.generateTestData(dataSource);
|
writer.generateTestData(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static {
|
||||||
* 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 userHomeDirectroy = System.getProperty("user.home");
|
||||||
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
String propertiesFileName = userHomeDirectroy + "/taskanaUnitTest.properties";
|
||||||
File f = new File(propertiesFileName);
|
File f = new File(propertiesFileName);
|
||||||
|
@ -79,6 +66,11 @@ public class AbstractAccTest {
|
||||||
dataSource = createDefaultDataSource();
|
dataSource = createDefaultDataSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DataSource getDataSource() {
|
||||||
|
if (dataSource == null) {
|
||||||
|
throw new RuntimeException("Datasource should be already initialized");
|
||||||
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +123,10 @@ public class AbstractAccTest {
|
||||||
return historyEvent;
|
return historyEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SimpleHistoryServiceImpl getHistoryService() {
|
||||||
|
return historyService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create Default DataSource for in-memory database.
|
* create Default DataSource for in-memory database.
|
||||||
*
|
*
|
||||||
|
@ -142,16 +138,15 @@ public class AbstractAccTest {
|
||||||
String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0";
|
String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0";
|
||||||
String dbUserName = "sa";
|
String dbUserName = "sa";
|
||||||
String dbPassword = "sa";
|
String dbPassword = "sa";
|
||||||
DataSource ds =
|
PooledDataSource ds =
|
||||||
new PooledDataSource(
|
new PooledDataSource(
|
||||||
Thread.currentThread().getContextClassLoader(),
|
Thread.currentThread().getContextClassLoader(),
|
||||||
jdbcDriver,
|
jdbcDriver,
|
||||||
jdbcUrl,
|
jdbcUrl,
|
||||||
dbUserName,
|
dbUserName,
|
||||||
dbPassword);
|
dbPassword);
|
||||||
((PooledDataSource) ds).setPoolTimeToWait(POOL_TIME_TO_WAIT);
|
ds.setPoolTimeToWait(POOL_TIME_TO_WAIT);
|
||||||
((PooledDataSource) ds)
|
ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
||||||
.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly
|
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
@ -203,19 +198,15 @@ public class AbstractAccTest {
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
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) {
|
} catch (IOException e) {
|
||||||
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
LOGGER.warn("createDataSourceFromProperties caught Exception " + e);
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
LOGGER.warn("Using default Datasource for Test");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(ds)) {
|
||||||
ds = createDefaultDataSource();
|
ds = createDefaultDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ public class QueryHistoryAccTest extends AbstractAccTest {
|
||||||
@Test
|
@Test
|
||||||
public void testListValuesAscendingAndDescending() {
|
public void testListValuesAscendingAndDescending() {
|
||||||
List<String> defaultList =
|
List<String> defaultList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.COMMENT, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.COMMENT, null);
|
||||||
List<String> ascendingList =
|
List<String> ascendingList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.ASCENDING);
|
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.ASCENDING);
|
||||||
List<String> descendingList =
|
List<String> descendingList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.DESCENDING);
|
.listValues(HistoryQueryColumnName.COMMENT, SortDirection.DESCENDING);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class QueryHistoryAccTest extends AbstractAccTest {
|
||||||
@Test
|
@Test
|
||||||
public void testComplexQuery() {
|
public void testComplexQuery() {
|
||||||
HistoryQuery query =
|
HistoryQuery query =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.businessProcessIdLike("just some string", "BPI:%")
|
.businessProcessIdLike("just some string", "BPI:%")
|
||||||
.domainLike("%A")
|
.domainLike("%A")
|
||||||
|
@ -64,8 +64,8 @@ public class QueryHistoryAccTest extends AbstractAccTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryListOffset() {
|
public void testQueryListOffset() {
|
||||||
List<HistoryEventImpl> result = historyService.createHistoryQuery().list(1, 2);
|
List<HistoryEventImpl> result = getHistoryService().createHistoryQuery().list(1, 2);
|
||||||
List<HistoryEventImpl> wrongList = historyService.createHistoryQuery().list();
|
List<HistoryEventImpl> wrongList = getHistoryService().createHistoryQuery().list();
|
||||||
|
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
|
|
||||||
|
@ -75,275 +75,292 @@ public class QueryHistoryAccTest extends AbstractAccTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCorrectResultWithWrongConstraints() {
|
public void testCorrectResultWithWrongConstraints() {
|
||||||
List<HistoryEventImpl> result = historyService.createHistoryQuery().list(1, 1000);
|
List<HistoryEventImpl> result = getHistoryService().createHistoryQuery().list(1, 1000);
|
||||||
assertEquals(2, result.size());
|
assertEquals(2, result.size());
|
||||||
assertEquals("created by Peter", result.get(0).getComment());
|
assertEquals("created by Peter", result.get(0).getComment());
|
||||||
|
|
||||||
result = historyService.createHistoryQuery().list(100, 1000);
|
result = getHistoryService().createHistoryQuery().list(100, 1000);
|
||||||
assertTrue(result.isEmpty());
|
assertTrue(result.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingle() {
|
public void testSingle() {
|
||||||
HistoryEventImpl single = historyService.createHistoryQuery().userIdIn("peter").single();
|
HistoryEventImpl single = getHistoryService().createHistoryQuery().userIdIn("peter").single();
|
||||||
assertEquals("CREATE", single.getEventType());
|
assertEquals("CREATE", single.getEventType());
|
||||||
|
|
||||||
single = historyService.createHistoryQuery().eventTypeIn("CREATE", "xy").single();
|
single = getHistoryService().createHistoryQuery().eventTypeIn("CREATE", "xy").single();
|
||||||
assertEquals("admin", single.getUserId());
|
assertEquals("admin", single.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCount() {
|
public void testCount() {
|
||||||
long count = historyService.createHistoryQuery().userIdIn("peter").count();
|
long count = getHistoryService().createHistoryQuery().userIdIn("peter").count();
|
||||||
assertEquals(1, count);
|
assertEquals(1, count);
|
||||||
|
|
||||||
count = historyService.createHistoryQuery().count();
|
count = getHistoryService().createHistoryQuery().count();
|
||||||
assertEquals(3, count);
|
assertEquals(3, count);
|
||||||
|
|
||||||
count = historyService.createHistoryQuery().userIdIn("klaus", "arnold", "benni").count();
|
count = getHistoryService().createHistoryQuery().userIdIn("klaus", "arnold", "benni").count();
|
||||||
assertEquals(0, count);
|
assertEquals(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryAttributesIn() {
|
public void testQueryAttributesIn() {
|
||||||
List<HistoryEventImpl> returnValues =
|
List<HistoryEventImpl> returnValues =
|
||||||
historyService.createHistoryQuery().businessProcessIdIn("BPI:01", "BPI:02").list();
|
getHistoryService().createHistoryQuery().businessProcessIdIn("BPI:01", "BPI:02").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().parentBusinessProcessIdIn("BPI:01").list();
|
returnValues =
|
||||||
|
getHistoryService().createHistoryQuery().parentBusinessProcessIdIn("BPI:01").list();
|
||||||
assertEquals(1, returnValues.size());
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
returnValues =
|
returnValues =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.taskIdIn("TKI:000000000000000000000000000000000000")
|
.taskIdIn("TKI:000000000000000000000000000000000000")
|
||||||
.list();
|
.list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().eventTypeIn("CREATE").list();
|
returnValues = getHistoryService().createHistoryQuery().eventTypeIn("CREATE").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||||
returnValues = historyService.createHistoryQuery().createdWithin(timeInterval).list();
|
returnValues = getHistoryService().createHistoryQuery().createdWithin(timeInterval).list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().userIdIn("admin").list();
|
returnValues = getHistoryService().createHistoryQuery().userIdIn("admin").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().domainIn("DOMAIN_A").list();
|
returnValues = getHistoryService().createHistoryQuery().domainIn("DOMAIN_A").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues =
|
returnValues =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.workbasketKeyIn("WBI:100000000000000000000000000000000001")
|
.workbasketKeyIn("WBI:100000000000000000000000000000000001")
|
||||||
.list();
|
.list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().porCompanyIn("00").list();
|
returnValues = getHistoryService().createHistoryQuery().porCompanyIn("00").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().porSystemIn("PASystem").list();
|
returnValues = getHistoryService().createHistoryQuery().porSystemIn("PASystem").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().porInstanceIn("22").list();
|
returnValues = getHistoryService().createHistoryQuery().porInstanceIn("22").list();
|
||||||
assertEquals(1, returnValues.size());
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().porTypeIn("VN").list();
|
returnValues = getHistoryService().createHistoryQuery().porTypeIn("VN").list();
|
||||||
assertEquals(0, returnValues.size());
|
assertEquals(0, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().porValueIn("11223344").list();
|
returnValues = getHistoryService().createHistoryQuery().porValueIn("11223344").list();
|
||||||
assertEquals(2, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().taskClassificationKeyIn("L140101").list();
|
|
||||||
assertEquals(2, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().taskClassificationCategoryIn("TASK").list();
|
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues =
|
returnValues =
|
||||||
historyService.createHistoryQuery().attachmentClassificationKeyIn("DOCTYPE_DEFAULT").list();
|
getHistoryService().createHistoryQuery().taskClassificationKeyIn("L140101").list();
|
||||||
assertEquals(1, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().custom1In("custom1").list();
|
|
||||||
assertEquals(3, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().custom2In("custom2").list();
|
|
||||||
assertEquals(1, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().custom3In("custom3").list();
|
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().custom4In("custom4").list();
|
returnValues =
|
||||||
assertEquals(1, returnValues.size());
|
getHistoryService().createHistoryQuery().taskClassificationCategoryIn("TASK").list();
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().commentIn("created a bug").list();
|
|
||||||
assertEquals(1, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().oldValueIn("old_val").list();
|
|
||||||
assertEquals(1, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newValueIn("new_val").list();
|
|
||||||
assertEquals(1, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().oldDataIn("123").list();
|
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newDataIn("456").list();
|
returnValues =
|
||||||
assertEquals(3, returnValues.size());
|
getHistoryService()
|
||||||
returnValues = historyService.createHistoryQuery().oldValueLike("old%").list();
|
.createHistoryQuery()
|
||||||
|
.attachmentClassificationKeyIn("DOCTYPE_DEFAULT")
|
||||||
|
.list();
|
||||||
assertEquals(1, returnValues.size());
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newValueLike("new_%").list();
|
returnValues = getHistoryService().createHistoryQuery().custom1In("custom1").list();
|
||||||
assertEquals(2, returnValues.size());
|
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().oldDataLike("%23%").list();
|
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newDataLike("456%").list();
|
returnValues = getHistoryService().createHistoryQuery().custom2In("custom2").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().custom3In("custom3").list();
|
||||||
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().custom4In("custom4").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().commentIn("created a bug").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().oldValueIn("old_val").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().newValueIn("new_val").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().oldDataIn("123").list();
|
||||||
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().newDataIn("456").list();
|
||||||
|
assertEquals(3, returnValues.size());
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().oldValueLike("old%").list();
|
||||||
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().newValueLike("new_%").list();
|
||||||
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().oldDataLike("%23%").list();
|
||||||
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
|
returnValues = getHistoryService().createHistoryQuery().newDataLike("456%").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSomeLikeMethods() {
|
public void testSomeLikeMethods() {
|
||||||
List<HistoryEventImpl> returnValues =
|
List<HistoryEventImpl> returnValues =
|
||||||
historyService.createHistoryQuery().businessProcessIdLike("BPI:0%").list();
|
getHistoryService().createHistoryQuery().businessProcessIdLike("BPI:0%").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
returnValues =
|
returnValues =
|
||||||
historyService.createHistoryQuery().parentBusinessProcessIdLike("BPI:01", " %").list();
|
getHistoryService().createHistoryQuery().parentBusinessProcessIdLike("BPI:01", " %").list();
|
||||||
assertEquals(1, returnValues.size());
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().taskIdLike("TKI:000000000000000%").list();
|
returnValues =
|
||||||
|
getHistoryService().createHistoryQuery().taskIdLike("TKI:000000000000000%").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().oldValueLike("old%").list();
|
returnValues = getHistoryService().createHistoryQuery().oldValueLike("old%").list();
|
||||||
assertEquals(1, returnValues.size());
|
assertEquals(1, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newValueLike("new_%").list();
|
returnValues = getHistoryService().createHistoryQuery().newValueLike("new_%").list();
|
||||||
assertEquals(2, returnValues.size());
|
assertEquals(2, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().oldDataLike("%23%").list();
|
returnValues = getHistoryService().createHistoryQuery().oldDataLike("%23%").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
|
|
||||||
returnValues = historyService.createHistoryQuery().newDataLike("456%").list();
|
returnValues = getHistoryService().createHistoryQuery().newDataLike("456%").list();
|
||||||
assertEquals(3, returnValues.size());
|
assertEquals(3, returnValues.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListValues() {
|
public void testListValues() {
|
||||||
List<String> returnedList =
|
List<String> returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.ID, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.ID, null);
|
||||||
assertEquals(3, returnedList.size());
|
assertEquals(3, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.BUSINESS_PROCESS_ID, null);
|
.listValues(HistoryQueryColumnName.BUSINESS_PROCESS_ID, null);
|
||||||
assertEquals(3, returnedList.size());
|
assertEquals(3, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.PARENT_BUSINESS_PROCESS_ID, null);
|
.listValues(HistoryQueryColumnName.PARENT_BUSINESS_PROCESS_ID, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.TASK_ID, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.TASK_ID, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.EVENT_TYPE, null);
|
getHistoryService()
|
||||||
|
.createHistoryQuery()
|
||||||
|
.listValues(HistoryQueryColumnName.EVENT_TYPE, null);
|
||||||
assertEquals(1, returnedList.size());
|
assertEquals(1, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.CREATED, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CREATED, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.USER_ID, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.USER_ID, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.DOMAIN, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.DOMAIN, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.WORKBASKET_KEY, null);
|
getHistoryService()
|
||||||
|
.createHistoryQuery()
|
||||||
|
.listValues(HistoryQueryColumnName.WORKBASKET_KEY, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.POR_COMPANY, null);
|
getHistoryService()
|
||||||
|
.createHistoryQuery()
|
||||||
|
.listValues(HistoryQueryColumnName.POR_COMPANY, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.POR_SYSTEM, null);
|
getHistoryService()
|
||||||
|
.createHistoryQuery()
|
||||||
|
.listValues(HistoryQueryColumnName.POR_SYSTEM, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.POR_INSTANCE, null);
|
getHistoryService()
|
||||||
|
.createHistoryQuery()
|
||||||
|
.listValues(HistoryQueryColumnName.POR_INSTANCE, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.POR_TYPE, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.POR_TYPE, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.POR_VALUE, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.POR_VALUE, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_KEY, null);
|
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_KEY, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_CATEGORY, null);
|
.listValues(HistoryQueryColumnName.TASK_CLASSIFICATION_CATEGORY, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService
|
getHistoryService()
|
||||||
.createHistoryQuery()
|
.createHistoryQuery()
|
||||||
.listValues(HistoryQueryColumnName.ATTACHMENT_CLASSIFICATION_KEY, null);
|
.listValues(HistoryQueryColumnName.ATTACHMENT_CLASSIFICATION_KEY, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.COMMENT, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.COMMENT, null);
|
||||||
assertEquals(3, returnedList.size());
|
assertEquals(3, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.OLD_VALUE, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.OLD_VALUE, null);
|
||||||
assertEquals(3, returnedList.size());
|
assertEquals(3, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.NEW_VALUE, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.NEW_VALUE, null);
|
||||||
assertEquals(3, returnedList.size());
|
assertEquals(3, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_1, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_1, null);
|
||||||
assertEquals(1, returnedList.size());
|
assertEquals(1, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_2, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_2, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_3, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_3, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_4, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.CUSTOM_4, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.OLD_DATA, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.OLD_DATA, null);
|
||||||
assertEquals(2, returnedList.size());
|
assertEquals(2, returnedList.size());
|
||||||
|
|
||||||
returnedList =
|
returnedList =
|
||||||
historyService.createHistoryQuery().listValues(HistoryQueryColumnName.NEW_DATA, null);
|
getHistoryService().createHistoryQuery().listValues(HistoryQueryColumnName.NEW_DATA, null);
|
||||||
assertEquals(1, returnedList.size());
|
assertEquals(1, returnedList.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class DbWriter {
|
||||||
ScriptRunner runner = null;
|
ScriptRunner runner = null;
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
runner = configScriptRunner(connection);
|
runner = configScriptRunner(connection);
|
||||||
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(INSERTVALUES)));
|
runner.runScript(new InputStreamReader(DbWriter.class.getResourceAsStream(INSERTVALUES)));
|
||||||
} finally {
|
} finally {
|
||||||
LOGGER.debug(outWriter.toString());
|
LOGGER.debug(outWriter.toString());
|
||||||
if (!errorWriter.toString().trim().isEmpty()) {
|
if (!errorWriter.toString().trim().isEmpty()) {
|
||||||
|
|
|
@ -32,11 +32,11 @@ public class TaskanaEngineConfigurationTest extends AbstractAccTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskanaHistoryEventWithNonDefaultSchemaName() throws SQLException {
|
public void testCreateTaskanaHistoryEventWithNonDefaultSchemaName() throws SQLException {
|
||||||
resetDb("SOMECUSTOMSCHEMANAME");
|
resetDb("SOMECUSTOMSCHEMANAME");
|
||||||
long count = historyService.createHistoryQuery().workbasketKeyIn("wbKey1").count();
|
long count = getHistoryService().createHistoryQuery().workbasketKeyIn("wbKey1").count();
|
||||||
assertEquals(0, count);
|
assertEquals(0, count);
|
||||||
historyService.create(
|
getHistoryService().create(
|
||||||
AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2"));
|
AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2"));
|
||||||
count = historyService.createHistoryQuery().workbasketKeyIn("wbKey1").count();
|
count = getHistoryService().createHistoryQuery().workbasketKeyIn("wbKey1").count();
|
||||||
assertEquals(1, count);
|
assertEquals(1, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class SampleDataGenerator {
|
||||||
runner.runScript(
|
runner.runScript(
|
||||||
new BufferedReader(
|
new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
this.getClass().getResourceAsStream(CLEAR), StandardCharsets.UTF_8)));
|
SampleDataGenerator.class.getResourceAsStream(CLEAR), StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
runner.setStopOnError(true);
|
runner.setStopOnError(true);
|
||||||
runner.setLogWriter(logWriter);
|
runner.setLogWriter(logWriter);
|
||||||
|
@ -58,7 +58,8 @@ public class SampleDataGenerator {
|
||||||
runner.runScript(
|
runner.runScript(
|
||||||
new BufferedReader(
|
new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
this.getClass().getResourceAsStream(HISTORY_EVENT), StandardCharsets.UTF_8)));
|
SampleDataGenerator.class.getResourceAsStream(HISTORY_EVENT),
|
||||||
|
StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("caught Exception {}", e, e);
|
LOGGER.error("caught Exception {}", e, e);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
import javax.ws.rs.client.Client;
|
import javax.ws.rs.client.Client;
|
||||||
import javax.ws.rs.client.ClientBuilder;
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
import org.jboss.arquillian.container.test.api.Deployment;
|
import org.jboss.arquillian.container.test.api.Deployment;
|
||||||
|
@ -42,12 +43,9 @@ public class TaskanaProducersTest {
|
||||||
|
|
||||||
Class.forName("org.h2.Driver");
|
Class.forName("org.h2.Driver");
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
try (Connection conn =
|
try (Connection conn = getConnection()) {
|
||||||
DriverManager.getConnection(
|
try (Statement statement = conn.createStatement()) {
|
||||||
"jdbc:h2:~/taskana-h2-data/testdb;AUTO_SERVER=TRUE;IGNORECASE=TRUE;LOCK_MODE=0",
|
ResultSet rs = statement.executeQuery("SELECT ID, OWNER FROM TASKANA.TASK");
|
||||||
"SA",
|
|
||||||
"SA")) {
|
|
||||||
ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASKANA.TASK");
|
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
resultCount++;
|
resultCount++;
|
||||||
|
@ -55,6 +53,7 @@ public class TaskanaProducersTest {
|
||||||
}
|
}
|
||||||
Assert.assertEquals(0, resultCount);
|
Assert.assertEquals(0, resultCount);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRollback() throws SQLException, ClassNotFoundException {
|
public void testRollback() throws SQLException, ClassNotFoundException {
|
||||||
|
@ -63,18 +62,23 @@ public class TaskanaProducersTest {
|
||||||
|
|
||||||
Class.forName("org.h2.Driver");
|
Class.forName("org.h2.Driver");
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
try (Connection conn =
|
try (Connection conn = getConnection()) {
|
||||||
DriverManager.getConnection(
|
try (Statement statement = conn.createStatement()) {
|
||||||
"jdbc:h2:~/taskana-h2-data/testdb;AUTO_SERVER=TRUE;IGNORECASE=TRUE;LOCK_MODE=0",
|
ResultSet rs = statement.executeQuery("SELECT ID, OWNER FROM TASKANA.TASK");
|
||||||
"SA",
|
|
||||||
"SA")) {
|
|
||||||
ResultSet rs = conn.createStatement().executeQuery("SELECT ID, OWNER FROM TASKANA.TASK");
|
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
resultCount++;
|
resultCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertEquals(0, resultCount);
|
Assert.assertEquals(0, resultCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws SQLException {
|
||||||
|
return DriverManager.getConnection(
|
||||||
|
"jdbc:h2:~/taskana-h2-data/testdb;AUTO_SERVER=TRUE;IGNORECASE=TRUE;LOCK_MODE=0",
|
||||||
|
"SA",
|
||||||
|
"SA");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class DbSchemaCreator {
|
||||||
if (!isSchemaPreexisting(connection)) {
|
if (!isSchemaPreexisting(connection)) {
|
||||||
String scriptPath =
|
String scriptPath =
|
||||||
selectDbScriptFileName(connection.getMetaData().getDatabaseProductName());
|
selectDbScriptFileName(connection.getMetaData().getDatabaseProductName());
|
||||||
InputStream resourceAsStream = this.getClass().getResourceAsStream(scriptPath);
|
InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(scriptPath);
|
||||||
BufferedReader reader =
|
BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
||||||
runner.runScript(getSqlSchemaNameParsed(reader));
|
runner.runScript(getSqlSchemaNameParsed(reader));
|
||||||
|
@ -135,7 +135,7 @@ public class DbSchemaCreator {
|
||||||
try {
|
try {
|
||||||
String scriptPath =
|
String scriptPath =
|
||||||
selectDbSchemaDetectionScript(connection.getMetaData().getDatabaseProductName());
|
selectDbSchemaDetectionScript(connection.getMetaData().getDatabaseProductName());
|
||||||
InputStream resourceAsStream = this.getClass().getResourceAsStream(scriptPath);
|
InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(scriptPath);
|
||||||
BufferedReader reader =
|
BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
|
||||||
runner.runScript(getSqlSchemaNameParsed(reader));
|
runner.runScript(getSqlSchemaNameParsed(reader));
|
||||||
|
|
|
@ -521,7 +521,8 @@ public class TaskanaEngineConfiguration {
|
||||||
boolean loadFromClasspath = loadFromClasspath(propertiesFile);
|
boolean loadFromClasspath = loadFromClasspath(propertiesFile);
|
||||||
try {
|
try {
|
||||||
if (loadFromClasspath) {
|
if (loadFromClasspath) {
|
||||||
InputStream inputStream = this.getClass().getResourceAsStream(propertiesFile);
|
InputStream inputStream =
|
||||||
|
TaskanaEngineConfiguration.class.getResourceAsStream(propertiesFile);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
LOGGER.error("taskana properties file {} was not found on classpath.", propertiesFile);
|
LOGGER.error("taskana properties file {} was not found on classpath.", propertiesFile);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -635,8 +635,8 @@ public class ClassificationQueryImpl implements ClassificationQuery {
|
||||||
private ClassificationQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
|
private ClassificationQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
|
||||||
String orderByDirection =
|
String orderByDirection =
|
||||||
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
||||||
orderBy.add(columnName.toString() + orderByDirection);
|
orderBy.add(columnName + orderByDirection);
|
||||||
orderColumns.add(columnName.toString());
|
orderColumns.add(columnName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1684,7 +1684,7 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
String orderByDirection =
|
String orderByDirection =
|
||||||
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
" " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
|
||||||
orderBy.add(columnName + orderByDirection);
|
orderBy.add(columnName + orderByDirection);
|
||||||
orderColumns.add(columnName.toString());
|
orderColumns.add(columnName);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,14 +295,6 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlSessionManager getSessionFromStack() {
|
|
||||||
Deque<SqlSessionManager> stack = getSessionStack();
|
|
||||||
if (stack.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return stack.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pushSessionToStack(SqlSessionManager session) {
|
private void pushSessionToStack(SqlSessionManager session) {
|
||||||
getSessionStack().push(session);
|
getSessionStack().push(session);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.taskana.security;
|
package pro.taskana.security;
|
||||||
|
|
||||||
|
import static pro.taskana.configuration.TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
|
@ -11,8 +13,6 @@ import javax.security.auth.Subject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the context information about the current (calling) user. The context is gathered from
|
* Provides the context information about the current (calling) user. The context is gathered from
|
||||||
* the JAAS subject.
|
* the JAAS subject.
|
||||||
|
@ -54,7 +54,7 @@ public final class CurrentUserContext {
|
||||||
for (Principal group : groups) {
|
for (Principal group : groups) {
|
||||||
String groupNameFound = group.getName();
|
String groupNameFound = group.getName();
|
||||||
String groupNameReturned = groupNameFound;
|
String groupNameReturned = groupNameFound;
|
||||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && groupNameFound != null) {
|
if (shouldUseLowerCaseForAccessIds() && groupNameFound != null) {
|
||||||
groupNameReturned = groupNameFound.toLowerCase();
|
groupNameReturned = groupNameFound.toLowerCase();
|
||||||
}
|
}
|
||||||
LOGGER.trace(
|
LOGGER.trace(
|
||||||
|
@ -102,7 +102,7 @@ public final class CurrentUserContext {
|
||||||
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
|
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
|
||||||
String userIdFound = o.toString();
|
String userIdFound = o.toString();
|
||||||
String userIdUsed = userIdFound;
|
String userIdUsed = userIdFound;
|
||||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
if (shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
||||||
userIdUsed = userIdFound.toLowerCase();
|
userIdUsed = userIdFound.toLowerCase();
|
||||||
}
|
}
|
||||||
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
||||||
|
@ -144,7 +144,7 @@ public final class CurrentUserContext {
|
||||||
if (!(principal instanceof Group)) {
|
if (!(principal instanceof Group)) {
|
||||||
String userIdFound = principal.getName();
|
String userIdFound = principal.getName();
|
||||||
String userIdUsed = userIdFound;
|
String userIdUsed = userIdFound;
|
||||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
if (shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
||||||
userIdUsed = userIdFound.toLowerCase();
|
userIdUsed = userIdFound.toLowerCase();
|
||||||
}
|
}
|
||||||
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
import static org.hamcrest.core.IsNot.not;
|
import static org.hamcrest.core.IsNot.not;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@ -222,7 +223,6 @@ public class UpdateClassificationAccTest extends AbstractAccTest {
|
||||||
final Instant before = Instant.now();
|
final Instant before = Instant.now();
|
||||||
Classification classification =
|
Classification classification =
|
||||||
classificationService.getClassification("CLI:100000000000000000000000000000000003");
|
classificationService.getClassification("CLI:100000000000000000000000000000000003");
|
||||||
Instant createdBefore = classification.getCreated();
|
|
||||||
final Instant modifiedBefore = classification.getModified();
|
final Instant modifiedBefore = classification.getModified();
|
||||||
classification.setPriority(1000);
|
classification.setPriority(1000);
|
||||||
classification.setServiceLevel("P15D");
|
classification.setServiceLevel("P15D");
|
||||||
|
@ -240,7 +240,7 @@ public class UpdateClassificationAccTest extends AbstractAccTest {
|
||||||
classificationService.getClassification("CLI:100000000000000000000000000000000003");
|
classificationService.getClassification("CLI:100000000000000000000000000000000003");
|
||||||
assertNotNull(updatedClassification);
|
assertNotNull(updatedClassification);
|
||||||
|
|
||||||
assertTrue(!modifiedBefore.isAfter(updatedClassification.getModified()));
|
assertFalse(modifiedBefore.isAfter(updatedClassification.getModified()));
|
||||||
// TODO - resume old behaviour after attachment query is possible.
|
// TODO - resume old behaviour after attachment query is possible.
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,22 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
private static final Logger LOGGER =
|
private static final Logger LOGGER =
|
||||||
LoggerFactory.getLogger(TaskanaEngineTestConfiguration.class);
|
LoggerFactory.getLogger(TaskanaEngineTestConfiguration.class);
|
||||||
private static final int POOL_TIME_TO_WAIT = 50;
|
private static final int POOL_TIME_TO_WAIT = 50;
|
||||||
private static DataSource dataSource = null;
|
private static DataSource dataSource;
|
||||||
private static String schemaName = null;
|
private static String schemaName = null;
|
||||||
|
|
||||||
private TaskanaEngineTestConfiguration() {}
|
private TaskanaEngineTestConfiguration() {}
|
||||||
|
|
||||||
|
static {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the Datasource used for Junit test. If the file {user.home}/taskanaUnitTest.properties
|
* 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,
|
* is present, the Datasource is created according to the properties jdbcDriver, jdbcUrl,
|
||||||
|
@ -38,16 +49,6 @@ public final class TaskanaEngineTestConfiguration {
|
||||||
* @return dataSource for unit test
|
* @return dataSource for unit test
|
||||||
*/
|
*/
|
||||||
public static DataSource getDataSource() {
|
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;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,9 @@ class TaskServiceImplIntExplicitTest {
|
||||||
classificationService = taskanaEngine.getClassificationService();
|
classificationService = taskanaEngine.getClassificationService();
|
||||||
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
|
taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.EXPLICIT);
|
||||||
workbasketService = taskanaEngine.getWorkbasketService();
|
workbasketService = taskanaEngine.getWorkbasketService();
|
||||||
DbSchemaCreator creator =
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
new DbSchemaCreator(dataSource, dataSource.getConnection().getSchema());
|
new DbSchemaCreator(dataSource, connection.getSchema()).run();
|
||||||
creator.run();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
@ -4,17 +4,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -23,7 +17,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||||
import pro.taskana.TimeInterval;
|
|
||||||
import pro.taskana.Workbasket;
|
import pro.taskana.Workbasket;
|
||||||
import pro.taskana.WorkbasketAccessItem;
|
import pro.taskana.WorkbasketAccessItem;
|
||||||
import pro.taskana.WorkbasketService;
|
import pro.taskana.WorkbasketService;
|
||||||
|
@ -36,11 +29,9 @@ import pro.taskana.exceptions.InvalidWorkbasketException;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
|
import pro.taskana.exceptions.WorkbasketAlreadyExistException;
|
||||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
||||||
import pro.taskana.impl.TaskanaEngineProxyForTest;
|
|
||||||
import pro.taskana.impl.WorkbasketImpl;
|
import pro.taskana.impl.WorkbasketImpl;
|
||||||
import pro.taskana.impl.configuration.TaskanaEngineTestConfiguration;
|
import pro.taskana.impl.configuration.TaskanaEngineTestConfiguration;
|
||||||
import pro.taskana.impl.util.IdGenerator;
|
import pro.taskana.impl.util.IdGenerator;
|
||||||
import pro.taskana.mappings.WorkbasketMapper;
|
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
import pro.taskana.security.JaasExtension;
|
import pro.taskana.security.JaasExtension;
|
||||||
import pro.taskana.security.WithAccessId;
|
import pro.taskana.security.WithAccessId;
|
||||||
|
@ -208,35 +199,6 @@ class WorkbasketServiceImplIntAutocommitTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateModifiedTimestamps(
|
|
||||||
Workbasket basket2, Workbasket basket3, Workbasket basket4, Workbasket basket1)
|
|
||||||
throws NoSuchFieldException, IllegalAccessException {
|
|
||||||
// created and modified timestamps are set by WorkbasketServiceImpl to 'now' when the workbasket
|
|
||||||
// is created
|
|
||||||
// in order to create timestamps distict from the current time, we must use the mapper directly
|
|
||||||
// to bypass
|
|
||||||
// WorkbasketServiceImpl
|
|
||||||
TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest(taskanaEngine);
|
|
||||||
SqlSession session = engineProxy.getSqlSession();
|
|
||||||
WorkbasketMapper mapper = session.getMapper(WorkbasketMapper.class);
|
|
||||||
|
|
||||||
WorkbasketImpl wb1 = (WorkbasketImpl) basket1;
|
|
||||||
final WorkbasketImpl wb2 = (WorkbasketImpl) basket2;
|
|
||||||
final WorkbasketImpl wb3 = (WorkbasketImpl) basket3;
|
|
||||||
final WorkbasketImpl wb4 = (WorkbasketImpl) basket4;
|
|
||||||
|
|
||||||
engineProxy.openConnection();
|
|
||||||
wb1.setModified(now.minus(Duration.ofDays(10L)));
|
|
||||||
mapper.update(wb1);
|
|
||||||
wb2.setModified(now.minus(Duration.ofDays(15L)));
|
|
||||||
mapper.update(wb2);
|
|
||||||
wb3.setModified(now.minus(Duration.ofDays(20L)));
|
|
||||||
mapper.update(wb3);
|
|
||||||
wb4.setModified(now.minus(Duration.ofDays(30L)));
|
|
||||||
mapper.update(wb4);
|
|
||||||
engineProxy.returnConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createWorkbasketWithSecurity(
|
private void createWorkbasketWithSecurity(
|
||||||
Workbasket wb,
|
Workbasket wb,
|
||||||
String accessId,
|
String accessId,
|
||||||
|
@ -263,12 +225,4 @@ class WorkbasketServiceImplIntAutocommitTest {
|
||||||
wb.setType(type);
|
wb.setType(type);
|
||||||
return wb;
|
return wb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeInterval today() {
|
|
||||||
Instant begin =
|
|
||||||
LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant();
|
|
||||||
Instant end =
|
|
||||||
LocalDateTime.of(LocalDate.now(), LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
|
|
||||||
return new TimeInterval(begin, end);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ class TaskanaTransactionIntTest {
|
||||||
DomainNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException {
|
DomainNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException {
|
||||||
|
|
||||||
final TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
final TaskanaEngineImpl taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||||
Connection connection = dataSource.getConnection();
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
|
||||||
assertNotEquals(connection.getSchema(), "PUBLIC");
|
assertNotEquals(connection.getSchema(), "PUBLIC");
|
||||||
jdbcTemplate.execute("INSERT INTO CUSTOMDB.TEST VALUES ('1', 'test')");
|
jdbcTemplate.execute("INSERT INTO CUSTOMDB.TEST VALUES ('1', 'test')");
|
||||||
|
@ -162,6 +162,7 @@ class TaskanaTransactionIntTest {
|
||||||
result = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM CUSTOMDB.TEST", Integer.class);
|
result = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM CUSTOMDB.TEST", Integer.class);
|
||||||
assertEquals(2, result);
|
assertEquals(2, result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWorkbasketCleanupJobTransaction() {
|
void testWorkbasketCleanupJobTransaction() {
|
||||||
|
|
|
@ -4,6 +4,8 @@ import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.UUID;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
@ -35,13 +37,13 @@ public class TransactionTest {
|
||||||
@Before
|
@Before
|
||||||
public void init() throws SQLException, ClassNotFoundException {
|
public void init() throws SQLException, ClassNotFoundException {
|
||||||
Class.forName("org.h2.Driver");
|
Class.forName("org.h2.Driver");
|
||||||
try (Connection conn =
|
try (Connection conn = getConnection()) {
|
||||||
DriverManager.getConnection(
|
try (Statement statement = conn.createStatement()) {
|
||||||
"jdbc:h2:mem:task-engine;IGNORECASE=TRUE;LOCK_MODE=0", "SA", "SA")) {
|
statement.executeUpdate("DELETE FROM TASK WHERE 1=1");
|
||||||
conn.createStatement().executeUpdate("DELETE FROM TASK WHERE 1=1");
|
|
||||||
conn.commit();
|
conn.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@ -49,15 +51,15 @@ public class TransactionTest {
|
||||||
restTemplate.getForEntity("http://127.0.0.1:" + port + "/test", String.class);
|
restTemplate.getForEntity("http://127.0.0.1:" + port + "/test", String.class);
|
||||||
|
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
try (Connection conn =
|
try (Connection conn = getConnection()) {
|
||||||
DriverManager.getConnection(
|
try (Statement statement = conn.createStatement()) {
|
||||||
"jdbc:h2:mem:task-engine;IGNORECASE=TRUE;LOCK_MODE=0", "SA", "SA")) {
|
ResultSet rs = statement.executeQuery("SELECT ID FROM TASK");
|
||||||
ResultSet rs = conn.createStatement().executeQuery("SELECT ID FROM TASK");
|
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
resultCount++;
|
resultCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertEquals(1, resultCount);
|
Assert.assertEquals(1, resultCount);
|
||||||
}
|
}
|
||||||
|
@ -68,10 +70,9 @@ public class TransactionTest {
|
||||||
restTemplate.postForEntity("http://127.0.0.1:" + port + "/test", null, String.class);
|
restTemplate.postForEntity("http://127.0.0.1:" + port + "/test", null, String.class);
|
||||||
|
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
try (Connection conn =
|
try (Connection conn = getConnection()) {
|
||||||
DriverManager.getConnection(
|
try (Statement statement = conn.createStatement()) {
|
||||||
"jdbc:h2:mem:task-engine;IGNORECASE=TRUE;LOCK_MODE=0", "SA", "SA")) {
|
ResultSet rs = statement.executeQuery("SELECT ID FROM TASK");
|
||||||
ResultSet rs = conn.createStatement().executeQuery("SELECT ID FROM TASK");
|
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
resultCount++;
|
resultCount++;
|
||||||
|
@ -81,3 +82,9 @@ public class TransactionTest {
|
||||||
Assert.assertEquals(0, resultCount);
|
Assert.assertEquals(0, resultCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws SQLException {
|
||||||
|
return DriverManager.getConnection(
|
||||||
|
"jdbc:h2:mem:task-engine;IGNORECASE=TRUE;LOCK_MODE=0", "SA", UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
@Component
|
@Component
|
||||||
public class RestHelper {
|
public class RestHelper {
|
||||||
|
|
||||||
public static RestTemplate template = getRestTemplate();
|
|
||||||
@Autowired Environment environment;
|
@Autowired Environment environment;
|
||||||
|
|
||||||
public String toUrl(String relativeUrl, Object... uriVariables) {
|
public String toUrl(String relativeUrl, Object... uriVariables) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
@Component
|
@Component
|
||||||
public class RestHelper {
|
public class RestHelper {
|
||||||
|
|
||||||
public static RestTemplate template = getRestTemplate();
|
public static final RestTemplate template = getRestTemplate();
|
||||||
@Autowired Environment environment;
|
@Autowired Environment environment;
|
||||||
|
|
||||||
public String toUrl(String relativeUrl, Object... uriVariables) {
|
public String toUrl(String relativeUrl, Object... uriVariables) {
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.util.Locale;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import org.junit.Assert;
|
import org.junit.Assume;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import pro.taskana.TaskanaSpringBootTest;
|
import pro.taskana.TaskanaSpringBootTest;
|
||||||
import pro.taskana.configuration.DB;
|
import pro.taskana.configuration.DB;
|
||||||
import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
|
import pro.taskana.configuration.SpringTaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.SystemException;
|
|
||||||
import pro.taskana.sampledata.SampleDataGenerator;
|
import pro.taskana.sampledata.SampleDataGenerator;
|
||||||
|
|
||||||
/** Test that the schema name can be customized. */
|
/** Test that the schema name can be customized. */
|
||||||
|
@ -24,51 +25,61 @@ class TestSchemaNameCustomizable {
|
||||||
|
|
||||||
@Autowired private DataSource dataSource;
|
@Autowired private DataSource dataSource;
|
||||||
|
|
||||||
void resetDb() {
|
void resetDb() throws SQLException {
|
||||||
SampleDataGenerator sampleDataGenerator;
|
SampleDataGenerator sampleDataGenerator;
|
||||||
try {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
if (DB.POSTGRESS.dbProductname.equals(
|
String databaseProductName = connection.getMetaData().getDatabaseProductName();
|
||||||
dataSource.getConnection().getMetaData().getDatabaseProductName())) {
|
isPostgres = DB.POSTGRESS.dbProductname.equals(databaseProductName);
|
||||||
isPostgres = true;
|
|
||||||
schemaName = schemaName.toLowerCase();
|
if (isPostgres) {
|
||||||
|
schemaName = schemaName.toLowerCase(Locale.ENGLISH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
new SpringTaskanaEngineConfiguration(dataSource, true, true, schemaName);
|
new SpringTaskanaEngineConfiguration(dataSource, true, true, schemaName);
|
||||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||||
sampleDataGenerator.generateSampleData();
|
sampleDataGenerator.generateSampleData();
|
||||||
} catch (SQLException e) {
|
}
|
||||||
throw new SystemException("tried to reset DB and caught Exception " + e, e);
|
|
||||||
|
@Test
|
||||||
|
void checkCustomSchemaNameIsDefined_Postgres() throws SQLException {
|
||||||
|
resetDb();
|
||||||
|
Assume.assumeTrue("Test only executed with Postgres database", isPostgres);
|
||||||
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
|
||||||
|
try (PreparedStatement preparedStatement =
|
||||||
|
connection.prepareStatement(
|
||||||
|
"SELECT tablename FROM pg_catalog.pg_tables where schemaname = ?")) {
|
||||||
|
preparedStatement.setString(1, schemaName);
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
boolean tablefound = false;
|
||||||
|
while (rs.next() && !tablefound) {
|
||||||
|
String tableName = rs.getString("tablename");
|
||||||
|
tablefound = tableName.equals("workbasket");
|
||||||
|
}
|
||||||
|
Assertions.assertTrue(tablefound, "Table workbasket should be there ...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void chekCustomSchemaNameIsDefined() {
|
void checkCustomSchemaNameIsDefined_OtherDb() throws SQLException {
|
||||||
resetDb();
|
resetDb();
|
||||||
ResultSet rs;
|
Assume.assumeFalse("Test only executed if NOT Postgres", isPostgres);
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
if (isPostgres) {
|
|
||||||
rs =
|
|
||||||
stmt.executeQuery(
|
|
||||||
"SELECT * FROM pg_catalog.pg_tables where schemaname = '"
|
|
||||||
+ schemaName.toLowerCase()
|
|
||||||
+ "'");
|
|
||||||
|
|
||||||
} else {
|
try (PreparedStatement preparedStatement =
|
||||||
rs =
|
connection.prepareStatement(
|
||||||
stmt.executeQuery(
|
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?")) {
|
||||||
"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"
|
preparedStatement.setString(1, schemaName);
|
||||||
+ schemaName
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
+ "'");
|
boolean tablefound = false;
|
||||||
|
while (rs.next() && !tablefound) {
|
||||||
|
String tableName = rs.getString("TABLE_NAME");
|
||||||
|
tablefound = tableName.equals("WORKBASKET");
|
||||||
|
}
|
||||||
|
Assertions.assertTrue(tablefound, "Table WORKBASKET should be there ...");
|
||||||
}
|
}
|
||||||
while (rs.next()) {
|
|
||||||
String tableName = rs.getString(isPostgres ? "tablename" : "TABLE_NAME");
|
|
||||||
if (tableName.equals(isPostgres ? "workbasket" : "WORKBASKET")) {
|
|
||||||
Assert.assertEquals(tableName, isPostgres ? "workbasket" : "WORKBASKET");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue