n3d1117 / book-manager

A simple book manager, built using test driven development (TDD) with Java and Maven.

Home Page:https://edoardo.fyi/blog/2020/10/book-manager/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Book Manager

Build on CI with Maven Coverage Status

Quality Gate Status Maintainability Rating Reliability Rating Security Rating

Bugs Code Smells Technical Debt Duplicated Lines (%) Vulnerabilities

A simple book manager, built using test driven development (TDD) with Java and Maven.

Screenshot

Requirements

  • Java 8
  • Maven
  • Docker

Run Tests

To test the app, clone this repository somewhere on your machine and run the following command:

mvn clean verify

Code Coverage

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

Mutation Testing

Similarly, you can enable mutation testing with PIT by adding the mutation-testing profile:

mvn clean verify -P mutation-testing

Run the app

  • 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]

Available 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

Coveralls Integration

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.

SonarQube Integration

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.

SonarCloud Integration

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.

Continuous Integration

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.

Project Report

Full project report is available here.

About

A simple book manager, built using test driven development (TDD) with Java and Maven.

https://edoardo.fyi/blog/2020/10/book-manager/


Languages

Language:Java 99.4%Language:Shell 0.5%Language:Dockerfile 0.1%