MVC controller test and spring -data-jpa EnableSpringDataWebSupport

I use spring -data-jpa @EnableSpringDataWebSupport and DomainClassConverter to not manually search for instances through the repository. When running a control test (stand-alone MockMvc test) on a controller, for example

 @RequestMapping(value = '/user/{userId}', method = RequestMethod.GET) public UserDetails detail(@PathVariable('userId') User user) { ... } 

I get a ConversionNotSupportedException . Is it possible to test such controllers? What should I do?

+6
source share
1 answer

I don’t know this will be an option, but in my case I used HttpClient to test my controllers with IntegrationTest

  HttpClient httpClient = login(HTTP_SERVER_DOMAIN, " user1@gmail.com ", "password"); GetMethod getAllAdvicesMethod = new GetMethod(adviceGetURL); getAllAdvicesMethod .addRequestHeader("Content-Type", "application/json"); try { httpClient.executeMethod(getAllAdvicesMethod); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 

You can use the Rest Template for Spring, and https://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate

0
source

Source: https://habr.com/ru/post/972403/


All Articles