Commit 916d42c4 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/auth-service!18
parents 8f890512 dc54d773
theGroup=ee.sm.ti.teis
theVersion=1.0.0
commonsVersion=1.1.0
commonApiGatewayVersion=1.0.0
schedulerVersion=1.0.0
theVersion=1.1.0
commonsVersion=1.2.0
commonApiGatewayVersion=1.2.0
schedulerVersion=1.1.0
pluginVersion=1.0.0
mapstructVersion=1.3.0.Final
......@@ -2,12 +2,11 @@ package ee.sm.ti.teis.authorization.userinfo;
import ee.sm.ti.teis.authorization.AuthServiceAppTestBase;
import ee.sm.ti.teis.authorization.person.IndividualPersonService;
import ee.sm.ti.teis.commongateway.person.CreatePersonResponse;
import ee.sm.ti.teis.commongateway.person.IndividualPersonDto;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.commongateway.person.PersonsResponse;
import ee.sm.ti.teis.authorization.person.IndividualPersonService.IndividualPersonResponseMessage;
import ee.sm.ti.teis.authorization.person.IndividualPersonService.IndividualPersonsResponseMessage;
import ee.sm.ti.teis.domain.person.IndividualPerson;
import ee.sm.ti.teis.domain.person.Person;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.PersonType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
......@@ -22,36 +21,33 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.PersonType.I;
import static java.util.Collections.emptyList;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ExtendWith(SpringExtension.class)
@SuppressWarnings({"squid:S00100", "squid:S1192"})
public class UserInfoControllerTest extends AuthServiceAppTestBase {
@Autowired
RabbitTemplate gwRabbitTemplate;
RabbitTemplate msRabbitTemplate;
@Autowired
private MockMvc mockMvc;
@BeforeEach
void setUp() {
PersonsResponse personsResponse = new PersonsResponse();
IndividualPersonsResponseMessage personsResponse = new IndividualPersonsResponseMessage();
personsResponse.setPayload(getPersons(), new RequestMetaDTO());
doReturn(personsResponse)
.when(gwRabbitTemplate)
.convertSendAndReceive(eq("api.PersonsRequest"), any(Object.class));
when(msRabbitTemplate.convertSendAndReceiveAsType(eq("domain.IndividualPerson.requestList"), any(Object.class), any())).thenReturn(personsResponse);
CreatePersonResponse personResponse = new CreatePersonResponse();
IndividualPersonResponseMessage personResponse = new IndividualPersonResponseMessage();
personResponse.setPayload(getNewPerson(), new RequestMetaDTO());
doReturn(personResponse)
.when(gwRabbitTemplate)
.convertSendAndReceive(eq("api.CreatePersonRequest"), any(Object.class));
when(msRabbitTemplate.convertSendAndReceiveAsType(eq("domain.IndividualPerson.create"), any(Object.class), any())).thenReturn(personResponse);
}
@Test
......@@ -92,11 +88,10 @@ public class UserInfoControllerTest extends AuthServiceAppTestBase {
@Test
@WithMockUser
public void create_new_person_when_unknown_code() throws Exception {
PersonsResponse personsResponse = new PersonsResponse();
personsResponse.setPayload(Collections.emptyList(), new RequestMetaDTO());
doReturn(personsResponse)
.when(gwRabbitTemplate)
.convertSendAndReceive(eq("api.PersonsRequest"), any(Object.class));
IndividualPersonsResponseMessage personsResponse = new IndividualPersonsResponseMessage();
personsResponse.setPayload(emptyList(), new RequestMetaDTO());
when(msRabbitTemplate.convertSendAndReceiveAsType(eq("domain.IndividualPerson.requestList"),
any(Object.class), any())).thenReturn(personsResponse);
mockMvc.perform(MockMvcRequestBuilders
.get("/internal/user-info")
......@@ -122,8 +117,7 @@ public class UserInfoControllerTest extends AuthServiceAppTestBase {
;
}
// FIXME: restore auth test, when basic auth is restored
@Disabled
@Test
public void auth_error_when_no_auth_header() throws Exception {
mockMvc.perform(MockMvcRequestBuilders
.get("/internal/user-info")
......@@ -156,33 +150,27 @@ public class UserInfoControllerTest extends AuthServiceAppTestBase {
;
}
private List<PersonDto> getPersons() {
List<PersonDto> persons = new ArrayList<>();
PersonDto person = PersonDto.builder()
private List<Person> getPersons() {
List<Person> persons = new ArrayList<>();
IndividualPerson individualPerson = IndividualPerson.builder()
.id(UUID.fromString("99aaa6bb-acad-4a66-a012-6da981fdf647"))
.personType(PersonType.I)
.individualPerson(IndividualPersonDto.builder()
.firstName("Juhan")
.lastName("Jurakas")
.idCode("12345678901")
.build())
.firstName("Juhan")
.lastName("Jurakas")
.idCode("12345678901")
.build();
Person person = Person.builder().personType(I).individualPerson(individualPerson).build();
persons.add(person);
return persons;
}
private PersonDto getNewPerson() {
return PersonDto.builder()
private IndividualPerson getNewPerson() {
IndividualPerson individualPerson = IndividualPerson.builder()
.id(UUID.fromString("8ebacd29-8872-4095-87cc-b646165980a0"))
.personType(PersonType.I)
.individualPerson(
IndividualPersonDto.builder()
.firstName(IndividualPersonService.NEW_PERSON_NAME)
.lastName(IndividualPersonService.NEW_PERSON_NAME)
.idCode("12345678901")
.build()
)
.personType(I)
.firstName(IndividualPersonService.NEW_PERSON_NAME)
.lastName(IndividualPersonService.NEW_PERSON_NAME)
.idCode("12345678901")
.build();
return individualPerson;
}
}
......@@ -33,6 +33,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().xssProtection().disable()
.and()
.authorizeRequests()
.antMatchers("/actuator/**").permitAll()
.anyRequest().authenticated()
......
package ee.sm.ti.teis.authorization.person;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.authorization.exception.TeisSystemException;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemCodeDto;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.person.*;
import ee.sm.ti.teis.commongateway.person.search.IndividualPersonSearchFilterDto;
import ee.sm.ti.teis.commongateway.person.search.PersonSearchFilterDto;
import ee.sm.ti.teis.domain.person.IndividualPerson;
import ee.sm.ti.teis.domain.person.Person;
import ee.sm.ti.teis.domainrequest.DomainCreateDTO;
import ee.sm.ti.teis.domainrequest.DomainQueryDTO;
import ee.sm.ti.teis.domainrequest.DomainQueryResponseDto;
import ee.sm.ti.teis.domainrequest.DomainResponseDTO;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.PersonType;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service;
import java.util.List;
import static ee.sm.ti.teis.types.enums.PersonType.I;
import static ee.sm.ti.teis.types.enums.classifier.ClassifierDefinitionCode.COUNTRY;
@Service
public class IndividualPersonService {
public static final String NEW_PERSON_NAME = "<unidentified>";
private final RabbitTemplate gwRabbitTemplate;
private final RabbitTemplate msRabbitTemplate;
@Autowired
public IndividualPersonService(RabbitTemplate gwRabbitTemplate) {
this.gwRabbitTemplate = gwRabbitTemplate;
public IndividualPersonService(RabbitTemplate msRabbitTemplate) {
this.msRabbitTemplate = msRabbitTemplate;
}
public PersonDto findPerson(String idCode, RequestMetaDTO requestMetaDTO) {
PersonsRequest personsRequest = new PersonsRequest();
PersonsRequest.Parameters filterParam = new PersonsRequest.Parameters();
PersonSearchFilterDto personSearchFilter = extractPersonSearchFilterFromCode(idCode);
filterParam.setPersonSearchFilter(personSearchFilter);
personsRequest.setPayload(filterParam, requestMetaDTO);
List<PersonDto> persons = getPersons(personsRequest);
if (!persons.isEmpty()) {
return persons.get(0);
public IndividualPerson findPerson(String idCode, RequestMetaDTO requestMetaDTO) {
FindIndividualPersonDomainRequest personsRequest = new FindIndividualPersonDomainRequest();
IndividualPerson individualPersonPayload = composeIndividualPerson(idCode);
personsRequest.setPayload(individualPersonPayload, requestMetaDTO);
List<Person> persons = getPersons(personsRequest);
if (!persons.isEmpty() && persons.get(0).getPersonType() == I) {
return persons.get(0).getIndividualPerson();
}
return null;
}
public PersonDto createPerson(String idCode, RequestMetaDTO requestMetaDTO) {
PersonSearchFilterDto personFilter = extractPersonSearchFilterFromCode(idCode);
return createPerson(personFilter.getIndividualPerson().getIdCode(),
personFilter.getIndividualPerson().getCountry().getCode(),
NEW_PERSON_NAME, NEW_PERSON_NAME, requestMetaDTO);
public IndividualPerson createPerson(String idCode, RequestMetaDTO requestMetaDTO) {
IndividualPerson individualPerson = composeIndividualPerson(idCode);
individualPerson.setFirstName(NEW_PERSON_NAME);
individualPerson.setLastName(NEW_PERSON_NAME);
return createPerson(individualPerson, requestMetaDTO);
}
PersonDto createPerson(String idCode, String countryCode, String firstName, String lastName, RequestMetaDTO requestMetaDTO) {
CreatePersonRequest personRequest = new CreatePersonRequest();
CreatePersonRequest.Parameters personParam = new CreatePersonRequest.Parameters();
IndividualPersonDto individualPersonDto = IndividualPersonDto.builder()
.idCode(idCode)
.country(ClassifierItemLightDto.builder().code(countryCode).build())
.firstName(firstName)
.lastName(lastName)
.build();
PersonDto personDto = PersonDto.builder()
.individualPerson(individualPersonDto)
.personType(PersonType.I)
.build();
personParam.setPerson(personDto);
personRequest.setPayload(personParam, requestMetaDTO);
CreatePersonResponse response = (CreatePersonResponse) gwRabbitTemplate.convertSendAndReceive(personRequest.routingKey(), personRequest);
IndividualPerson createPerson(IndividualPerson individualPerson, RequestMetaDTO requestMetaDTO) {
CreateIndividualPersonDomainRequest personRequest = new CreateIndividualPersonDomainRequest();
personRequest.setPayload(individualPerson, requestMetaDTO);
ParameterizedTypeReference<IndividualPersonResponseMessage> responseType = ParameterizedTypeReference.forType(IndividualPersonResponseMessage.class);
IndividualPersonResponseMessage response = msRabbitTemplate.convertSendAndReceiveAsType(personRequest.routingKey(), personRequest, responseType);
if (response != null) {
return response.processResponse();
}
throw new TeisSystemException(personRequest.getRequestMetaDTO().getRequestId());
}
List<PersonDto> getPersons(PersonsRequest requestDTO) {
PersonsResponse response = (PersonsResponse) gwRabbitTemplate.convertSendAndReceive(requestDTO.routingKey(), requestDTO);
List<Person> getPersons(FindIndividualPersonDomainRequest requestDTO) {
ParameterizedTypeReference<IndividualPersonsResponseMessage> responseType = ParameterizedTypeReference.forType(IndividualPersonsResponseMessage.class);
IndividualPersonsResponseMessage response = msRabbitTemplate.convertSendAndReceiveAsType(requestDTO.routingKey(), requestDTO, responseType);
if (response != null) {
return response.processResponse();
}
throw new TeisSystemException(requestDTO.getRequestMetaDTO().getRequestId());
}
PersonSearchFilterDto extractPersonSearchFilterFromCode(String idCode) {
IndividualPerson composeIndividualPerson(String idCode) {
if (idCode != null && idCode.length() == 11) {
idCode = "ee" + idCode;
}
if (idCode == null || !idCode.matches("^[a-z]{2}\\d{11}")) {
throw new IllegalArgumentException("Person id code has to match pattern: ^[a-z]{2}\\d{11}");
}
ClassifierItemCodeDto countryCode = new ClassifierItemCodeDto();
countryCode.setCode(idCode.substring(0, 2));
PersonSearchFilterDto searchFilter = new PersonSearchFilterDto();
searchFilter.setPersonType(PersonType.I);
searchFilter.setIndividualPerson(
IndividualPersonSearchFilterDto.builder()
.idCode(idCode.substring(2))
.country(countryCode)
.build());
return searchFilter;
return IndividualPerson.builder()
.personType(I)
.idCode(idCode.substring(2))
.countryId(COUNTRY.name() + "__" + idCode.substring(0, 2).toUpperCase())
.build();
}
public static class FindIndividualPersonDomainRequest extends DomainQueryDTO<IndividualPerson, ErrorDTO> {
}
public static class IndividualPersonsResponseMessage extends DomainQueryResponseDto<List<Person>, ErrorDTO> {
}
public static class CreateIndividualPersonDomainRequest extends DomainCreateDTO<IndividualPerson, ErrorDTO> {
}
public static class IndividualPersonResponseMessage extends DomainResponseDTO<IndividualPerson, ErrorDTO> {
}
}
......@@ -52,7 +52,7 @@ public class PersonCompaniesService {
private final RoleService roleService;
@Value("${teis.xroad.timeout:30}")
private int TIMEOUT = 30;
private int xroadTimeout = 30;
public PersonCompaniesService(RepresentativesService representativesService,
PersonMsService personMsService,
......@@ -69,7 +69,7 @@ public class PersonCompaniesService {
}
@Cacheable(value = "userCompanies", key = "#request.payload.id", cacheResolver = "prefixedCacheResolver")
@Cacheable(value = "userCompanies", key = "#request.payload.id", cacheResolver = "prefixedCacheResolver", unless = "#result == null or #result.isEmpty()")
public List<UserCompanyDto> composeUserCompanyList(GetMyCompaniesRequest request) {
try {
......@@ -105,7 +105,7 @@ public class PersonCompaniesService {
private ArRepresentations getArRepresentations(CompletableFuture<ArRepresentations> arFuture, ArRepresentations employersFromAr) {
try {
employersFromAr = arFuture.get(TIMEOUT, TimeUnit.SECONDS);
employersFromAr = arFuture.get(xroadTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
// IGNORE errors coming from AR API, to be able to use the system without AR
log.error(e.getMessage(), e);
......@@ -116,7 +116,7 @@ public class PersonCompaniesService {
private TorEmployers getTorEmployers(CompletableFuture<TorEmployers> torFuture, TorEmployers employersFromTor) {
try {
employersFromTor = torFuture.get(TIMEOUT, TimeUnit.SECONDS);
employersFromTor = torFuture.get(xroadTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
// IGNORE errors coming from TOR API, to be able to use the system without TOR
log.error(e.getMessage(), e);
......@@ -126,7 +126,7 @@ public class PersonCompaniesService {
private List<UserCompanyDto> getUserCompanyDtos(CompletableFuture<List<UserCompanyDto>> companyDtos, List<UserCompanyDto> userCompanyDtos) throws InterruptedException, ExecutionException {
try {
userCompanyDtos = companyDtos.get(TIMEOUT, TimeUnit.SECONDS);
userCompanyDtos = companyDtos.get(xroadTimeout, TimeUnit.SECONDS);
} catch (TimeoutException e) {
log.error(e.getMessage(), e);
}
......
......@@ -37,7 +37,7 @@ public class SelectedCompanyService {
}
@Cacheable(value = "userSelectedCompany", key = "#userId", cacheResolver = "prefixedCacheResolver")
@Cacheable(value = "userSelectedCompany", key = "#userId", cacheResolver = "prefixedCacheResolver", unless = "#result == null")
public UserCompanyDto getSelectedCompany(String userId, UserCompanyDto userCompany, RequestMetaDTO requestMetaDTO) {
if (userCompany == null) {
return null;
......
......@@ -25,7 +25,8 @@ public class UserInfoController {
public UserInfo findUserInfo(@RequestParam("personalCode") String personalCode,
@RequestParam(value = "includeRoles", required = false) boolean includeRoles) {
RequestMetaDTO requestMetaDTO = RequestMetaDTO.builder()
.requestId(requestIdGenerator.genereateRequestId()).build();
.requestId(requestIdGenerator.genereateRequestId())
.build();
return portalUserInfoService.getUserInfo(personalCode, requestMetaDTO, includeRoles);
}
......
......@@ -2,8 +2,8 @@ package ee.sm.ti.teis.authorization.userinfo;
import ee.sm.ti.teis.authorization.person.IndividualPersonService;
import ee.sm.ti.teis.authorization.role.RolePrivilegeService;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.domain.person.IndividualPerson;
import ee.sm.ti.teis.domain.role.RolePrivilege;
import ee.sm.ti.teis.security.JwtUserInfo;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
......@@ -59,15 +59,14 @@ public class UserInfoService {
}
public UserInfo getPortalUser(String personalCode, RequestMetaDTO requestMetaDTO) {
PersonDto personDto = individualPersonService.findPerson(personalCode, requestMetaDTO);
if (personDto == null || personDto.getIndividualPerson() == null) {
personDto = individualPersonService.createPerson(personalCode, requestMetaDTO);
IndividualPerson individualPerson = individualPersonService.findPerson(personalCode, requestMetaDTO);
if (individualPerson == null) {
individualPerson = individualPersonService.createPerson(personalCode, requestMetaDTO);
}
UserInfo userInfo = new UserInfo();
userInfo.setPersonId(personDto.getId().toString());
userInfo.setFullName(personDto.getIndividualPerson().getFirstName() + " " +
personDto.getIndividualPerson().getLastName());
userInfo.setPersonalCode(personDto.getIndividualPerson().getIdCode());
userInfo.setPersonId(individualPerson.getId().toString());
userInfo.setFullName(individualPerson.getFirstName() + " " + individualPerson.getLastName());
userInfo.setPersonalCode(individualPerson.getIdCode());
return userInfo;
}
......
......@@ -2,9 +2,8 @@ package ee.sm.ti.teis.authorization.person;
import ee.sm.ti.teis.RequestIdGenerator;
import ee.sm.ti.teis.authorization.exception.TeisSystemException;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.commongateway.person.PersonsRequest;
import ee.sm.ti.teis.commongateway.person.PersonsResponse;
import ee.sm.ti.teis.authorization.person.IndividualPersonService.FindIndividualPersonDomainRequest;
import ee.sm.ti.teis.domain.person.Person;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.PersonType;
import org.junit.jupiter.api.Test;
......@@ -28,43 +27,43 @@ public class IndividualPersonServiceTest {
@Mock
private RequestIdGenerator requestIdGenerator;
@Mock
private RabbitTemplate gwRabbitTemplate;
private RabbitTemplate msRabbitTemplate;
@InjectMocks
IndividualPersonService individualPersonService;
@Test
public void return_correct_personal_code() {
assertThat(individualPersonService.extractPersonSearchFilterFromCode("ee12345678901").getIndividualPerson().getIdCode()).isEqualTo("12345678901");
assertThat(individualPersonService.extractPersonSearchFilterFromCode("ee12345678901").getPersonType()).isEqualTo(PersonType.I);
assertThat(individualPersonService.extractPersonSearchFilterFromCode("ee12345678901").getIndividualPerson().getCountry().getCode()).isEqualTo("ee");
assertThat(individualPersonService.composeIndividualPerson("ee12345678901").getIdCode()).isEqualTo("12345678901");
assertThat(individualPersonService.composeIndividualPerson("ee12345678901").getPersonType()).isEqualTo(PersonType.I);
assertThat(individualPersonService.composeIndividualPerson("ee12345678901").getCountryId()).isEqualTo("COUNTRY__EE");
}
@Test
public void throws_exception_when_invalid_personal_code() {
assertThrows(IllegalArgumentException.class, () -> individualPersonService.extractPersonSearchFilterFromCode("1234567890"));
assertThrows(IllegalArgumentException.class, () -> individualPersonService.composeIndividualPerson("1234567890"));
}
@Test
public void throws_exception_when_personal_code_is_null() {
assertThrows(IllegalArgumentException.class, () -> individualPersonService.extractPersonSearchFilterFromCode(null));
assertThrows(IllegalArgumentException.class, () -> individualPersonService.composeIndividualPerson(null));
}
@Test
public void get_persons_throws_exception_when_rabbit_response_is_null() {
PersonsRequest personsRequest = new PersonsRequest();
FindIndividualPersonDomainRequest personsRequest = new FindIndividualPersonDomainRequest();
personsRequest.setRequestMetaDTO(RequestMetaDTO.builder().requestId("x").build());
when(gwRabbitTemplate.convertSendAndReceive(any(String.class), any(Object.class))).thenReturn(null);
when(msRabbitTemplate.convertSendAndReceiveAsType(any(String.class), any(Object.class), any())).thenReturn(null);
assertThrows(TeisSystemException.class, () -> individualPersonService.getPersons(personsRequest));
}
@Test
public void get_persons_from_rabbit() {
PersonsRequest personsRequest = new PersonsRequest();
PersonsResponse response = new PersonsResponse();
FindIndividualPersonDomainRequest personsRequest = new FindIndividualPersonDomainRequest();
IndividualPersonService.IndividualPersonsResponseMessage response = new IndividualPersonService.IndividualPersonsResponseMessage();
UUID personId = UUID.randomUUID();
response.setPayload(List.of(PersonDto.builder().id(personId).build()), new RequestMetaDTO());
when(gwRabbitTemplate.convertSendAndReceive(any(String.class), any(Object.class))).thenReturn(response);
response.setPayload(List.of(Person.builder().id(personId).build()), new RequestMetaDTO());
when(msRabbitTemplate.convertSendAndReceiveAsType(any(String.class), any(Object.class), any())).thenReturn(response);
assertThat(individualPersonService.getPersons(personsRequest).get(0).getId()).isEqualTo(personId);
}
}
......@@ -6,9 +6,8 @@ import ee.sm.ti.teis.authorization.person.PersonMapper;
import ee.sm.ti.teis.authorization.role.RolePrivilegeService;
import ee.sm.ti.teis.authorization.userinfo.UserInfo;
import ee.sm.ti.teis.authorization.userinfo.UserInfoMsService;
import ee.sm.ti.teis.commongateway.person.IndividualPersonDto;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.domain.person.IndividualPerson;
import ee.sm.ti.teis.domain.person.LegalPerson;
import ee.sm.ti.teis.domain.role.RolePrivilege;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
......@@ -23,6 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.PersonType.I;
import static java.util.List.of;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
......@@ -60,7 +60,7 @@ public class MockPortalUserInfoServiceTest {
RequestMetaDTO requestMetaDTO = testUtils.createRandomPerson(privileges);
when(rolePrivilegeService.getPrivilegesByRoleCodes(any(), any(RequestMetaDTO.class))).thenReturn(of(RolePrivilege.builder()
.privilege(RolePrivilegeCode.EX_MANAGE_LOCATIONS).build()));
when(individualPersonService.findPerson(any(), any())).thenReturn(getPersonDto(personalCode));
when(individualPersonService.findPerson(any(), any())).thenReturn(getPerson(personalCode));
when(personService.getLegalPerson(any(), any())).thenReturn(getPerson());
UserInfo userInfo = portalUserInfoService.getUserInfo(personalCode, requestMetaDTO, roles, privileges, companyRegCode);
assertTrue(userInfo.getRoles().contains("PRIVILEGE"));
......@@ -80,17 +80,16 @@ public class MockPortalUserInfoServiceTest {
return legalPerson;
}
PersonDto getPersonDto(String personCode) {
IndividualPersonDto individualPerson = IndividualPersonDto.builder()
IndividualPerson getPerson(String personCode) {
IndividualPerson individualPerson = IndividualPerson.builder()
.id(UUID.randomUUID())
.personType(I)
.firstName("Janes")
.lastName("Rebane")
.idCode(personCode)
.build();
return PersonDto.builder()
.id(UUID.randomUUID())
.individualPerson(individualPerson)
.build();
return individualPerson;
}
OfficialUser makeOfficialUser(String idCode, String firstName, String lastName) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment