Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1.  
  2.     @Autowired
  3.     private UserService userService;
  4.  
  5.     @PostMapping("/register")
  6.     public ResponseEntity<?> register(@RequestBody PostRegisterRequestDto dto) {
  7.         User u = userService.register(dto);
  8.         return new ResponseEntity<>(u, HttpStatus.OK);
  9.     }
  10.  
  11.  
  12.   @Test
  13.     @WithMockUser(username = "test", password = "test", roles = "USER")
  14.     public void whenChuj_thenCHuj() throws Exception {
  15.         PostRegisterRequestDto dto = new PostRegisterRequestDto("Username,", "Password",
  16.                 "Phonenumber", "firstname", "lastname",
  17.                 "asdsadsa");
  18.         User u = new User("a", "b", "c", true,
  19.                 true, true, LocalDateTime.now(), LocalDateTime.now(), new Role("role1"));
  20.         given(userService.register(dto)).willReturn(u);
  21.         String dupa = objectMapper.writeValueAsString(dto);
  22.         this
  23.                 .mockMvc
  24.                 .perform(post("/user/register").contentType(MediaType.APPLICATION_JSON_VALUE)
  25.                         .content(objectMapper.writeValueAsString(dto)))
  26.                 .andExpect(status().isOk()).andExpect(content().json(objectMapper.writeValueAsString(u)));
  27.  
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement