Questions tagged [spring-mvc-test]
241 questions
6
votes
1 answer
In Spring boot:Cannot find template location: class path resource [templates/] (please add some templates or check your Thymeleaf configuration)
I have gone through https://github.com/spring-projects/spring-boot/issues/424 but my project structure contains .html files at the /templates diretory as shown below
.
|-- java
| `-- com
| `-- projectx
| |-- config
| | …

MasterCode
- 975
- 5
- 21
- 44
6
votes
1 answer
Testing Forwarding in a Spring MVC App
Is there any way of testing the functionality of a forward:/ view being returned from a Spring MVC controller in a JUnit test?
I'm using the MockMvc functionality from Spring 3.2 and my controller under certain circumstances forwards to another (by…

DeejUK
- 12,891
- 19
- 89
- 169
5
votes
2 answers
How to format Spring REST Docs in response body with mockMvc
I write my API documentation with Spring REST Docs.
Code example:
@Override
public void getById(String urlTemplate, PathParametersSnippet pathParametersSnippet, Object... urlVariables) throws Exception {
resultActions =…

FreeOnGoo
- 868
- 1
- 8
- 26
5
votes
1 answer
Differences between create MockMvc from WebApplicationContext and create MockMvc from your Controller instance?
When i create MockMvc for restful-webservice testing with spring MVC 3.2.3 using WebApplicationContext like this:
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc =…

nhduc
- 55
- 1
- 5
5
votes
1 answer
Integration Tests of Spring MVC controller
I have a controller which returns XML data in response of a call. Below is the code
@RequestMapping(value = "/balance.xml",method = RequestMethod.GET,produces="application/xml")
public AccountBalanceList…

Bilal Nasir
- 65
- 1
- 7
4
votes
1 answer
spring boot - web mvc test does not find controller mapping
In this spring-boot project the following WebMvcTest fails because the GET /items mapping from the ItemController is not found
@RunWith(SpringRunner.class)
@WebMvcTest(ItemController.class)
@AutoConfigureMockMvc
public class Test_ItemController {
…

tenticon
- 2,639
- 4
- 32
- 76
4
votes
1 answer
Configuration of spring-security doesn't seem to be applied while testing
I have configured a standalone mockMvc with a corresponding xml security config for testing my controller that is annotated with @PreAuthorize(hasAnyRole('DM,CD')). But the result of my tests always is tatus 200, even though I make a call with a…

ryzhman
- 674
- 10
- 22
4
votes
1 answer
How to configure HandlerMethodArgumentResolver in spring boot test
I am writing a unit for a controller with spting boot @WebMvcTest.
Using @WebMvcTest, I will be able to inject a MockMvc object as given below :-
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
@WebMvcTest
class…

Manu
- 3,467
- 3
- 29
- 28
4
votes
0 answers
What would cause a Spring URL to work when running the application but not during tests?
A Spring Boot application provides a REST API. It has several containers and is unit-tested. I have modified this application to add a new controller with a new PUT route, to upload a file.
When I run this application with mvn spring-boot:run, I…

elaforma
- 652
- 1
- 9
- 29
4
votes
1 answer
Convert List to Page in spring data mongo?
I am really struggling to convert List users to Page in spring data mongo? Note Page is an API from org.springframework.data.domain.Page;
I am using Pagination of Spring Data Mongo, so I need to sent Page and not the List…
user5268786
4
votes
0 answers
MockMVC async testing with custom return value handler
I am trying to use MockMvc to test my Spring 4.1 controller with an async result. I have followed the same pattern as described…

David Fox
- 41
- 4
4
votes
1 answer
Unit Testing Spring MVC REST controllers when result Object/json contains a Long field type
I have a problem when trying to test the JSON output from a Spring REST Service using MockMvcResultMatchers where the returned object should contain a Long value.
The test will only pass when the value within the JSON object is is higher than…

Ken
- 654
- 8
- 18
4
votes
1 answer
Runtime error while running a Spring Session + Spring Boot application
I am trying to run this Spring Session example available here but, I've used Maven instead of Gradle. I get the following error both while a) Running the WAR file and b) Deploying the WAR in an WildFly8.2 server
A quick search suggests that the…

yathirigan
- 5,619
- 22
- 66
- 104
4
votes
2 answers
Testing Spring Security Controller Using Spring Mvc Test
Login jsp form and spring security xml configuration look like:
4
votes
1 answer
Error message = Required MultipartFile parameter 'file' is not present
Testing a spring file upload form, the controlelr signature looks like this
@RequestMapping(value = "upload", method = RequestMethod.POST)
@ResponseBody
public void upload(@RequestParam("file") MultipartFile multipartFile) {}
and the test…

NimChimpsky
- 46,453
- 60
- 198
- 311