11package com .booking .backend .controller ;
22
3+ import com .booking .backend .entity .Organization ;
4+ import com .booking .backend .entity .Person ;
5+ import com .booking .backend .repository .PersonRepository ;
6+ import org .junit .jupiter .api .AfterEach ;
7+ import org .junit .jupiter .api .BeforeEach ;
38import org .junit .jupiter .api .Test ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
11+ import org .springframework .boot .test .context .SpringBootTest ;
12+ import org .springframework .test .web .servlet .MockMvc ;
413
14+ import static org .hamcrest .Matchers .hasSize ;
15+ import static org .hamcrest .Matchers .is ;
516import static org .junit .jupiter .api .Assertions .*;
17+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
18+ import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
19+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
20+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
621
22+ @ SpringBootTest
23+ @ AutoConfigureMockMvc
724class PersonControllerTest {
825
9- @ Test
10- void getPersonById () {
26+ @ Autowired
27+ private MockMvc mockMvc ;
28+
29+ @ Autowired
30+ private PersonRepository personRepository ;
31+
32+
33+ @ BeforeEach
34+ void init () {
35+ personRepository .save (
36+ new Person (1L , "Alex" ));
37+ }
38+
39+ @ AfterEach
40+ void destroy () {
41+ personRepository .deleteAll ();
1142 }
1243
1344 @ Test
14- void addNewBooking () {
45+ void getPersonById () throws Exception {
46+ mockMvc .perform (get ("/person" ).param ("id" , "1" ))
47+ .andDo (print ())
48+ .andExpect (status ().isOk ())
49+ .andExpect (jsonPath ("$.id" , is (1 )));
1550 }
1651}
0 commit comments