|
| 1 | +package org.baeldung.converter.controller; |
| 2 | + |
| 3 | +import org.baeldung.Application; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 8 | +import org.springframework.boot.test.context.SpringBootTest; |
| 9 | +import org.springframework.test.context.junit4.SpringRunner; |
| 10 | +import org.springframework.test.web.servlet.MockMvc; |
| 11 | + |
| 12 | +import static org.hamcrest.CoreMatchers.is; |
| 13 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 14 | +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
| 15 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
| 16 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 17 | + |
| 18 | +@RunWith(SpringRunner.class) |
| 19 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class) |
| 20 | +@AutoConfigureMockMvc |
| 21 | +public class StringToEmployeeConverterControllerTest { |
| 22 | + |
| 23 | + @Autowired |
| 24 | + private MockMvc mockMvc; |
| 25 | + |
| 26 | + @Test |
| 27 | + public void getStringToEmployeeTest() throws Exception { |
| 28 | + mockMvc.perform(get("/string-to-employee?employee=1,2000")) |
| 29 | + .andDo(print()) |
| 30 | + .andExpect(jsonPath("$.id", is(1))) |
| 31 | + .andExpect(jsonPath("$.salary", is(2000.0))) |
| 32 | + .andExpect(status().isOk()); |
| 33 | + } |
| 34 | +} |
0 commit comments