We have a controller, let's say something like this:
@Controller @RequestMapping("/api") public Controller UserController { @RequestMapping("/users/{userId}") public User getUser(@PathVariable String userId){
We have an integration test, for example:
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @SpringApplicationConfiguration(classes= MyApp.class) @IntegrationTest("server:port:0") public class UserControllerIT { @Autowired private WebApplicationContext context; @Test public void getUser(){ test().when() .get("/api/users/{userId}", "123") .then() .statusCode(200); } }
How can we avoid hard coding "/ api / users / {userId}" in the test? How can we search for a query by name. The above query mapping should have a default name of UC # getUser
The only thing I've seen is something like MvcUriComponentsBuilder, which seems to require it to be used in the context of the request (so it will be used in .jsps to create URLs for controllers).
What is the best way to handle this? Should I show mappings as static strings on controllers? I would prefer to at least avoid this.
source share