From f555785f594040b215c58fe0a83b8f9c0ca72024 Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Mon, 12 Jul 2021 13:48:26 +0200 Subject: Refactor creating random results in tests --- .../eidas/v2/test/tasks/InitialSearchTaskTest.java | 666 +++++++++------------ 1 file changed, 293 insertions(+), 373 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 cca94188..b0de3460 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 @@ -23,59 +23,15 @@ 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.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import javax.xml.namespace.QName; - -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; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.web.context.request.RequestContextHolder; -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; 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; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidPostProcessingException; -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.exception.*; 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; @@ -96,6 +52,36 @@ import eu.eidas.auth.commons.attribute.ImmutableAttributeMap; import eu.eidas.auth.commons.attribute.PersonType; import eu.eidas.auth.commons.light.impl.LightRequest; import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; +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; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.xml.namespace.QName; +import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { @@ -105,10 +91,10 @@ import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse; @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) public class InitialSearchTaskTest { - + private static final String EE = "EE"; private static final String DE = "DE"; - + private static final String EE_ST = EE + "/ST/"; private static final String DE_ST = DE + "/ST/"; @@ -116,19 +102,20 @@ public class InitialSearchTaskTest { private IZmrClient zmrClient; @Mock private IErnpClient ernpClient; - - @Autowired private List handlers; + + @Autowired + private List handlers; private RegisterSearchService registerSearchService; - - private final ICcSpecificEidProcessingService eidPostProcessor = createEidPostProcessor(); + + private final ICcSpecificEidProcessingService eidPostProcessor = createEidPostProcessor(); private InitialSearchTask task; - + final ExecutionContext executionContext = new ExecutionContextImpl(); private TestRequestImpl pendingReq; private final String randomBpk = RandomStringUtils.randomNumeric(6); - private final String randomPsydonym = RandomStringUtils.randomNumeric(10); - private final String randomPersonalIdentifier_DE = DE_ST + randomPsydonym; - private final String randomPersonalIdentifier_EE = EE_ST + randomPsydonym; + private final String randomPseudonym = RandomStringUtils.randomNumeric(10); + private final String randomPersonalIdentifier_DE = DE_ST + randomPseudonym; + private final String randomPersonalIdentifier_EE = EE_ST + randomPseudonym; private final String randomFamilyName = randomAlphabetic(10); private final String randomGivenName = randomAlphabetic(10); private final String randomPlaceOfBirth = randomAlphabetic(10); @@ -141,7 +128,7 @@ public class InitialSearchTaskTest { @Before public void setUp() throws URISyntaxException, EaafStorageException { MockitoAnnotations.initMocks(this); - + registerSearchService = new RegisterSearchService(handlers, zmrClient, ernpClient); task = new InitialSearchTask(registerSearchService, eidPostProcessor); @@ -181,228 +168,170 @@ public class InitialSearchTaskTest { @DirtiesContext 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(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")); - Mockito.when(zmrClient.update(any(), any(), any())).thenThrow( - new IllegalStateException("ZMR update should not be neccessary")); - + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(zmrRegisterResult(randomRegisterResult(oldGivenName, randomBpk))); + + 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")); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + // execute test task.execute(pendingReq, executionContext); - + // validate state //INFO: has to be the old givenName because ZMR allows no update of MDS information checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, oldGivenName, randomBirthDate, DE); - + } - /** - * TODO: include again if ERnP update is implementet. Maybe we can update MDS based on ERnP. - * + * TODO: include again if ERnP update is implementet. Maybe we can update MDS based on ERnP. + *

* One match, but register update needed. - * @throws EidasSAuthenticationException + * + * @throws EidasSAuthenticationException */ @Ignore @Test @DirtiesContext public void singlePersonalIdMatchUpdateNecessary_Ernp() throws TaskExecutionException, EidasSAuthenticationException { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); - + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(emptyZmrRegisterResult()); + String oldRandomGivenName = randomAlphabetic(10); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.singletonList( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(oldRandomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build())); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.singletonList(randomRegisterResult(oldRandomGivenName, randomBpk))); // execute test task.execute(pendingReq, executionContext); - + // validate state checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } + @NotNull + private ZmrSoapClient.ZmrRegisterResult emptyZmrRegisterResult() { + return new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId()); + } + /** * Two matches by PersonalId found in ZMR - * @throws EidasSAuthenticationException + * + * @throws EidasSAuthenticationException */ @Test @DirtiesContext 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()); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(new ZmrRegisterResult(Arrays.asList(randomRegisterResult(), randomRegisterResult(newRandomGivenName, randomBpk)), generateRandomProcessId())); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.emptyList()); // 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()); - + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); + } /** * Two matches by PersonalId found in ZMR - * @throws EidasSAuthenticationException + * + * @throws EidasSAuthenticationException */ @Test @DirtiesContext 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()); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, 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)); - + // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); - assertFalse("Wrong flag 'manualFixNeeded'", - ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); - + assertFalse("Wrong flag 'manualFixNeeded'", + ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); + } /** * Two matches by PersonalId found in ErnP - * @throws EidasSAuthenticationException + * + * @throws EidasSAuthenticationException */ @Test @DirtiesContext public void multiPersonalIdMatch_Ernp() throws EidasSAuthenticationException { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId())); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(emptyZmrRegisterResult()); 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() - )); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Arrays.asList(randomRegisterResult(), randomRegisterResult(newRandomGivenName, randomBpk))); // 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()); - + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); + } /** * Two matches by PersonalId - * @throws EidasSAuthenticationException + * + * @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())); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(zmrRegisterResult(randomRegisterResult())); 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() - )); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.singletonList(randomRegisterResult())); // 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()); - + 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() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build())); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(emptyZmrRegisterResult()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.singletonList(randomRegisterResult())); // execute test task.execute(pendingReq, executionContext); - + // validate state checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } @@ -413,23 +342,16 @@ public class InitialSearchTaskTest { @Test @DirtiesContext public void singlePersonalIdMatchNoUpdate_Zmr() throws Exception { - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( - new ZmrRegisterResult(Collections.singletonList( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()), - generateRandomProcessId())); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); - Mockito.when(zmrClient.update(any(), any(), any())).thenThrow( - new IllegalStateException("ZMR update should not be neccessary")); - + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(zmrRegisterResult(randomRegisterResult())); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.emptyList()); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + // execute test task.execute(pendingReq, executionContext); - + // validate state checkMatchingSuccessState(pendingReq, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); } @@ -439,50 +361,50 @@ public class InitialSearchTaskTest { */ @Test @DirtiesContext - public void singlePersonFindWithCountySpecifics_Zmr() throws Exception { + public void singlePersonFindWithCountySpecifics_Zmr() throws Exception { final AuthenticationResponse response = buildDummyAuthResponseDE(randomGivenName, randomFamilyName, randomPersonalIdentifier_DE, randomBirthDate, randomPlaceOfBirth, randomBirthName); - TestRequestImpl pendingReq1 = new TestRequestImpl(); + TestRequestImpl pendingReq1 = new TestRequestImpl(); pendingReq1.getSessionData(AuthProcessDataWrapper.class) .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - - BigInteger zmrProcessId = generateRandomProcessId(); + + BigInteger zmrProcessId = generateRandomProcessId(); RegisterResult zmrResult = RegisterResult.builder() .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) + .pseudonym(Collections.singletonList(randomPseudonym)) .givenName(randomGivenName) .familyName(randomFamilyName) .dateOfBirth(randomBirthDate) .placeOfBirth(randomPlaceOfBirth) .birthName(randomBirthName) - .build(); - 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(zmrResult) - ,zmrProcessId)); - Mockito.when(zmrClient.update(eq(zmrProcessId), eq(zmrResult) , any())).thenReturn( - new ZmrRegisterResult(Collections.singletonList(RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym, RandomStringUtils.randomAlphanumeric(10))) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .placeOfBirth(randomPlaceOfBirth) - .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()); + .build(); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + Mockito.when(zmrClient.searchCountrySpecific(eq(zmrProcessId), any(PersonSuchenRequest.class), eq(DE))) + .thenReturn(zmrRegisterResult(zmrResult, zmrProcessId)); + RegisterResult randomRegisterResult = RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Arrays.asList(randomPseudonym, RandomStringUtils.randomAlphanumeric(10))) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .placeOfBirth(randomPlaceOfBirth) + .birthName(randomBirthName) + .build(); + Mockito.when(zmrClient.update(eq(zmrProcessId), eq(zmrResult), any())) + .thenReturn(zmrRegisterResult(randomRegisterResult, 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 checkMatchingSuccessState(pendingReq1, randomBpk, randomFamilyName, randomGivenName, randomBirthDate, DE); - + } /** @@ -499,79 +421,80 @@ public class InitialSearchTaskTest { TestRequestImpl pendingReq1 = new TestRequestImpl(); pendingReq1.getSessionData(AuthProcessDataWrapper.class) .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - - BigInteger zmrProcessId = generateRandomProcessId(); - 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() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .placeOfBirth(randomPlaceOfBirth) - .birthName(randomBirthName) - .build(), - RegisterResult.builder() - .bpk(newRandomBpk) - .pseudonym(Arrays.asList(newRandomPseudonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .placeOfBirth(randomPlaceOfBirth) - .birthName(randomBirthName) - .build()) - ,zmrProcessId)); - - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); - + + BigInteger zmrProcessId = generateRandomProcessId(); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + RegisterResult randomResult1 = RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Collections.singletonList(randomPseudonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .placeOfBirth(randomPlaceOfBirth) + .birthName(randomBirthName) + .build(); + RegisterResult randomResult2 = RegisterResult.builder() + .bpk(newRandomBpk) + .pseudonym(Collections.singletonList(newRandomPseudonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .placeOfBirth(randomPlaceOfBirth) + .birthName(randomBirthName) + .build(); + Mockito.when(zmrClient.searchCountrySpecific(eq(zmrProcessId), any(PersonSuchenRequest.class), eq(DE))) + .thenReturn(new ZmrRegisterResult(Arrays.asList(randomResult1, randomResult2), zmrProcessId)); + + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.emptyList()); + // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, () -> task.execute(pendingReq1, executionContext)); - + // validate state assertTrue("Wrong exception", (exception.getOriginalException() instanceof WorkflowException)); - assertTrue("Wrong flag 'manualFixNeeded'", - ((WorkflowException)exception.getOriginalException()).isRequiresManualFix()); - + assertTrue("Wrong flag 'manualFixNeeded'", + ((WorkflowException) exception.getOriginalException()).isRequiresManualFix()); + } /** * NO match found in ZMR and ErnP with Initial and MDS search - * @throws EidasSAuthenticationException - * @throws URISyntaxException - * @throws EaafStorageException + * + * @throws EidasSAuthenticationException + * @throws URISyntaxException + * @throws EaafStorageException */ @Test @DirtiesContext public void noResultByAnySearch() throws TaskExecutionException, EidasSAuthenticationException, URISyntaxException, EaafStorageException { BigInteger zmrProcessId = generateRandomProcessId(); pendingReq.getSessionData(AuthProcessDataWrapper.class) - .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, + .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, buildDummyAuthResponse(randomGivenName, randomFamilyName, randomPersonalIdentifier_EE, randomBirthDate)); - - 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(zmrClient.update(any(), any(), any())).thenThrow( - new IllegalStateException("ZMR update should not be neccessary")); - - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_EE)).thenReturn(Collections.emptyList()); - - + + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, EE)) + .thenReturn(new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, EE)) + .thenReturn(new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_EE)) + .thenReturn(Collections.emptyList()); + // execute task task.execute(pendingReq, executionContext); - + // 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 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)); @@ -579,35 +502,29 @@ public class InitialSearchTaskTest { Assert.assertNull("Wrong transition", transitionGUI); Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK); Assert.assertTrue("Wrong transition", transitionErnb); - + } /** - * Find one match with MDS search in ERnP. + * Find one match with MDS search in ERnP. */ @Test @DirtiesContext 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, 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()); - Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)).thenReturn( - Collections.singletonList( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build())); + .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, + buildDummyAuthResponse(randomGivenName, randomFamilyName, randomPersonalIdentifier_EE, randomBirthDate)); + + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, 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()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)) + .thenReturn(Collections.singletonList(randomRegisterResult())); // execute test task.execute(pendingReq, executionContext); @@ -618,35 +535,28 @@ public class InitialSearchTaskTest { } /** - * Find one match with MDS search in ZMR. + * Find one match with MDS search in ZMR. */ @Test @DirtiesContext public void resultByMdsSearch_Zmr() throws TaskExecutionException, EidasSAuthenticationException { - BigInteger zmrProcessId = generateRandomProcessId(); - Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPsydonym, DE)).thenReturn( - new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); - Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, DE)).thenReturn( - new ZmrRegisterResult(Collections.singletonList(RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()), - zmrProcessId)); - Mockito.when(zmrClient.update(any(), any(), any())).thenThrow( - new IllegalStateException("ZMR update should not be neccessary")); - + BigInteger zmrProcessId = generateRandomProcessId(); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) + .thenReturn(new ZmrRegisterResult(Collections.emptyList(), zmrProcessId)); + Mockito.when(zmrClient.searchWithMds(zmrProcessId, randomGivenName, randomFamilyName, randomBirthDate, DE)) + .thenReturn(zmrRegisterResult(randomRegisterResult(), zmrProcessId)); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); - - + + // execute test task.execute(pendingReq, executionContext); // validate state checkIntermediateResult(1); - + } /** @@ -655,66 +565,76 @@ public class InitialSearchTaskTest { @Test @DirtiesContext public void multipleResultsByMdsSearch() throws TaskExecutionException, EidasSAuthenticationException { - BigInteger zmrProcessId = generateRandomProcessId(); - 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(Arrays.asList( - RegisterResult.builder() - .bpk(randomBpk + "2") - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build()), - zmrProcessId)); - Mockito.when(zmrClient.update(any(), any(), any())).thenThrow( - new IllegalStateException("ZMR update should not be neccessary")); - - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)).thenReturn(Collections.emptyList()); - Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)).thenReturn( - Arrays.asList( - RegisterResult.builder() - .bpk(randomBpk) - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build(), - RegisterResult.builder() - .bpk(randomBpk + "1") - .pseudonym(Arrays.asList(randomPsydonym)) - .givenName(randomGivenName) - .familyName(randomFamilyName) - .dateOfBirth(randomBirthDate) - .build())); + BigInteger zmrProcessId = generateRandomProcessId(); + Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, 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(zmrRegisterResult(randomRegisterResult(randomBpk + "2"), zmrProcessId)); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) + .thenReturn(Collections.emptyList()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)) + .thenReturn(Arrays.asList(randomRegisterResult(), randomRegisterResult(randomBpk + "1"))); // execute test task.execute(pendingReq, executionContext); // validate state checkIntermediateResult(3); - + + } + + @NotNull + private ZmrRegisterResult zmrRegisterResult(RegisterResult registerResult, BigInteger processId) { + return new ZmrRegisterResult(Collections.singletonList(registerResult), processId); + } + + @NotNull + private ZmrRegisterResult zmrRegisterResult(RegisterResult registerResult) { + return zmrRegisterResult(registerResult, generateRandomProcessId()); + } + + @NotNull + private RegisterResult randomRegisterResult() { + return randomRegisterResult(randomGivenName, randomBpk); + } + + @NotNull + private RegisterResult randomRegisterResult(String randomBpk) { + return randomRegisterResult(randomGivenName, randomBpk); + } + + @NotNull + private RegisterResult randomRegisterResult(String randomGivenName, String randomBpk) { + return RegisterResult.builder() + .bpk(randomBpk) + .pseudonym(Collections.singletonList(randomPseudonym)) + .givenName(randomGivenName) + .familyName(randomFamilyName) + .dateOfBirth(randomBirthDate) + .build(); } @NotNull private AuthenticationResponse buildDummyAuthResponseRandomPerson() throws URISyntaxException { - return buildDummyAuthResponse(randomGivenName, randomFamilyName, DE_ST + randomPsydonym, randomBirthDate); + return buildDummyAuthResponse(randomGivenName, randomFamilyName, DE_ST + randomPseudonym, randomBirthDate); } private BigInteger generateRandomProcessId() { return new BigInteger(RandomStringUtils.randomNumeric(10)); - + } - - 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)); + + 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()); @@ -722,25 +642,25 @@ public class InitialSearchTaskTest { assertEquals("wrong familyName", familyName, personInfo.getFamilyName()); assertEquals("wrong dateOfBirth", birhday, personInfo.getDateOfBirth()); assertEquals("wrong countryCode", countryCode, personInfo.getCountryCode()); - + } - - private void checkIntermediateResult(int resultSize) { + + 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)); + + assertNotNull("find no eIDAS inbut data", MatchingTaskUtils.getInitialEidasData(pendingReq)); assertNull("Find final matching data but no match sould be found", MatchingTaskUtils.getFinalMatchingResult(pendingReq)); - + RegisterStatusResults 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 { -- cgit v1.2.3