Skip to content

Instantly share code, notes, and snippets.

@roshanadh
Last active October 21, 2022 18:03
Show Gist options
  • Save roshanadh/8dc3e4180d8267c7f5d2312f7a5679b1 to your computer and use it in GitHub Desktop.
Save roshanadh/8dc3e4180d8267c7f5d2312f7a5679b1 to your computer and use it in GitHub Desktop.
Testing GET /batteries/:id
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