Untitled
unknown
plain_text
9 months ago
1.2 kB
4
Indexable
Never
@Test public void addPostHappyPath() throws Exception { String url = "/products/post"; PostDto postDto = new PostDto(1, "26-01-2024", new ProductDto( 1, "Teclado Gamer", "Gamer", "Racer", "Black", "Special Edition"), 100, 1500.50); RequestBuilder request = MockMvcRequestBuilders.post(url) .content( mapper.writeValueAsString(postDto) ) .contentType(MediaType.APPLICATION_JSON); ResultMatcher statusExpected = MockMvcResultMatchers.status().isOk(); PostDto expected = new PostDto(1, "26-01-2024", new ProductDto( 1, "Teclado Gamer", "Gamer", "Racer", "Black", "Special Edition"), 100, 1500.50); ResultMatcher bodyExpected = MockMvcResultMatchers.content().json( mapper.writeValueAsString(expected) ); ResultMatcher contentTypeExpected = MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON); mockMvc.perform(request) .andDo(MockMvcResultHandlers.print()) .andExpectAll(statusExpected, bodyExpected, contentTypeExpected); }
Leave a Comment