Skip to content

Commit 635627b

Browse files
authored
Harden tests, CI and project documentation
* Add Java 21 Maven CI * Expand API integration coverage * Complete Maven project metadata * Align README with tested API contract * Update project page for CI and API contract
1 parent ff02534 commit 635627b

5 files changed

Lines changed: 417 additions & 68 deletions

File tree

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ci-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
java-21:
18+
name: Java 21
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v6
25+
26+
- name: Set up Java 21
27+
uses: actions/setup-java@v5
28+
with:
29+
distribution: temurin
30+
java-version: "21"
31+
cache: maven
32+
33+
- name: Ensure Maven Wrapper is executable
34+
run: chmod +x mvnw
35+
36+
- name: Verify with Maven Wrapper
37+
run: ./mvnw --batch-mode --no-transfer-progress clean verify

README.md

Lines changed: 142 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Spring Boot Process API Basics
22

3-
**Java 21 · Spring Boot · REST API · Spring Data JPA · H2 · Validation · Maven**
3+
[![CI](https://github.com/DataTideHH/spring-boot-process-api-basics/actions/workflows/ci.yml/badge.svg)](https://github.com/DataTideHH/spring-boot-process-api-basics/actions/workflows/ci.yml)
44

5-
Small Java 21 / Spring Boot learning project that exposes process-check data through a simple REST API.
5+
**Java 21 · Spring Boot 4.1 · REST API · Spring Data JPA · H2 · Validation · Maven · GitHub Actions**
6+
7+
Small Java 21 / Spring Boot learning project that exposes validated process-check data through a layered REST API.
68

79
Project page: https://datatidehh.github.io/spring-boot-process-api-basics/
810

@@ -19,12 +21,16 @@ It demonstrates:
1921
- REST endpoints for a small process-related resource
2022
- layered backend structure with controller, service and repository
2123
- request validation
24+
- status-based filtering
25+
- explicit HTTP success and error behavior
2226
- basic persistence with Spring Data JPA
23-
- an H2 in-memory database for local development
24-
- a local Maven build and test workflow
27+
- an H2 in-memory database for local development and tests
28+
- automated API integration tests with MockMvc
29+
- a reproducible Maven Wrapper workflow
30+
- GitHub Actions CI on Java 21
2531
- synthetic sample data for process-oriented API testing
2632

27-
The goal is not to present a large enterprise backend. The goal is to document a clean first step from Java basics toward a small Spring Boot REST API that handles structured process data.
33+
The goal is not to present a large enterprise backend. The goal is to document a clean first step from Java basics toward a small, tested Spring Boot REST API that handles structured process data.
2834

2935
---
3036

@@ -43,12 +49,15 @@ It complements my main Data/BI portfolio projects around SQL, Python, Power BI,
4349
| Layer | Tool / Concept | Purpose |
4450
|---|---|---|
4551
| Language | Java 21 | Main implementation language |
46-
| Framework | Spring Boot | REST API application framework |
47-
| API layer | Spring Web | HTTP endpoints and JSON responses |
52+
| Framework | Spring Boot 4.1 | REST API application framework |
53+
| API layer | Spring Web MVC | HTTP endpoints and JSON responses |
4854
| Persistence | Spring Data JPA | Repository abstraction and entity persistence |
49-
| Database | H2 | In-memory local development database |
50-
| Validation | Jakarta Validation | Request validation for incoming data |
51-
| Build tool | Maven Wrapper | Reproducible local build workflow |
55+
| Database | H2 | In-memory local development and test database |
56+
| Validation | Jakarta Validation | Validation for incoming request data |
57+
| Error format | Spring `ProblemDetail` | Consistent `application/problem+json` responses |
58+
| Tests | JUnit 5, Spring Boot Test, MockMvc | API integration and persistence verification |
59+
| Build tool | Maven Wrapper | Reproducible builds on Windows, macOS and Linux |
60+
| CI | GitHub Actions | Automated Java 21 Maven verification |
5261

5362
---
5463

@@ -68,17 +77,28 @@ Current package focus:
6877
src/main/java/de/datatidehh/processapi/processcheck/
6978
```
7079

80+
The API uses request and response records instead of exposing the JPA entity directly.
81+
7182
---
7283

73-
## API Endpoints
84+
## API Contract
7485

75-
| Method | Endpoint | Purpose |
76-
|---|---|---|
77-
| `GET` | `/api/process-checks` | Return all process-check records |
78-
| `GET` | `/api/process-checks/{id}` | Return one process-check record by ID |
79-
| `POST` | `/api/process-checks` | Create a new process-check record |
80-
| `PUT` | `/api/process-checks/{id}` | Update an existing process-check record |
81-
| `DELETE` | `/api/process-checks/{id}` | Delete a process-check record |
86+
| Method | Endpoint | Success | Purpose |
87+
|---|---|---:|---|
88+
| `GET` | `/api/process-checks` | `200 OK` | Return all process-check records |
89+
| `GET` | `/api/process-checks?status=OK` | `200 OK` | Filter records by `OK`, `WARNING` or `CRITICAL` |
90+
| `GET` | `/api/process-checks/{id}` | `200 OK` | Return one process-check record by ID |
91+
| `POST` | `/api/process-checks` | `201 Created` | Create a record and return its URI in `Location` |
92+
| `PUT` | `/api/process-checks/{id}` | `200 OK` | Replace the editable values of an existing record |
93+
| `DELETE` | `/api/process-checks/{id}` | `204 No Content` | Delete an existing record |
94+
95+
Typical client errors:
96+
97+
| Situation | Result |
98+
|---|---:|
99+
| Invalid request body | `400 Bad Request` |
100+
| Invalid status query value | `400 Bad Request` |
101+
| Unknown record ID | `404 Not Found` |
82102

83103
---
84104

@@ -95,16 +115,48 @@ src/main/java/de/datatidehh/processapi/processcheck/
95115
}
96116
```
97117

118+
Request validation requires:
119+
120+
- a non-blank `processName`
121+
- a non-blank `owner`
122+
- a valid status: `OK`, `WARNING` or `CRITICAL`
123+
- a non-null ISO local date-time value
124+
- `slaMinutes` of at least `1`
125+
126+
---
127+
128+
## Error Response Example
129+
130+
Requests for unknown IDs return a standard Spring `ProblemDetail` response with media type `application/problem+json`:
131+
132+
```json
133+
{
134+
"type": "about:blank",
135+
"title": "Process check not found",
136+
"status": 404,
137+
"detail": "Process check not found: 999999",
138+
"instance": "/api/process-checks/999999"
139+
}
140+
```
141+
98142
---
99143

100144
## Run Locally
101145

146+
### macOS or Linux
147+
102148
From the repository root:
103149

104150
```bash
105151
./mvnw spring-boot:run
106152
```
107153

154+
### Windows PowerShell
155+
156+
```powershell
157+
.\mvnw.cmd spring-boot:run
158+
```
159+
108160
Then open:
109161

110162
```text
@@ -121,19 +173,53 @@ At first startup, the API returns an empty JSON array because the H2 database is
121173

122174
## Build and Test
123175

124-
Run:
176+
### macOS or Linux
125177

126178
```bash
127-
./mvnw clean package
179+
./mvnw clean verify
180+
```
181+
182+
### Windows PowerShell
183+
184+
```powershell
185+
.\mvnw.cmd clean verify
128186
```
129187

130-
The project has been built and smoke-tested locally with Java 21 and the Maven Wrapper.
188+
The automated suite verifies:
189+
190+
- application context startup
191+
- unfiltered and status-filtered list requests
192+
- empty filter results
193+
- invalid status handling
194+
- lookup by ID
195+
- `404` Problem Detail responses
196+
- successful creation with `201 Created` and `Location`
197+
- request validation failures
198+
- update behavior and persisted values
199+
- successful deletion with `204 No Content`
200+
- update and delete behavior for unknown IDs
201+
202+
---
203+
204+
## Continuous Integration
205+
206+
The workflow under `.github/workflows/ci.yml` runs for pull requests and pushes to `main`.
207+
208+
It uses:
209+
210+
- an Ubuntu GitHub-hosted runner
211+
- Eclipse Temurin Java 21
212+
- Maven dependency caching
213+
- the repository's Maven Wrapper
214+
- `clean verify` as the build and test gate
215+
216+
The workflow has read-only repository permissions and cancels superseded runs for the same branch or pull request.
131217

132218
---
133219

134220
## Manual API Test Flow
135221

136-
The API was manually tested with curl for the full CRUD flow:
222+
The full CRUD flow can also be exercised manually with curl, an API client or an IDE HTTP client:
137223

138224
```text
139225
POST /api/process-checks create a process-check record
@@ -148,13 +234,11 @@ Example test data:
148234
```text
149235
processName: Daily sales import
150236
owner: Data Operations
151-
status: OK / WARNING
237+
status: OK / WARNING / CRITICAL
152238
lastCheckedAt: 2026-07-10T00:25:00
153239
slaMinutes: 60
154240
```
155241

156-
After deletion, the list endpoint returns an empty JSON array again.
157-
158242
---
159243

160244
## H2 Database Note
@@ -168,12 +252,33 @@ That means:
168252
- inserted records are lost when the application stops
169253
- this is suitable for a small learning project, not for production persistence
170254

171-
The H2 console is available locally while the application is running:
255+
The H2 console is available while the application is running:
172256

173257
```text
174258
http://localhost:8080/h2-console
175259
```
176260

261+
Connection values:
262+
263+
```text
264+
JDBC URL: jdbc:h2:mem:processdb
265+
User: sa
266+
Password: <empty>
267+
```
268+
269+
---
270+
271+
## Learning References
272+
273+
The related official documentation is curated in [`open-learning-resources`](https://github.com/DataTideHH/open-learning-resources):
274+
275+
- [Spring Boot Documentation](https://github.com/DataTideHH/open-learning-resources/tree/main/resources/java/spring-boot-documentation)
276+
- [Spring Data JPA Documentation](https://github.com/DataTideHH/open-learning-resources/tree/main/resources/java/spring-data-jpa-documentation)
277+
- [Apache Maven and Maven Wrapper Documentation](https://github.com/DataTideHH/open-learning-resources/tree/main/resources/java/apache-maven-and-wrapper-documentation)
278+
- [GitHub Actions Documentation](https://github.com/DataTideHH/open-learning-resources/tree/main/resources/git/github-actions-documentation)
279+
280+
This keeps the project implementation connected to official primary documentation without mirroring dynamic framework documentation locally.
281+
177282
---
178283

179284
## GitHub Pages Project Site
@@ -206,14 +311,18 @@ This repository demonstrates a small but realistic backend foundation:
206311

207312
- Java 21 project workflow
208313
- Spring Boot application structure
209-
- REST endpoint design
314+
- REST endpoint and HTTP-status design
210315
- JSON request and response handling
211-
- CRUD operations
316+
- CRUD operations and status filtering
212317
- layered backend organization
213318
- request validation
214-
- basic persistence abstraction with Spring Data JPA
215-
- local development with H2
216-
- Maven build and test workflow
319+
- standard Problem Detail error responses
320+
- explicit transaction boundaries
321+
- persistence abstraction with Spring Data JPA
322+
- local development and testing with H2
323+
- automated integration testing
324+
- reproducible Maven builds
325+
- GitHub Actions CI
217326
- public portfolio documentation for a focused learning project
218327

219328
---
@@ -222,9 +331,9 @@ This repository demonstrates a small but realistic backend foundation:
222331

223332
This is a learning project.
224333

225-
It does not include production database configuration, Docker deployment, a frontend UI, cloud deployment, monitoring infrastructure or enterprise-scale error handling.
334+
It does not include production database configuration, Docker deployment, authentication and authorization, a frontend UI, cloud deployment, monitoring infrastructure, pagination or enterprise-scale operational error handling.
226335

227-
These omissions are intentional. The current scope is limited to a clean, understandable Spring Boot REST API baseline.
336+
These omissions are intentional. The current scope is limited to a clean, understandable and tested Spring Boot REST API baseline.
228337

229338
---
230339

0 commit comments

Comments
 (0)