Proof of Concept: Dockerized Database Integration Tests
for Atlassian Server App
A simple Proof of Concept on how to run Database Integration Tests with real dockerized PostgreSQL or MySQL Databases during Atlassian JIRA Server App development. This PoC is based on UnitTests for Active Objects.
- Docker is installed and on PATH
- Java 8 JDK is installed and on PATH
- Atlassian Plugin SDK is installed and on PATH
Running the Tests
We can run the same test against different database engines.
Run tests against embedded HSQLDB
Run tests against dockerized PostgreSQL
(1) Start dockerized PostgreSQL database
docker run --name postgres95 \ -d --rm -p 5441:5432 \ -e POSTGRES_PASSWORD=jira \ -e POSTGRES_USER=jira \ -e POSTGRES_DB=jira \ postgres:9.5 \ postgres -c 'log_statement=all'
(2) Run tests against it
atlas-unit-test -Dao.test.database=postgres \ -Ddb.url=jdbc:postgresql://localhost:5441/jira \ -Ddb.schema=public \ -Ddb.username=jira \ -Ddb.password=jira
We can see the tables and indexes:
(3) See logged queries
docker logs postgres95
(4) Shutdown dockerized PostgreSQL database.
docker kill postgres95
Run tests against dockerized MySQL
(1) Start dockerized MySQL database
docker run --name mysql56 \ -d --rm \ -p 3316:3306 \ -e MYSQL_RANDOM_ROOT_PASSWORD=true \ -e MYSQL_USER=jira \ -e MYSQL_PASSWORD=jira \ -e MYSQL_DATABASE=jira \ mysql:5.6
(2) Run tests against it
atlas-unit-test -Dao.test.database=mysql \ -Ddb.url=jdbc:mysql://localhost:3316/jira?autoReconnect=true \ -Ddb.username=jira \ -Ddb.password=jira
- Note that MySQL uses no so called "schema". So we skip the definition.
(3) Shutdown dockerized MySQL database.
docker kill mysql56
Classes and Tests
- Businss Logic
OwnersAndPets.feature= BDD Gherkin file for Feature for business logic in
Feature_OwnersAndPets_Test= BDD Cucumber Test Feature for business logic in
Feature_OwnersAndPets_Scenario_FindOwnersWithPets= BDD Test Scenario
Feature_OwnersAndPets_Scenario_FindPetsWithoutOwners= BDD Test Scenario
- Why not
- Because even though it is named 'integration-test' it starts a full JIRA instance
and runs tests against it. We only want to instantiate Active Objects with a real database and not the whole JIRA context.
That is why we use the
- Because even though it is named 'integration-test' it starts a full JIRA instance and runs tests against it. We only want to instantiate Active Objects with a real database and not the whole JIRA context. That is why we use the
- Why not use
- You can do that if you want a Left Join
- The PoC wants to show how to perform an Inner Join