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");
}
}
Aggregations