Add test with request param

This commit is contained in:
Oleg Zhurakousky
2023-03-03 12:58:02 +01:00
parent fd14b43bce
commit fcf6315a53
2 changed files with 14 additions and 2 deletions

View File

@@ -43,7 +43,6 @@ public class PetsController {
@RequestMapping(path = "/pets", method = RequestMethod.GET)
public Pet[] listPets(@RequestParam("limit") Optional<Integer> limit, Principal principal) {
System.out.println("=====> EXECUTING");
int queryLimit = 10;
if (limit.isPresent()) {
queryLimit = limit.get();

View File

@@ -47,6 +47,19 @@ public class RequestResponseTests {
assertThat(pets.get(0)).isInstanceOf(Pet.class);
}
@Test
public void validateGetListOfPojosWithParam() throws Exception {
ProxyHttpServletRequest request = new ProxyHttpServletRequest(null, "GET", "/pets");
request.setParameter("limit", "5");
ProxyHttpServletResponse response = new ProxyHttpServletResponse();
mvc.service(request, response);
TypeReference<List<Pet>> tr = new TypeReference<List<Pet>>() {
};
List<Pet> pets = mapper.readValue(response.getContentAsByteArray(), tr);
assertThat(pets.size()).isEqualTo(5);
assertThat(pets.get(0)).isInstanceOf(Pet.class);
}
@Test
public void validateGetPojo() throws Exception {
HttpServletRequest request = new ProxyHttpServletRequest(null, "GET", "/pets/6e3cc370-892f-4efe-a9eb-82926ff8cc5b");
@@ -58,7 +71,7 @@ public class RequestResponseTests {
}
@Test
public void validatePost() throws Exception {
public void validatePostWithBody() throws Exception {
ProxyHttpServletRequest request = new ProxyHttpServletRequest(null, "POST", "/pets/");
String jsonPet = "{\n"
+ " \"id\":\"1234\",\n"