Search in sources :

Example 1 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterInvalidPassword.

@Test
@Transactional
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.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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterInvalidEmail.

@Test
@Transactional
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterValid.

@Test
@Transactional
public void testRegisterValid() throws Exception {
    ManagedUserVM validUser = new ManagedUserVM();
    validUser.setLogin("joe");
    validUser.setPassword("password");
    validUser.setFirstName("Joe");
    validUser.setLastName("Shmoe");
    validUser.setEmail("joe@example.com");
    validUser.setActivated(true);
    validUser.setImageUrl("http://placehold.it/50x50");
    validUser.setLangKey(Constants.DEFAULT_LANGUAGE);
    validUser.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    assertThat(userRepository.findOneByLogin("joe").isPresent()).isFalse();
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
    assertThat(userRepository.findOneByLogin("joe").isPresent()).isTrue();
}
Also used : 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 4 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterDuplicateLogin.

@Test
@Transactional
public void testRegisterDuplicateLogin() throws Exception {
    // Good
    ManagedUserVM validUser = new ManagedUserVM();
    validUser.setLogin("alice");
    validUser.setPassword("password");
    validUser.setFirstName("Alice");
    validUser.setLastName("Something");
    validUser.setEmail("alice@example.com");
    validUser.setActivated(true);
    validUser.setImageUrl("http://placehold.it/50x50");
    validUser.setLangKey(Constants.DEFAULT_LANGUAGE);
    validUser.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    // Duplicate login, different email
    ManagedUserVM duplicatedUser = new ManagedUserVM();
    duplicatedUser.setLogin(validUser.getLogin());
    duplicatedUser.setPassword(validUser.getPassword());
    duplicatedUser.setFirstName(validUser.getFirstName());
    duplicatedUser.setLastName(validUser.getLastName());
    duplicatedUser.setEmail("alicejr@example.com");
    duplicatedUser.setActivated(validUser.isActivated());
    duplicatedUser.setImageUrl(validUser.getImageUrl());
    duplicatedUser.setLangKey(validUser.getLangKey());
    duplicatedUser.setCreatedBy(validUser.getCreatedBy());
    duplicatedUser.setCreatedDate(validUser.getCreatedDate());
    duplicatedUser.setLastModifiedBy(validUser.getLastModifiedBy());
    duplicatedUser.setLastModifiedDate(validUser.getLastModifiedDate());
    duplicatedUser.setAuthorities(new HashSet<>(validUser.getAuthorities()));
    // 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();
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ManagedUserVM

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

the class UserResourceIntTest method createUserWithExistingEmail.

@Test
@Transactional
public void createUserWithExistingEmail() throws Exception {
    // Initialize the database
    userRepository.saveAndFlush(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)

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