Обязательный параметр списка 'ids' отсутствует - PullRequest
0 голосов
/ 14 июля 2020

Я тестирую контроллер и столкнулся с проблемой, которую не могу решить. Не понимаю, зачем нужны идентификаторы и где их не хватает.

Вот мой контроллер

@GetMapping(value = "/ads/in/rubrics")
    public List<Ad> findAllAdInRubricByIds(@RequestParam(value = "ids", required = true) List<Integer> ids) {
        return adService.findAllAdInRubricByIds(ids);
    }

метод тестирования

@Test
    public void findAllAdInRubricByIds() throws Exception {

        List<Ad> ads = new ArrayList<>();
        ads.add(initAd());

        Mockito.when(controller.findAllAdInRubricByIds(((ArgumentMatchers.anyList())))).thenReturn(ads);

        mockMvc.perform(
                get("/ad/ads/in/rubrics"))
                .andDo(print())
                .andExpect(status().isOk())
                .andExpect(jsonPath("$[0].id").value(0));

    }

Ошибка

MockHttpServletResponse:
           Status = 400
    Error message = Required List parameter 'ids' is not present
          Headers = []
     Content type = null
             Body = 
    Forwarded URL = null
   Redirected URL = null
          Cookies = []


java.lang.AssertionError: Status 
Expected :200
Actual   :400

1 Ответ

2 голосов
/ 14 июля 2020

Как указано в сообщении об ошибке - Обязательный параметр списка 'ids' отсутствует, добавьте идентификаторы в параметр запроса, как показано ниже:

mockMvc.perform(
            get("/ad/ads/in/rubrics?ids=1,2,3"))
...