Last active
October 21, 2022 18:03
-
-
Save roshanadh/8dc3e4180d8267c7f5d2312f7a5679b1 to your computer and use it in GitHub Desktop.
Testing GET /batteries/:id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package np.com.roshanadhikary.testdemo; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | |
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
@SpringBootTest | |
@AutoConfigureMockMvc | |
class ApplicationTests { | |
// .. | |
@Test | |
void shouldFetchBatteryID1() throws Exception { | |
mockMvc | |
.perform(get("/batteries/1")) | |
.andDo(print()) | |
.andExpect(status().isOk()) | |
.andExpect(jsonPath("$.id").value(1)) | |
.andExpect(jsonPath("$.name").value(H2Bootstrap.mockBatteries.get(0).getName())) | |
.andExpect(jsonPath("$.postcode").value(H2Bootstrap.mockBatteries.get(0).getPostcode())) | |
.andExpect(jsonPath("$.capacity").value(H2Bootstrap.mockBatteries.get(0).getCapacity())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment