use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
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)), new ArrayList<String>());
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 de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class AccountResourceIntTest method testRegisterValid.
@Test
@Transactional
public void testRegisterValid() throws Exception {
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"joe", // password
"password", // firstName
"Joe", // lastName
"Shmoe", // email
"joe@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)), new ArrayList<String>());
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
Optional<User> user = userRepository.findOneByLogin("joe");
assertThat(user.isPresent()).isTrue();
}
use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class AccountResourceIntTest method testRegisterNullPassword.
@Test
@Transactional
public void testRegisterNullPassword() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login
"bob", // invalid null password
null, // firstName
"Bob", // lastName
"Green", // email
"bob@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)), new ArrayList<String>());
restUserMockMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(invalidUser))).andExpect(status().isBadRequest());
Optional<User> user = userRepository.findOneByLogin("bob");
assertThat(user.isPresent()).isFalse();
}
use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class UserResourceIntTest method updateUserExistingEmail.
@Test
@Transactional
public void updateUserExistingEmail() throws Exception {
// Initialize the database with 2 users
userRepository.saveAndFlush(user);
User anotherUser = new User();
anotherUser.setLogin("jhipster");
anotherUser.setPassword(RandomStringUtils.random(60));
anotherUser.setActivated(true);
anotherUser.setEmail("jhipster@localhost");
anotherUser.setFirstName("java");
anotherUser.setLastName("hipster");
anotherUser.setImageUrl("");
anotherUser.setLangKey("en");
userRepository.saveAndFlush(anotherUser);
// Update the user
User updatedUser = userRepository.findOne(user.getId());
Set<String> authorities = new HashSet<>();
authorities.add(AuthoritiesConstants.USER);
ManagedUserVM managedUserVM = new ManagedUserVM(updatedUser.getId(), updatedUser.getLogin(), updatedUser.getPassword(), updatedUser.getFirstName(), updatedUser.getLastName(), // this email should already be used by anotherUser
"jhipster@localhost", updatedUser.getActivated(), updatedUser.getImageUrl(), updatedUser.getLangKey(), updatedUser.getCreatedBy(), updatedUser.getCreatedDate(), updatedUser.getLastModifiedBy(), updatedUser.getLastModifiedDate(), authorities, new ArrayList<String>());
restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
}
use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class UserResourceIntTest method createUserWithExistingEmail.
@Test
@Transactional
public void createUserWithExistingEmail() throws Exception {
// Initialize the database
userRepository.saveAndFlush(user);
int databaseSizeBeforeCreate = userRepository.findAll().size();
Set<String> authorities = new HashSet<>();
authorities.add(AuthoritiesConstants.USER);
ManagedUserVM managedUserVM = new ManagedUserVM(null, "anotherlogin", DEFAULT_PASSWORD, DEFAULT_FIRSTNAME, DEFAULT_LASTNAME, // this email should already be used
DEFAULT_EMAIL, true, DEFAULT_IMAGEURL, DEFAULT_LANGKEY, null, null, null, null, authorities, new ArrayList<String>());
// Create the User
restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
// Validate the User in the database
List<User> userList = userRepository.findAll();
assertThat(userList).hasSize(databaseSizeBeforeCreate);
}
Aggregations