Skip to content

daemonctl/sonar-java-spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Multi-Module Java Spring Boot Math API ๐Ÿงฎ

Java Spring Boot Maven SonarQube JaCoCo

A RESTful API service for mathematical operations and geometry calculations developed with Spring Boot. The project is developed with SonarQube code quality analysis and JaCoCo test coverage reporting.

๐Ÿ“‹ Table of Contents

๐Ÿš€ Features

  • โœ… Basic Math Operations: Addition, subtraction, multiplication, division
  • โœ… Advanced Mathematics: Power calculation, factorial computation
  • โœ… Geometry Calculations: Circle area, rectangle area, distance between two points
  • โœ… RESTful API: Modern REST API design
  • โœ… Comprehensive Test Coverage: 80%+ line coverage, 70%+ branch coverage
  • โœ… SonarQube Integration: Code quality analysis
  • โœ… JaCoCo Reports: Detailed test coverage reports
  • โœ… Spring Boot DevTools: Hot reload in development environment

๐Ÿ›  Technologies

  • Java 21 - Latest LTS version
  • Spring Boot 3.2.5 - Web framework
  • Spring Web - RESTful web services
  • Spring WebFlux - Reactive programming
  • Spring Data REST - REST repository
  • Maven - Dependency management
  • JUnit 5 - Unit testing
  • JaCoCo - Code coverage
  • SonarQube - Code quality analysis

๐Ÿ“ฆ Installation

Requirements

  • Java 21 or higher
  • Maven 3.6 or higher
  • SonarQube Server (optional, for code quality analysis)

Steps

  1. Clone the project:
git clone https://github.com/daemonctl/sonar-java-spring.git
cd multi-module-java
  1. Install dependencies:
mvn clean install
  1. Run the application:
mvn spring-boot:run
  1. Generate test coverage report:
mvn clean test jacoco:report

The application will start running at http://localhost:8080.

๐ŸŽฏ Usage

You can test the API using the following endpoints in your browser or Postman:

# Addition operation
curl "http://localhost:8080/api/math/add?a=5&b=3"

# Multiplication operation
curl "http://localhost:8080/api/math/multiply?a=4&b=7"

# Circle area calculation
curl "http://localhost:8080/api/math/circle-area?radius=5"

๐Ÿ”— API Endpoints

Math Operations

Method Endpoint Parameters Description
GET /api/math/add a, b Adds two numbers
GET /api/math/subtract a, b Subtracts two numbers
GET /api/math/multiply a, b Multiplies two numbers
GET /api/math/divide a, b Divides two numbers
GET /api/math/power base, exponent Power calculation
GET /api/math/factorial n Factorial calculation

Geometry Operations

Method Endpoint Parameters Description
GET /api/math/circle-area radius Circle area calculation
GET /api/math/rectangle-area length, width Rectangle area
GET /api/math/distance x1, y1, x2, y2 Distance between two points

Example Usage

# Addition
GET /api/math/add?a=10&b=5
Response: 15.0

# Factorial
GET /api/math/factorial?n=5
Response: 120

# Circle area
GET /api/math/circle-area?radius=3
Response: 28.274333882308138

# Distance calculation
GET /api/math/distance?x1=0&y1=0&x2=3&y2=4
Response: 5.0

๐Ÿ“Š Test Coverage

The project is developed with high test coverage targets:

  • Line Coverage: Minimum 80%
  • Branch Coverage: Minimum 70%

Viewing Coverage Report

# Generate test and coverage report
mvn clean test jacoco:report

# View the report
open target/site/jacoco/index.html

Coverage Index Report Coverage Report

๐Ÿ” SonarQube Integration

The project is configured to perform code quality analysis with SonarQube.

Running SonarQube Analysis

  1. Start SonarQube server (with Docker):
docker run -d --name sonarqube -p 9000:9000 sonarqube:latest
  1. Analyze the project:
mvn clean verify sonar:sonar
  1. View results: http://localhost:9000

SonarQube Report

SonarQube Configuration

  • Project Key: java-spring-sonar
  • Project Name: java-spring-sonar
  • Code Coverage: JaCoCo XML reports
  • Test Reports: JUnit XML reports

๐Ÿ“ Project Structure

multi-module-java/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/
โ”‚   โ”‚   โ”œโ”€โ”€ java/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ com/turkcell/multimodule/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ MultiModuleJavaApplication.java
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ controller/
โ”‚   โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ MathController.java
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ service/
โ”‚   โ”‚   โ”‚           โ”œโ”€โ”€ Calculator.java
โ”‚   โ”‚   โ”‚           โ””โ”€โ”€ MathGeometry.java
โ”‚   โ”‚   โ””โ”€โ”€ resources/
โ”‚   โ”‚       โ””โ”€โ”€ application.properties
โ”‚   โ””โ”€โ”€ test/
โ”‚       โ””โ”€โ”€ java/
โ”‚           โ””โ”€โ”€ com/turkcell/multimodule/
โ”‚               โ”œโ”€โ”€ MultiModuleJavaApplicationTest.java
โ”‚               โ”œโ”€โ”€ controller/
โ”‚               โ”‚   โ””โ”€โ”€ MathControllerTest.java
โ”‚               โ””โ”€โ”€ service/
โ”‚                   โ”œโ”€โ”€ CalculatorTest.java
โ”‚                   โ””โ”€โ”€ MathGeometryTest.java
โ”œโ”€โ”€ target/
โ”œโ”€โ”€ image/
โ”œโ”€โ”€ pom.xml
โ”œโ”€โ”€ sonar-project.properties
โ””โ”€โ”€ README.md

Class Descriptions

  • MultiModuleJavaApplication: Spring Boot main class
  • MathController: Controller managing REST API endpoints
  • Calculator: Basic mathematical operations service
  • MathGeometry: Geometry calculations service

๐Ÿงช Running Tests

# Run all tests
mvn test

# Run a specific test class
mvn test -Dtest=CalculatorTest

# Run tests with coverage
mvn clean test jacoco:report

๐Ÿ”ง Development

Adding New Features

  1. Add new method to service (Calculator.java or MathGeometry.java)
  2. Add endpoint to controller (MathController.java)
  3. Write unit tests
  4. Check coverage
  5. Run SonarQube analysis

Code Quality Checks

  • Minimum Line Coverage: 80%
  • Minimum Branch Coverage: 70%
  • SonarQube Quality Gate: Passed
  • No Code Smells: Critical/Major issues

๐Ÿค Contributing

  1. Fork the project
  2. Create feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push the branch (git push origin feature/new-feature)
  5. Create Pull Request

Contribution Rules

  • Code coverage should not fall below 80%
  • All tests must pass
  • SonarQube quality gate must pass
  • Code should include English comment lines

๐Ÿ“„ License

This project is licensed under the MIT License. See LICENSE file for details.

๐Ÿ“ž Contact


โญ If you like this project, don't forget to give it a star!

About

An example of SonarQube integration in a Java Spring project. Includes code quality analysis and basic configuration steps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages