Search in sources :

Example 51 with ManagedUserVM

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

the class UserResourceIntTest method createUserWithExistingLogin.

@Test
@Transactional
public void createUserWithExistingLogin() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    mockUserSearchRepository.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.setImageUrl(DEFAULT_IMAGEURL);
    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) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with ManagedUserVM

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

the class UserResourceIntTest method createUserWithExistingEmail.

@Test
@Transactional
public void createUserWithExistingEmail() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(user);
    mockUserSearchRepository.save(user);
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setLogin("anotherlogin");
    managedUserVM.setPassword(DEFAULT_PASSWORD);
    managedUserVM.setFirstName(DEFAULT_FIRSTNAME);
    managedUserVM.setLastName(DEFAULT_LASTNAME);
    // this email should already be used
    managedUserVM.setEmail(DEFAULT_EMAIL);
    managedUserVM.setActivated(true);
    managedUserVM.setImageUrl(DEFAULT_IMAGEURL);
    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) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterInvalidPassword.

@Test
public void testRegisterInvalidPassword() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM();
    invalidUser.setLogin("bob");
    // password with only 3 digits
    invalidUser.setPassword("123");
    invalidUser.setFirstName("Bob");
    invalidUser.setLastName("Green");
    invalidUser.setEmail("bob@example.com");
    invalidUser.setActivated(true);
    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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 54 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterNullPassword.

@Test
public void testRegisterNullPassword() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM();
    invalidUser.setLogin("bob");
    // invalid null password
    invalidUser.setPassword(null);
    invalidUser.setFirstName("Bob");
    invalidUser.setLastName("Green");
    invalidUser.setEmail("bob@example.com");
    invalidUser.setActivated(true);
    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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 55 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterAdminIsIgnored.

@Test
public void testRegisterAdminIsIgnored() throws Exception {
    ManagedUserVM validUser = new ManagedUserVM();
    validUser.setLogin("badguy");
    validUser.setPassword("password");
    validUser.setFirstName("Bad");
    validUser.setLastName("Guy");
    validUser.setEmail("badguy@example.com");
    validUser.setActivated(true);
    validUser.setLangKey(Constants.DEFAULT_LANGUAGE);
    validUser.setAuthorities(Collections.singleton(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(AuthoritiesConstants.USER);
}
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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) 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