Search in sources :

Example 1 with UserPassword

use of com.salesmanager.shop.model.user.UserPassword in project shopizer by shopizer-ecommerce.

the class UserApiIntegrationTest method createUserChangePassword.

@Test
public void createUserChangePassword() throws Exception {
    PersistableUser newUser = new PersistableUser();
    newUser.setDefaultLanguage("en");
    newUser.setEmailAddress("test@test.com");
    newUser.setFirstName("Test");
    newUser.setLastName("User");
    newUser.setUserName("test@test.com");
    newUser.setPassword(CREATED_PASSWORD);
    newUser.setRepeatPassword(CREATED_PASSWORD);
    PersistableGroup g = new PersistableGroup();
    g.setName("ADMIN");
    newUser.getGroups().add(g);
    final HttpEntity<PersistableUser> persistableUser = new HttpEntity<PersistableUser>(newUser, getHeader());
    ReadableUser user = null;
    final ResponseEntity<ReadableUser> response = testRestTemplate.exchange(String.format("/api/v1/private/user/"), HttpMethod.POST, persistableUser, ReadableUser.class);
    if (response.getStatusCode() != HttpStatus.OK) {
        throw new Exception(response.toString());
    } else {
        user = response.getBody();
        assertNotNull(user);
    }
    String oldPassword = CREATED_PASSWORD;
    String newPassword = NEW_CREATED_PASSWORD;
    String repeatPassword = newPassword;
    UserPassword userPassword = new UserPassword();
    userPassword.setPassword(oldPassword);
    userPassword.setChangePassword(newPassword);
    final HttpEntity<UserPassword> changePasswordEntity = new HttpEntity<UserPassword>(userPassword, getHeader());
    final ResponseEntity<Void> changePassword = testRestTemplate.exchange(String.format("/api/v1/private/user/" + user.getId() + "/password"), HttpMethod.PATCH, changePasswordEntity, Void.class);
    if (changePassword.getStatusCode() != HttpStatus.OK) {
        throw new Exception(response.toString());
    } else {
        assertNotNull("Password changed");
    }
}
Also used : PersistableGroup(com.salesmanager.shop.model.security.PersistableGroup) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) HttpEntity(org.springframework.http.HttpEntity) UserPassword(com.salesmanager.shop.model.user.UserPassword) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersistableGroup (com.salesmanager.shop.model.security.PersistableGroup)1 PersistableUser (com.salesmanager.shop.model.user.PersistableUser)1 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)1 UserPassword (com.salesmanager.shop.model.user.UserPassword)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1