Search in sources :

Example 6 with PersistableUser

use of com.salesmanager.shop.model.user.PersistableUser 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

PersistableUser (com.salesmanager.shop.model.user.PersistableUser)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 User (com.salesmanager.core.model.user.User)5 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)5 PersistableGroup (com.salesmanager.shop.model.security.PersistableGroup)4 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)4 Group (com.salesmanager.core.model.user.Group)3 ReadableGroup (com.salesmanager.shop.model.security.ReadableGroup)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 UserPassword (com.salesmanager.shop.model.user.UserPassword)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1