22
33This project is built so you can learn, test, and modify small examples instead of reading a large codebase.
44
5+ Full repo learning notes are in [ docs/README.md] ( ./docs/README.md ) .
6+
57## What this repo teaches
68
79### Plain Java
@@ -15,6 +17,10 @@ This project is built so you can learn, test, and modify small examples instead
1517- exceptions
1618- packages
1719- annotations
20+ - interfaces
21+ - inheritance and polymorphism
22+ - generics
23+ - streams and lambdas
1824
1925### Spring Boot
2026
@@ -24,16 +30,25 @@ This project is built so you can learn, test, and modify small examples instead
2430- request/response model
2531- Swagger UI
2632- OpenAPI YAML
33+ - validation
34+ - JPA + H2 persistence
35+ - basic authentication with Spring Security
36+ - unit, repository, and integration tests
2737
2838## Start here
2939
3040Read these files in order:
3141
32421 . ` src/main/java/com/example/demo/basics/model/Student.java `
33432 . ` src/test/java/com/example/demo/basics/model/StudentTest.java `
34- 3 . ` src/main/java/com/example/demo/spring/service/StudentService.java `
35- 4 . ` src/main/java/com/example/demo/spring/controller/StudentController.java `
36- 5 . ` src/test/java/com/example/demo/spring/controller/StudentControllerTest.java `
44+ 3 . ` src/main/java/com/example/demo/basics/interfaces/Notifier.java `
45+ 4 . ` src/main/java/com/example/demo/basics/inheritance/LearningStudent.java `
46+ 5 . ` src/main/java/com/example/demo/basics/generics/Box.java `
47+ 6 . ` src/main/java/com/example/demo/basics/streams/StudentAnalytics.java `
48+ 7 . ` src/main/java/com/example/demo/spring/service/StudentService.java `
49+ 8 . ` src/main/java/com/example/demo/spring/persistence/service/CourseService.java `
50+ 9 . ` src/main/java/com/example/demo/spring/persistence/controller/CourseController.java `
51+ 10 . ` src/test/java/com/example/demo/spring/persistence/controller/CourseControllerIntegrationTest.java `
3752
3853## Package guide
3954
@@ -43,6 +58,14 @@ Read these files in order:
4358 - custom exception example
4459- ` com.example.demo.basics.model `
4560 - plain Java class with fields, constructors, methods, ` if ` , ` for ` , ` List ` , and ` Map `
61+ - ` com.example.demo.basics.interfaces `
62+ - interface and implementation examples
63+ - ` com.example.demo.basics.inheritance `
64+ - inheritance and polymorphism examples
65+ - ` com.example.demo.basics.generics `
66+ - generic class example
67+ - ` com.example.demo.basics.streams `
68+ - streams and lambda-style collection processing
4669- ` com.example.demo.spring.repository `
4770 - in-memory data storage
4871- ` com.example.demo.spring.service `
@@ -51,6 +74,8 @@ Read these files in order:
5174 - HTTP endpoints and error handling
5275- ` com.example.demo.spring.model `
5376 - request and response models
77+ - ` com.example.demo.spring.persistence `
78+ - validation, JPA, H2, and security examples
5479
5580## Run the app
5681
@@ -72,6 +97,7 @@ Then open:
7297
7398- ` http://localhost:8080/api/students `
7499- ` http://localhost:8080/swagger-ui.html `
100+ - ` http://localhost:8080/h2-console `
75101
76102To stop it:
77103
@@ -110,6 +136,25 @@ curl -X POST http://localhost:8080/api/students \
110136 }'
111137```
112138
139+ Get secured courses with basic auth:
140+
141+ ``` bash
142+ curl -u student:password http://localhost:8080/api/courses
143+ ```
144+
145+ Create a secured database-backed course:
146+
147+ ``` bash
148+ curl -u student:password -X POST http://localhost:8080/api/courses \
149+ -H " Content-Type: application/json" \
150+ -d ' {
151+ "title": "Spring Data JPA",
152+ "level": "intermediate",
153+ "durationInHours": 7,
154+ "published": true
155+ }'
156+ ```
157+
113158## Swagger and OpenAPI
114159
115160After starting the app with ` ./gradlew bootRun ` , open:
@@ -144,6 +189,12 @@ Run the tests inside a container:
144189docker compose run --rm test
145190```
146191
192+ Different test layers in this repo:
193+
194+ - unit tests: small classes without Spring, such as ` StudentTest ` and ` CourseServiceTest `
195+ - repository tests: JPA + H2 with a Spring Boot integration test, such as ` CourseRepositoryTest `
196+ - integration tests: full Spring Boot + MockMvc, such as ` StudentControllerTest ` and ` CourseControllerIntegrationTest `
197+
147198## GitHub CI
148199
149200This repo includes a GitHub Actions workflow at ` .github/workflows/ci.yml ` .
@@ -160,7 +211,8 @@ It runs on every push and pull request, sets up Java 17, and executes:
1602112 . In ` Student.java ` , add another method such as ` averageScore() ` .
1612123 . In ` StudentService.java ` , change how new students are created.
1622134 . In ` StudentController.java ` , add a new endpoint such as ` DELETE /api/students/{id} ` .
163- 5 . In ` StudentControllerTest.java ` , add a test before you change the code.
214+ 5 . In ` CourseController.java ` , add a new secured endpoint such as ` DELETE /api/courses/{id} ` .
215+ 6 . In ` CourseControllerIntegrationTest.java ` , add a failing test before you change the code.
164216
165217## Quick concept map
166218
@@ -170,6 +222,13 @@ It runs on every push and pull request, sets up Java 17, and executes:
170222- ` for ` : ` totalScore ` , ` subjectSummary ` , service mapping methods
171223- ` List ` : subjects
172224- ` Map ` : scores
225+ - Interfaces: ` Notifier ` , ` EmailNotifier `
226+ - Inheritance: ` Person ` , ` LearningStudent `
227+ - Generics: ` Box<T> `
228+ - Streams: ` StudentAnalytics `
173229- Exceptions: ` InvalidScoreException ` , ` StudentNotFoundException `
174- - Annotations: ` @LearningExample ` , ` @Service ` , ` @RestController ` , ` @RestControllerAdvice `
230+ - Annotations: ` @LearningExample ` , ` @Service ` , ` @RestController ` , ` @RestControllerAdvice ` , ` @Entity ` , ` @Valid `
175231- Dependency injection: ` StudentController ` gets ` StudentService ` , ` StudentService ` gets ` InMemoryStudentRepository `
232+ - Validation: ` CreateCourseRequest `
233+ - Persistence: ` CourseEntity ` , ` CourseRepository ` , H2
234+ - Security: HTTP basic auth for ` /api/courses/** ` with user ` student ` / ` password `
0 commit comments