aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java63
1 files changed, 61 insertions, 2 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java
index 6298e250..c3beff33 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/CreateNewErnpEntryTaskTest.java
@@ -27,6 +27,9 @@ 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.core.MsEidasNodeConstants;
+import at.asitplus.eidas.specific.core.MsEidasNodeConstants.MatchingStates;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.ernp.ErnpRestClient.ErnpRegisterResult;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.ErnpPersonRegisterResult;
@@ -55,7 +58,7 @@ public class CreateNewErnpEntryTaskTest {
@Mock ErnpRestClient ernpClient;
- final ExecutionContext executionContext = new ExecutionContextImpl();
+ private ExecutionContext executionContext;
private TestRequestImpl pendingReq;
/**
@@ -70,6 +73,8 @@ public class CreateNewErnpEntryTaskTest {
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+ executionContext = new ExecutionContextImpl();
+
pendingReq = new TestRequestImpl();
pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10));
@@ -145,10 +150,64 @@ public class CreateNewErnpEntryTaskTest {
assertEquals("givenyname", input.getGivenName(), result.getGivenName());
assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth());
assertEquals("bpk", bpk, result.getBpk());
- assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode());
+ assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode());
+ assertEquals("matching state", MatchingStates.BY_NEW_ERNP_ENTRY,
+ pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE));
}
+ @Test
+ @SneakyThrows
+ public void insertErnpByAutoselectionSuccess() {
+ String bpk = RandomStringUtils.randomAlphabetic(5);
+ SimpleEidasData input = buildInputData();
+ Mockito.when(ernpClient.add(input))
+ .thenReturn(ernpRegisterResult(Arrays.asList(buildErnpResultEntry(input, bpk))));
+
+ executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_TASK, true);
+
+ // perform test
+ task.execute(pendingReq, executionContext);
+
+ // validate state
+ MatchedPersonResult result = MatchingTaskUtils.getFinalMatchingResult(pendingReq);
+ assertNotNull("no matching result", result);
+ assertEquals("familyname", input.getFamilyName(), result.getFamilyName());
+ assertEquals("givenyname", input.getGivenName(), result.getGivenName());
+ assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth());
+ assertEquals("bpk", bpk, result.getBpk());
+ assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode());
+ assertEquals("matching state", MatchingStates.BY_NEW_ERNP_ENTRY,
+ pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void insertErnpByUserSuccess() {
+ String bpk = RandomStringUtils.randomAlphabetic(5);
+ SimpleEidasData input = buildInputData();
+ Mockito.when(ernpClient.add(input))
+ .thenReturn(ernpRegisterResult(Arrays.asList(buildErnpResultEntry(input, bpk))));
+
+ executionContext.put(Constants.TRANSITION_TO_CREATE_NEW_ERNP_ENTRY_BY_USER_TASK, true);
+
+ // perform test
+ task.execute(pendingReq, executionContext);
+
+ // validate state
+ MatchedPersonResult result = MatchingTaskUtils.getFinalMatchingResult(pendingReq);
+ assertNotNull("no matching result", result);
+ assertEquals("familyname", input.getFamilyName(), result.getFamilyName());
+ assertEquals("givenyname", input.getGivenName(), result.getGivenName());
+ assertEquals("dateOfBirth", input.getDateOfBirth(), result.getDateOfBirth());
+ assertEquals("bpk", bpk, result.getBpk());
+ assertEquals("countryCode", input.getCitizenCountryCode(), result.getCountryCode());
+ assertEquals("matching state", MatchingStates.BY_USER_TO_NEW_ERNP_ENTRY,
+ pendingReq.getRawData(MsEidasNodeConstants.DATA_MATCHING_STATE));
+
+ }
+
@NotNull
private ErnpRegisterResult ernpRegisterResult(List<RegisterResult> registerResult) {