aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test/java/at
diff options
context:
space:
mode:
authorThomas <>2022-03-10 15:32:01 +0100
committerThomas <>2022-03-10 15:32:01 +0100
commit51984cd48762b50cf64fc8f6aa54be1a8e7bf31a (patch)
treef3e3c1c91043190816481a9fbd28f11432a4ed03 /modules/authmodule-eIDAS-v2/src/test/java/at
parent7405ddcd0bd5326c1a0e2e187086a90caad8ebea (diff)
downloadNational_eIDAS_Gateway-51984cd48762b50cf64fc8f6aa54be1a8e7bf31a.tar.gz
National_eIDAS_Gateway-51984cd48762b50cf64fc8f6aa54be1a8e7bf31a.tar.bz2
National_eIDAS_Gateway-51984cd48762b50cf64fc8f6aa54be1a8e7bf31a.zip
chore(matching): inject REST endpoint for address wizard by GUI model
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java119
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java3
2 files changed, 119 insertions, 3 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
new file mode 100644
index 00000000..539a41d2
--- /dev/null
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateAustrianResidenceGuiTaskTest.java
@@ -0,0 +1,119 @@
+package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Locale;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.context.request.RequestContextHolder;
+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.tasks.GenerateAustrianResidenceGuiTask;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
+import at.gv.egiz.eaaf.core.impl.idp.process.ExecutionContextImpl;
+import lombok.SneakyThrows;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {
+ "/SpringTest-context_tasks_test.xml",
+ "/SpringTest-context_basic_mapConfig.xml",
+ "/common_gui.beans.xml"
+})
+@WebAppConfiguration
+public class GenerateAustrianResidenceGuiTaskTest {
+
+
+ @Autowired
+ GenerateAustrianResidenceGuiTask task;
+
+ private ExecutionContextImpl executionContext = new ExecutionContextImpl();
+ private TestRequestImpl pendingReq;
+ private MockHttpServletRequest httpReq;
+ private MockHttpServletResponse httpResp;
+
+ @BeforeClass
+ public static void classInitializer() {
+ Locale.setDefault(Locale.ENGLISH);
+
+ }
+
+ /**
+ * jUnit test set-up.
+ */
+ @Before
+ public void initialize() {
+ httpReq = new MockHttpServletRequest("POST", "https://localhost/ms_connector");
+ httpResp = new MockHttpServletResponse();
+ RequestContextHolder.resetRequestAttributes();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
+
+ pendingReq = new TestRequestImpl();
+ pendingReq.setAuthUrl("https://localhost/ms_connector");
+ pendingReq.setPendingReqId(RandomStringUtils.randomAlphanumeric(10));
+
+ LocaleContextHolder.resetLocaleContext();
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void jsonResponse() throws TaskExecutionException, UnsupportedEncodingException {
+ httpReq.addHeader("Accept", "application/json");
+
+ 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");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void htmlResponse() throws TaskExecutionException, UnsupportedEncodingException {
+
+ 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"));
+
+ }
+
+ 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());
+
+ }
+
+
+}
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
index ff994061..68b73734 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/GenerateOtherLoginMethodGuiTaskTest.java
@@ -25,7 +25,6 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;
@@ -48,8 +47,6 @@ public class GenerateOtherLoginMethodGuiTaskTest {
private static final String TEST_PATTER_REQ_PARAM =
"<input type=\"hidden\" name=\"loginSelection\" value=\"{0}\">";
- private static ObjectMapper mapper = new ObjectMapper();
-
@Autowired
GenerateOtherLoginMethodGuiTask task;