Search in sources :

Example 6 with ManagedUserVM

use of com.baeldung.web.rest.vm.ManagedUserVM in project tutorials by eugenp.

the class UserResourceIntegrationTest 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);
    int databaseSizeBeforeUpdate = userRepository.findAll().size();
    // Update the user
    User updatedUser = userRepository.findOne(user.getId());
    Set<String> autorities = new HashSet<>();
    autorities.add("ROLE_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(), autorities);
    restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
}
Also used : User(com.baeldung.domain.User) ManagedUserVM(com.baeldung.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ManagedUserVM

use of com.baeldung.web.rest.vm.ManagedUserVM in project tutorials by eugenp.

the class UserResourceIntegrationTest method createUserWithExistingLogin.

@Test
@Transactional
public void createUserWithExistingLogin() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    Set<String> autorities = new HashSet<>();
    autorities.add("ROLE_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, autorities);
    // 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);
}
Also used : User(com.baeldung.domain.User) ManagedUserVM(com.baeldung.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ManagedUserVM

use of com.baeldung.web.rest.vm.ManagedUserVM in project tutorials by eugenp.

the class UserResourceIntegrationTest method updateUserExistingLogin.

@Test
@Transactional
public void updateUserExistingLogin() throws Exception {
    // Initialize the database
    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);
    int databaseSizeBeforeUpdate = userRepository.findAll().size();
    // Update the user
    User updatedUser = userRepository.findOne(user.getId());
    Set<String> autorities = new HashSet<>();
    autorities.add("ROLE_USER");
    ManagedUserVM managedUserVM = new ManagedUserVM(updatedUser.getId(), // this login should already be used by anotherUser
    "jhipster", updatedUser.getPassword(), updatedUser.getFirstName(), updatedUser.getLastName(), updatedUser.getEmail(), updatedUser.getActivated(), updatedUser.getImageUrl(), updatedUser.getLangKey(), updatedUser.getCreatedBy(), updatedUser.getCreatedDate(), updatedUser.getLastModifiedBy(), updatedUser.getLastModifiedDate(), autorities);
    restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
}
Also used : User(com.baeldung.domain.User) ManagedUserVM(com.baeldung.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with ManagedUserVM

use of com.baeldung.web.rest.vm.ManagedUserVM in project tutorials by eugenp.

the class UserResourceIntegrationTest method updateUserLogin.

@Test
@Transactional
public void updateUserLogin() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    int databaseSizeBeforeUpdate = userRepository.findAll().size();
    // Update the user
    User updatedUser = userRepository.findOne(user.getId());
    Set<String> autorities = new HashSet<>();
    autorities.add("ROLE_USER");
    ManagedUserVM managedUserVM = new ManagedUserVM(updatedUser.getId(), UPDATED_LOGIN, UPDATED_PASSWORD, UPDATED_FIRSTNAME, UPDATED_LASTNAME, UPDATED_EMAIL, updatedUser.getActivated(), UPDATED_IMAGEURL, UPDATED_LANGKEY, updatedUser.getCreatedBy(), updatedUser.getCreatedDate(), updatedUser.getLastModifiedBy(), updatedUser.getLastModifiedDate(), autorities);
    restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isOk());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeUpdate);
    User testUser = userList.get(userList.size() - 1);
    assertThat(testUser.getLogin()).isEqualTo(UPDATED_LOGIN);
    assertThat(testUser.getFirstName()).isEqualTo(UPDATED_FIRSTNAME);
    assertThat(testUser.getLastName()).isEqualTo(UPDATED_LASTNAME);
    assertThat(testUser.getEmail()).isEqualTo(UPDATED_EMAIL);
    assertThat(testUser.getImageUrl()).isEqualTo(UPDATED_IMAGEURL);
    assertThat(testUser.getLangKey()).isEqualTo(UPDATED_LANGKEY);
}
Also used : User(com.baeldung.domain.User) ManagedUserVM(com.baeldung.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ManagedUserVM

use of com.baeldung.web.rest.vm.ManagedUserVM in project tutorials by eugenp.

the class UserResourceIntegrationTest method createUserWithExistingEmail.

@Test
@Transactional
public void createUserWithExistingEmail() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    Set<String> autorities = new HashSet<>();
    autorities.add("ROLE_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, autorities);
    // 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);
}
Also used : User(com.baeldung.domain.User) ManagedUserVM(com.baeldung.web.rest.vm.ManagedUserVM) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.baeldung.domain.User)16 ManagedUserVM (com.baeldung.web.rest.vm.ManagedUserVM)16 Test (org.junit.Test)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 Transactional (org.springframework.transaction.annotation.Transactional)15 HashSet (java.util.HashSet)8 UserRepository (com.baeldung.repository.UserRepository)1 SecurityUtils (com.baeldung.security.SecurityUtils)1 MailService (com.baeldung.service.MailService)1 UserService (com.baeldung.service.UserService)1 UserDTO (com.baeldung.service.dto.UserDTO)1 HeaderUtil (com.baeldung.web.rest.util.HeaderUtil)1 KeyAndPasswordVM (com.baeldung.web.rest.vm.KeyAndPasswordVM)1 Timed (com.codahale.metrics.annotation.Timed)1 java.util (java.util)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Valid (javax.validation.Valid)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1