11
11
import org .springframework .beans .factory .annotation .Autowired ;
12
12
import org .springframework .http .MediaType ;
13
13
14
+ import com .fasterxml .jackson .core .JsonProcessingException ;
15
+ import com .naturalprogrammer .spring .lemon .commons .domain .ResetPasswordForm ;
14
16
import com .naturalprogrammer .spring .lemon .commons .security .JwtService ;
15
17
import com .naturalprogrammer .spring .lemon .commons .util .LecUtils ;
18
+ import com .naturalprogrammer .spring .lemon .util .LemonUtils ;
16
19
17
20
public class ResetPasswordMvcTests extends AbstractMvcTests {
18
21
@@ -37,9 +40,8 @@ public void testResetPassword() throws Exception {
37
40
//Thread.sleep(1001L);
38
41
39
42
mvc .perform (post ("/api/core/reset-password" )
40
- .param ("code" , forgotPasswordCode )
41
- .param ("newPassword" , NEW_PASSWORD )
42
- .header ("contentType" , MediaType .APPLICATION_FORM_URLENCODED ))
43
+ .contentType (MediaType .APPLICATION_JSON )
44
+ .content (form (forgotPasswordCode , NEW_PASSWORD )))
43
45
.andExpect (status ().is (200 ))
44
46
.andExpect (header ().string (LecUtils .TOKEN_RESPONSE_HEADER_NAME , containsString ("." )))
45
47
.andExpect (jsonPath ("$.id" ).value (ADMIN_ID ));
@@ -49,9 +51,8 @@ public void testResetPassword() throws Exception {
49
51
50
52
// Repeating shouldn't work
51
53
mvc .perform (post ("/api/core/reset-password" )
52
- .param ("code" , forgotPasswordCode )
53
- .param ("newPassword" , NEW_PASSWORD )
54
- .header ("contentType" , MediaType .APPLICATION_FORM_URLENCODED ))
54
+ .contentType (MediaType .APPLICATION_JSON )
55
+ .content (form (forgotPasswordCode , NEW_PASSWORD )))
55
56
.andExpect (status ().is (401 ));
56
57
}
57
58
@@ -60,23 +61,29 @@ public void testResetPasswordInvalidData() throws Exception {
60
61
61
62
// Wrong code
62
63
mvc .perform (post ("/api/core/reset-password" )
63
- .param ("code" , "wrong-code" )
64
- .param ("newPassword" , "abc99!" )
65
- .header ("contentType" , MediaType .APPLICATION_FORM_URLENCODED ))
64
+ .contentType (MediaType .APPLICATION_JSON )
65
+ .content (form ("wrong-code" , "abc99!" )))
66
66
.andExpect (status ().is (401 ));
67
67
68
68
// Blank password
69
69
mvc .perform (post ("/api/core/reset-password" )
70
- .param ("code" , forgotPasswordCode )
71
- .param ("newPassword" , "" )
72
- .header ("contentType" , MediaType .APPLICATION_FORM_URLENCODED ))
70
+ .contentType (MediaType .APPLICATION_JSON )
71
+ .content (form (forgotPasswordCode , "" )))
73
72
.andExpect (status ().is (422 ));
74
73
75
74
// Invalid password
76
75
mvc .perform (post ("/api/core/reset-password" )
77
- .param ("code" , forgotPasswordCode )
78
- .param ("newPassword" , "abc" )
79
- .header ("contentType" , MediaType .APPLICATION_FORM_URLENCODED ))
76
+ .contentType (MediaType .APPLICATION_JSON )
77
+ .content (form (forgotPasswordCode , "abc" )))
80
78
.andExpect (status ().is (422 ));
81
79
}
80
+
81
+ private String form (String code , String newPassword ) throws JsonProcessingException {
82
+
83
+ ResetPasswordForm form = new ResetPasswordForm ();
84
+ form .setCode (code );
85
+ form .setNewPassword (newPassword );
86
+
87
+ return LemonUtils .toJson (form );
88
+ }
82
89
}
0 commit comments