A simple book manager, built using test driven development (TDD) with Java and Maven.
- Java 8
- Maven
- Docker
To test the app, clone this repository somewhere on your machine and run the following command:
mvn clean verify
You can enable 100% code coverage checks with JaCoCo by adding the jacoco-check
profile to the previous command:
mvn clean verify -P jacoco-check
Similarly, you can enable mutation testing with PIT by adding the mutation-testing
profile:
mvn clean verify -P mutation-testing
- Build the fat Jar file using Maven:
mvn -DskipTests=true clean package
This will create a file called book-manager-1.0-SNAPSHOT-jar-with-dependencies.jar
inside target
folder. Alternatively, you can download a precompiled fat .jar
from the releases page.
- A MongoDB replica set is required for MongoDB transactions, as stated in documentation. This project includes a
Dockerfile
that automatically deploys a single node replica set. You can build the image with:
docker build -t book-manager-db .
- Once done, run the image (specifying the port) and wait a few seconds:
docker run -p 27017:27017 --rm book-manager-db
- Finally, start the app:
java -jar target/book-manager-1.0-SNAPSHOT-jar-with-dependencies.jar [options]
Option | Description |
---|---|
--mongo-replica-set-url |
The URL of the MongoDB replica set. Defaults to mongodb://localhost:27017 |
--db-name |
The database name. Defaults to bookmanager |
--db-author-collection |
Name of the authors collection in database. Defaults to authors |
--db-book-collection |
Name of the books collection in database. Defaults to books |
To enable Coveralls integration, enable the jacoco-report
profile to generate the JaCoCo report, and then add the coveralls:report
goal:
mvn clean verify -P jacoco-report coveralls:report -D repoToken=YOUR_COVERALLS_TOKEN
Note: replace YOUR_COVERALLS_TOKEN
with your Coveralls token.
To test the project locally with SonarQube, a Docker Compose file is included in the sonarqube
folder. Run the following commands to start the local analysis:
$ cd sonarqube
$ docker-compose up
$ cd ..
$ mvn clean verify sonar:sonar
See sonarqube folder for more information.
To enable SonarCloud code analysis, enable the sonar:sonar
goal when testing:
mvn clean verify sonar:sonar \
-D sonar.host.url=SONAR_URL \
-D sonar.organization=SONAR_ORGANIZATION \
-D sonar.projectKey=SONAR_PROJECT
Note: replace SONAR_URL
, SONAR_ORGANIZATION
and SONAR_PROJECT
with your values. You'll find them in the SonarCloud dashboard once you set up the project. You will also need to specify an environment variable SONAR_TOKEN
with your own SonarCloud token.
This repository uses Github Actions to build, test, and deploy the app right from GitHub. Check out the .github/workflows
folder for more information.
To increase reliability, all tests on CI servers are executed on a secondary desktop with TightVNC, using the execute-on-vnc.sh
script included in this project, as recommended in the official AssertJ Swing documentation.
Full project report is available here.