From 74dedc575020f47d530f2e905daa22d5a4197e1e Mon Sep 17 00:00:00 2001 From: jgomer2001 Date: Fri, 28 Oct 2022 14:25:25 -0500 Subject: [PATCH] test: enable tests and minor refactoring #2672 --- .../java/io/jans/agama/test/BaseTest.java | 27 +++++++------ .../java/io/jans/agama/test/MathFlowTest.java | 2 +- .../io/jans/agama/test/UidOnlyAuthTest.java | 38 ++++--------------- agama/engine/src/test/resources/testng.xml | 14 +++---- .../test/resources/pass/triggers_calls.txt | 5 ++- 5 files changed, 35 insertions(+), 51 deletions(-) diff --git a/agama/engine/src/test/java/io/jans/agama/test/BaseTest.java b/agama/engine/src/test/java/io/jans/agama/test/BaseTest.java index cbfee164568..4e65c03ad5a 100644 --- a/agama/engine/src/test/java/io/jans/agama/test/BaseTest.java +++ b/agama/engine/src/test/java/io/jans/agama/test/BaseTest.java @@ -33,13 +33,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; -//import org.testng.annotations.Test; import static org.testng.Assert.*; public class BaseTest { private static String AGAMA_ACR = "agama"; - private Map map = null; + private static Map MAP = null; Logger logger = LogManager.getLogger(getClass()); WebClient client = null; @@ -65,23 +64,23 @@ public void init(ITestContext context) throws IOException { Properties prop = new Properties(); prop.load(Files.newBufferedReader(Paths.get(propertiesFile), UTF_8)); - map = new Hashtable<>(); + MAP = new Hashtable<>(); //do not bother about empty keys... but //If a value is found null, this will throw a NPE since we are using a Hashtable - prop.forEach((key, value) -> map.put(key.toString(), value.toString())); - context.getSuite().getXmlSuite().setParameters(map); + prop.forEach((key, value) -> MAP.put(key.toString(), value.toString())); + context.getSuite().getXmlSuite().setParameters(MAP); } String authzRequestUrl(String flowQName, Map inputs) { OAuthParams p = new OAuthParams(); - p.setAuthzEndpoint(map.get("authzEndpoint")); - p.setClientId(map.get("clientId")); - p.setRedirectUri(map.get("redirectUri")); + p.setAuthzEndpoint(MAP.get("authzEndpoint")); + p.setClientId(MAP.get("clientId")); + p.setRedirectUri(MAP.get("redirectUri")); p.setScopes(Collections.singletonList("openid")); - String queryParam = URLEncoder.encode(map.get("custParamName"), UTF_8); + String queryParam = URLEncoder.encode(MAP.get("custParamName"), UTF_8); StringBuilder builder = new StringBuilder(flowQName); if (inputs != null) { @@ -108,6 +107,10 @@ String authzRequestUrl(String flowQName, Map inputs) { } HtmlPage launch(String flowQName, Map parameters) { + return launch(flowQName, parameters, true); + } + + HtmlPage launch(String flowQName, Map parameters, boolean ensureOKStatus) { //Generate an authn request and launch it in the htmlUnit browser String url = authzRequestUrl(flowQName, parameters); @@ -116,8 +119,10 @@ HtmlPage launch(String flowQName, Map parameters) { Page p = client.getPage(url); //Check it is an ok web page - assertTrue(p.isHtmlPage(), "Not an html page"); - assertOK(p); + assertTrue(p.isHtmlPage(), "Not an html page"); + if (ensureOKStatus) { + assertOK(p); + } return (HtmlPage) p; } catch (IOException e) { diff --git a/agama/engine/src/test/java/io/jans/agama/test/MathFlowTest.java b/agama/engine/src/test/java/io/jans/agama/test/MathFlowTest.java index 7bc90353edf..387965048de 100644 --- a/agama/engine/src/test/java/io/jans/agama/test/MathFlowTest.java +++ b/agama/engine/src/test/java/io/jans/agama/test/MathFlowTest.java @@ -17,7 +17,7 @@ public class MathFlowTest extends BaseTest { @Test public void runEmpty() { - HtmlPage page = launch(QNAME, Collections.singletonMap("numbers",Collections.emptyList())); + HtmlPage page = launch(QNAME, Collections.singletonMap("numbers",Collections.emptyList()), false); logger.info("Landed at {}", page.getUrl()); assertServerError(page); } diff --git a/agama/engine/src/test/java/io/jans/agama/test/UidOnlyAuthTest.java b/agama/engine/src/test/java/io/jans/agama/test/UidOnlyAuthTest.java index d4d290e5c78..68e13851e78 100644 --- a/agama/engine/src/test/java/io/jans/agama/test/UidOnlyAuthTest.java +++ b/agama/engine/src/test/java/io/jans/agama/test/UidOnlyAuthTest.java @@ -6,7 +6,6 @@ import java.util.Collections; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -15,18 +14,11 @@ public class UidOnlyAuthTest extends BaseTest { private static final String QNAME = "io.jans.agama.test.auth.uidOnly"; - - @BeforeClass - public void enableJS() { - client.getOptions().setJavaScriptEnabled(true); - } - + @Test public void randUid() { - start("" + Math.random()); - HtmlPage page = (HtmlPage) currentPageAfter(2000); - + HtmlPage page = (HtmlPage) start("" + Math.random()); assertOK(page); assertTrue(page.getUrl().toString().endsWith("error.htm")); assertTextContained(page.getVisibleText().toLowerCase(), "failed", "authenticate"); @@ -37,36 +29,22 @@ public void randUid() { @Parameters("redirectUri") public void adminUid(String redirectUri) { - start("admin"); - Page page = currentPageAfter(2000); - + Page page = start("admin"); assertOK(page); assertTrue(page.getUrl().toString().startsWith(redirectUri)); } - private HtmlPage start(String uid) { + private Page start(String uid) { HtmlPage page = launch(QNAME, Collections.singletonMap("uid", uid)); //click on the "Continue" button HtmlSubmitInput button = page.getForms().get(0).getInputByValue("Continue"); - return doClick(button); - } - - private Page currentPageAfter(long wait) { - - try { - //wait for the auto-submitting javascript to execute (see finished.ftlh) and redirections to take place - Thread.sleep(wait); - Page p = client.getCurrentWindow().getEnclosedPage(); - - logger.debug("Landed at {}", p.getUrl()); - return p; - } catch (Exception e) { - fail(e.getMessage(), e); - } - return null; + page = (HtmlPage) doClick(button); + //click on the "Continue" button (at finish template) + button = page.getForms().get(0).getInputByValue("Continue"); + return doClick(button); } diff --git a/agama/engine/src/test/resources/testng.xml b/agama/engine/src/test/resources/testng.xml index 9a75f0fb6fb..4453f36ed62 100644 --- a/agama/engine/src/test/resources/testng.xml +++ b/agama/engine/src/test/resources/testng.xml @@ -4,43 +4,43 @@ - + - + - + - + - + - + - + diff --git a/agama/transpiler/src/test/resources/pass/triggers_calls.txt b/agama/transpiler/src/test/resources/pass/triggers_calls.txt index 4f8a0f7c822..62b521f5c9d 100644 --- a/agama/transpiler/src/test/resources/pass/triggers_calls.txt +++ b/agama/transpiler/src/test/resources/pass/triggers_calls.txt @@ -7,8 +7,9 @@ When pepperoni is forgotten o."-x" = Trigger oh.no some params.here Trigger $bah.humbug no params - Override templates "pea/body.ftl" "" "pea/media.ftl" "fluff.ftl" - "caravan.ftl" "../whoops.ftlh" + Override templates "pea/body.ftl" "" "pea/media.ftl" "fluff.ftl" + + "caravan.ftl" "../whoops.ftlh" x256 = Call java.lang.Math#incrementExact 255