Search in sources :

Example 26 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method updateUserExistingLogin.

@Test
public void updateUserExistingLogin() throws Exception {
    // Initialize the database
    userRepository.save(user);
    User anotherUser = new User();
    anotherUser.setId(UUID.randomUUID().toString());
    anotherUser.setLogin("jhipster");
    anotherUser.setPassword(RandomStringUtils.random(60));
    anotherUser.setActivated(true);
    anotherUser.setEmail("jhipster@localhost");
    anotherUser.setFirstName("java");
    anotherUser.setLastName("hipster");
    anotherUser.setLangKey("en");
    userRepository.save(anotherUser);
    // Update the user
    User updatedUser = userRepository.findById(user.getId()).get();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(updatedUser.getId());
    // this login should already be used by anotherUser
    managedUserVM.setLogin("jhipster");
    managedUserVM.setPassword(updatedUser.getPassword());
    managedUserVM.setFirstName(updatedUser.getFirstName());
    managedUserVM.setLastName(updatedUser.getLastName());
    managedUserVM.setEmail(updatedUser.getEmail());
    managedUserVM.setActivated(updatedUser.getActivated());
    managedUserVM.setLangKey(updatedUser.getLangKey());
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    restUserMockMvc.perform(put("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
}
Also used : User(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 27 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method createUser.

@Test
public void createUser() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    // Create the User
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setLogin(DEFAULT_LOGIN);
    managedUserVM.setPassword(DEFAULT_PASSWORD);
    managedUserVM.setFirstName(DEFAULT_FIRSTNAME);
    managedUserVM.setLastName(DEFAULT_LASTNAME);
    managedUserVM.setEmail(DEFAULT_EMAIL);
    managedUserVM.setActivated(true);
    managedUserVM.setLangKey(DEFAULT_LANGKEY);
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isCreated());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeCreate + 1);
    User testUser = userList.get(userList.size() - 1);
    assertThat(testUser.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(testUser.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(testUser.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(testUser.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(testUser.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
}
Also used : User(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method createUserWithExistingLogin.

@Test
public void createUserWithExistingLogin() throws Exception {
    // Initialize the database
    userRepository.save(user);
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    // this login should already be used
    managedUserVM.setLogin(DEFAULT_LOGIN);
    managedUserVM.setPassword(DEFAULT_PASSWORD);
    managedUserVM.setFirstName(DEFAULT_FIRSTNAME);
    managedUserVM.setLastName(DEFAULT_LASTNAME);
    managedUserVM.setEmail("anothermail@localhost");
    managedUserVM.setActivated(true);
    managedUserVM.setLangKey(DEFAULT_LANGKEY);
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    // 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(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method updateUserLogin.

@Test
public void updateUserLogin() throws Exception {
    // Initialize the database
    userRepository.save(user);
    int databaseSizeBeforeUpdate = userRepository.findAll().size();
    // Update the user
    User updatedUser = userRepository.findById(user.getId()).get();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(updatedUser.getId());
    managedUserVM.setLogin(UPDATED_LOGIN);
    managedUserVM.setPassword(UPDATED_PASSWORD);
    managedUserVM.setFirstName(UPDATED_FIRSTNAME);
    managedUserVM.setLastName(UPDATED_LASTNAME);
    managedUserVM.setEmail(UPDATED_EMAIL);
    managedUserVM.setActivated(updatedUser.getActivated());
    managedUserVM.setLangKey(UPDATED_LANGKEY);
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    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.getLangKey()).isEqualTo(UPDATED_LANGKEY);
}
Also used : User(io.github.jhipster.sample.domain.User) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-mongodb by jhipster.

the class AccountResourceIntTest method testRegisterInvalidEmail.

@Test
public void testRegisterInvalidEmail() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM();
    invalidUser.setLogin("bob");
    invalidUser.setPassword("password");
    invalidUser.setFirstName("Bob");
    invalidUser.setLastName("Green");
    // <-- invalid
    invalidUser.setEmail("invalid");
    invalidUser.setActivated(true);
    invalidUser.setImageUrl("http://placehold.it/50x50");
    invalidUser.setLangKey(Constants.DEFAULT_LANGUAGE);
    invalidUser.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    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();
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ManagedUserVM(io.github.jhipster.sample.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ManagedUserVM (io.github.jhipster.sample.web.rest.vm.ManagedUserVM)96 Test (org.junit.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)96 User (io.github.jhipster.sample.domain.User)90 Transactional (org.springframework.transaction.annotation.Transactional)64 WithMockUser (org.springframework.security.test.context.support.WithMockUser)42 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)16