Search in sources :

Example 6 with UserDTO

use of com.furyviewer.service.dto.UserDTO in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testSaveInvalidEmail.

@Test
@Transactional
@WithMockUser("save-invalid-email")
public void testSaveInvalidEmail() throws Exception {
    User user = new User();
    user.setLogin("save-invalid-email");
    user.setEmail("save-invalid-email@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.saveAndFlush(user);
    UserDTO userDTO = new UserDTO(// id
    null, // login
    "not-used", // firstName
    "firstname", // lastName
    "lastname", // email
    "invalid email", // activated
    false, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isBadRequest());
    assertThat(userRepository.findOneByEmailIgnoreCase("invalid email")).isNotPresent();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(com.furyviewer.service.dto.UserDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with UserDTO

use of com.furyviewer.service.dto.UserDTO in project FuryViewer by TheDoctor-95.

the class UserServiceIntTest method assertThatAnonymousUserIsNotGet.

@Test
@Transactional
public void assertThatAnonymousUserIsNotGet() {
    user.setLogin(Constants.ANONYMOUS_USER);
    if (!userRepository.findOneByLogin(Constants.ANONYMOUS_USER).isPresent()) {
        userRepository.saveAndFlush(user);
    }
    final PageRequest pageable = new PageRequest(0, (int) userRepository.count());
    final Page<UserDTO> allManagedUsers = userService.getAllManagedUsers(pageable);
    assertThat(allManagedUsers.getContent().stream().noneMatch(user -> Constants.ANONYMOUS_USER.equals(user.getLogin()))).isTrue();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserDTO(com.furyviewer.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with UserDTO

use of com.furyviewer.service.dto.UserDTO 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)

Aggregations

UserDTO (com.furyviewer.service.dto.UserDTO)8 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 User (com.furyviewer.domain.User)5 Transactional (org.springframework.transaction.annotation.Transactional)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Timed (com.codahale.metrics.annotation.Timed)1 Authority (com.furyviewer.domain.Authority)1 PageRequest (org.springframework.data.domain.PageRequest)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1