diff options
author | Thomas <> | 2022-02-03 15:50:33 +0100 |
---|---|---|
committer | Thomas <> | 2022-02-08 09:35:52 +0100 |
commit | b70915cf52ecb08c881d33e8c65b6256922fc0f4 (patch) | |
tree | c203b5f743269ca6b64818e6d731b4c1a0bedd59 /eidas_modules/authmodule-eIDAS-v2/src/test | |
parent | a3d1b2e9aaad4b00031cfcd76e26940697c876c2 (diff) | |
download | National_eIDAS_Gateway-b70915cf52ecb08c881d33e8c65b6256922fc0f4.tar.gz National_eIDAS_Gateway-b70915cf52ecb08c881d33e8c65b6256922fc0f4.tar.bz2 National_eIDAS_Gateway-b70915cf52ecb08c881d33e8c65b6256922fc0f4.zip |
refactor(ernp): change API of ERnP client to same model as ZMR client
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test')
-rw-r--r-- | eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java | 185 |
1 files changed, 119 insertions, 66 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 c14af84c..d6d49370 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,7 +23,48 @@ 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.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.ernp.ErnpRestClient.ErnpRegisterResult; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.IErnpClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.IZmrClient; import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClient; @@ -31,7 +72,11 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrSoapClien 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.exception.*; +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.handler.CountrySpecificDetailSearchProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.GenericEidProcessor; import at.asitplus.eidas.specific.modules.auth.eidas.v2.service.ICcSpecificEidProcessingService; @@ -52,36 +97,6 @@ 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 = { @@ -176,6 +191,13 @@ public class InitialSearchTaskTest { Mockito.when(zmrClient.update(any(), any(), any())) .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); + Mockito.when(ernpClient.searchWithMds(any(), any(), any(), any())) + .thenThrow(new IllegalStateException("MDS search should not be neccessary")); + Mockito.when(ernpClient.update(any(), any())) + .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); + // execute test task.execute(pendingReq, executionContext); @@ -200,8 +222,8 @@ public class InitialSearchTaskTest { .thenReturn(emptyZmrRegisterResult()); String oldRandomGivenName = randomAlphabetic(10); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Collections.singletonList(randomRegisterResult(oldRandomGivenName, randomBpk))); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(ernpRegisterResult(randomRegisterResult(oldRandomGivenName, randomBpk))); // execute test task.execute(pendingReq, executionContext); @@ -210,11 +232,8 @@ public class InitialSearchTaskTest { 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 * @@ -226,8 +245,8 @@ public class InitialSearchTaskTest { String newRandomGivenName = randomAlphabetic(10); 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()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -251,8 +270,8 @@ public class InitialSearchTaskTest { public void withErrorFromZmr() throws EidasSAuthenticationException { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenThrow(new ZmrCommunicationException("jUnit ZMR error", null)); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Collections.emptyList()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -277,8 +296,9 @@ public class InitialSearchTaskTest { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenReturn(emptyZmrRegisterResult()); String newRandomGivenName = randomAlphabetic(10); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Arrays.asList(randomRegisterResult(), randomRegisterResult(newRandomGivenName, randomBpk))); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(ernpRegisterResult( + Arrays.asList(randomRegisterResult(), randomRegisterResult(newRandomGivenName, randomBpk)))); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -301,9 +321,8 @@ public class InitialSearchTaskTest { public void multiPersonalIdMatch_ErnpAndZmr() throws EidasSAuthenticationException { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenReturn(zmrRegisterResult(randomRegisterResult())); - String newRandomGivenName = randomAlphabetic(10); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Collections.singletonList(randomRegisterResult())); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(ernpRegisterResult(randomRegisterResult())); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -324,8 +343,13 @@ public class InitialSearchTaskTest { public void singlePersonalIdMatchNoUpdate_Ernp() throws Exception { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenReturn(emptyZmrRegisterResult()); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Collections.singletonList(randomRegisterResult())); + Mockito.when(zmrClient.update(any(), any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); + + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(ernpRegisterResult(randomRegisterResult())); + Mockito.when(ernpClient.update(any(), any())) + .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); // execute test task.execute(pendingReq, executionContext); @@ -342,8 +366,8 @@ public class InitialSearchTaskTest { public void singlePersonalIdMatchNoUpdate_Zmr() throws Exception { Mockito.when(zmrClient.searchWithPersonIdentifier(null, randomPseudonym, DE)) .thenReturn(zmrRegisterResult(randomRegisterResult())); - Mockito.when(ernpClient.searchWithPersonIdentifier(randomPersonalIdentifier_DE)) - .thenReturn(Collections.emptyList()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); Mockito.when(zmrClient.update(any(), any(), any())) .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); @@ -394,8 +418,8 @@ public class InitialSearchTaskTest { 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()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); // execute test task.execute(pendingReq1, executionContext); @@ -444,8 +468,8 @@ public class InitialSearchTaskTest { 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()); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); // execute task TaskExecutionException exception = assertThrows(TaskExecutionException.class, @@ -480,9 +504,12 @@ public class InitialSearchTaskTest { 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(ernpClient.searchWithPersonIdentifier(randomPseudonym, EE)) + .thenReturn(emptyErnpRegisterResult()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate, EE)) + .thenReturn(new ErnpRegisterResult(Collections.emptyList())); + Mockito.when(ernpClient.update(any(), any())) + .thenThrow(new IllegalStateException("ZMR update should not be neccessary")); // execute task task.execute(pendingReq, executionContext); @@ -519,10 +546,10 @@ public class InitialSearchTaskTest { 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())); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, EE)) + .thenReturn(emptyErnpRegisterResult()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate, EE)) + .thenReturn(ernpRegisterResult(randomRegisterResult())); // execute test task.execute(pendingReq, executionContext); @@ -546,8 +573,14 @@ public class InitialSearchTaskTest { 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.searchWithPersonIdentifier(randomPseudonym, DE)).thenReturn( + emptyErnpRegisterResult()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate, DE)) + .thenReturn(emptyErnpRegisterResult()); + Mockito.when(ernpClient.update(any(), any())) + .thenThrow(new IllegalStateException("ERnP update should not be neccessary")); + // execute test task.execute(pendingReq, executionContext); @@ -573,10 +606,10 @@ public class InitialSearchTaskTest { 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"))); + Mockito.when(ernpClient.searchWithPersonIdentifier(randomPseudonym, DE)) + .thenReturn(emptyErnpRegisterResult()); + Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate, DE)) + .thenReturn(ernpRegisterResult(Arrays.asList(randomRegisterResult(), randomRegisterResult(randomBpk + "1")))); // execute test task.execute(pendingReq, executionContext); @@ -587,6 +620,16 @@ public class InitialSearchTaskTest { } @NotNull + private ZmrSoapClient.ZmrRegisterResult emptyZmrRegisterResult() { + return new ZmrRegisterResult(Collections.emptyList(), generateRandomProcessId()); + } + + @NotNull + private ErnpRegisterResult emptyErnpRegisterResult() { + return new ErnpRegisterResult(Collections.emptyList()); + } + + @NotNull private ZmrRegisterResult zmrRegisterResult(RegisterResult registerResult, BigInteger processId) { return new ZmrRegisterResult(Collections.singletonList(registerResult), processId); } @@ -597,6 +640,16 @@ public class InitialSearchTaskTest { } @NotNull + private ErnpRegisterResult ernpRegisterResult(RegisterResult registerResult) { + return new ErnpRegisterResult(Collections.singletonList(registerResult)); + } + + @NotNull + private ErnpRegisterResult ernpRegisterResult(List<RegisterResult> registerResult) { + return new ErnpRegisterResult(registerResult); + } + + @NotNull private RegisterResult randomRegisterResult() { return randomRegisterResult(randomGivenName, randomBpk); } |