Код контроллера:
@RestController("WebphoneController")
@RequestMapping("/webphone")
public class WebphoneController {
Logger LOG = LoggerFactory.getLogger(WebphoneController.class);
@Autowired
private WebphoneService webphoneService;
@RequestMapping(value = "/findUsers",
method = { RequestMethod.GET },
consumes = "application/json",
produces = "application/json")
@ResponseBody
public ResponseEntity<List<User>> findUsers(
@RequestBody(required=true) WebphoneFilter webphoneFilter,
@RequestParam(value = "pageSize", required = false, defaultValue = "10000") int pageSize
) {
}
}
Код модульного теста
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { MicroUiApplication.class, CommonConfiguration.class, WebMvcConfig.class}, webEnvironment=WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations= "classpath:application.properties")
@ActiveProfiles("dev")
public class WebphoneControllerTests {
@LocalServerPort
int randomServerPort;
@Test
public void webophoneController_whenGivenWebphoneFilter_shouldReturnListOfUsers() throws URISyntaxException {
final String baseUrl = "http://localhost:" + randomServerPort + "/webphone/findUsers";
WebphoneFilter filter = new WebphoneFilter();
filter.setOrgLeaderId("jn1488");
URI uri = new URI(baseUrl);
/*String requestJson = Util.Object2Json(filter);
System.out.println(requestJson);
*/
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity entity = new HttpEntity<>(filter,headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity answer = restTemplate.exchange(uri, HttpMethod.GET, entity, List.class);
System.out.println("webophoneController_whenGivenWebphoneFilter_shouldReturnListOfUsers>>>>"+ answer);
Assert.assertEquals(HttpStatus.SC_OK, answer.getStatusCode());
}
}