1616import org .junit .runner .RunWith ;
1717import org .springframework .beans .factory .annotation .Autowired ;
1818import org .springframework .security .crypto .password .PasswordEncoder ;
19- import org .springframework .test .context .ActiveProfiles ;
2019import org .springframework .test .context .ContextConfiguration ;
2120import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
2221import org .springframework .test .context .support .AnnotationConfigContextLoader ;
2827
2928@ RunWith (SpringJUnit4ClassRunner .class )
3029@ ContextConfiguration (classes = { ConfigTest .class , PersistenceJPAConfig .class }, loader = AnnotationConfigContextLoader .class )
31- @ ActiveProfiles ("test" )
32- public class RegistrationAPIChangePasswordTest {
30+ public class ChangePasswordApiTest {
31+
32+ private final String URL_PREFIX = "http://localhost:8080/spring-security-login-and-registration" ;
33+ private final String URL = URL_PREFIX + "/user/updatePassword" ;
3334
3435 @ Autowired
3536 private UserRepository userRepository ;
3637
3738 @ Autowired
3839 private PasswordEncoder passwordEncoder ;
3940
40- private final String URL_PREFIX = "http://localhost:8080/spring-security-login-and-registration" ;
41-
42- private final String URL = URL_PREFIX + "/user/updatePassword" ;
43-
44- FormAuthConfig formConfig = new FormAuthConfig (URL_PREFIX + "/j_spring_security_check" , "j_username" , "j_password" );
41+ private final FormAuthConfig formConfig = new FormAuthConfig (URL_PREFIX + "/j_spring_security_check" , "j_username" , "j_password" );
4542
4643 @ Before
4744 public void init () {
@@ -60,6 +57,8 @@ public void init() {
6057 }
6158 }
6259
60+ // test
61+
6362 @ Test
6463 public void givenLoggedInUser_whenChangingPassword_thenCorrect () {
6564 final RequestSpecification request =
RestAssured .
given ().
auth ().
form (
"[email protected] " ,
"test" ,
formConfig );
@@ -99,4 +98,5 @@ public void givenNotAuthenticatedUser_whenChangingPassword_thenRedirect() {
9998 assertEquals (302 , response .statusCode ());
10099 assertFalse (response .body ().asString ().contains ("Password updated successfully" ));
101100 }
101+
102102}
0 commit comments