Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestController
- public class ReservationController
- {
- @Autowired private Reservation reservation;
- @RequestMapping(value="/reservation", produces=MediaType.APPLICATION_JSON_UTF8_VALUE, method=RequestMethod.POST)
- @ResponseBody
- public Reservation getReservation()
- {
- return reservation;
- }
- }
- public class Reservation
- {
- private long id;
- private String reservationName;
- public Reservation() {
- super();
- this.id = 333;
- this.reservationName = "prova123";
- }
- public Reservation(long id, String reservationName) {
- super();
- this.id = id;
- this.reservationName = reservationName;
- }
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getReservationName() {
- return reservationName;
- }
- public void setReservationName(String reservationName) {
- this.reservationName = reservationName;
- }
- @Override
- public String toString() {
- return "Reservation [id=" + id + ", reservationName=" + reservationName + "]";
- }
- }
- @WebMvcTest
- @RunWith(SpringRunner.class)
- public class MvcTest
- {
- @Autowired private MockMvc mockMvc;
- @MockBean(name="reservation")
- private Reservation reservation;
- @Test public void postReservation() throws Exception
- {
- mockMvc.perform(MockMvcRequestBuilders.post("/reservation"))
- .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
- .andExpect(MockMvcResultMatchers.status().isOk());
- }
Add Comment
Please, Sign In to add comment