diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 0024b4b84..40a8bf853 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -273,10 +273,14 @@ jobs: database: POSTGRES - module: taskana-test-api database: DB2 + - module: taskana-simplehistory-provider + database: DB2 + - module: taskana-simplehistory-provider + database: POSTGRES - module: taskana-rest-spring-example-boot database: DB2 - module: taskana-rest-spring-example-wildfly - database: POSTGRES_10 + database: POSTGRES steps: - name: Git checkout uses: actions/checkout@v3 diff --git a/lib/taskana-core/src/test/resources/container-license-acceptance.txt b/common/taskana-common-test/src/main/resources/container-license-acceptance.txt similarity index 100% rename from lib/taskana-core/src/test/resources/container-license-acceptance.txt rename to common/taskana-common-test/src/main/resources/container-license-acceptance.txt diff --git a/common/taskana-common/src/main/resources/sql/postgres/taskana-schema-postgres.sql b/common/taskana-common/src/main/resources/sql/postgres/taskana-schema-postgres.sql index 8b3d42b48..370aa2a94 100644 --- a/common/taskana-common/src/main/resources/sql/postgres/taskana-schema-postgres.sql +++ b/common/taskana-common/src/main/resources/sql/postgres/taskana-schema-postgres.sql @@ -351,9 +351,6 @@ CREATE SEQUENCE SCHEDULED_JOB_SEQ START WITH 1 INCREMENT BY 1 CACHE 10; -SET -search_path TO taskana; - CREATE INDEX IDX_CLASSIFICATION_ID ON CLASSIFICATION (ID ASC, CUSTOM_8, CUSTOM_7, CUSTOM_6, CUSTOM_5, CUSTOM_4, CUSTOM_3, CUSTOM_2, CUSTOM_1, APPLICATION_ENTRY_POINT, diff --git a/docker-databases/prepare_db.sh b/docker-databases/prepare_db.sh index 9cb208f0c..0f776ba44 100755 --- a/docker-databases/prepare_db.sh +++ b/docker-databases/prepare_db.sh @@ -10,11 +10,11 @@ export TOP_PID=$$ #H #H %FILE% #H -#H downloads and starts docker image for taskana unit tests. +#H downloads and starts docker image for TASKANA unit tests. #H #H %FILE% stop [database] #H -#H stops the database and removes 'taskanaUnitTest.properties'. +#H stops the database. #H If no database was provided all databases are stopped. #H #H database: diff --git a/history/taskana-simplehistory-provider/pom.xml b/history/taskana-simplehistory-provider/pom.xml index f66ba1df0..b7c5d462e 100644 --- a/history/taskana-simplehistory-provider/pom.xml +++ b/history/taskana-simplehistory-provider/pom.xml @@ -79,5 +79,18 @@ postgresql test + + com.ibm.db2.jcc + db2jcc4 + ${version.db2} + + + + + novatec public + novatec-repository + https://repository.novatec-gmbh.de/content/repositories/novatec/ + + diff --git a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java index 741ad2746..cd4b0d6a2 100644 --- a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java +++ b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/WorkbasketHistoryQueryImpl.java @@ -29,14 +29,13 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { private static final String SQL_EXCEPTION_MESSAGE = "Method openConnection() could not open a connection to the database."; - private TaskanaHistoryEngineImpl taskanaHistoryEngine; + private final TaskanaHistoryEngineImpl taskanaHistoryEngine; + private final List orderColumns; @SuppressWarnings("unused") private WorkbasketHistoryQueryColumnName columnName; private List orderBy; - private List orderColumns; - private String[] idIn; private String[] workbasketIdIn; private String[] eventTypeIn; @@ -413,6 +412,11 @@ public class WorkbasketHistoryQueryImpl implements WorkbasketHistoryQuery { return addOrderCriteria("USER_ID", sortDirection); } + @Override + public WorkbasketHistoryQuery orderById(SortDirection sortDirection) { + return addOrderCriteria("ID", sortDirection); + } + @Override public WorkbasketHistoryQuery orderByDomain(SortDirection sortDirection) { return addOrderCriteria("DOMAIN", sortDirection); diff --git a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java index 23af7e921..3083dbb4f 100644 --- a/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java +++ b/history/taskana-simplehistory-provider/src/main/java/pro/taskana/simplehistory/impl/workbasket/WorkbasketHistoryQuery.java @@ -272,6 +272,16 @@ public interface WorkbasketHistoryQuery */ WorkbasketHistoryQuery orderByUserId(SortDirection sortDirection); + /** + * Sort the query result by {@linkplain WorkbasketHistoryEvent#getId() id} of the {@linkplain + * WorkbasketHistoryEvent}. + * + * @param sortDirection Determines whether the result is sorted in ascending or descending order. + * If sortDirection is null, the result is sorted in ascending order + * @return the query + */ + WorkbasketHistoryQuery orderById(SortDirection sortDirection); + /** * Sort the query result by Domain. * diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/AbstractAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/AbstractAccTest.java index 2b5002fbb..7972a8b19 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/AbstractAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/AbstractAccTest.java @@ -1,19 +1,10 @@ package acceptance; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Field; -import java.util.Objects; -import java.util.Properties; import javax.sql.DataSource; -import org.apache.ibatis.datasource.pooled.PooledDataSource; import org.apache.ibatis.session.SqlSessionManager; import org.junit.jupiter.api.BeforeAll; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.platform.commons.JUnitException; import pro.taskana.TaskanaEngineConfiguration; import pro.taskana.common.api.TaskanaEngine; @@ -21,6 +12,7 @@ import pro.taskana.common.api.TaskanaEngine.ConnectionManagementMode; import pro.taskana.common.internal.JobMapper; import pro.taskana.common.internal.TaskanaEngineImpl; import pro.taskana.common.internal.util.IdGenerator; +import pro.taskana.common.test.config.DataSourceGenerator; import pro.taskana.sampledata.SampleDataGenerator; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; import pro.taskana.simplehistory.impl.TaskanaHistoryEngineImpl; @@ -35,29 +27,10 @@ import pro.taskana.task.internal.models.ObjectReferenceImpl; /** Set up database for tests. */ public abstract class AbstractAccTest { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAccTest.class); - private static final String USER_HOME_DIRECTORY = System.getProperty("user.home"); - private static final int POOL_TIME_TO_WAIT = 50; - private static final DataSource DATA_SOURCE; protected static TaskanaEngineConfiguration taskanaEngineConfiguration; protected static TaskanaHistoryEngineImpl taskanaHistoryEngine; protected static TaskanaEngine taskanaEngine; private static SimpleHistoryServiceImpl historyService; - private static String schemaName; - - static { - String propertiesFileName = USER_HOME_DIRECTORY + "/taskanaUnitTest.properties"; - File f = new File(propertiesFileName); - if (f.exists() && !f.isDirectory()) { - DATA_SOURCE = createDataSourceFromProperties(propertiesFileName); - } else { - DATA_SOURCE = createDefaultDataSource(); - } - } - - protected AbstractAccTest() { - // not called - } /** * create taskHistoryEvent object. @@ -109,13 +82,15 @@ public abstract class AbstractAccTest { } protected static void resetDb(String schemaName) throws Exception { - DataSource dataSource = getDataSource(); + DataSource dataSource = DataSourceGenerator.getDataSource(); taskanaEngineConfiguration = new TaskanaEngineConfiguration( dataSource, false, - schemaName != null && !schemaName.isEmpty() ? schemaName : getSchemaName()); + schemaName != null && !schemaName.isEmpty() + ? schemaName + : DataSourceGenerator.getSchemaName()); taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine(ConnectionManagementMode.AUTOCOMMIT); taskanaHistoryEngine = TaskanaHistoryEngineImpl.createTaskanaEngine(taskanaEngine); @@ -123,41 +98,12 @@ public abstract class AbstractAccTest { historyService.initialize( taskanaEngineConfiguration.buildTaskanaEngine(ConnectionManagementMode.AUTOCOMMIT)); - SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, getSchemaName()); + SampleDataGenerator sampleDataGenerator = + new SampleDataGenerator(dataSource, taskanaEngineConfiguration.getSchemaName()); sampleDataGenerator.clearDb(); sampleDataGenerator.generateTestData(); } - protected static DataSource getDataSource() { - if (DATA_SOURCE == null) { - throw new RuntimeException("Datasource should be already initialized"); - } - return DATA_SOURCE; - } - - /** - * returns the SchemaName used for Junit test. If the file {user.home}/taskanaUnitTest.properties - * is present, the SchemaName is created according to the property schemaName. 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 - * schemaName=TASKANA If any of these properties is missing, or the file doesn't exist, the - * default schemaName TASKANA is created used. - * - * @return String for unit test - */ - protected static String getSchemaName() { - if (schemaName == null) { - String propertiesFileName = USER_HOME_DIRECTORY + "/taskanaUnitTest.properties"; - File f = new File(propertiesFileName); - if (f.exists() && !f.isDirectory()) { - schemaName = getSchemaNameFromPropertiesObject(propertiesFileName); - } else { - schemaName = "TASKANA"; - } - } - return schemaName; - } - protected static SimpleHistoryServiceImpl getHistoryService() { return historyService; } @@ -195,156 +141,38 @@ public abstract class AbstractAccTest { } protected static WorkbasketHistoryEventMapper getWorkbasketHistoryEventMapper() { - - SqlSessionManager manager = null; - - Field sessionManager; try { - sessionManager = TaskanaHistoryEngineImpl.class.getDeclaredField("sessionManager"); - + Field sessionManager = TaskanaHistoryEngineImpl.class.getDeclaredField("sessionManager"); sessionManager.setAccessible(true); - - manager = (SqlSessionManager) sessionManager.get(taskanaHistoryEngine); - + SqlSessionManager manager = (SqlSessionManager) sessionManager.get(taskanaHistoryEngine); + return manager.getMapper(WorkbasketHistoryEventMapper.class); } catch (Exception e) { - LOGGER.warn("Caught unexpected exception ", e); + throw new JUnitException( + String.format( + "Could not extract %s from %s", + WorkbasketHistoryEventMapper.class, TaskanaHistoryEngineImpl.class)); } - return manager.getMapper(WorkbasketHistoryEventMapper.class); } protected static ClassificationHistoryEventMapper getClassificationHistoryEventMapper() { - - SqlSessionManager manager = null; - - Field sessionManager; try { - sessionManager = TaskanaHistoryEngineImpl.class.getDeclaredField("sessionManager"); + Field sessionManager = TaskanaHistoryEngineImpl.class.getDeclaredField("sessionManager"); sessionManager.setAccessible(true); - manager = (SqlSessionManager) sessionManager.get(taskanaHistoryEngine); + SqlSessionManager manager = (SqlSessionManager) sessionManager.get(taskanaHistoryEngine); + return manager.getMapper(ClassificationHistoryEventMapper.class); } catch (Exception e) { - LOGGER.warn("Caught unexpected exception ", e); + throw new JUnitException( + String.format( + "Could not extract %s from %s", + ClassificationHistoryEventMapper.class, TaskanaHistoryEngineImpl.class)); } - return manager.getMapper(ClassificationHistoryEventMapper.class); } @BeforeAll static void setupTest() throws Exception { resetDb(null); } - - /** - * create Default DataSource for in-memory database. - * - * @return the TASKANA default datasource. - */ - private static DataSource createDefaultDataSource() { - - String jdbcDriver = "org.h2.Driver"; - String jdbcUrl = "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0"; - String dbUserName = "sa"; - String dbPassword = "sa"; - PooledDataSource ds = - new PooledDataSource( - Thread.currentThread().getContextClassLoader(), - jdbcDriver, - jdbcUrl, - dbUserName, - dbPassword); - ds.setPoolTimeToWait(POOL_TIME_TO_WAIT); - ds.forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly - - return ds; - } - - /** - * create data source from properties file. - * - * @param propertiesFileName the name of the properties file. - * @return the datasource constructed from the information in the properties file. - */ - private static DataSource createDataSourceFromProperties(String propertiesFileName) { - DataSource ds = null; - try (InputStream input = new FileInputStream(propertiesFileName)) { - Properties prop = new Properties(); - prop.load(input); - boolean propertiesFileIsComplete = true; - String warningMessage = ""; - String jdbcDriver = prop.getProperty("jdbcDriver"); - if (jdbcDriver == null || jdbcDriver.length() == 0) { - propertiesFileIsComplete = false; - warningMessage += ", jdbcDriver property missing"; - } - String jdbcUrl = prop.getProperty("jdbcUrl"); - if (jdbcUrl == null || jdbcUrl.length() == 0) { - propertiesFileIsComplete = false; - warningMessage += ", jdbcUrl property missing"; - } - String dbUserName = prop.getProperty("dbUserName"); - if (dbUserName == null || dbUserName.length() == 0) { - propertiesFileIsComplete = false; - warningMessage += ", dbUserName property missing"; - } - String dbPassword = prop.getProperty("dbPassword"); - if (dbPassword == null || dbPassword.length() == 0) { - propertiesFileIsComplete = false; - warningMessage += ", dbPassword property missing"; - } - - if (propertiesFileIsComplete) { - ds = - new PooledDataSource( - Thread.currentThread().getContextClassLoader(), - jdbcDriver, - jdbcUrl, - dbUserName, - dbPassword); - ((PooledDataSource) ds) - .forceCloseAll(); // otherwise the MyBatis pool is not initialized correctly - } else { - LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage); - LOGGER.warn("Using default Datasource for Test"); - } - - } catch (IOException e) { - LOGGER.warn("createDataSourceFromProperties caught Exception " + e); - LOGGER.warn("Using default Datasource for Test"); - } - if (Objects.isNull(ds)) { - ds = createDefaultDataSource(); - } - return ds; - } - - private static String getSchemaNameFromPropertiesObject(String propertiesFileName) { - String schemaName = "TASKANA"; - try (InputStream input = new FileInputStream(propertiesFileName)) { - Properties prop = new Properties(); - prop.load(input); - boolean propertiesFileIsComplete = true; - String warningMessage = ""; - schemaName = prop.getProperty("schemaName"); - if (schemaName == null || schemaName.length() == 0) { - propertiesFileIsComplete = false; - warningMessage += ", schemaName property missing"; - } - - if (!propertiesFileIsComplete) { - LOGGER.warn("propertiesFile " + propertiesFileName + " is incomplete" + warningMessage); - LOGGER.warn("Using default Datasource for Test"); - schemaName = "TASKANA"; - } - - } catch (FileNotFoundException e) { - LOGGER.warn("getSchemaNameFromPropertiesObject caught Exception " + e); - LOGGER.warn("Using default schemaName for Test"); - } catch (IOException e) { - LOGGER.warn("createDataSourceFromProperties caught Exception " + e); - LOGGER.warn("Using default Datasource for Test"); - } - - return schemaName; - } } diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/events/task/CreateHistoryEventOnTaskUpdateAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/events/task/CreateHistoryEventOnTaskUpdateAccTest.java index 2515c9172..b0421953d 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/events/task/CreateHistoryEventOnTaskUpdateAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/events/task/CreateHistoryEventOnTaskUpdateAccTest.java @@ -3,15 +3,15 @@ package acceptance.events.task; import static org.assertj.core.api.Assertions.assertThat; import acceptance.AbstractAccTest; +import java.time.Instant; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import pro.taskana.common.api.TimeInterval; import pro.taskana.common.test.security.JaasExtension; import pro.taskana.common.test.security.WithAccessId; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; -import pro.taskana.simplehistory.impl.TaskHistoryQueryImpl; -import pro.taskana.simplehistory.impl.task.TaskHistoryQueryMapper; import pro.taskana.spi.history.api.events.task.TaskHistoryEvent; import pro.taskana.spi.history.api.events.task.TaskHistoryEventType; import pro.taskana.task.api.TaskService; @@ -26,28 +26,21 @@ class CreateHistoryEventOnTaskUpdateAccTest extends AbstractAccTest { @Test @WithAccessId(user = "admin") void should_CreateUpdatedHistoryEvent_When_TaskIsCreated() throws Exception { - final String taskId = "TKI:000000000000000000000000000000000000"; - TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper(); - - List events = - taskHistoryQueryMapper.queryHistoryEvents( - (TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId)); - - assertThat(events).hasSize(3); + Instant before = Instant.now(); Task task = taskService.getTask(taskId); task.setName("someUpdatedName"); taskService.updateTask(task); + List events = + historyService + .createTaskHistoryQuery() + .taskIdIn(taskId) + .createdWithin(new TimeInterval(before, null)) + .list(); - events = - taskHistoryQueryMapper.queryHistoryEvents( - (TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId)); - - assertThat(events).hasSize(4); - - String eventType = events.get(0).getEventType(); - - assertThat(eventType).isEqualTo(TaskHistoryEventType.UPDATED.getName()); + assertThat(events) + .extracting(TaskHistoryEvent::getEventType) + .containsExactly(TaskHistoryEventType.UPDATED.getName()); } } diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java index 5830e0bc6..61f5d4e45 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/jobs/HistoryCleanupJobAccTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.function.ThrowingConsumer; import pro.taskana.classification.internal.jobs.ClassificationChangedJob; import pro.taskana.common.api.ScheduledJob; import pro.taskana.common.internal.util.Pair; +import pro.taskana.common.test.config.DataSourceGenerator; import pro.taskana.common.test.security.JaasExtension; import pro.taskana.common.test.security.WithAccessId; import pro.taskana.simplehistory.impl.jobs.HistoryCleanupJob; @@ -32,7 +33,7 @@ class HistoryCleanupJobAccTest extends AbstractAccTest { @BeforeEach void before() throws Exception { - resetDb(getSchemaName()); + resetDb(DataSourceGenerator.getSchemaName()); } @Test diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryClassificationHistoryAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryClassificationHistoryAccTest.java index 76d99e0ab..cf61f01ac 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryClassificationHistoryAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryClassificationHistoryAccTest.java @@ -81,12 +81,12 @@ class QueryClassificationHistoryAccTest extends AbstractAccTest { assertThat(offsetAndLimitResult).hasSize(2); assertThat(offsetAndLimitResult.get(0).getUserId()) - .isNotEqualTo(regularResult.get(0).getUserId()); - assertThat(offsetAndLimitResult.get(0).getUserId()).isEqualTo(regularResult.get(1).getUserId()); + .isNotEqualTo(regularResult.get(0).getUserId()) + .isEqualTo(regularResult.get(1).getUserId()); } @Test - void should_ReturnEmptyList_When_ProvidingWrongContraints() { + void should_ReturnEmptyList_When_ProvidingWrongConstraints() { List result = historyService.createClassificationHistoryQuery().list(1, 1000); assertThat(result).hasSize(10); @@ -120,7 +120,7 @@ class QueryClassificationHistoryAccTest extends AbstractAccTest { ClassificationHistoryQuery query = getHistoryService().createClassificationHistoryQuery().userIdIn("peter"); - assertThatThrownBy(() -> query.single()).isInstanceOf(TooManyResultsException.class); + assertThatThrownBy(query::single).isInstanceOf(TooManyResultsException.class); } @Test diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryTaskHistoryAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryTaskHistoryAccTest.java index 8487ae789..c60515122 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryTaskHistoryAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryTaskHistoryAccTest.java @@ -77,8 +77,8 @@ class QueryTaskHistoryAccTest extends AbstractAccTest { assertThat(offsetAndLimitResult).hasSize(2); assertThat(offsetAndLimitResult.get(0).getUserId()) - .isNotEqualTo(regularResult.get(0).getUserId()); - assertThat(offsetAndLimitResult.get(0).getUserId()).isEqualTo(regularResult.get(1).getUserId()); + .isNotEqualTo(regularResult.get(0).getUserId()) + .isEqualTo(regularResult.get(1).getUserId()); } @Test @@ -276,10 +276,7 @@ class QueryTaskHistoryAccTest extends AbstractAccTest { assertThat(returnValues).hasSize(14); returnValues = - getHistoryService() - .createTaskHistoryQuery() - .parentBusinessProcessIdLike("BPI:01", " %") - .list(); + getHistoryService().createTaskHistoryQuery().parentBusinessProcessIdLike("BPI:01%").list(); assertThat(returnValues).hasSize(7); returnValues = diff --git a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java index 6e58caa64..a29f481cf 100644 --- a/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/acceptance/query/QueryWorkbasketHistoryAccTest.java @@ -20,15 +20,10 @@ import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEvent; import pro.taskana.spi.history.api.events.workbasket.WorkbasketHistoryEventType; import pro.taskana.workbasket.api.WorkbasketCustomField; -/** Test for Workbasket History queries. */ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { private final SimpleHistoryServiceImpl historyService = getHistoryService(); - public QueryWorkbasketHistoryAccTest() { - super(); - } - @Test void should_ConfirmEquality_When_UsingListValuesAscendingAndDescending() { List defaultList = @@ -53,7 +48,6 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { @Test void should_ReturnHistoryEvents_For_ComplexQuery() { - WorkbasketHistoryQuery query = historyService .createWorkbasketHistoryQuery() @@ -82,12 +76,12 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { assertThat(offsetAndLimitResult).hasSize(2); assertThat(offsetAndLimitResult.get(0).getUserId()) - .isNotEqualTo(regularResult.get(0).getUserId()); - assertThat(offsetAndLimitResult.get(0).getUserId()).isEqualTo(regularResult.get(1).getUserId()); + .isNotEqualTo(regularResult.get(0).getUserId()) + .isEqualTo(regularResult.get(1).getUserId()); } @Test - void should_ReturnEmptyList_When_ProvidingWrongContraints() { + void should_ReturnEmptyList_When_ProvidingWrongConstraints() { List result = historyService.createWorkbasketHistoryQuery().list(1, 1000); assertThat(result).hasSize(9); @@ -117,11 +111,10 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { @Test void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() { - WorkbasketHistoryQuery query = getHistoryService().createWorkbasketHistoryQuery().userIdIn("peter"); - assertThatThrownBy(() -> query.single()).isInstanceOf(TooManyResultsException.class); + assertThatThrownBy(query::single).isInstanceOf(TooManyResultsException.class); } @Test @@ -277,6 +270,10 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { historyService .createWorkbasketHistoryQuery() .orderByCustomAttribute(1, SortDirection.ASCENDING) + // values of custom1 do not differ and are larger than 3 (n=5). + // Therefore, in order to guarantee the sort order, + // we have to define a secondary (unique) sort option + .orderById(SortDirection.ASCENDING) .listPage(0, 3); assertThat(results) .extracting(WorkbasketHistoryEvent::getId) @@ -289,6 +286,10 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { historyService .createWorkbasketHistoryQuery() .orderByCustomAttribute(2, SortDirection.ASCENDING) + // values of custom1 do not differ and are larger than 3 (n=5). + // Therefore, in order to guarantee the sort order, + // we have to define a secondary (unique) sort option + .orderById(SortDirection.ASCENDING) .listPage(0, 3); assertThat(results) .extracting(WorkbasketHistoryEvent::getId) @@ -301,6 +302,10 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { historyService .createWorkbasketHistoryQuery() .orderByCustomAttribute(3, SortDirection.ASCENDING) + // values of custom1 do not differ and are larger than 3 (n=5). + // Therefore, in order to guarantee the sort order, + // we have to define a secondary (unique) sort option + .orderById(SortDirection.ASCENDING) .listPage(0, 3); assertThat(results) .extracting(WorkbasketHistoryEvent::getId) @@ -313,6 +318,10 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { historyService .createWorkbasketHistoryQuery() .orderByCustomAttribute(4, SortDirection.ASCENDING) + // values of custom1 do not differ and are larger than 3 (n=5). + // Therefore, in order to guarantee the sort order, + // we have to define a secondary (unique) sort option + .orderById(SortDirection.ASCENDING) .listPage(0, 3); assertThat(results) .extracting(WorkbasketHistoryEvent::getId) @@ -324,7 +333,6 @@ class QueryWorkbasketHistoryAccTest extends AbstractAccTest { @Test void should_ReturnHistoryEvents_For_DifferentLikeAttributes() { - List returnValues = historyService .createWorkbasketHistoryQuery() diff --git a/history/taskana-simplehistory-provider/src/test/java/configuration/TaskanaEngineConfigurationTest.java b/history/taskana-simplehistory-provider/src/test/java/configuration/TaskanaEngineConfigurationTest.java index d7c9855db..f60467d3a 100644 --- a/history/taskana-simplehistory-provider/src/test/java/configuration/TaskanaEngineConfigurationTest.java +++ b/history/taskana-simplehistory-provider/src/test/java/configuration/TaskanaEngineConfigurationTest.java @@ -8,15 +8,16 @@ import org.junit.jupiter.api.Test; import pro.taskana.TaskanaEngineConfiguration; import pro.taskana.common.api.TaskanaEngine; +import pro.taskana.common.test.config.DataSourceGenerator; /** Unit Test for TaskanaEngineConfigurationTest. */ class TaskanaEngineConfigurationTest extends AbstractAccTest { @Test void testCreateTaskanaEngine() throws Exception { - DataSource ds = getDataSource(); + DataSource ds = DataSourceGenerator.getDataSource(); TaskanaEngineConfiguration taskEngineConfiguration = - new TaskanaEngineConfiguration(ds, false, false, getSchemaName()); + new TaskanaEngineConfiguration(ds, false, false, DataSourceGenerator.getSchemaName()); TaskanaEngine te = taskEngineConfiguration.buildTaskanaEngine();