Search in sources :

Example 56 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class UserServiceIntTest method testFindNotActivatedUsersByCreationDateBefore.

@Test
@Transactional
public void testFindNotActivatedUsersByCreationDateBefore() {
    Instant now = Instant.now();
    user.setActivated(false);
    User dbUser = userRepository.saveAndFlush(user);
    dbUser.setCreatedDate(now.minus(4, ChronoUnit.DAYS));
    userRepository.saveAndFlush(user);
    List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minus(3, ChronoUnit.DAYS));
    assertThat(users).isNotEmpty();
    userService.removeNotActivatedUsers();
    users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minus(3, ChronoUnit.DAYS));
    assertThat(users).isEmpty();
}
Also used : User(com.furyviewer.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class UserJWTControllerIntTest method testAuthorizeWithRememberMe.

@Test
@Transactional
public void testAuthorizeWithRememberMe() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller-remember-me");
    user.setEmail("user-jwt-controller-remember-me@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller-remember-me");
    login.setPassword("test");
    login.setRememberMe(true);
    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(com.furyviewer.web.rest.vm.LoginVM) User(com.furyviewer.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class UserResourceIntTest method testUserEquals.

@Test
@Transactional
public void testUserEquals() throws Exception {
    TestUtil.equalsVerifier(User.class);
    User user1 = new User();
    user1.setId(1L);
    User user2 = new User();
    user2.setId(user1.getId());
    assertThat(user1).isEqualTo(user2);
    user2.setId(2L);
    assertThat(user1).isNotEqualTo(user2);
    user1.setId(null);
    assertThat(user1).isNotEqualTo(user2);
}
Also used : User(com.furyviewer.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class UserResourceIntTest method testUserDTOtoUser.

@Test
public void testUserDTOtoUser() {
    UserDTO userDTO = new UserDTO(DEFAULT_ID, DEFAULT_LOGIN, DEFAULT_FIRSTNAME, DEFAULT_LASTNAME, DEFAULT_EMAIL, true, DEFAULT_IMAGEURL, DEFAULT_LANGKEY, DEFAULT_LOGIN, null, DEFAULT_LOGIN, null, Stream.of(AuthoritiesConstants.USER).collect(Collectors.toSet()));
    User user = userMapper.userDTOToUser(userDTO);
    assertThat(user.getId()).isEqualTo(DEFAULT_ID);
    assertThat(user.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(user.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(user.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(user.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(user.getActivated()).isEqualTo(true);
    assertThat(user.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
    assertThat(user.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(user.getCreatedBy()).isNull();
    assertThat(user.getCreatedDate()).isNotNull();
    assertThat(user.getLastModifiedBy()).isNull();
    assertThat(user.getLastModifiedDate()).isNotNull();
    assertThat(user.getAuthorities()).extracting("name").containsExactly(AuthoritiesConstants.USER);
}
Also used : User(com.furyviewer.domain.User) UserDTO(com.furyviewer.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 60 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class UserResourceIntTest method createUserWithExistingId.

@Test
@Transactional
public void createUserWithExistingId() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    Set<String> authorities = new HashSet<>();
    authorities.add(AuthoritiesConstants.USER);
    ManagedUserVM managedUserVM = new ManagedUserVM(1L, DEFAULT_LOGIN, DEFAULT_PASSWORD, DEFAULT_FIRSTNAME, DEFAULT_LASTNAME, DEFAULT_EMAIL, true, DEFAULT_IMAGEURL, DEFAULT_LANGKEY, null, null, null, null, authorities);
    // 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(com.furyviewer.domain.User) ManagedUserVM(com.furyviewer.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.furyviewer.domain.User)65 Test (org.junit.Test)52 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)52 Transactional (org.springframework.transaction.annotation.Transactional)37 WithMockUser (org.springframework.security.test.context.support.WithMockUser)22 ManagedUserVM (com.furyviewer.web.rest.vm.ManagedUserVM)16 Authority (com.furyviewer.domain.Authority)6 UserDTO (com.furyviewer.service.dto.UserDTO)5 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Timed (com.codahale.metrics.annotation.Timed)2 KeyAndPasswordVM (com.furyviewer.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.furyviewer.web.rest.vm.LoginVM)2 UserExt (com.furyviewer.domain.UserExt)1 UserRepository (com.furyviewer.repository.UserRepository)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 EmailAlreadyUsedException (com.furyviewer.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.furyviewer.web.rest.errors.LoginAlreadyUsedException)1 URI (java.net.URI)1 java.util (java.util)1