Search in sources :

Example 76 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra by jhipster.

the class AccountResourceIntTest method testSaveExistingEmailAndLogin.

@Test
@WithMockUser("save-existing-email-and-login")
public void testSaveExistingEmailAndLogin() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("save-existing-email-and-login");
    user.setEmail("save-existing-email-and-login@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.save(user);
    UserDTO userDTO = new UserDTO();
    userDTO.setLogin("not-used");
    userDTO.setFirstName("firstname");
    userDTO.setLastName("lastname");
    userDTO.setEmail("save-existing-email-and-login@example.com");
    userDTO.setActivated(false);
    userDTO.setLangKey(Constants.DEFAULT_LANGUAGE);
    userDTO.setAuthorities(Collections.singleton(AuthoritiesConstants.ADMIN));
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin("save-existing-email-and-login").orElse(null);
    assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email-and-login@example.com");
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 77 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra by jhipster.

the class UserJWTControllerIntTest method testAuthorize.

@Test
public void testAuthorize() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("user-jwt-controller");
    user.setEmail("user-jwt-controller@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.save(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller");
    login.setPassword("test");
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(io.github.jhipster.sample.web.rest.vm.LoginVM) User(io.github.jhipster.sample.domain.User) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 78 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method createUserWithExistingId.

@Test
public void createUserWithExistingId() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(UUID.randomUUID().toString());
    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));
    // An entity with an existing ID cannot be created, so this API call must fail
    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 79 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra by jhipster.

the class UserResourceIntTest method createEntity.

/**
 * Create a User.
 *
 * This is a static method, as tests for other entities might also need it,
 * if they test an entity which has a required relationship to the User entity.
 */
public static User createEntity() {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin(DEFAULT_LOGIN);
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    user.setEmail(DEFAULT_EMAIL);
    user.setFirstName(DEFAULT_FIRSTNAME);
    user.setLastName(DEFAULT_LASTNAME);
    user.setLangKey(DEFAULT_LANGKEY);
    return user;
}
Also used : User(io.github.jhipster.sample.domain.User)

Example 80 with User

use of io.github.jhipster.sample.domain.User 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)

Aggregations

User (io.github.jhipster.sample.domain.User)329 Test (org.junit.Test)251 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)251 Transactional (org.springframework.transaction.annotation.Transactional)150 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 ManagedUserVM (io.github.jhipster.sample.web.rest.vm.ManagedUserVM)90 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)38 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)32 Authority (io.github.jhipster.sample.domain.Authority)24 PasswordChangeDTO (io.github.jhipster.sample.service.dto.PasswordChangeDTO)24 MimeMessage (javax.mail.internet.MimeMessage)24 Instant (java.time.Instant)21 Before (org.junit.Before)13 Timed (com.codahale.metrics.annotation.Timed)12 KeyAndPasswordVM (io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM)12 Scheduled (org.springframework.scheduling.annotation.Scheduled)8 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 UserDetails (org.springframework.security.core.userdetails.UserDetails)7 PersistentToken (io.github.jhipster.sample.domain.PersistentToken)6