How hamvocke/spring-testing works
Project type and purpose
• This is a Spring Boot–based microservice whose primary purpose is to expose a small REST API (“hello” and “weather” endpoints), persist Person entities in a database, and demonstrate a comprehensive test suite arranged according to the Test Pyramid. It is not a full multi-module monolith or a frontend/backend web app with UI—it’s a single back-end service with an external HTTP dependency (the OpenWeatherMap API) and an in-memory/PostgreSQL data store.
File structure
• Top-level build and CI: build.gradle, gradlew, .circleci/config.yml, Dockerfile, startDatabase.sh
• Main code under src/main/java/example:
• ExampleApplication.java – Spring Boot entry point
• ExampleController.java – REST controller defining /hello and /weather endpoints
• person/Person.java, person/PersonRepository.java – JPA entity and repository
• weather/WeatherClient.java, weather/WeatherResponse.java – HTTP client & DTO for external API
• Config: src/main/resources/application.properties, env files (.envrc, env.sample) for WEATHER_API_KEY and database
• Tests under src/test/java/example: unit tests, integration tests (DB, HTTP stubs), end-to-end tests (Selenium, RestAssured), consumer-driven contracts (Pact), and test helpers
• Docker and database startup script to spin up PostgreSQL on 15432
Key insights from the README
• The architecture is a classic 3-tier layered service:
1. Web/API layer (Controller)
2. Service/Data layer (Repository → Database)
3. Integration layer (HTTP Client → External Weather API)
• It demonstrates all levels of the test pyramid: Unit → Integration → End-to-End → Acceptance (Pact), using JUnit, Mockito, MockMvc, RestAssured, WireMock, Pact.
• The service runs on port 8080, connects to Postgres and OpenWeatherMap via JSON/HTTP.