[英]JUnit test controller error
這是我的控制器:
@RestController
@RequestMapping(value = Constants.COMPANY, produces = MediaType.APPLICATION_JSON_VALUE)
public class CompanyController {
@Autowired
private CompanyService companyService;
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity find(@ModelAttribute CompanyDto request, @Valid @ModelAttribute PageableRequestModel pageRequest) {
final Page<CompanyDto> dtoPg = companyService.find(request, pageRequest.getPageable());
return new ResponseEntity(PagedResponseDto.of(dtoPg), HttpStatus.OK);
}
}
這是我的控制器測試:
@Test
public void testListAll() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(COMPANY))
.andExpect(MockMvcResultMatchers.status().isOk());
}
為什么錯誤'嵌套異常是java.lang.IllegalArgumentException:頁面必需!' ?? 幫我
Running controller.CompanyControllerTest
06 Jan 2017 10:02:36,117 INFO: org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping - Mapped "{[/company],methods=[PUT],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<com.kartuku.voucherweb.dto.ResponseDto> com.kartuku.voucherweb.controller.CompanyController.put(java.util.List<com.kartuku.voucherweb.dto.CompanyDto>) At line: 532.
06 Jan 2017 10:02:36,117 INFO: org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping - Mapped "{[/company],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity com.kartuku.voucherweb.controller.CompanyController.find(com.kartuku.voucherweb.dto.CompanyDto,com.kartuku.voucherweb.util.PageableRequestModel) At line: 532.
06 Jan 2017 10:02:36,117 INFO: org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping - Mapped "{[/company],methods=[DELETE],produces=[application/json]}" onto public org.springframework.http.ResponseEntity com.kartuku.voucherweb.controller.CompanyController.delete(java.util.List<com.kartuku.voucherweb.dto.CompanyDto>) At line: 532.
06 Jan 2017 10:02:36,129 INFO: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.test.web.servlet.setup.StubWebApplicationContext@15b5480 At line: 532.
06 Jan 2017 10:02:36,157 INFO: org.springframework.mock.web.MockServletContext - Initializing Spring FrameworkServlet '' At line: 430.
06 Jan 2017 10:02:36,157 INFO: org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization started At line: 488.
06 Jan 2017 10:02:36,157 INFO: org.springframework.test.web.servlet.TestDispatcherServlet - FrameworkServlet '': initialization completed in 0 ms At line: 507.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.16 sec <<< FAILURE! - in controller.CompanyControllerTest
testListAll(controller.CompanyControllerTest) Time elapsed: 0.16 sec <<< ERROR!
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: page required !
at org.springframework.util.Assert.notNull(Assert.java:115)
at com.kartuku.voucherweb.dto.PagedResponseDto.of(PagedResponseDto.java:29)
at com.kartuku.voucherweb.controller.CompanyController.find(CompanyController.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:170)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
at controller.CompanyControllerTest.testListAll(CompanyControllerTest.java:51)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.