aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src
diff options
context:
space:
mode:
authorChristian Kollmann <christian.kollmann@a-sit.at>2021-01-12 15:25:51 +0100
committerChristian Kollmann <christian.kollmann@a-sit.at>2021-01-12 15:25:51 +0100
commitccad318ae01794b246f5ca02c954fe94a92be515 (patch)
tree3d1d72ecc43f5fdf2857784b9003c8cb1a5c71c1 /eidas_modules/authmodule-eIDAS-v2/src
parent130df15476c455adb1a232fc555917ff69f0f09b (diff)
downloadNational_eIDAS_Gateway-ccad318ae01794b246f5ca02c954fe94a92be515.tar.gz
National_eIDAS_Gateway-ccad318ae01794b246f5ca02c954fe94a92be515.tar.bz2
National_eIDAS_Gateway-ccad318ae01794b246f5ca02c954fe94a92be515.zip
Use clear Arrange-Act-Assert structure in tests
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java88
1 files changed, 31 insertions, 57 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 c18dabb9..99764aad 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
@@ -135,13 +135,15 @@ public class InitialSearchTaskFirstTest {
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
String randomBpk = RandomStringUtils.randomNumeric(6);
String newFirstName = RandomStringUtils.randomAlphabetic(5);
- zmrResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, newFirstName, randomFamilyName, randomDate));
- Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
+ String randomPseudonym = DE_ST + randomIdentifier;
+ Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
+ new RegisterResult(randomBpk, randomPseudonym, newFirstName, randomFamilyName, randomDate)));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
+
Assert.assertEquals("Wrong bpk", bPk, randomBpk);
}
@@ -152,19 +154,18 @@ public class InitialSearchTaskFirstTest {
@DirtiesContext
public void testNode100_UserIdentifiedUpdateNecessary_b() throws TaskExecutionException {
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
- ArrayList<RegisterResult> ernpResult = new ArrayList<>();
String randomBpk = RandomStringUtils.randomNumeric(6);
String newRandomGivenName = RandomStringUtils.randomAlphabetic(10);
- ernpResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, newRandomGivenName, randomFamilyName, randomDate));
- Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
+ Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
+ new RegisterResult(randomBpk, DE_ST+randomIdentifier, newRandomGivenName, randomFamilyName, randomDate)));
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
+
Assert.assertEquals("Wrong bpk", bPk, randomBpk);
}
-
/**
* Two matches found in ZMR
*/
@@ -180,6 +181,7 @@ public class InitialSearchTaskFirstTest {
TaskExecutionException exception = assertThrows(TaskExecutionException.class,
() -> task.execute(pendingReq, executionContext));
+
Throwable origE = exception.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
}
@@ -201,6 +203,7 @@ public class InitialSearchTaskFirstTest {
TaskExecutionException exception = assertThrows(TaskExecutionException.class,
() -> task.execute(pendingReq, executionContext));
+
Throwable origE = exception.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
}
@@ -213,10 +216,8 @@ public class InitialSearchTaskFirstTest {
public void testNode102_UserIdentified_a() throws Exception {
String randomBpk = RandomStringUtils.randomNumeric(12);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
-
- ArrayList<RegisterResult> ernpResult = new ArrayList<>();
- ernpResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate));
- Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
+ Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
+ new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate)));
task.execute(pendingReq, executionContext);
String bPk = (String)
@@ -231,13 +232,12 @@ public class InitialSearchTaskFirstTest {
@DirtiesContext
public void testNode102_UserIdentified_b() throws Exception {
String randomBpk = RandomStringUtils.randomNumeric(14);
-
- ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate));
- Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
+ Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
+ new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate)));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
task.execute(pendingReq, executionContext);
+
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
Assert.assertEquals("Wrong bpk", bPk, randomBpk);
@@ -255,22 +255,14 @@ public class InitialSearchTaskFirstTest {
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
- ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
-
String newRandomPseudonym = IT_ST + randomIdentifier + RandomStringUtils.randomNumeric(2);
- zmrResultSpecific.add(new RegisterResult(bpkRegister, newRandomPseudonym, randomGivenName, randomFamilyName,
- randomDate, null, null, taxNumber, null));
-
- Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(zmrResultSpecific);
-
+ Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(Collections.singletonList(
+ new RegisterResult(bpkRegister, newRandomPseudonym, randomGivenName, randomFamilyName,
+ randomDate, null, null, taxNumber, null)));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
-
- List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernpClient, zmrClient);
- handlers.add(it);
- task = new InitialSearchTask(handlers, ernpClient, zmrClient);
+ task = new InitialSearchTask(Collections.singletonList(new ItSpecificDetailSearchProcessor(ernpClient, zmrClient)),
+ ernpClient, zmrClient);
task.execute(pendingReq1, executionContext);
@@ -292,22 +284,14 @@ public class InitialSearchTaskFirstTest {
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
- ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
-
- zmrResultSpecific.add(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate,
- randomPlaceOfBirth, randomBirthName,null, null));
-
Mockito.when(zmrClient.searchDeSpecific(randomGivenName, randomFamilyName, randomDate, randomPlaceOfBirth,
- randomBirthName)).thenReturn(zmrResultSpecific);
-
+ randomBirthName))
+ .thenReturn(Collections.singletonList(new RegisterResult(randomBpk, randomPseudonym, randomGivenName,
+ randomFamilyName, randomDate, randomPlaceOfBirth, randomBirthName,null, null)));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
-
- List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernpClient, zmrClient);
- handlers.add(de);
- task = new InitialSearchTask(handlers, ernpClient, zmrClient);
+ task = new InitialSearchTask(Collections.singletonList(new DeSpecificDetailSearchProcessor(ernpClient, zmrClient)),
+ ernpClient, zmrClient);
task.execute(pendingReq1, executionContext);
@@ -331,26 +315,21 @@ public class InitialSearchTaskFirstTest {
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
-
zmrResultSpecific.add(new RegisterResult(bpk1, pseudonym1, randomGivenName, randomFamilyName, randomDate,
randomPlaceOfBirth, randomBirthName,null, null));
zmrResultSpecific.add(new RegisterResult(bpk2, pseudonym2, randomGivenName, randomFamilyName, randomDate,
randomPlaceOfBirth, randomBirthName,null, null));
Mockito.when(zmrClient.searchDeSpecific(randomGivenName, randomFamilyName, randomDate, randomPlaceOfBirth,
randomBirthName)).thenReturn(zmrResultSpecific);
-
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
-
- List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernpClient, zmrClient);
- handlers.add(de);
- task = new InitialSearchTask(handlers, ernpClient, zmrClient);
+ task = new InitialSearchTask(Collections.singletonList(new DeSpecificDetailSearchProcessor(ernpClient, zmrClient)),
+ ernpClient, zmrClient);
TaskExecutionException exception = assertThrows(TaskExecutionException.class,
() -> task.execute(pendingReq1, executionContext));
+
Throwable origE = exception.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
}
@@ -366,26 +345,20 @@ public class InitialSearchTaskFirstTest {
TestRequestImpl pendingReq1 = new TestRequestImpl();
pendingReq1.getSessionData(AuthProcessDataWrapper.class)
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
-
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
-
zmrResultSpecific.add(new RegisterResult("bpkMax", IT_ST+randomIdentifier+"4", randomGivenName,
randomFamilyName, randomDate, null, null, fakeTaxNumber, null));
zmrResultSpecific.add(new RegisterResult("bpkMax1", IT_ST+randomIdentifier+"5", randomGivenName,
randomFamilyName, randomDate, null, null, fakeTaxNumber, null));
Mockito.when(zmrClient.searchItSpecific(fakeTaxNumber)).thenReturn(zmrResultSpecific);
-
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
-
- List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
- ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernpClient, zmrClient);
- handlers.add(it);
- task = new InitialSearchTask(handlers, ernpClient, zmrClient);
-
+ task = new InitialSearchTask(Collections.singletonList(new ItSpecificDetailSearchProcessor(ernpClient, zmrClient)),
+ ernpClient, zmrClient);
TaskExecutionException exception = assertThrows(TaskExecutionException.class,
() -> task.execute(pendingReq1, executionContext));
+
Throwable origE = exception.getOriginalException();
Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));
}
@@ -400,6 +373,7 @@ public class InitialSearchTaskFirstTest {
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
task.execute(pendingReq, executionContext);
+
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
Assert.assertEquals("Wrong bpk", "TODO-Temporary-Endnode-105", bPk);