use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class AccountResourceIntTest method testRegisterDuplicateLogin.
@Test
@Transactional
public void testRegisterDuplicateLogin() throws Exception {
// Good
ManagedUserVM validUser = new ManagedUserVM(// id
null, // login
"alice", // password
"password", // firstName
"Alice", // lastName
"Something", // email
"alice@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>());
// Duplicate login, different email
ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), validUser.getLogin(), validUser.getPassword(), validUser.getFirstName(), validUser.getLastName(), "alicejr@example.com", true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities(), validUser.getGroups());
// Good user
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
// Duplicate login
restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
Optional<User> userDup = userRepository.findOneByEmailIgnoreCase("alicejr@example.com");
assertThat(userDup.isPresent()).isFalse();
}
use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class AccountResourceIntTest method testRegisterInvalidEmail.
@Test
@Transactional
public void testRegisterInvalidEmail() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login
"bob", // password
"password", // firstName
"Bob", // lastName
"Green", // email <-- invalid
"invalid", // 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 AccountResourceIntTest method testRegisterInvalidLogin.
@Test
@Transactional
public void testRegisterInvalidLogin() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login <-- invalid
"funky-log!n", // password
"password", // firstName
"Funky", // lastName
"One", // email
"funky@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.findOneByEmailIgnoreCase("funky@example.com");
assertThat(user.isPresent()).isFalse();
}
use of de.tum.in.www1.artemis.web.rest.vm.ManagedUserVM in project ArTEMiS by ls1intum.
the class AccountResourceIntTest method testRegisterInvalidPassword.
@Test
@Transactional
public void testRegisterInvalidPassword() throws Exception {
ManagedUserVM invalidUser = new ManagedUserVM(// id
null, // login
"bob", // password with only 3 digits
"123", // 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 createUserWithExistingLogin.
@Test
@Transactional
public void createUserWithExistingLogin() 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, // this login should already be used
DEFAULT_LOGIN, DEFAULT_PASSWORD, DEFAULT_FIRSTNAME, DEFAULT_LASTNAME, "anothermail@localhost", 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