Skip to content

Commit

Permalink
Add support for person identification in tests (#3578)
Browse files Browse the repository at this point in the history
#deploy-test-pdl-forvalter #deploy-pdl-forvalter

Added support for setting person identification (FNR_IDENT and DNR_IDENT) in various tests to ensure correct data handling. Enhanced validation logic for address handling based on the type of identification in service classes.
  • Loading branch information
krharum authored Aug 13, 2024
1 parent c2fedc7 commit 154afe5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static java.util.Objects.nonNull;
import static no.nav.pdl.forvalter.utils.ArtifactUtils.getKilde;
import static no.nav.pdl.forvalter.utils.ArtifactUtils.getMaster;
import static no.nav.pdl.forvalter.utils.IdenttypeUtility.isNotNpidIdent;
import static no.nav.pdl.forvalter.utils.TestnorgeIdentUtility.isTestnorgeIdent;
import static org.apache.commons.lang3.BooleanUtils.isFalse;
import static org.apache.commons.lang3.BooleanUtils.isTrue;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
Expand Down Expand Up @@ -225,4 +227,8 @@ private void sortAdresser(List<T> adresser) {
adresser.get(i - 1).setId(adresser.size() - i + 1);
}
}
protected boolean isIdSupported(AdresseDTO adresse, String ident) {

return isNotNpidIdent(ident) && !isTestnorgeIdent(ident) && !adresse.isPdlMaster();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static no.nav.pdl.forvalter.utils.IdenttypeUtility.getIdenttype;
import static no.nav.pdl.forvalter.utils.TestnorgeIdentUtility.isTestnorgeIdent;
import static no.nav.testnav.libs.data.pdlforvalter.v1.AdressebeskyttelseDTO.AdresseBeskyttelse.STRENGT_FORTROLIG;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.FNR;
import static org.apache.commons.lang3.BooleanUtils.isNotTrue;
Expand Down Expand Up @@ -115,7 +116,13 @@ private void handle(BostedadresseDTO bostedadresse, PersonDTO person) {
}

} else if (bostedadresse.countAdresser() == 0) {
bostedadresse.setVegadresse(new VegadresseDTO());

if (isTestnorgeIdent(person.getIdent())) {
bostedadresse.setUtenlandskAdresse(new UtenlandskAdresseDTO());

} else {
bostedadresse.setVegadresse(new VegadresseDTO());
}
}

} else if (bostedadresse.countAdresser() == 0) {
Expand All @@ -139,14 +146,14 @@ private void buildBoadresse(BostedadresseDTO bostedadresse, PersonDTO person) {

var vegadresse =
adresseServiceConsumer.getVegadresse(bostedadresse.getVegadresse(), bostedadresse.getAdresseIdentifikatorFraMatrikkelen());
bostedadresse.setAdresseIdentifikatorFraMatrikkelen(vegadresse.getMatrikkelId());
bostedadresse.setAdresseIdentifikatorFraMatrikkelen(isIdSupported(bostedadresse, person.getIdent()) ? vegadresse.getMatrikkelId() : null);
mapperFacade.map(vegadresse, bostedadresse.getVegadresse());

} else if (nonNull(bostedadresse.getMatrikkeladresse())) {

var matrikkeladresse =
adresseServiceConsumer.getMatrikkeladresse(bostedadresse.getMatrikkeladresse(), bostedadresse.getAdresseIdentifikatorFraMatrikkelen());
bostedadresse.setAdresseIdentifikatorFraMatrikkelen(matrikkeladresse.getMatrikkelId());
bostedadresse.setAdresseIdentifikatorFraMatrikkelen(isIdSupported(bostedadresse, person.getIdent()) ? matrikkeladresse.getMatrikkelId() : null);
mapperFacade.map(matrikkeladresse, bostedadresse.getMatrikkeladresse());

} else if (nonNull(bostedadresse.getUtenlandskAdresse())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void handle(KontaktadresseDTO kontaktadresse, PersonDTO person) {
if (nonNull(kontaktadresse.getVegadresse())) {
var vegadresse =
adresseServiceConsumer.getVegadresse(kontaktadresse.getVegadresse(), kontaktadresse.getAdresseIdentifikatorFraMatrikkelen());
kontaktadresse.setAdresseIdentifikatorFraMatrikkelen(kontaktadresse.getMaster() == Master.FREG ? vegadresse.getMatrikkelId() : null);
kontaktadresse.setAdresseIdentifikatorFraMatrikkelen(isIdSupported(kontaktadresse, person.getIdent()) ? vegadresse.getMatrikkelId() : null);
mapperFacade.map(vegadresse, kontaktadresse.getVegadresse());
kontaktadresse.getVegadresse().setKommunenummer(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import no.nav.pdl.forvalter.exception.InvalidRequestException;
import no.nav.pdl.forvalter.utils.IdenttypeUtility;
import no.nav.testnav.libs.data.pdlforvalter.v1.AdressebeskyttelseDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.DbVersjonDTO.Master;
import no.nav.testnav.libs.data.pdlforvalter.v1.OppholdsadresseDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.StatsborgerskapDTO;
Expand Down Expand Up @@ -114,14 +113,14 @@ protected void handle(OppholdsadresseDTO oppholdsadresse, PersonDTO person) {
if (nonNull(oppholdsadresse.getVegadresse())) {
var vegadresse =
adresseServiceConsumer.getVegadresse(oppholdsadresse.getVegadresse(), oppholdsadresse.getAdresseIdentifikatorFraMatrikkelen());
oppholdsadresse.setAdresseIdentifikatorFraMatrikkelen(oppholdsadresse.getMaster() == Master.FREG ?
oppholdsadresse.setAdresseIdentifikatorFraMatrikkelen(isIdSupported(oppholdsadresse, person.getIdent()) ?
vegadresse.getMatrikkelId() : null);
mapperFacade.map(vegadresse, oppholdsadresse.getVegadresse());

} else if (nonNull(oppholdsadresse.getMatrikkeladresse())) {
var matrikkeladresse =
adresseServiceConsumer.getMatrikkeladresse(oppholdsadresse.getMatrikkeladresse(), oppholdsadresse.getAdresseIdentifikatorFraMatrikkelen());
oppholdsadresse.setAdresseIdentifikatorFraMatrikkelen(matrikkeladresse.getMatrikkelId());
oppholdsadresse.setAdresseIdentifikatorFraMatrikkelen(isIdSupported(oppholdsadresse, person.getIdent()) ? matrikkeladresse.getMatrikkelId() : null);
mapperFacade.map(matrikkeladresse, oppholdsadresse.getMatrikkeladresse());

} else if (nonNull(oppholdsadresse.getUtenlandskAdresse())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static java.util.Objects.nonNull;
import static no.nav.pdl.forvalter.utils.TestnorgeIdentUtility.isTestnorgeIdent;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@UtilityClass
Expand All @@ -30,7 +31,8 @@ public static boolean hasSpraak(String spraak) {

public static DbVersjonDTO.Master getMaster(DbVersjonDTO artifact, PersonDTO person) {

return getMaster(artifact, person.getIdenttype());
return isTestnorgeIdent(person.getIdent()) ? DbVersjonDTO.Master.PDL :
getMaster(artifact, person.getIdenttype());
}

public static DbVersjonDTO.Master getMaster(DbVersjonDTO artifact, Identtype identtype) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void whenStrengtFortroligOrFortroligAndIdentypeDnr_thenThrowExecption() {
void whenStrengtFortroligUtland_thenSetMasterToPdl() {

var request = PersonDTO.builder()
.ident(DNR_IDENT)
.adressebeskyttelse(List.of(AdressebeskyttelseDTO.builder()
.gradering(STRENGT_FORTROLIG_UTLAND)
.isNew(true)
Expand All @@ -85,6 +86,7 @@ void whenStrengtFortroligUtland_thenSetMasterToPdl() {
void whenStrengtFortrolig_thenSetKontaktadresseClearOtherAdresses() {

var request = PersonDTO.builder()
.ident(DNR_IDENT)
.adressebeskyttelse(List.of(AdressebeskyttelseDTO.builder()
.gradering(STRENGT_FORTROLIG)
.isNew(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void whenValueProvided_thenKeepValue() {

var target = folkeregisterPersonstatusService.convert(
PersonDTO.builder()
.ident(FNR_IDENT)
.folkeregisterPersonstatus(List.of(FolkeregisterPersonstatusDTO.builder()
.status(FORSVUNNET)
.isNew(true)
Expand All @@ -55,6 +56,7 @@ void whenDoedsfallExists_thenUseDoedsfall() {

var target = folkeregisterPersonstatusService.convert(
PersonDTO.builder()
.ident(FNR_IDENT)
.folkeregisterPersonstatus(
List.of(FolkeregisterPersonstatusDTO.builder()
.isNew(true)
Expand All @@ -73,6 +75,7 @@ void whenOppholdExists_thenUseOpphold() {

var target = folkeregisterPersonstatusService.convert(
PersonDTO.builder()
.ident(FNR_IDENT)
.folkeregisterPersonstatus(
List.of(FolkeregisterPersonstatusDTO.builder()
.isNew(true)
Expand All @@ -90,6 +93,7 @@ void whenUtflyttingExists_thenUseUpphold() {

var target = folkeregisterPersonstatusService.convert(
PersonDTO.builder()
.ident(FNR_IDENT)
.folkeregisterPersonstatus(
List.of(FolkeregisterPersonstatusDTO.builder()
.isNew(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@ExtendWith(MockitoExtension.class)
class InnflyttingServiceTest {

private static final String DNR_IDENT = "45023412345";

@Mock
private KodeverkConsumer kodeverkConsumer;

Expand Down Expand Up @@ -52,6 +54,7 @@ void whenEmptyLandkode_thenProvideRandomCountry() {
when(kodeverkConsumer.getTilfeldigLand()).thenReturn("IND");

var request = PersonDTO.builder()
.ident(DNR_IDENT)
.innflytting(List.of(InnflyttingDTO.builder()
.isNew(true)
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@ExtendWith(MockitoExtension.class)
class UtflyttingServiceTest {

private static final String FNR_IDENT = "03012312345";
@Mock
private KodeverkConsumer kodeverkConsumer;

Expand Down Expand Up @@ -52,6 +53,7 @@ void whenEmptyLandkode_thenProvideCountryFromGeografiskeKodeverkConsumer() {
when(kodeverkConsumer.getTilfeldigLand()).thenReturn("TGW");

var request = PersonDTO.builder()
.ident(FNR_IDENT)
.utflytting(List.of(UtflyttingDTO.builder().isNew(true).build()))
.build();

Expand Down

0 comments on commit 154afe5

Please sign in to comment.