Skip to content

francescofiora/books

Repository files navigation

books

SpringBoot Rest Api tutorial with OpenApi 3.0 and Mysql. Yes, yet another tutorial with "book, author and publisher" as entities.

Topics covered

  • Spring Boot Rest Api
  • Swagger UI for visualizing APIs
  • Error Handling
  • JSON Web Token Authentication
  • Mapper for POJO<->DTO
  • Logging
  • Testing
    • Repositories using DataJpaTest
    • Services using Mockito
    • EndPoints using WebMvcTest
    • POJOs and DTOs using OpenPojo
    • End to End Test with TestRestTemplate
    • Integration test using TestContainers and Cucumber

Getting Started

Compile

./gradlew clean build

Dependency-Check

./gradlew dependencyCheckAnalyze --info

Pitest

./gradlew pitest

SonarQube

Run SonarQube

docker compose -f docker/docker-compose-sonar.yml up

For SonarQube configuration follow this link: Try Out SonarQube

Scan project

./gradlew sonarqube \
-Dsonar.projectKey=yourProjectKey \
-Dsonar.token=yourAuthenticationToken

Reports

build/reports/checkstyle/main.html
build/reports/checkstyle/test.html
build/reports/tests/test/index.html
build/reports/jacoco/test/html/index.html
build/reports/dependency-check-report.html
build/reports/pitest/index.html

Using Docker for tests

There is a docker compose file to run MySql and phpMyAdmin.

docker compose -f docker/docker-compose.yml up

How to execute

  • gradle: ./gradlew bootRun
  • fat jar: java -jar ./build/libs/books-1.0-SNAPSHOT.jar

Run the application with JMX support

java -Dendpoints.jmx.enabled=true \
-Dcom.sun.management.jmxremote.port=9999 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar ./build/libs/books-1.0-SNAPSHOT.jar

jconsole service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi

API documentation

http://localhost:8081/swagger-ui.html

System Integration Test environment

Create Docker images

./gradlew jibDockerBuild

Manual tests - execute all applications with Docker

docker compose -f docker/docker-compose-all.yml up

Integration Test

cd books-integration-test/
./gradlew clean build

Technologies used