liveBook · Manning

WebApplicationContext

As explained in Spring Start Here, Second Edition

WebApplicationContext is a Spring application context that contains web-layer configuration, controllers, and their required components.

A WebApplicationContext represents an application’s web configuration, including its controllers and the components they need. In a controller integration test, inject it and use MockMvcBuilders.webAppContextSetup(context).build() to create a client for calling endpoints. section 16.2

Testing a transfer endpoint

Use MockMvc to send a simulated POST request to /transfer. The test can keep the web setup while replacing the repository with a mock, then check the endpoint’s response. section 16.2

Figure 16.2 A controller integration test. A tool such as MockMvc lets the test execute the web layer without starting a real server. The test sends a simulated HTTP request to the controller, while the developer decides which objects in the request-processing flow are real and which ones are replaced with mocks.

Shows how MockMvc exercises the web layer without starting a real server, while allowing selected objects to be mocked. section 16.2

How Spring Start Here, Second Edition covers it

How deep it goes
Defines it as web configuration containing controllers and required components, then shows injection and MockMvc setup.
Examples
Uses a money-transfer POST request to /transfer with mocked repository behavior.
What you can do after
Apply it via MockMvc to call an endpoint and verify its response while retaining the Spring web setup.
How it connects
Connects the Spring application context, controllers, MockMvc, and repository mocks in endpoint testing.

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.