【发布时间】:2018-11-13 17:28:38
【问题描述】:
我在 spring-application 中有一个 restcontroller 返回一个对象列表...
@GetMapping
@Override
public ResponseEntity readAll(@QuerydslPredicate(root = Entity.class) Predicate predicate, Pageable pageable){
...
}
如果我运行它,一切正常。我可以通过可分页和谓词过滤请求。但是如果我运行 junit 测试,它会失败......
@Test
public void readAllTest(){
MockMvcBuilders.standaloneSetup(*myController*)
.build().perform(MockMvcRequestBuilders.get(*myUri*)
.accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
)
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
}
收到以下错误消息... org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 java.lang.IllegalStateException: No primary or default constructor found for interface com.querydsl.core.types.Predicate
有人知道如何使用 Pageable 和 Predicate 测试 restcontroller 吗?
【问题讨论】:
标签: spring junit mockito querydsl