jeudi 25 avril 2019

Getting assertion error while performing test on mockmvc

I am getting assertion error saying it's getting 406 and expected 200. Not sure how to fix this. For your info i am trying to upgrade spring boot 1.5.2 to 2.1.4

Below is my code -

@ContextConfiguration(classes = ChangeController.class)
@WebAppConfiguration
public class ChangeControllerTest extends AbstractJUnit4SpringContextTests {

        private MockMvc mockMvc;

        @Autowired
        private WebApplicationContext wac;

        @Before
        public void setup() {
            this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();

        }

         @Test
        public void verifyInvalidToDoArgument() throws Exception {
            mockMvc.perform(MockMvcRequestBuilders.get("/log").accept(MediaType.APPLICATION_JSON))
                    .andExpect(status().isOk())
                    .andDo(print());
        }


}

Controller class

@Controller
@RequestMapping("/log")
public class ChangeController {
    @ApiIgnore

    @RequestMapping(method = RequestMethod.GET, produces = {"text/plain"})
    public
    @ResponseBody
    String generate() {

        return "some string is here
               ";

    }
}

Below is console response-

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

Aucun commentaire:

Enregistrer un commentaire