TSK-1735: replaced taskanaUnitTest.properties with testcontainers
This commit is contained in:
parent
fb4234b6f1
commit
9da7304bca
|
@ -274,15 +274,13 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: ${{ env.ARTIFACTS_TASKANA_JARS_NAME }}
|
name: ${{ env.ARTIFACTS_TASKANA_JARS_NAME }}
|
||||||
path: ${{ env.ARTIFACTS_TASKANA_JARS_PATH }}
|
path: ${{ env.ARTIFACTS_TASKANA_JARS_PATH }}
|
||||||
- name: Prepare database
|
|
||||||
run: docker-databases/prepare_db.sh ${{ matrix.database }}
|
|
||||||
- name: Generate JavaDoc for Rest Documentation
|
- name: Generate JavaDoc for Rest Documentation
|
||||||
if: matrix.module == 'taskana-simplehistory-rest-spring'
|
if: matrix.module == 'taskana-simplehistory-rest-spring'
|
||||||
run: ./mvnw -B validate -pl :taskana-rest-spring
|
run: ./mvnw -B validate -pl :taskana-rest-spring
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./mvnw -B verify -pl :${{matrix.module}} -Dcheckstyle.skip
|
run: ./mvnw -B verify -pl :${{matrix.module}} -Dcheckstyle.skip
|
||||||
env:
|
env:
|
||||||
db.type: ${{ matrix.database }}
|
DB: ${{ matrix.database }}
|
||||||
- name: Upload JaCoCo Report
|
- name: Upload JaCoCo Report
|
||||||
if: matrix.database == 'H2'
|
if: matrix.database == 'H2'
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All in taskana-core DB2" type="JUnit" factoryName="JUnit" folderName="lib">
|
||||||
|
<module name="taskana-core" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<envs>
|
||||||
|
<env name="DB" value="DB2" />
|
||||||
|
</envs>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,15 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="All in taskana-core POSTGRES" type="JUnit" factoryName="JUnit" folderName="lib">
|
||||||
|
<module name="taskana-core" />
|
||||||
|
<option name="PACKAGE_NAME" value="" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<envs>
|
||||||
|
<env name="DB" value="POSTGRES" />
|
||||||
|
</envs>
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Run ArchitectureTest" type="JUnit" factoryName="JUnit" folderName="lib">
|
||||||
|
<module name="taskana-core" />
|
||||||
|
<extension name="coverage">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="pro.taskana.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<option name="PACKAGE_NAME" value="acceptance" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="acceptance.ArchitectureTest" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -106,6 +106,28 @@
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>db2</artifactId>
|
||||||
|
<version>${version.testcontainers}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>${version.testcontainers}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- TEST DEPENDENCIES -->
|
<!-- TEST DEPENDENCIES -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package testapi.util;
|
package pro.taskana.common.test;
|
||||||
|
|
||||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package pro.taskana.common.test.config;
|
package pro.taskana.common.test.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.Optional;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
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;
|
||||||
import org.slf4j.Logger;
|
import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
import pro.taskana.common.internal.configuration.DB;
|
||||||
|
import pro.taskana.common.test.DockerContainerCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataSourceGenerator provides the proper {@linkplain DataSource} for all Integration tests.
|
* The DataSourceGenerator provides the proper {@linkplain DataSource} for all Integration tests.
|
||||||
|
@ -23,22 +21,22 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public final class DataSourceGenerator {
|
public final class DataSourceGenerator {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceGenerator.class);
|
|
||||||
private static final DataSource DATA_SOURCE;
|
private static final DataSource DATA_SOURCE;
|
||||||
private static final String SCHEMA_NAME;
|
private static final String SCHEMA_NAME;
|
||||||
|
|
||||||
private static final String DEFAULT_SCHEMA_NAME = "TASKANA";
|
|
||||||
private static final int POOL_TIME_TO_WAIT = 50;
|
private static final int POOL_TIME_TO_WAIT = 50;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String propertiesFileName = System.getProperty("user.home") + "/taskanaUnitTest.properties";
|
DB db = retrieveDatabaseFromEnv();
|
||||||
File f = new File(propertiesFileName);
|
Optional<JdbcDatabaseContainer<?>> dockerContainer =
|
||||||
if (f.exists() && !f.isDirectory()) {
|
DockerContainerCreator.createDockerContainer(db);
|
||||||
DATA_SOURCE = createDataSourceFromProperties(propertiesFileName);
|
|
||||||
SCHEMA_NAME = getSchemaNameFromPropertiesObject(propertiesFileName);
|
SCHEMA_NAME = determineSchemaName(db);
|
||||||
|
if (dockerContainer.isPresent()) {
|
||||||
|
dockerContainer.get().start();
|
||||||
|
DATA_SOURCE = DockerContainerCreator.createDataSource(dockerContainer.get());
|
||||||
} else {
|
} else {
|
||||||
DATA_SOURCE = createDataSourceForH2();
|
DATA_SOURCE = createDataSourceForH2();
|
||||||
SCHEMA_NAME = DEFAULT_SCHEMA_NAME;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,84 +50,19 @@ public final class DataSourceGenerator {
|
||||||
return SCHEMA_NAME;
|
return SCHEMA_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DataSource createDataSourceFromProperties(String propertiesFileName) {
|
private static String determineSchemaName(DB db) {
|
||||||
DataSource ds;
|
return db == DB.POSTGRES ? "taskana" : "TASKANA";
|
||||||
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 {} is incomplete {}", propertiesFileName, warningMessage);
|
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
|
||||||
ds = createDataSourceForH2();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.warn("createDataSourceFromProperties caught Exception ", e);
|
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
|
||||||
ds = createDataSourceForH2();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSchemaNameFromPropertiesObject(String propertiesFileName) {
|
private static DB retrieveDatabaseFromEnv() {
|
||||||
String schemaName = DEFAULT_SCHEMA_NAME;
|
String property = System.getenv("DB");
|
||||||
try (InputStream input = new FileInputStream(propertiesFileName)) {
|
DB db;
|
||||||
Properties prop = new Properties();
|
try {
|
||||||
prop.load(input);
|
db = DB.valueOf(property);
|
||||||
boolean propertiesFileIsComplete = true;
|
} catch (Exception ex) {
|
||||||
String warningMessage = "";
|
db = DB.H2;
|
||||||
schemaName = prop.getProperty("schemaName");
|
|
||||||
if (schemaName == null || schemaName.length() == 0) {
|
|
||||||
propertiesFileIsComplete = false;
|
|
||||||
warningMessage += ", schemaName property missing";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!propertiesFileIsComplete) {
|
|
||||||
LOGGER.warn("propertiesFile {} is incomplete {}", propertiesFileName, warningMessage);
|
|
||||||
LOGGER.warn("Using default Datasource for Test");
|
|
||||||
schemaName = DEFAULT_SCHEMA_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.warn("getSchemaNameFromPropertiesObject caught Exception ", e);
|
|
||||||
LOGGER.warn("Using default schemaName for Test");
|
|
||||||
}
|
}
|
||||||
|
return db;
|
||||||
return schemaName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DataSource createDataSourceForH2() {
|
private static DataSource createDataSourceForH2() {
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
<version>${version.archunit}</version>
|
<version>${version.archunit}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>org.testcontainers</groupId>
|
||||||
<artifactId>db2</artifactId>
|
<artifactId>db2</artifactId>
|
||||||
<version>${version.testcontainers}</version>
|
<version>${version.testcontainers}</version>
|
||||||
|
|
|
@ -28,8 +28,10 @@ import pro.taskana.task.api.models.TaskSummary;
|
||||||
import pro.taskana.task.internal.builder.TaskBuilder;
|
import pro.taskana.task.internal.builder.TaskBuilder;
|
||||||
import pro.taskana.task.internal.jobs.helper.TaskUpdatePriorityWorker;
|
import pro.taskana.task.internal.jobs.helper.TaskUpdatePriorityWorker;
|
||||||
import pro.taskana.task.internal.models.TaskImpl;
|
import pro.taskana.task.internal.models.TaskImpl;
|
||||||
|
import pro.taskana.workbasket.api.WorkbasketPermission;
|
||||||
import pro.taskana.workbasket.api.WorkbasketService;
|
import pro.taskana.workbasket.api.WorkbasketService;
|
||||||
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
import pro.taskana.workbasket.api.models.WorkbasketSummary;
|
||||||
|
import pro.taskana.workbasket.internal.builder.WorkbasketAccessItemBuilder;
|
||||||
|
|
||||||
@TaskanaIntegrationTest
|
@TaskanaIntegrationTest
|
||||||
class TaskUpdatePriorityWorkerAccTest {
|
class TaskUpdatePriorityWorkerAccTest {
|
||||||
|
@ -42,18 +44,29 @@ class TaskUpdatePriorityWorkerAccTest {
|
||||||
TaskSummary task1;
|
TaskSummary task1;
|
||||||
TaskSummary task2;
|
TaskSummary task2;
|
||||||
Task completedTask;
|
Task completedTask;
|
||||||
|
ClassificationSummary classificationSummary;
|
||||||
|
WorkbasketSummary workbasketSummary;
|
||||||
|
|
||||||
@WithAccessId(user = "admin")
|
@WithAccessId(user = "admin")
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
void setUp(ClassificationService classificationService, WorkbasketService workbasketService)
|
void setUp(ClassificationService classificationService, WorkbasketService workbasketService)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ClassificationSummary classificationSummary =
|
classificationSummary =
|
||||||
DefaultTestEntities.defaultTestClassification()
|
DefaultTestEntities.defaultTestClassification()
|
||||||
.buildAndStore(classificationService)
|
.buildAndStore(classificationService)
|
||||||
.asSummary();
|
.asSummary();
|
||||||
WorkbasketSummary workbasketSummary =
|
workbasketSummary =
|
||||||
DefaultTestEntities.defaultTestWorkbasket().buildAndStore(workbasketService).asSummary();
|
DefaultTestEntities.defaultTestWorkbasket().buildAndStore(workbasketService).asSummary();
|
||||||
|
|
||||||
|
// Currently, we have a bug: TSK-1736
|
||||||
|
// Because of that we need at least one WorkbasketAccessItem with the correct permissions.
|
||||||
|
// Otherwise, the DB2 will not work.
|
||||||
|
WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
|
||||||
|
.workbasketId(workbasketSummary.getId())
|
||||||
|
.accessId("whatever")
|
||||||
|
.permission(WorkbasketPermission.READ)
|
||||||
|
.buildAndStore(workbasketService);
|
||||||
|
|
||||||
TaskBuilder taskBuilder =
|
TaskBuilder taskBuilder =
|
||||||
TaskBuilder.newTask()
|
TaskBuilder.newTask()
|
||||||
.classificationSummary(classificationSummary)
|
.classificationSummary(classificationSummary)
|
||||||
|
@ -127,16 +140,8 @@ class TaskUpdatePriorityWorkerAccTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithAccessId(user = "admin")
|
@WithAccessId(user = "admin")
|
||||||
void should_executeBatch(
|
void should_executeBatch() throws Exception {
|
||||||
WorkbasketService workbasketService, ClassificationService classificationService)
|
|
||||||
throws Exception {
|
|
||||||
// given
|
// given
|
||||||
ClassificationSummary classificationSummary =
|
|
||||||
DefaultTestEntities.defaultTestClassification()
|
|
||||||
.buildAndStore(classificationService)
|
|
||||||
.asSummary();
|
|
||||||
WorkbasketSummary workbasketSummary =
|
|
||||||
DefaultTestEntities.defaultTestWorkbasket().buildAndStore(workbasketService).asSummary();
|
|
||||||
Task oldTask =
|
Task oldTask =
|
||||||
TaskBuilder.newTask()
|
TaskBuilder.newTask()
|
||||||
.classificationSummary(classificationSummary)
|
.classificationSummary(classificationSummary)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package testapi.extensions;
|
package testapi.extensions;
|
||||||
|
|
||||||
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
|
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
|
||||||
import static testapi.util.DockerContainerCreator.createDockerContainer;
|
import static pro.taskana.common.test.DockerContainerCreator.createDataSource;
|
||||||
|
import static pro.taskana.common.test.DockerContainerCreator.createDockerContainer;
|
||||||
import static testapi.util.ExtensionCommunicator.getClassLevelStore;
|
import static testapi.util.ExtensionCommunicator.getClassLevelStore;
|
||||||
import static testapi.util.ExtensionCommunicator.isTopLevelClass;
|
import static testapi.util.ExtensionCommunicator.isTopLevelClass;
|
||||||
|
|
||||||
|
@ -21,7 +22,6 @@ import org.testcontainers.containers.JdbcDatabaseContainer;
|
||||||
import testapi.CleanTaskanaContext;
|
import testapi.CleanTaskanaContext;
|
||||||
import testapi.TaskanaEngineConfigurationModifier;
|
import testapi.TaskanaEngineConfigurationModifier;
|
||||||
import testapi.WithServiceProvider;
|
import testapi.WithServiceProvider;
|
||||||
import testapi.util.DockerContainerCreator;
|
|
||||||
|
|
||||||
import pro.taskana.common.internal.configuration.DB;
|
import pro.taskana.common.internal.configuration.DB;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class TestContainerExtension implements AfterAllCallback, InvocationInter
|
||||||
.ifPresentOrElse(
|
.ifPresentOrElse(
|
||||||
container -> {
|
container -> {
|
||||||
container.start();
|
container.start();
|
||||||
store.put(STORE_DATA_SOURCE, DockerContainerCreator.createDataSource(container));
|
store.put(STORE_DATA_SOURCE, createDataSource(container));
|
||||||
store.put(STORE_CONTAINER, container);
|
store.put(STORE_CONTAINER, container);
|
||||||
},
|
},
|
||||||
() -> store.put(STORE_DATA_SOURCE, createDataSourceForH2()));
|
() -> store.put(STORE_DATA_SOURCE, createDataSourceForH2()));
|
||||||
|
@ -87,7 +87,7 @@ public class TestContainerExtension implements AfterAllCallback, InvocationInter
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DB retrieveDatabaseFromEnv() {
|
private static DB retrieveDatabaseFromEnv() {
|
||||||
String property = System.getenv("db.type");
|
String property = System.getenv("DB");
|
||||||
DB db;
|
DB db;
|
||||||
try {
|
try {
|
||||||
db = DB.valueOf(property);
|
db = DB.valueOf(property);
|
||||||
|
|
Loading…
Reference in New Issue