With Spring Boot, I want to test my @RestController, everything is good except when I try to test a request mapping with @PathParam.
This involve the interface (in this case TestController) holding the annotation for request mapping ! If I remove the interface all is good ... Seemes to be an issue ...
My Controller :
public interface TestController {
@RequestMapping(value = "/bar/{foo}/baz", method = RequestMethod.GET)
String test(@PathVariable("foo") String foo);
@RestController
class TestControllerImpl implements TestController {
@Override
public String test(String foo) {
return foo;
}
}
}
My Tests :
@Test
public void notworkingtest() throws Exception {
//THIS TEST SHOULD WORK, BUT DON'T ...
final MockMvc mockMvc = ...
mockMvc.perform(get("/bar/{foo}/baz", "foovalue") // Or get("/bar/foovalue/baz")
.contentType("text/plain"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().string("foovalue"));
}
@Test
public void strangeworkingtest() throws Exception {
//THIS TEST WORKS, BUT WHY ?!?
final MockMvc mockMvc = ...
mockMvc.perform(get("/bar/{foo}/baz", "WhatEverValue")
.param("foo", "foovalue") // This param should be useless ...
.contentType("text/plain"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().string("foovalue"));
}
The second test is working when I had .param("foo","foovalue) and keep the get("/bar/{foo}/baz", "WhatEverValue") ...
If I remove the interface of the Controller it works ...
Can someone explain to me ?
Thx