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