From 20fcdf7cd830af9f23645c71f536af95418ad1be Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Thu, 4 Mar 2021 15:04:08 +0100 Subject: Refactor SimpleEidasData to make it immutable --- ...eceiveAustrianResidenceGuiResponseTaskTest.java | 11 ++++++----- ...eceiveMobilePhoneSignatureResponseTaskTest.java | 23 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java index 38693f49..d9405251 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveAustrianResidenceGuiResponseTaskTest.java @@ -175,11 +175,12 @@ public class ReceiveAustrianResidenceGuiResponseTaskTest { @NotNull private SimpleEidasData setupEidasData() throws EaafStorageException { - SimpleEidasData result = new SimpleEidasData(); - result.setPseudonym(RandomStringUtils.randomAlphabetic(8)); - result.setFamilyName(RandomStringUtils.randomAlphabetic(8)); - result.setGivenName(RandomStringUtils.randomAlphabetic(8)); - result.setDateOfBirth("1970-01-01"); + SimpleEidasData result = SimpleEidasData.builder() + .pseudonym(RandomStringUtils.randomAlphabetic(8)) + .familyName(RandomStringUtils.randomAlphabetic(8)) + .givenName(RandomStringUtils.randomAlphabetic(8)) + .dateOfBirth("1970-01-01") + .build(); AuthProcessDataWrapper authProcessDataWrapper = pendingReq.getSessionData(AuthProcessDataWrapper.class); authProcessDataWrapper.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, result); return result; diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java index 01688214..77b87264 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/ReceiveMobilePhoneSignatureResponseTaskTest.java @@ -314,8 +314,9 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { setupMetadataResolver(); initResponse("/data/Response_with_EID.xml", true); AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - SimpleEidasData eidData = createEidasDataMatchingToSamlResponse(); - eidData.setFamilyName(eidData.getFamilyName() + "notmatching"); + SimpleEidasData eidData = createEidasDataMatchingToSamlResponse() + .familyName("notmatching") + .build(); authProcessData.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidData); TaskExecutionException e = assertThrows(TaskExecutionException.class, @@ -331,7 +332,7 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { setupMetadataResolver(); initResponse("/data/Response_with_EID.xml", true); AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - SimpleEidasData eidData = createEidasDataMatchingToSamlResponse(); + SimpleEidasData eidData = createEidasDataMatchingToSamlResponse().build(); authProcessData.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidData); MergedRegisterSearchResult registerSearchResult = new MergedRegisterSearchResult(Collections.emptyList(), Collections.emptyList()); Mockito.when(registerSearchService.searchWithBpkZp(eq(BPK_FROM_ID_AUSTRIA))).thenReturn(registerSearchResult); @@ -350,7 +351,7 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { setupMetadataResolver(); initResponse("/data/Response_with_EID.xml", true); AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - SimpleEidasData eidData = createEidasDataMatchingToSamlResponse(); + SimpleEidasData eidData = createEidasDataMatchingToSamlResponse().build(); authProcessData.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidData); MergedRegisterSearchResult registerSearchResult = buildResultWithOneMatch(); Mockito.when(registerSearchService.searchWithBpkZp(eq(BPK_FROM_ID_AUSTRIA))).thenReturn(registerSearchResult); @@ -370,7 +371,7 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { setupMetadataResolver(); initResponse("/data/Response_with_EID.xml", true); AuthProcessDataWrapper authProcessData = pendingReq.getSessionData(AuthProcessDataWrapper.class); - SimpleEidasData eidData = createEidasDataMatchingToSamlResponse(); + SimpleEidasData eidData = createEidasDataMatchingToSamlResponse().build(); authProcessData.setGenericDataToSession(Constants.DATA_SIMPLE_EIDAS, eidData); MergedRegisterSearchResult registerSearchResult = buildResultWithTwoMatches(); Mockito.when(registerSearchService.searchWithBpkZp(eq(BPK_FROM_ID_AUSTRIA))).thenReturn(registerSearchResult); @@ -400,14 +401,12 @@ public class ReceiveMobilePhoneSignatureResponseTaskTest { return new MergedRegisterSearchResult(results, Collections.emptyList()); } - @NotNull - private SimpleEidasData createEidasDataMatchingToSamlResponse() { + private SimpleEidasData.SimpleEidasDataBuilder createEidasDataMatchingToSamlResponse() { // data from "/data/Response_with_EID.xml" - SimpleEidasData result = new SimpleEidasData(); - result.setFamilyName("Mustermann"); - result.setGivenName("Max"); - result.setDateOfBirth("1940-01-01"); - return result; + return SimpleEidasData.builder() + .familyName("Mustermann") + .givenName("Max") + .dateOfBirth("1940-01-01"); } private void addSamlResponseToHttpReq(Response response) throws TransformerException, IOException, MarshallingException { -- cgit v1.2.3