diff --git a/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c003/service/AnprC003ServiceImpl.java b/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c003/service/AnprC003ServiceImpl.java index 7b16ac8..97babee 100644 --- a/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c003/service/AnprC003ServiceImpl.java +++ b/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c003/service/AnprC003ServiceImpl.java @@ -9,14 +9,14 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.Random; @Service public class AnprC003ServiceImpl implements AnprC003Service { - private final Faker faker = new Faker(); public RispostaE002OK generateRispostaE002OK(RichiestaE002 request) { validateRequest(request); - return buildResponse(); + return buildResponse(request.getCriteriRicerca().getIdANPR()); } private void validateRequest(RichiestaE002 request) { @@ -30,30 +30,34 @@ private void validateRequest(RichiestaE002 request) { } } - private RispostaE002OK buildResponse() { - List infoSubjects = generateInfoSubject(); + private RispostaE002OK buildResponse(String idAnpr) { + List infoSubjects = generateInfoSubject(idAnpr); List subjectList = List.of(new TipoDatiSoggettiEnte(infoSubjects)); return RispostaE002OK.builder() - .idOperazioneANPR(faker.idNumber().valid()) + .idOperazioneANPR("003") .listaSoggetti(new TipoListaSoggetti(subjectList)) .listaAnomalie(new ArrayList<>()) .build(); } - private List generateInfoSubject() { + private List generateInfoSubject(String idAnpr) { + long seed = idAnpr.hashCode(); + Random random = new Random(seed); + Faker faker = new Faker(random); + return List.of( - createTipoInfoSoggettoEnte("firstName", faker.name().firstName(), "First name of the subject"), - createTipoInfoSoggettoEnte("lastName", faker.name().lastName(), "Last name of the subject"), - createTipoInfoSoggettoEnte("dateOfBirth", "", "Date of birth of the subject"), - createTipoInfoSoggettoEnte("street", faker.address().streetAddress(), "Street address of the subject"), - createTipoInfoSoggettoEnte("city", faker.address().city(), "City of residence of the subject"), - createTipoInfoSoggettoEnte("postalCode", faker.address().zipCode(), "Postal code of the subject"), - createTipoInfoSoggettoEnte("country", faker.address().country(), "Country of residence of the subject") + createTipoInfoSoggettoEnte("firstName", faker.name().firstName(), "First name of the subject", faker), + createTipoInfoSoggettoEnte("lastName", faker.name().lastName(), "Last name of the subject", faker), + createTipoInfoSoggettoEnte("dateOfBirth", "", "Date of birth of the subject", faker), + createTipoInfoSoggettoEnte("street", faker.address().streetAddress(), "Street address of the subject", faker), + createTipoInfoSoggettoEnte("city", faker.address().city(), "City of residence of the subject", faker), + createTipoInfoSoggettoEnte("postalCode", faker.address().zipCode(), "Postal code of the subject", faker), + createTipoInfoSoggettoEnte("country", faker.address().country(), "Country of residence of the subject", faker) ); } - private TipoInfoSoggettoEnte createTipoInfoSoggettoEnte(String key, String value, String description) { + private TipoInfoSoggettoEnte createTipoInfoSoggettoEnte(String key, String value, String description, Faker faker) { if ("dateOfBirth".equals(key)) { value = LocalDate.ofInstant(faker.date().birthday().toInstant(), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } diff --git a/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c030/service/AnprC030ServiceImpl.java b/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c030/service/AnprC030ServiceImpl.java index a7d5d36..7eb4a38 100644 --- a/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c030/service/AnprC030ServiceImpl.java +++ b/src/main/java/it/gov/pagopa/payhub/mocks/anpr/c030/service/AnprC030ServiceImpl.java @@ -35,7 +35,7 @@ private RispostaE002OK buildResponse(RichiestaE002 request) { String idAnpr = generateIdAnprFromCF(fiscalCode); return RispostaE002OK.builder() - .idOperazioneANPR(request.getDatiRichiesta().getCasoUso()) + .idOperazioneANPR("030") .listaSoggetti(buildSubjectList(idAnpr)) .listaAnomalie(new ArrayList<>()) .build();