Search in sources :

Example 71 with User

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

the class AccountResourceIntTest method testRequestPasswordResetUpperCaseEmail.

@Test
public void testRequestPasswordResetUpperCaseEmail() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    user.setLogin("password-reset");
    user.setEmail("password-reset@example.com");
    userRepository.save(user);
    restMvc.perform(post("/api/account/reset-password/init").content("password-reset@EXAMPLE.COM")).andExpect(status().isOk());
}
Also used : User(io.github.jhipster.sample.domain.User) 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 72 with User

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

the class AccountResourceIntTest method testChangePasswordTooSmall.

@Test
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-too-small");
    user.setEmail("change-password-too-small@example.com");
    userRepository.save(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO(currentPassword, "new")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) 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 73 with User

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

the class AccountResourceIntTest method testActivateAccount.

@Test
public void testActivateAccount() throws Exception {
    final String activationKey = "some activation key";
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("activate-account");
    user.setEmail("activate-account@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(false);
    user.setActivationKey(activationKey);
    userRepository.save(user);
    restMvc.perform(get("/api/activate?key={activationKey}", activationKey)).andExpect(status().isOk());
    user = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(user.getActivated()).isTrue();
}
Also used : User(io.github.jhipster.sample.domain.User) 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 74 with User

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

the class AccountResourceIntTest method testSaveAccount.

@Test
@WithMockUser("save-account")
public void testSaveAccount() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    user.setLogin("save-account");
    user.setEmail("save-account@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-account@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(user.getLogin()).orElse(null);
    assertThat(updatedUser.getFirstName()).isEqualTo(userDTO.getFirstName());
    assertThat(updatedUser.getLastName()).isEqualTo(userDTO.getLastName());
    assertThat(updatedUser.getEmail()).isEqualTo(userDTO.getEmail());
    assertThat(updatedUser.getLangKey()).isEqualTo(userDTO.getLangKey());
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
    assertThat(updatedUser.getActivated()).isEqualTo(true);
    assertThat(updatedUser.getAuthorities()).isEmpty();
}
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 75 with User

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

the class AccountResourceIntTest method testGetExistingAccount.

@Test
public void testGetExistingAccount() throws Exception {
    Set<String> authorities = new HashSet<>();
    authorities.add(AuthoritiesConstants.ADMIN);
    User user = new User();
    user.setLogin("test");
    user.setFirstName("john");
    user.setLastName("doe");
    user.setEmail("john.doe@jhipster.com");
    user.setLangKey("en");
    user.setAuthorities(authorities);
    when(mockUserService.getUserWithAuthorities()).thenReturn(Optional.of(user));
    restUserMockMvc.perform(get("/api/account").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.login").value("test")).andExpect(jsonPath("$.firstName").value("john")).andExpect(jsonPath("$.lastName").value("doe")).andExpect(jsonPath("$.email").value("john.doe@jhipster.com")).andExpect(jsonPath("$.langKey").value("en")).andExpect(jsonPath("$.authorities").value(AuthoritiesConstants.ADMIN));
}
Also used : User(io.github.jhipster.sample.domain.User) 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)

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