|
| 1 | +Project developed by **XPEHO**. |
| 2 | + |
| 3 | +## 👤 Author |
| 4 | +- [x] [Add Sonarqube in the project](https://github.com/XPEHO/spring_boot_java_random_user/issues/2) |
| 5 | +- [x] [Add PostgreSQL database with docker](https://github.com/XPEHO/spring_boot_java_random_user/issues/6) |
| 6 | +- [ ] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5) |
| 7 | +- [ ] [Add this endpoint get /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/8) |
| 8 | +- [ ] [Add this endpoint put /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9) |
| 9 | +- [ ] [Add this endpoint delete /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/10) |
| 10 | +- [ ] [Add this endpoint post /user](https://github.com/XPEHO/spring_boot_java_random_user/issues/11) |
| 11 | +## ✅ Todo |
| 12 | +- **URL**: [https://randomuser.me/api/](https://randomuser.me/api/) |
| 13 | +- **Documentation**: [https://randomuser.me/documentation](https://randomuser.me/documentation) |
| 14 | +This project consumes the public **Random User Generator** API: |
| 15 | +## 🌐 External API |
| 16 | + └── java/com/xpeho/spring_boot_java_random_user/ |
| 17 | + └── SpringBootJavaRandomUserApplicationTests.java |
| 18 | +│ └── application.properties # Configuration |
| 19 | +│ │ └── SpringBootJavaRandomUserApplication.java # Entry point |
| 20 | +## 📁 Project structure |
| 21 | +Generated reports: |
| 22 | + |
| 23 | +- HTML report: `target/site/jacoco/index.html` |
| 24 | +- XML report (used by SonarQube): `target/site/jacoco/jacoco.xml` |
| 25 | + |
| 26 | +mvn clean verify sonar:sonar |
| 27 | +``` |
| 28 | +
|
| 29 | +### Generate the JaCoCo coverage report locally |
| 30 | +
|
| 31 | +Run: |
| 32 | +
|
| 33 | +```bash |
| 34 | +./mvnw clean verify |
| 35 | +- Java 25 setup (Temurin) |
| 36 | +- Maven build + tests + SonarQube analysis: |
| 37 | +### What it runs |
| 38 | +- `push` on all branches |
| 39 | +- `pull_request` |
| 40 | +### Workflow triggers |
| 41 | +.github/workflows/sonar.yaml |
| 42 | +Tests use **Testcontainers** to spin up ephemeral Docker containers for external dependencies (e.g. PostgreSQL). |
| 43 | +
|
| 44 | +> **Prerequisite for tests**: Docker must be installed and running. |
| 45 | +
|
| 46 | +--- |
| 47 | +
|
| 48 | +## 🔎 Code Quality (SonarQube) |
| 49 | +
|
| 50 | +A GitHub Actions workflow is configured in: |
| 51 | +./mvnw test |
| 52 | +Run unit and integration tests: |
| 53 | +## 🧪 Tests |
| 54 | +--- |
| 55 | +
|
| 56 | +## 📖 API Documentation (Swagger UI) |
| 57 | +
|
| 58 | +Once the project is running, the interactive documentation is available at: |
| 59 | +
|
| 60 | +``` |
| 61 | +http://localhost:8080/api |
| 62 | +``` |
| 63 | +
|
| 64 | +The raw OpenAPI specification (JSON) is available at: |
| 65 | +
|
| 66 | +``` |
| 67 | +http://localhost:8080/v3/api-docs |
| 68 | +``` |
| 69 | +
|
| 70 | +--- |
| 71 | +
|
| 72 | +## 🔍 Monitoring (Actuator) |
| 73 | +
|
| 74 | +Spring Boot Actuator is enabled. Health endpoints are available at: |
| 75 | +
|
| 76 | +``` |
| 77 | +http://localhost:8080/actuator |
| 78 | +http://localhost:8080/actuator/health |
| 79 | +``` |
| 80 | +./mvnw clean package |
| 81 | +java -jar target/spring_boot_java_random_user-0.0.1-SNAPSHOT.jar |
| 82 | +### Build and run the JAR |
| 83 | +mvn spring-boot:run |
| 84 | +### With Maven installed |
| 85 | +./mvnw spring-boot:run |
| 86 | +### With the Maven Wrapper (recommended) |
| 87 | +## 🚀 Running the project |
| 88 | +### Properties to configure |
| 89 | +
|
| 90 | +```properties |
| 91 | +spring.application.name=spring_boot_java_random_user |
| 92 | +
|
| 93 | +# Swagger UI — available at /api |
| 94 | +springdoc.swagger-ui.path=/api |
| 95 | +
|
| 96 | +# PostgreSQL datasource (add these if you use persistence) |
| 97 | +spring.datasource.url=jdbc:postgresql://localhost:5432/<database_name> |
| 98 | +spring.datasource.username=<username> |
| 99 | +spring.datasource.password=<password> |
| 100 | +spring.datasource.driver-class-name=org.postgresql.Driver |
| 101 | +``` |
| 102 | + |
| 103 | +> ⚠️ **Common startup error**: |
| 104 | +> ``` |
| 105 | +> Failed to configure a DataSource: 'url' attribute is not specified |
| 106 | +> and no embedded datasource could be configured. |
| 107 | +> Reason: Failed to determine a suitable driver class |
| 108 | +> ``` |
| 109 | +> This error occurs because the PostgreSQL driver is present in the dependencies but the datasource URL is not configured. |
| 110 | +> **Fix**: either add the `spring.datasource.*` properties above, or exclude the DataSource auto-configuration if no database is needed: |
| 111 | +> ```properties |
| 112 | +> spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration |
| 113 | +> ``` |
| 114 | +## 📋 Prerequisites |
| 115 | +
|
| 116 | +- **Java 25** (or compatible version) |
| 117 | +- **Maven** (or use the included `./mvnw` wrapper) |
| 118 | +- **PostgreSQL** running (if data persistence is enabled) |
| 119 | +
|
| 120 | +--- |
| 121 | +
|
| 122 | +## ⚙️ Configuration |
| 123 | +
|
| 124 | +The main configuration file is located at: |
| 125 | +
|
| 126 | +``` |
| 127 | +src/main/resources/application.properties |
| 128 | +``` |
| 129 | +| Technology | Version | |
| 130 | +|----------------------|-----------------| |
| 131 | +| Java | 25 | |
| 132 | +| Spring Boot | 4.0.3 | |
| 133 | +| Spring Web MVC | (managed by Boot) | |
| 134 | +| Spring Actuator | (managed by Boot) | |
| 135 | +| springdoc-openapi | 3.0.1 | |
| 136 | +| PostgreSQL (driver) | (managed by Boot) | |
| 137 | +| Testcontainers | (managed by Boot) | |
| 138 | +| Maven | Wrapper included | |
| 139 | +## 🛠️ Tech Stack |
| 140 | +Spring Boot Java project that exposes a REST API consuming the public [Random User](https://randomuser.me/) API. |
| 141 | +The interactive API documentation is available via **Swagger UI / OpenAPI**. |
1 | 142 | # spring_boot_java_random_user |
2 | 143 |
|
3 | 144 | Spring Boot Java project that exposes a REST API consuming the public [Random User](https://randomuser.me/) API. |
|
0 commit comments