Guest User

Untitled

a guest
Dec 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. @RestController
  2. public class ReservationController
  3. {
  4. @Autowired private Reservation reservation;
  5.  
  6. @RequestMapping(value="/reservation", produces=MediaType.APPLICATION_JSON_UTF8_VALUE, method=RequestMethod.POST)
  7. @ResponseBody
  8. public Reservation getReservation()
  9. {
  10.  
  11. return reservation;
  12. }
  13. }
  14.  
  15. public class Reservation
  16. {
  17. private long id;
  18. private String reservationName;
  19.  
  20. public Reservation() {
  21. super();
  22. this.id = 333;
  23. this.reservationName = "prova123";
  24. }
  25.  
  26. public Reservation(long id, String reservationName) {
  27. super();
  28. this.id = id;
  29. this.reservationName = reservationName;
  30. }
  31.  
  32. public long getId() {
  33. return id;
  34. }
  35.  
  36. public void setId(long id) {
  37. this.id = id;
  38. }
  39.  
  40. public String getReservationName() {
  41. return reservationName;
  42. }
  43.  
  44. public void setReservationName(String reservationName) {
  45. this.reservationName = reservationName;
  46. }
  47.  
  48. @Override
  49. public String toString() {
  50. return "Reservation [id=" + id + ", reservationName=" + reservationName + "]";
  51. }
  52. }
  53.  
  54. @WebMvcTest
  55. @RunWith(SpringRunner.class)
  56. public class MvcTest
  57. {
  58. @Autowired private MockMvc mockMvc;
  59.  
  60. @MockBean(name="reservation")
  61. private Reservation reservation;
  62.  
  63. @Test public void postReservation() throws Exception
  64. {
  65. mockMvc.perform(MockMvcRequestBuilders.post("/reservation"))
  66. .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
  67. .andExpect(MockMvcResultMatchers.status().isOk());
  68. }
Add Comment
Please, Sign In to add comment