6

I'm using spring-data-jpa @EnableSpringDataWebSupport and DomainClassConverter to not manually lookup the instances via the repository. When a do a controller test (MockMvc standalone setup test) on a controller like

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

}

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

fracz
  • 20,536
  • 18
  • 103
  • 149
  • What do you mean by using `@ESDWS` *and* `DCC`. The former implicitly activates the latter. Are you sure, your web setup includes the configuration class annotated with `@ESDWS`? – Oliver Drotbohm Jul 18 '14 at 12:26
  • Doesn't this only work in non-standalone mode? – M. Deinum Jun 16 '15 at 11:55
  • @M.Deinum, maybe. But [I'm not able to run the WebAppContext setup because of Spring Security proxy](http://stackoverflow.com/questions/26747076/can-not-build-mockmvc-there-is-already-handler-of-type-x-mapped), so I need to configure it in standalone mode. – fracz Jun 19 '15 at 09:11
  • Then just test your controller, you either work with the framework and do proper testing, if you only want to unit test your controller then do just that. Create an instance, call the method with an instance of `User` and see what happens. If you want to do an integration test, configure it accordingly. – M. Deinum Jun 19 '15 at 09:14
  • Why is someone else as the topic starter suddenly commenting and "hijacking" this question...? – M. Deinum Jun 19 '15 at 09:16
  • @M.Deinum, can we talk on the [chat](http://chat.stackoverflow.com/transcript/message/23980903#23980903)? – fracz Jun 19 '15 at 09:20

1 Answers1

0

I dont know it would be an option, but in my case I used to use 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 Rest Template for Spring as well https://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate

paul
  • 12,873
  • 23
  • 91
  • 153
  • This queries an instance of the application that is deployed somewhere, doesn't it? Sorry, this is not what we are looking for here. – fracz Jun 19 '15 at 09:14