Untitled
unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
@SpringBootTest @AutoConfigureMockMvc public class PriorityControllerTest { @MockBean PriorityController priorityController; @Autowired private MockMvc mockMvc; @MockBean private PriorityMapper priorityMapper; @Test void createPriority() throws Exception { PriorityCreateRequest priorityCreateRequest = new PriorityCreateRequest("Very very high", "#123"); BindingResult bindingResult = new BeanPropertyBindingResult(priorityCreateRequest, "priorityCreateRequest"); Priority priority1 = new Priority(1L, priorityCreateRequest.getTitle(), priorityCreateRequest.getColor()); Mockito.when(priorityMapper.createPriority(priorityCreateRequest, bindingResult)).thenReturn(priority1); //System.out.println(new ObjectMapper().writeValueAsString(priorityCreateRequest)); mockMvc.perform(post("/api/v1/priority/new") .content(new ObjectMapper().writeValueAsString(priorityCreateRequest)) .contentType(MediaType.APPLICATION_JSON_VALUE)) //.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").exists()) .andExpect(jsonPath("$.title").value("Very very high")) .andExpect(jsonPath("$.color").value("#123")); } }