1st Version of ReservationControllerTest
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | |
import org.springframework.test.context.junit4.SpringRunner; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | |
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | |
import com.its.reservation.web.ReservationController; | |
/** | |
* @author Dhaval | |
* | |
*/ | |
@RunWith(SpringRunner.class) | |
@WebMvcTest(ReservationController.class) | |
public class ReservationControllerTest { | |
@Autowired | |
private MockMvc mockMvc; | |
@Test | |
public void getReservation_shouldReturnReservationInfo() { | |
try { | |
mockMvc.perform(MockMvcRequestBuilders.get("/reservation/Dhaval")) | |
.andExpect(MockMvcResultMatchers.status().isOk()) | |
.andExpect(MockMvcResultMatchers.jsonPath("firstName").value("Dhaval")) | |
.andExpect(MockMvcResultMatchers.jsonPath("lastName").value("Shah")); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment