aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java
index 539a41d2..1fc96e10 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java
@@ -26,6 +26,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.json.JsonMapper;
+import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.GenerateAustrianResidenceGuiTask;
import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
@@ -95,6 +96,35 @@ public class GenerateAustrianResidenceGuiTaskTest {
@Test
@SneakyThrows
+ public void jsonResponseWithError() throws TaskExecutionException, UnsupportedEncodingException {
+ httpReq.addHeader("Accept", "application/json");
+
+ String reason = RandomStringUtils.randomAlphabetic(5);
+ executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED, true);
+ executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON, reason);
+
+ task.execute(pendingReq, executionContext);
+
+ //result validation
+ Assert.assertEquals("httpStausCode", 200, httpResp.getStatus());
+ Assert.assertEquals("http ContentType", "application/json;charset=UTF-8", httpResp.getContentType());
+ final String content = httpResp.getContentAsString();
+ assertNotNull("response body is null", content);
+ Assert.assertFalse("response body is empty", content.isEmpty());
+ final JsonNode json = new JsonMapper().readTree(content);
+ assertNotNull("response body is null", json);
+ checkJsonElement(json, "wizardEndpoint", "https://localhost/ms_connector/residency/search");
+
+ assertNotNull("advancedMatchFailed", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED));
+ assertTrue("advancedMatchFailed", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED).asBoolean());
+ assertNotNull("advancedMatchingFailedReason", json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED_REASON));
+ assertEquals("advancedMatchingFailedReason", reason,
+ json.get(Constants.HTML_FORM_ADVANCED_MATCHING_FAILED_REASON).asText());
+
+ }
+
+ @Test
+ @SneakyThrows
public void htmlResponse() throws TaskExecutionException, UnsupportedEncodingException {
task.execute(pendingReq, executionContext);
@@ -109,6 +139,29 @@ public class GenerateAustrianResidenceGuiTaskTest {
}
+ @Test
+ @SneakyThrows
+ public void htmlResponseWithError() throws TaskExecutionException, UnsupportedEncodingException {
+
+ String reason = RandomStringUtils.randomAlphabetic(5);
+ executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED, true);
+ executionContext.put(Constants.CONTEXT_FLAG_ADVANCED_MATCHING_FAILED_REASON, reason);
+
+ task.execute(pendingReq, executionContext);
+
+ //result validation
+ Assert.assertEquals("httpStausCode", 200, httpResp.getStatus());
+ Assert.assertEquals("http ContentType", "text/html;charset=UTF-8", httpResp.getContentType());
+ final String content = httpResp.getContentAsString();
+ assertNotNull("response body is null", content);
+ Assert.assertFalse("response body is empty", content.isEmpty());
+ assertTrue("no wizard endpoint", content.contains("https://localhost/ms_connector/residency/search"));
+
+ Assert.assertTrue("missing errorfield", content.contains("<div id=\"matchingError\""));
+ Assert.assertTrue("missing errorfield", content.contains(reason));
+
+ }
+
private void checkJsonElement(JsonNode json, String key, String expected) {
assertTrue("no element: " + key, json.has(key));
assertEquals("wrong element:" + key, expected, json.get(key).asText());