aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules
diff options
context:
space:
mode:
authorChristian Kollmann <christian.kollmann@a-sit.at>2021-01-12 14:17:52 +0100
committerChristian Kollmann <christian.kollmann@a-sit.at>2021-01-12 14:20:36 +0100
commitb0f2b00b460e1c8419ea631bdbd1da1c33150bce (patch)
treeeafc839576d3c2068b6edc57e256f418303e8451 /eidas_modules
parent55d809e4b4df5c7ca9ba2bdf371f7f9376302ea8 (diff)
downloadNational_eIDAS_Gateway-b0f2b00b460e1c8419ea631bdbd1da1c33150bce.tar.gz
National_eIDAS_Gateway-b0f2b00b460e1c8419ea631bdbd1da1c33150bce.tar.bz2
National_eIDAS_Gateway-b0f2b00b460e1c8419ea631bdbd1da1c33150bce.zip
Streamline mock creation in tests
Diffstat (limited to 'eidas_modules')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java53
1 files changed, 7 insertions, 46 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 a1dce0f2..12a0969d 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
@@ -50,7 +50,9 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.annotation.DirtiesContext;
@@ -69,13 +71,14 @@ import java.util.List;
import java.util.Random;
@RunWith(SpringJUnit4ClassRunner.class)
-
@ContextConfiguration("/SpringTest-context_tasks_test.xml")
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class InitialSearchTaskFirstTest {
private InitialSearchTask task;
+ @Mock
private IZmrClient zmrClient;
+ @Mock
private IErnpClient ernpClient;
final ExecutionContext executionContext = new ExecutionContextImpl();
@@ -108,6 +111,9 @@ public class InitialSearchTaskFirstTest {
*/
@Before
public void setUp() throws URISyntaxException, EaafStorageException {
+ MockitoAnnotations.initMocks(this);
+ task = new InitialSearchTask(new ArrayList<CountrySpecificDetailSearchProcessor>(), ernpClient, zmrClient);
+
httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler");
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
@@ -125,20 +131,15 @@ public class InitialSearchTaskFirstTest {
* One match, but register update needed
*/
public void testNode100_UserIdentifiedUpdateNecessary_a() throws Exception {
-
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));
-
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
@@ -151,20 +152,14 @@ public class InitialSearchTaskFirstTest {
* One match, but register update needed
*/
public void testNode100_UserIdentifiedUpdateNecessary_b() throws TaskExecutionException {
-
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
-
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
String randomBpk = RandomStringUtils.randomNumeric(6);
ernpResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, "Max_new", randomFamilyName, randomDate));
-
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
@@ -179,18 +174,14 @@ public class InitialSearchTaskFirstTest {
* Two matches found in ZMR
*/
public void testNode101_ManualFixNecessary_a() throws Exception {
-
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
zmrResult.add(new RegisterResult("bpkMax", DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate));
zmrResult.add(new RegisterResult("bpkMax", DE_ST+randomIdentifier, "Maximilian", randomFamilyName, randomDate));
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
@@ -209,7 +200,6 @@ public class InitialSearchTaskFirstTest {
public void testNode101_ManualFixNecessary_b() throws Exception {
String randombpk = RandomStringUtils.random(5);
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
@@ -217,11 +207,8 @@ public class InitialSearchTaskFirstTest {
ernpResult.add(new RegisterResult(randombpk, DE_ST+randomIdentifier, randomGivenName+RandomStringUtils.random(2),
randomFamilyName,
randomDate));
-
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
try {
task.execute(pendingReq, executionContext);
Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false);
@@ -237,19 +224,14 @@ public class InitialSearchTaskFirstTest {
* One match, no register update needed
*/
public void testNode102_UserIdentified_a() throws Exception {
-
String randomBpk = RandomStringUtils.randomNumeric(12);
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
ernpResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate));
-
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
@@ -266,16 +248,11 @@ public class InitialSearchTaskFirstTest {
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
zmrResult.add(new RegisterResult(randomBpk, DE_ST+randomIdentifier, randomGivenName, randomFamilyName, randomDate));
-
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
-
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
@@ -296,7 +273,6 @@ public class InitialSearchTaskFirstTest {
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
@@ -308,7 +284,6 @@ public class InitialSearchTaskFirstTest {
Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(zmrResultSpecific);
ArrayList<RegisterResult> ernpResultInitial = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResultInitial);
List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
@@ -347,7 +322,6 @@ public class InitialSearchTaskFirstTest {
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
@@ -358,7 +332,6 @@ public class InitialSearchTaskFirstTest {
Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific);
ArrayList<RegisterResult> ernpResultInitial = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResultInitial);
List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
@@ -399,7 +372,6 @@ public class InitialSearchTaskFirstTest {
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
@@ -412,7 +384,6 @@ public class InitialSearchTaskFirstTest {
Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific);
ArrayList<RegisterResult> ernpResultInitial = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResultInitial);
List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
@@ -442,7 +413,6 @@ public class InitialSearchTaskFirstTest {
.setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);
ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResultInitial);
ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>();
@@ -455,7 +425,6 @@ public class InitialSearchTaskFirstTest {
Mockito.when(zmrClient.searchItSpecific(fakeTaxNumber)).thenReturn(zmrResultSpecific);
ArrayList<RegisterResult> ernpResultInitial = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResultInitial);
List<CountrySpecificDetailSearchProcessor> handlers = new ArrayList<>();
@@ -478,16 +447,12 @@ public class InitialSearchTaskFirstTest {
* NO match found in ZMR and ErnP with Initial search
*/
public void testNode105_TemporaryEnd() throws TaskExecutionException {
-
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
- zmrClient = Mockito.mock(IZmrClient.class);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
- ernpClient = Mockito.mock(IErnpClient.class);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
- task = new InitialSearchTask(emptyHandlers(), ernpClient, zmrClient);
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
@@ -562,8 +527,4 @@ public class InitialSearchTaskFirstTest {
.attributeValueMarshaller(marshaller).build();
}
- private List<CountrySpecificDetailSearchProcessor> emptyHandlers() {
- return new ArrayList<>();
- }
-
}