
How to Test Spring Controllers With MockMvc Step by Step
Test Spring MVC controllers with MockMvc and WebMvcTest: status, JSON, validation, security, uploads and exception handlers without a server.
Tag
223 posts

Test Spring MVC controllers with MockMvc and WebMvcTest: status, JSON, validation, security, uploads and exception handlers without a server.

Write readable API tests with REST Assured: given when then, JSON path checks, request specs, authentication, schema validation and Spring Boot setup.

Fetch only the columns you need with Spring Data JPA projections: interface and record DTOs, dynamic, nested and open projections, and limits.

Build dynamic JPA search queries with the Criteria API, the static metamodel and Spring Data Specifications, including paging, joins and the count query trap.

Use Hibernate StatelessSession to import and export large data sets without a persistence context, with JDBC batching, scrollable queries and the trade-offs.

Implement soft deletes with Hibernate: the @SoftDelete annotation, filtering deleted rows, restoring, unique constraints and when a real delete is better.

Build a Java application image in GitHub Actions and push it to a registry with Buildx, tags from Git, layer caching and a read-only token where possible.

Stop SQL injection in Java by binding values with parameters in JDBC, JPA and Spring, allow-listing identifiers and limiting what the database account can do.

Make POST endpoints safe to retry with an Idempotency-Key header, a unique constraint and a stored response, and know which methods are idempotent already.

Test asynchronous code with Awaitility instead of Thread.sleep: await until a condition holds, tune timeouts and poll intervals, and avoid flaky waits.

Choose synchronous requests or asynchronous messages between Java services based on whether the caller needs an answer now, and design for failure either way.

Configure a Quarkus application with profiles: the built in dev, test and prod, the percent prefix syntax, custom profiles, environment variables and secrets.