diff options
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java')
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java | 409 |
1 files changed, 271 insertions, 138 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java index 34bca782..bb732f1c 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java @@ -24,14 +24,18 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import java.math.BigInteger; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -44,6 +48,7 @@ import org.apache.commons.lang3.RandomStringUtils; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -62,6 +67,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.IZmrClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient.ZmrRegisterResult; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.MatchedPersonResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.SimpleEidasData; import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernp.IErnpClient; @@ -69,10 +75,12 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcess import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasAttributeException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.WorkflowException; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ZmrCommunicationException; import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.CountrySpecificDetailSearchProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.GenericEidProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidProcessingService; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.RegisterSearchService.RegisterSearchResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask; import at.asitplus.eidas.specific.modules.auth.eidas.v2.utils.MatchingTaskUtils; import at.gv.bmi.namespace.zmr_su.zmr._20040201.PersonSuchenRequest; @@ -100,11 +108,9 @@ public class InitialSearchTaskTest { private static final String EE = "EE"; private static final String DE = "DE"; - private static final String IT = "IT"; private static final String EE_ST = EE + "/ST/"; private static final String DE_ST = DE + "/ST/"; - private static final String IT_ST = IT + "/ST/"; @Mock private IZmrClient zmrClient; @@ -173,130 +179,215 @@ public class InitialSearchTaskTest { */ @Test @DirtiesContext - public void testNode100_UserIdentifiedUpdateNecessary_a() throws Exception { - String newFirstName = randomAlphabetic(10); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + public void singlePersonalIdMatchUpdateNecessary_Zmr() throws Exception { + String oldGivenName = randomAlphabetic(10); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.singletonList( RegisterResult.builder() .bpk(randomBpk) .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(newFirstName) + .givenName(oldGivenName) .familyName(randomFamilyName) .dateOfBirth(randomBirthDate) .build()), generateRandomProcessId())); + + Mockito.when(zmrClient.searchCountrySpecific(any(), any(), any())).thenThrow( + new IllegalStateException("CountrySpecific search search should not be neccessary")); + Mockito.when(zmrClient.searchWithMds(any(), any(), any(), any(), any())).thenThrow( + new IllegalStateException("MDS search should not be neccessary")); + + // execute test task.execute(pendingReq, executionContext); - String bPk = readBpkFromSessionData(pendingReq); - - Assert.assertEquals("Wrong bpk", randomBpk, bPk); + + // validate state + //INFO: has to be the old givenName because ZMR allows no update of MDS information + checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, oldGivenName, randomBirthDate, DE); + } + /** - * One match, but register update needed + * TODO: include again if ERnP update is implementet. Maybe we can update MDS based on ERnP. + * + * One match, but register update needed. * @throws EidasSAuthenticationException */ + @Ignore @Test @DirtiesContext - public void testNode100_UserIdentifiedUpdateNecessary_b() throws TaskExecutionException, EidasSAuthenticationException { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + public void singlePersonalIdMatchUpdateNecessary_Ernp() throws TaskExecutionException, EidasSAuthenticationException { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); - String newRandomGivenName = randomAlphabetic(10); + String oldRandomGivenName = randomAlphabetic(10); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.singletonList( RegisterResult.builder() .bpk(randomBpk) .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(newRandomGivenName) + .givenName(oldRandomGivenName) .familyName(randomFamilyName) .dateOfBirth(randomBirthDate) .build())); + // execute test task.execute(pendingReq, executionContext); - String bPk = readBpkFromSessionData(pendingReq); - - Assert.assertEquals("Wrong bpk", randomBpk, bPk); + + // validate state + checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } /** - * Two matches found in ZMR + * Two matches by PersonalId found in ZMR * @throws EidasSAuthenticationException */ @Test @DirtiesContext - public void testNode101_ManualFixNecessary_a() throws EidasSAuthenticationException { - ArrayList<RegisterResult> zmrResult = new ArrayList<>(); - zmrResult.add( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()); - String newRandomGivenName = randomGivenName + randomAlphabetic(2); - zmrResult.add( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(newRandomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( - new ZmrRegisterResult(zmrResult, generateRandomProcessId())); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); + public void multiPersonalIdMatch_Zmr() throws EidasSAuthenticationException { + String newRandomGivenName = randomAlphabetic(10); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( + new ZmrRegisterResult(Arrays.asList( + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build(), + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(newRandomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build() + ), + generateRandomProcessId())); + Mockito.when(ernpClient.searchWithPersonIdentifier( + randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); + // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); - Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE instanceof WorkflowException)); + + // validate state + assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); + } - /** - * Two matches found in ErnP + * Two matches by PersonalId found in ZMR * @throws EidasSAuthenticationException */ @Test @DirtiesContext - public void testNode101_ManualFixNecessary_b() throws EidasSAuthenticationException { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); - ArrayList<RegisterResult> ernpResult = new ArrayList<>(); - ernpResult.add( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()); - String newRandomGivenName = randomGivenName + randomAlphabetic(2); - ernpResult.add( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(newRandomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(ernpResult); + public void withErrorFromZmr() throws EidasSAuthenticationException { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenThrow( + new ZmrCommunicationException("jUnit ZMR error", null)); + Mockito.when(ernpClient.searchWithPersonIdentifier( + randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); + // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq, executionContext)); - Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE instanceof WorkflowException)); + + // validate state + assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); + assertFalse("Wrong flag 'manualFixNeeded'", + ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); + } /** - * One match, no register update needed + * Two matches by PersonalId found in ErnP + * @throws EidasSAuthenticationException */ @Test @DirtiesContext - public void testNode102_UserIdentified_a() throws Exception { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + public void multiPersonalIdMatch_Ernp() throws EidasSAuthenticationException { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( + new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); + String newRandomGivenName = randomAlphabetic(10); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn( + Arrays.asList( + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build(), + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(newRandomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build() + )); + + // execute task + TaskExecutionException exception = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + // validate state + assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); + + } + + /** + * Two matches by PersonalId + * @throws EidasSAuthenticationException + */ + @Test + @DirtiesContext + public void multiPersonalIdMatch_ErnpAndZmr() throws EidasSAuthenticationException { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( + new ZmrRegisterResult(Arrays.asList( + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build() + ), generateRandomProcessId())); + String newRandomGivenName = randomAlphabetic(10); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn( + Arrays.asList( + RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build() + )); + + // execute task + TaskExecutionException exception = assertThrows(TaskExecutionException.class, + () -> task.execute(pendingReq, executionContext)); + + // validate state + assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); + + } + + /** + * One match by PersonalId, no register update needed + */ + @Test + @DirtiesContext + public void singlePersonalIdMatchNoUpdate_Ernp() throws Exception { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.singletonList( RegisterResult.builder() @@ -307,18 +398,20 @@ public class InitialSearchTaskTest { .dateOfBirth(randomBirthDate) .build())); + // execute test task.execute(pendingReq, executionContext); - String bPk = readBpkFromSessionData(pendingReq); - Assert.assertEquals("Wrong bpk", randomBpk, bPk); + + // validate state + checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } /** - * One match, no register update needed + * One match by PersonalId, no register update needed */ @Test @DirtiesContext - public void testNode102_UserIdentified_b() throws Exception { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + public void singlePersonalIdMatchNoUpdate_Zmr() throws Exception { + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.singletonList( RegisterResult.builder() .bpk(randomBpk) @@ -330,27 +423,27 @@ public class InitialSearchTaskTest { generateRandomProcessId())); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); + // execute test task.execute(pendingReq, executionContext); - - String bPk = readBpkFromSessionData(pendingReq); - Assert.assertEquals("Wrong bpk", randomBpk, bPk); + + // validate state + checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } /** - * Multiple matches found in ZMR and ErnP with detail search + * Find single person in ZMR by country specifics. */ @Test @DirtiesContext - public void testNode103_UserIdentified_DE() throws Exception { + public void singlePersonFindWithCountySpecifics_Zmr() throws Exception { final AuthenticationResponse response = buildDummyAuthResponseDE(randomGivenName, randomFamilyName, - randomPersonalIdentifier_DE, - randomBirthDate, randomPlaceOfBirth, randomBirthName); + randomPersonalIdentifier_DE, randomBirthDate, randomPlaceOfBirth, randomBirthName); TestRequestImpl pendingReq1 = new TestRequestImpl(); pendingReq1.getSessionData(AuthProcessDataWrapper.class) .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); BigInteger zmrProcessId = generateRandomProcessId(); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchCountrySpecific(eq(zmrProcessId), any(PersonSuchenRequest.class), eq(DE))).thenReturn( new ZmrRegisterResult(Collections.singletonList( @@ -364,23 +457,25 @@ public class InitialSearchTaskTest { .birthName(randomBirthName) .build()) ,zmrProcessId)); + Mockito.when(zmrClient.searchWithMds(any(), any(), any(), any(), any())).thenThrow( + new IllegalStateException("MDS search should not be neccessary")); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); // execute test task.execute(pendingReq1, executionContext); - + // validate state - String resultBpk = readBpkFromSessionData(pendingReq1); - Assert.assertEquals("Wrong bpk", randomBpk, resultBpk); + checkMatchingSuccessState(pendingReq1, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } /** - * Multiple matches found in ZMR and ErnP with detail search + * Multiple matches found in ZMR by country specifics. */ @Test @DirtiesContext - public void testNode104_ManualFixNecessary_DE() throws Exception { + public void multiplePersonFindWithCountySpecifics_Zmr() throws Exception { String newRandomPseudonym = randomPersonalIdentifier_DE + RandomStringUtils.randomNumeric(2); String newRandomBpk = randomBpk + RandomStringUtils.randomNumeric(6); final AuthenticationResponse response = buildDummyAuthResponseDE(randomGivenName, randomFamilyName, @@ -391,9 +486,8 @@ public class InitialSearchTaskTest { .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); BigInteger zmrProcessId = generateRandomProcessId(); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( + new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchCountrySpecific(eq(zmrProcessId), any(PersonSuchenRequest.class), eq(DE))).thenReturn( new ZmrRegisterResult(Arrays.asList( RegisterResult.builder() @@ -416,14 +510,17 @@ public class InitialSearchTaskTest { .build()) ,zmrProcessId)); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); - // execute test + // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq1, executionContext)); - - // check error - Throwable origE = exception.getOriginalException(); - Assert.assertTrue("Wrong exception", (origE instanceof WorkflowException)); + + // validate state + assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); + } /** @@ -434,44 +531,51 @@ public class InitialSearchTaskTest { */ @Test @DirtiesContext - public void testNode505_TransitionToInsertErnbTask() throws TaskExecutionException, EidasSAuthenticationException, URISyntaxException, EaafStorageException { + public void noResultByAnySearch() throws TaskExecutionException, EidasSAuthenticationException, URISyntaxException, EaafStorageException { BigInteger zmrProcessId = generateRandomProcessId(); pendingReq.getSessionData(AuthProcessDataWrapper.class) .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, buildDummyAuthResponse(randomGivenName, randomFamilyName, randomPersonalIdentifier_EE, randomBirthDate)); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_EE)).thenReturn( + + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, EE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, EE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_EE)).thenReturn(Collections.emptyList()); + + // execute task task.execute(pendingReq, executionContext); - String bPk = readBpkFromSessionData(pendingReq); - Assert.assertNull("Wrong bpk", bPk); + + // validate state + assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); + + assertNull("Find intermediate matching data but matching should be finished", + MatchingTaskUtils.getIntermediateMatchingResult(pendingReq)); + assertNull("Find final matching data but no match sould be found", + MatchingTaskUtils.getFinalMatchingResult(pendingReq)); Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); Assert.assertNull("Wrong transition", transitionGUI); Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertTrue("Wrong transition", transitionErnb); + } /** - * NO match found in ZMR and ErnP with Initial search, one match with MDS search in Ernb - * @throws EidasSAuthenticationException - * @throws URISyntaxException - * @throws EaafStorageException + * Find one match with MDS search in ERnP. */ @Test @DirtiesContext - public void testNode505_TransitionToGUI_Ernb() throws TaskExecutionException, EidasSAuthenticationException, URISyntaxException, EaafStorageException { + public void resultByMdsSearch_Ernb() throws TaskExecutionException, EidasSAuthenticationException, URISyntaxException, EaafStorageException { BigInteger zmrProcessId = generateRandomProcessId(); pendingReq.getSessionData(AuthProcessDataWrapper.class) .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, buildDummyAuthResponse(randomGivenName, randomFamilyName, randomPersonalIdentifier_EE, randomBirthDate)); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_EE)).thenReturn( + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, EE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, EE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); @@ -487,24 +591,22 @@ public class InitialSearchTaskTest { .dateOfBirth(randomBirthDate) .build())); + // execute test task.execute(pendingReq, executionContext); - assertThrows(WorkflowException.class, () -> readBpkFromSessionData(pendingReq)); - Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); - Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); - Assert.assertNull("Wrong transition", transitionErnb); + // validate state + checkIntermediateResult(1); + } /** - * NO match found in ZMR and ErnP with Initial search, one match with MDS search in ZMR - * @throws EidasSAuthenticationException + * Find one match with MDS search in ZMR. */ @Test @DirtiesContext - public void testNode505_TransitionToGUI_Zmr() throws TaskExecutionException, EidasSAuthenticationException { + public void resultByMdsSearch_Zmr() throws TaskExecutionException, EidasSAuthenticationException { BigInteger zmrProcessId = generateRandomProcessId(); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); @@ -518,29 +620,35 @@ public class InitialSearchTaskTest { .build()), zmrProcessId)); + // execute test task.execute(pendingReq, executionContext); - assertThrows(WorkflowException.class, () -> readBpkFromSessionData(pendingReq)); - Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); - Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); - Assert.assertNull("Wrong transition", transitionErnb); + // validate state + checkIntermediateResult(1); + } /** - * NO match found in ZMR and ErnP with Initial search, multiple matches found with MDS search - * @throws EidasSAuthenticationException + * resultByMdsSearch */ @Test @DirtiesContext - public void testNode505_TransitionToGUI_Ernb_multi() throws TaskExecutionException, EidasSAuthenticationException { + public void multipleResultsByMdsSearch() throws TaskExecutionException, EidasSAuthenticationException { BigInteger zmrProcessId = generateRandomProcessId(); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPersonalIdentifier_DE)).thenReturn( + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchCountrySpecific(eq(zmrProcessId), any(PersonSuchenRequest.class), any(String.class))).thenReturn( new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + new ZmrRegisterResult(Arrays.asList( + RegisterResult.builder() + .bpk(randomBpk + "2") + .pseudonym(Arrays.asList(randomPsydonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build()), + zmrProcessId)); Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)).thenReturn( @@ -560,13 +668,12 @@ public class InitialSearchTaskTest { .dateOfBirth(randomBirthDate) .build())); + // execute test task.execute(pendingReq, executionContext); - assertThrows(WorkflowException.class, () -> readBpkFromSessionData(pendingReq)); - Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); - Assert.assertTrue("Wrong transition", transitionGUI); - Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); - Assert.assertNull("Wrong transition", transitionErnb); + // validate state + checkIntermediateResult(3); + } @NotNull @@ -579,6 +686,38 @@ public class InitialSearchTaskTest { } + private void checkMatchingSuccessState(IRequest pendingReq, String bpk, String familyName, String givenName, + String birhday, String countryCode) { + assertNull("Find intermediate matching data but matching should be finished", + MatchingTaskUtils.getIntermediateMatchingResult(pendingReq)); + assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); + + MatchedPersonResult personInfo = MatchingTaskUtils.getFinalMatchingResult(pendingReq); + assertNotNull("no final matching result", personInfo); + assertEquals("wrong bpk", bpk, personInfo.getBpk()); + assertEquals("wrong givenName", givenName, personInfo.getGivenName()); + assertEquals("wrong familyName", familyName, personInfo.getFamilyName()); + assertEquals("wrong dateOfBirth", birhday, personInfo.getDateOfBirth()); + assertEquals("wrong countryCode", countryCode, personInfo.getCountryCode()); + + } + + private void checkIntermediateResult(int resultSize) { + Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK); + Assert.assertTrue("Wrong transition", transitionGUI); + Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); + Assert.assertNull("Wrong transition", transitionErnb); + + assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); + assertNull("Find final matching data but no match sould be found", + MatchingTaskUtils.getFinalMatchingResult(pendingReq)); + + RegisterSearchResult result = MatchingTaskUtils.getIntermediateMatchingResult(pendingReq); + assertNotNull("Find no intermediate matching data", result); + assertEquals("wrong intermediate result size", resultSize, result.getResultCount()); + + } + @NotNull private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier, String dateOfBirth) throws URISyntaxException { @@ -646,10 +785,4 @@ public class InitialSearchTaskTest { .attributeValueMarshaller(marshaller).build(); } - private String readBpkFromSessionData(TestRequestImpl pendingReq) throws WorkflowException { - return MatchingTaskUtils.getInitialRegisterResult(pendingReq) != null - ? MatchingTaskUtils.getInitialRegisterResult(pendingReq).getBpk() - : null; - - } } |