Search in sources :

Example 71 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterAdminIsIgnored.

@Test
@Transactional
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.setImageUrl("http://placehold.it/50x50");
    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(authorityRepository.findById(AuthoritiesConstants.USER).get());
}
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 72 with ManagedUserVM

use of io.github.jhipster.sample.web.rest.vm.ManagedUserVM in project jhipster-sample-app-websocket 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 73 with ManagedUserVM

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

the class AccountResourceIntTest method testRegisterInvalidLogin.

@Test
@Transactional
public void testRegisterInvalidLogin() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM();
    // <-- invalid
    invalidUser.setLogin("funky-log!n");
    invalidUser.setPassword("password");
    invalidUser.setFirstName("Funky");
    invalidUser.setLastName("One");
    invalidUser.setEmail("funky@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.findOneByEmailIgnoreCase("funky@example.com");
    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 74 with ManagedUserVM

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

the class UserResourceIntTest 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);
    // 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.setImageUrl(updatedUser.getImageUrl());
    managedUserVM.setLangKey(updatedUser.getLangKey());
    managedUserVM.setCreatedBy(updatedUser.getCreatedBy());
    managedUserVM.setCreatedDate(updatedUser.getCreatedDate());
    managedUserVM.setLastModifiedBy(updatedUser.getLastModifiedBy());
    managedUserVM.setLastModifiedDate(updatedUser.getLastModifiedDate());
    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) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 75 with ManagedUserVM

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

the class UserResourceIntTest method createUserWithExistingLogin.

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

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