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
We can run the same test against different database engines.
git clone https://github.com/comsysto/poc-dockerized-database-integration-tests-atlassian-plugin.git
cd poc-dockerized-database-integration-tests-atlassian-plugin
atlas-unit-test
(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
(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 \
--innodb-lock-wait-timeout=800 \
--transaction-isolation=READ-COMMITTED
(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
- Businss Logic
OwnerEntity
= Active Objects EntityPetEntity
= Active Objects EntityPetAndOwnerDataAccessServiceImpl
= Data Access API works with ActiveObjects
- Test
OwnersAndPets.feature
= BDD Gherkin file for Feature for business logic inPetAndOwnerDataAccessServiceImpl
Feature_OwnersAndPets_Test
= BDD Cucumber Test Feature for business logic inPetAndOwnerDataAccessServiceImpl
Feature_OwnersAndPets_Scenario_FindOwnersWithPets
= BDD Test ScenarioFeature_OwnersAndPets_Scenario_FindPetsWithoutOwners
= BDD Test Scenario
- Why not
atlas-integration-test
?- 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
atlas-unit-test
command.
- 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
@ManyToOne
Annotations?- You can do that if you want a Left Join
- The PoC wants to show how to perform an Inner Join