aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2020-12-18 17:24:55 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2021-01-15 14:20:33 +0100
commit65da83cd168a87fe15c6e03a0178fe78780854fd (patch)
treeac7651aedb28268bb751b57e6a2ba1f52c5e3165 /eidas_modules/authmodule-eIDAS-v2/src/test
parent1dd2f63eb54befa7b347051c509d33dd8448bff0 (diff)
downloadNational_eIDAS_Gateway-65da83cd168a87fe15c6e03a0178fe78780854fd.tar.gz
National_eIDAS_Gateway-65da83cd168a87fe15c6e03a0178fe78780854fd.tar.bz2
National_eIDAS_Gateway-65da83cd168a87fe15c6e03a0178fe78780854fd.zip
constructor based injection, randomized values for testing, added constants
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/InitialSearchTaskFirstTest.java289
1 files changed, 115 insertions, 174 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
index d366fefc..f7fc6b06 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java
@@ -2,20 +2,17 @@ package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.DummyErnbClient;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.IErnbClient;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ManualFixNecessaryException;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.DeSpecificDetailSearchProcessor;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.ICountrySpecificDetailSearchProcessor;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.ItSpecificDetailSearchProcessor;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask;
-import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.DummyZmrClient;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.IZmrClient;
import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
import at.gv.egiz.eaaf.core.exceptions.EaafStorageException;
import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
import at.gv.egiz.eaaf.core.impl.idp.auth.data.AuthProcessDataWrapper;
-import at.gv.egiz.eaaf.core.impl.idp.module.test.DummySpConfiguration;
import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
import eu.eidas.auth.commons.attribute.AttributeDefinition;
@@ -33,7 +30,6 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -62,20 +58,16 @@ public class InitialSearchTaskFirstTest {
@InjectMocks
private InitialSearchTask task;
- // NOTE: Is defined as @Mock, but also manually mocked in "testNode100a" etc -- why?
- @Mock
private IZmrClient zmrClient;
-
- // NOTE: Is defined as @Mock, but also manually mocked in "testNode100a" etc -- why?
- @Mock
private IErnbClient ernbClient;
final ExecutionContext executionContext = new ExecutionContextImpl();
private MockHttpServletRequest httpReq;
private MockHttpServletResponse httpResp;
private TestRequestImpl pendingReq;
- private DummySpConfiguration oaParam;
-
+ private String randomIdentifier = RandomStringUtils.randomNumeric(10);
+ private String randomFamilyName = RandomStringUtils.randomNumeric(11);
+ private String randomGivenName = RandomStringUtils.randomNumeric(12);
/**
* jUnit class initializer.
*
@@ -86,7 +78,6 @@ public class InitialSearchTaskFirstTest {
final String current = new java.io.File(".").toURI().toString();
System.setProperty("eidas.ms.configuration", current
+ "src/test/resources/config/junit_config_1.properties");
-
}
/**
@@ -94,19 +85,15 @@ public class InitialSearchTaskFirstTest {
*/
@Before
public void setUp() throws URISyntaxException, EaafStorageException {
- // NOTE: PowerMockito should not be needed, as we don't want to test static and private methods
- task = PowerMockito.spy(task);
-
httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
- final AuthenticationResponse response = buildDummyAuthResponseMaxMustermann();
+ final AuthenticationResponse response = buildDummyAuthResponseRandomPerson();
pendingReq = new TestRequestImpl();
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
}
@Test
@@ -120,22 +107,18 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
String randomBpk = RandomStringUtils.randomNumeric(6);
- zmrResult.add(new RegisterResult(randomBpk,"de/st/max123", "Max_new", "Mustermann", "2011-01-01"));
+ zmrResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, "Max_new", randomFamilyName, "2011-01-01"));
- // NOTE: Are we using Mockito or these fixed strings in DummyZmrClient?
- // NOTE: Please mock an interface, not a concrete class
- // NOTE: But DummyZmrClient is also defined as a bean "ZmrClientForeIDAS" in "eidas_v2_auth.beans.xml"?
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
String bPk = (String)
@@ -159,19 +142,18 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);//"de/st/max123"???
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
String randomBpk = RandomStringUtils.randomNumeric(6);
- ernbResult.add(new RegisterResult(randomBpk,"de/st/max123", "Max_new", "Mustermann", "2011-01-01"));
+ ernbResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, "Max_new", randomFamilyName, "2011-01-01"));
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
String bPk = (String)
@@ -193,24 +175,20 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "2011-01-01"));
- zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Maximilian", "Mustermann", "2011-01-01"));
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01"));
+ zmrResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, "Maximilian", randomFamilyName, "2011-01-01"));
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
- String bPk = (String)
- pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
-
} catch (final TaskExecutionException e) {
Throwable origE = e.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
@@ -227,25 +205,21 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "2011-01-01"));
- ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Maximilian", "Mustermann", "2011-01-01"));
+ ernbResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01"));
+ ernbResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, "Maximilian", randomFamilyName, "2011-01-01"));
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
- String bPk = (String)
- pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
-
} catch (final TaskExecutionException e) {
Throwable origE = e.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
@@ -259,26 +233,25 @@ public class InitialSearchTaskFirstTest {
*/
public void testNode102a() throws Exception {
+ String randomBpk = RandomStringUtils.randomNumeric(12);;
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "2011-01-01"));
+ ernbResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01"));
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertTrue("Wrong bpk", bPk.equals("bpkMax"));
-
+ Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk));
} catch (final TaskExecutionException e) {
Assert.assertTrue("Wrong workflow, should not reach this point", false);
}
@@ -290,27 +263,26 @@ public class InitialSearchTaskFirstTest {
* One match, no register update needed
*/
public void testNode102b() throws Exception {
-
+ String randomBpk = RandomStringUtils.randomNumeric(14);
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "2011-01-01"));
+ zmrResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01"));
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertTrue("Wrong bpk", bPk.equals("bpkMax"));
+ Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk));
} catch (final TaskExecutionException e) {
Assert.assertTrue("Wrong workflow, should not reach this point", false);
@@ -323,40 +295,36 @@ public class InitialSearchTaskFirstTest {
* One match found in ZMR and ErnB with detail search
*/
public void testNode103IT() throws Exception {
- String bpkRegister = "bpkMax";
- String taxNumber = "tax123";
- final AuthenticationResponse response = buildDummyAuthResponseMaxMustermannIT_Tax(taxNumber);
+ String bpkRegister = RandomStringUtils.randomNumeric(14);
+ String taxNumber = RandomStringUtils.randomNumeric(14);
+ final AuthenticationResponse response = buildDummyAuthResponseRandomPersonIT_Tax(taxNumber);
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
//Mock ZMR initial search
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResultInitial);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
//String bpk, String pseudonym, String givenName, String familyName, String dateOfBirth,
// String placeOfBirth, String birthName, String taxNumber, PostalAddressType address
- zmrResultSpecific.add(new RegisterResult(bpkRegister,"it/st/max1234", "Max", "Mustermann", "2011-01-01", null,
- null, taxNumber, null));
+ zmrResultSpecific.add(new RegisterResult(bpkRegister, "it/st/"+randomIdentifier+"4", randomGivenName, randomFamilyName,
+ "2011-01-01", null, null, taxNumber, null));
Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(zmrResultSpecific);
- task.setZmrClient(zmrClient);
//Mock ernb initial search
ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResultInitial);//"de/st/max123"???
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial);
- task.setErnbClient(ernbClient);
//Mock country specific search
List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor();
- it.setErnbClient(ernbClient);
- it.setZmrClient(zmrClient);
+ ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernbClient, zmrClient);
handlers.add(it);
- task.setHandlers(handlers);
+ task = new InitialSearchTask(handlers, ernbClient, zmrClient);
try {
task.execute(pendingReq1, executionContext);
@@ -375,8 +343,8 @@ public class InitialSearchTaskFirstTest {
* Multiple matches found in ZMR and ErnB with detail search
*/
public void testNode103DE() throws Exception {
- String givenName = "Max";
- String familyName = "Mustermann";
+ String givenName = randomGivenName;
+ String familyName = randomFamilyName;
String pseudonym = "de/st/max1234";
String bpk = "bpkMax";
String dateOfBirth = "2011-01-01";
@@ -390,33 +358,26 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR initial search
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResultInitial);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
- zmrResultSpecific.add(new RegisterResult(bpk, pseudonym, givenName, familyName, dateOfBirth, placeOfBirth, birthName,
+ zmrResultSpecific.add(new RegisterResult(bpk, pseudonym, givenName, familyName, dateOfBirth, placeOfBirth,
+ birthName,
null, null));
- //.searchDeSpecific(eidData.getGivenName(), eidData.getFamilyName(), eidData.getDateOfBirth(),
- // eidData.getPlaceOfBirth(), eidData.getBirthName()
Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific);
- task.setZmrClient(zmrClient);
-
//Mock ernb initial search
ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResultInitial);//"de/st/max123"???
-
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial);
//Mock country specific search
List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor();
- de.setErnbClient(ernbClient);
- de.setZmrClient(zmrClient);
+ DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernbClient, zmrClient);
handlers.add(de);
- task.setHandlers(handlers);
+ task = new InitialSearchTask(handlers, ernbClient, zmrClient);
try {
task.execute(pendingReq1, executionContext);
@@ -435,8 +396,8 @@ public class InitialSearchTaskFirstTest {
* Multiple matches found in ZMR and ErnB with detail search
*/
public void testNode104DE() throws Exception {
- String givenName = "Max";
- String familyName = "Mustermann";
+ String givenName = randomGivenName;
+ String familyName = randomFamilyName;
String pseudonym1 = "de/st/max1234";
String pseudonym2 = "de/st/max12345";
String bpk1 = "bpkMax";
@@ -452,34 +413,29 @@ public class InitialSearchTaskFirstTest {
//Mock ZMR initial search
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResultInitial);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
- zmrResultSpecific.add(new RegisterResult(bpk1, pseudonym1, givenName, familyName, dateOfBirth, placeOfBirth, birthName,
+ zmrResultSpecific.add(new RegisterResult(bpk1, pseudonym1, givenName, familyName, dateOfBirth, placeOfBirth,
+ birthName,
null, null));
- zmrResultSpecific.add(new RegisterResult(bpk2, pseudonym2, givenName, familyName, dateOfBirth, placeOfBirth, birthName,
+ zmrResultSpecific.add(new RegisterResult(bpk2, pseudonym2, givenName, familyName, dateOfBirth, placeOfBirth,
+ birthName,
null, null));
- //.searchDeSpecific(eidData.getGivenName(), eidData.getFamilyName(), eidData.getDateOfBirth(),
- // eidData.getPlaceOfBirth(), eidData.getBirthName()
Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific);
- task.setZmrClient(zmrClient);
//Mock ernb initial search
ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResultInitial);//"de/st/max123"???
-
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial);
//Mock country specific search
List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor();
- de.setErnbClient(ernbClient);
- de.setZmrClient(zmrClient);
+ DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernbClient, zmrClient);
handlers.add(de);
- task.setHandlers(handlers);
+ task = new InitialSearchTask(handlers, ernbClient, zmrClient);
try {
task.execute(pendingReq1, executionContext);
@@ -498,43 +454,34 @@ public class InitialSearchTaskFirstTest {
* Multiple matches found in ZMR and ErnB with detail search
*/
public void testNode104IT() throws Exception {
-
- String fakeTaxNumber = "tax123";
- final AuthenticationResponse response = buildDummyAuthResponseMaxMustermannIT_Tax(fakeTaxNumber);
+ String fakeTaxNumber = RandomStringUtils.randomNumeric(14);;
+ final AuthenticationResponse response = buildDummyAuthResponseRandomPersonIT_Tax(fakeTaxNumber);
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
//Mock ZMR initial search
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResultInitial);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
- //String bpk, String pseudonym, String givenName, String familyName, String dateOfBirth,
- // String placeOfBirth, String birthName, String taxNumber, PostalAddressType address
- zmrResultSpecific.add(new RegisterResult("bpkMax","it/st/max1234", "Max", "Mustermann", "2011-01-01", null, null,
+
+ zmrResultSpecific.add(new RegisterResult("bpkMax", "it/st/"+randomIdentifier+"4", randomGivenName, randomFamilyName, "2011-01-01", null, null,
fakeTaxNumber, null));
- zmrResultSpecific.add(new RegisterResult("bpkMax1","it/st/max1235", "Max", "Mustermann", "2011-01-01", null, null,
+ zmrResultSpecific.add(new RegisterResult("bpkMax1", "it/st/"+randomIdentifier+"5", randomGivenName, randomFamilyName, "2011-01-01", null, null,
fakeTaxNumber, null));
Mockito.when(zmrClient.searchItSpecific(fakeTaxNumber)).thenReturn(zmrResultSpecific);
-
- task.setZmrClient(zmrClient);
-
//Mock ernb initial search
ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResultInitial);//"de/st/max123"???
-
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial);
//Mock country specific search
List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor();
- it.setErnbClient(ernbClient);
- it.setZmrClient(zmrClient);
+ ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernbClient, zmrClient);
handlers.add(it);
- task.setHandlers(handlers);
+ task = new InitialSearchTask(handlers, ernbClient, zmrClient);
try {
task.execute(pendingReq1, executionContext);
@@ -552,27 +499,25 @@ public class InitialSearchTaskFirstTest {
/**
* NO match found in ZMR and ErnB with Initial search
*/
- public void testNode105() throws Exception {
+ public void testNode105() {
//Mock ZMR
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(DummyZmrClient.class);
- Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"???
- task.setZmrClient(zmrClient);
+ zmrClient = Mockito.mock(IZmrClient.class);
+ Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);
//Mock ernb
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
- ernbClient = Mockito.mock(DummyErnbClient.class);
- Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"???
- task.setErnbClient(ernbClient);
+ ernbClient = Mockito.mock(IErnbClient.class);
+ Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult);
+ task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- // NOTE: Why "105"? Extract in a constant
- Assert.assertTrue("Wrong bpk", bPk.equals("105"));
+ Assert.assertTrue("Wrong bpk", bPk.equals("TODO-Temporary-Endnode-105"));
} catch (final TaskExecutionException e) {
Assert.assertTrue("Wrong workflow, should not reach this point", false);
}
@@ -580,27 +525,17 @@ public class InitialSearchTaskFirstTest {
@NotNull
- private AuthenticationResponse buildDummyAuthResponse() throws URISyntaxException {
- return buildDummyAuthResponse(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
- "de/st/" + RandomStringUtils.randomNumeric(64), "2001-01-01");
- }
-
- @NotNull
- private AuthenticationResponse buildDummyAuthResponseMaxMustermann() throws URISyntaxException {
- // NOTE: Those strings "de/st/max123" seem to be somehow relevant, but where do we need to use that exact string again?
+ private AuthenticationResponse buildDummyAuthResponseRandomPerson() throws URISyntaxException {
+ // NOTE: Those strings "de/st/max123" seem to be somehow relevant, but where do we need to use that exact string
+ // again?
// NOTE: If not, why not using random strings?
- return buildDummyAuthResponse("Max", "Mustermann",
- "de/st/max123", "2011-01-01");
- }
-
- private AuthenticationResponse buildDummyAuthResponseMaxMustermannIT() throws URISyntaxException {
- return buildDummyAuthResponse("Max", "Mustermann",
- "it/st/max123", "2011-01-01");
+ return buildDummyAuthResponse(randomGivenName, randomFamilyName,
+ "de/st/"+randomIdentifier, "2011-01-01");
}
- private AuthenticationResponse buildDummyAuthResponseMaxMustermannIT_Tax(String taxNumber) throws URISyntaxException {
- return buildDummyAuthResponse("Max", "Mustermann",
- "it/st/max123", "2011-01-01", taxNumber, null, null);
+ private AuthenticationResponse buildDummyAuthResponseRandomPersonIT_Tax(String taxNumber) throws URISyntaxException {
+ return buildDummyAuthResponse(randomGivenName, randomFamilyName,
+ "it/st/"+randomIdentifier, "2011-01-01", taxNumber, null, null);
}
@NotNull
@@ -611,10 +546,11 @@ public class InitialSearchTaskFirstTest {
@NotNull
private AuthenticationResponse buildDummyAuthResponseDE(String givenName, String familyName, String identifier,
- String dateOfBirth, String placeOfBirth,
+ String dateOfBirth, String placeOfBirth,
String birthName) throws URISyntaxException {
return buildDummyAuthResponse(givenName, familyName, identifier, dateOfBirth, null, placeOfBirth, birthName);
}
+
@NotNull
private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier,
String dateOfBirth, String taxNumber, String placeOfBirth,
@@ -653,13 +589,13 @@ public class InitialSearchTaskFirstTest {
.put(attributeDef3, givenName)
.put(attributeDef4, dateOfBirth);
- if(taxNumber != null) {
+ if (taxNumber != null) {
builder.put(attributeDef5, taxNumber);
}
- if(birthName != null) {
+ if (birthName != null) {
builder.put(attributeDef7, birthName);
}
- if(placeOfBirth != null) {
+ if (placeOfBirth != null) {
builder.put(attributeDef6, placeOfBirth);
}
final ImmutableAttributeMap attributeMap = builder.build();
@@ -669,4 +605,9 @@ public class InitialSearchTaskFirstTest {
"afaf")
.attributes(attributeMap).build();
}
+
+ private List<ICountrySpecificDetailSearchProcessor> emptyHandlers() {
+ return new ArrayList<>();
+ }
+
}