use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.
the class UserMapper method userFromId.
public User userFromId(Long id) {
if (id == null) {
return null;
}
User user = new User();
user.setId(id);
return user;
}
use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.
the class AccountResourceIntTest method testRegisterDuplicateEmail.
@Test
@Transactional
public void testRegisterDuplicateEmail() throws Exception {
// Good
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"john", // password
"password", // firstName
"John", // lastName
"Doe", // email
"john@example.com", // activated
true, // imageUrl
"http://placehold.it/50x50", // langKey
Constants.DEFAULT_LANGUAGE, // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.USER)));
// Duplicate email, different login
ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), "johnjr", validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), validUser.getEmail(), true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities());
// Good user
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
// Duplicate email
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
// Duplicate email - with uppercase email address
final ManagedUserVM userWithUpperCaseEmail = new ManagedUserVM(validUser.getId(), "johnjr", validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), validUser.getEmail().toUpperCase(), true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities());
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userWithUpperCaseEmail))).andExpect(status().is4xxClientError());
Optional<User> userDup = userRepository.findOneByLogin("johnjr");
assertThat(userDup.isPresent()).isFalse();
}
use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.
the class AccountResourceIntTest method testRegisterAdminIsIgnored.
@Test
@Transactional
public void testRegisterAdminIsIgnored() throws Exception {
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"badguy", // password
"password", // firstName
"Bad", // lastName
"Guy", // email
"badguy@example.com", // activated
true, // imageUrl
"http://placehold.it/50x50", // langKey
Constants.DEFAULT_LANGUAGE, // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
Optional<User> userDup = userRepository.findOneByLogin("badguy");
assertThat(userDup.isPresent()).isTrue();
assertThat(userDup.get().getAuthorities()).hasSize(1).containsExactly(authorityRepository.findOne(AuthoritiesConstants.USER));
}
use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.
the class AccountResourceIntTest method testSaveExistingEmail.
@Test
@Transactional
@WithMockUser("save-existing-email")
public void testSaveExistingEmail() throws Exception {
User user = new User();
user.setLogin("save-existing-email");
user.setEmail("save-existing-email@example.com");
user.setPassword(RandomStringUtils.random(60));
user.setActivated(true);
userRepository.saveAndFlush(user);
User anotherUser = new User();
anotherUser.setLogin("save-existing-email2");
anotherUser.setEmail("save-existing-email2@example.com");
anotherUser.setPassword(RandomStringUtils.random(60));
anotherUser.setActivated(true);
userRepository.saveAndFlush(anotherUser);
UserDTO userDTO = new UserDTO(// id
null, // login
"not-used", // firstName
"firstname", // lastName
"lastname", // email
"save-existing-email2@example.com", // activated
false, // imageUrl
"http://placehold.it/50x50", // langKey
Constants.DEFAULT_LANGUAGE, // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("save-existing-email").orElse(null);
assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email@example.com");
}
use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.
the class AccountResourceIntTest method testSaveInvalidEmail.
@Test
@Transactional
@WithMockUser("save-invalid-email")
public void testSaveInvalidEmail() throws Exception {
User user = new User();
user.setLogin("save-invalid-email");
user.setEmail("save-invalid-email@example.com");
user.setPassword(RandomStringUtils.random(60));
user.setActivated(true);
userRepository.saveAndFlush(user);
UserDTO userDTO = new UserDTO(// id
null, // login
"not-used", // firstName
"firstname", // lastName
"lastname", // email
"invalid email", // activated
false, // imageUrl
"http://placehold.it/50x50", // langKey
Constants.DEFAULT_LANGUAGE, // createdBy
null, // createdDate
null, // lastModifiedBy
null, // lastModifiedDate
null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isBadRequest());
assertThat(userRepository.findOneByEmailIgnoreCase("invalid email")).isNotPresent();
}
Aggregations