Search in sources :

Example 1 with UserDTO

use of py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class UserApplicationMapper method entityToUserDto.

public UserDTO entityToUserDto(UserApplicationEntity entity) {
    UserDTO dto = userMapper.entityToDto(entity.getUser());
    entity.getApplicationOpt().ifPresent(application -> dto.setApplication(applicationMapper.entityToDto(application)));
    entity.getOrganizationOpt().ifPresent(organization -> dto.setOrganization(organizationMapper.entityToDto(organization)));
    return dto;
}
Also used : UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO)

Example 2 with UserDTO

use of py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class UserMapper method entityToDto.

@Override
public UserDTO entityToDto(UserEntity entity) {
    UserDTO dto = modelMapper.map(entity, UserDTO.class);
    dto.setPass(null);
    return dto;
}
Also used : UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO)

Example 3 with UserDTO

use of py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO in project FP-PSP-SERVER by FundacionParaguaya.

the class UserControllerTest method requestingPostUserShouldFailIfUserAlreadyExists.

@Test
public void requestingPostUserShouldFailIfUserAlreadyExists() throws Exception {
    UserDTO dto = UserDTO.builder().username("admin").email("foo@bar").pass("123").build();
    when(userService.addUser(anyObject())).thenThrow(new CustomParameterizedException("User already exists.", new ImmutableMultimap.Builder<String, String>().put("username", dto.getUsername()).build().asMap()));
    String json = TestHelper.mapToJson(dto);
    mockMvc.perform(post("/api/v1/users").content(json).contentType(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isBadRequest()).andExpect(jsonPath("$.message", containsString("User already exists."))).andExpect(jsonPath("$.fieldErrors.[0].field", is("username"))).andExpect(jsonPath("$.fieldErrors.[0].messages[0]").value("admin"));
}
Also used : CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) UserDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

UserDTO (py.org.fundacionparaguaya.pspserver.security.dtos.UserDTO)3 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1