Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(agama): augment test cases #6998

Merged
merged 6 commits into from Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions agama/transpiler/src/main/resources/JSGenerator.ftl
Expand Up @@ -64,10 +64,10 @@ try {

_it = _actionCall(
<#if .node.static_call?size gt 0>
null, false, "${.node.static_call.qname}", "${.node.static_call.ALPHANUM}"
null, "${.node.static_call.qname}", "${.node.static_call.ALPHANUM}"
, <@util_argslist node=.node.static_call />
<#else>
${.node.oo_call.variable}, true, null, "${.node.oo_call.ALPHANUM}"
${.node.oo_call.variable}, null, "${.node.oo_call.ALPHANUM}"
, <@util_argslist node=.node.oo_call />
</#if>
)
Expand Down
6 changes: 2 additions & 4 deletions agama/transpiler/src/main/resources/util.js
Expand Up @@ -42,9 +42,7 @@ function _equals(a, b) {
return _scriptUtils.testEquality(_scan(a), _scan(b))
}

function _actionCall(instance, instanceRequired, clsName, method, args) {
if (instanceRequired && _isNil(instance))
throw new TypeError("Cannot call method " + method + " of null")
function _actionCall(instance, clsName, method, args) {
return _scriptUtils.callAction(instance, clsName, method, args.map(_scan))
}

Expand Down Expand Up @@ -78,7 +76,7 @@ function _flowCall(flowName, basePath, urlOverrides, args) {
}

function _flowCallErr(e) {
return { value: _makeJavaException(e), bubbleUp: false }
return { value: _makeJavaException(null, e), bubbleUp: false }
}

function _makeJavaException(qname, e) {
Expand Down
Expand Up @@ -121,7 +121,13 @@ public static Pair<Object, Exception> callAction(Object instance, String actionC
Object result = null;
Exception ex = null;
try {
result = CdiUtil.bean(ActionService.class).callAction(instance, actionClassName, methodName, params);

if (instance == null && actionClassName == null) {
ex = new IllegalArgumentException("Cannot call method " + methodName + " of null");
} else {
result = CdiUtil.bean(ActionService.class)
.callAction(instance, actionClassName, methodName, params);
}
} catch (Exception e) {
LOG.warn("Exception raised when executing Call - class: {}, method: {}",
actionClassName == null ? instance.getClass().getName() : actionClassName, methodName);
Expand Down
@@ -0,0 +1,28 @@
package io.jans.agama.test;

import org.testng.annotations.Test;

public class CrashedFlowsTest extends BaseTest {

private static final String QNAME = "io.jans.agama.test.broken";

@Test
public void subflows() {

for (int i = 0; i < 3; i++) {
assertServerError(launch(QNAME + ".flow" + (i+1), null, false));
}

}

@Test
public void parent1() {
validateFinishPage(launch(QNAME + ".parent", null), true);
}

@Test
public void parent2() {
validateFinishPage(launch(QNAME + ".sub.parent", null), true);
}

}
@@ -0,0 +1,37 @@
package io.jans.agama.test;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

import org.testng.annotations.Test;

public class TemplateOverridesTest extends BaseTest {

@Test
public void override() {

HtmlPage page = launch("io.jans.agama.test.ot.flow2", null);

//click on the "Continue" button
HtmlSubmitInput button = page.getForms().get(0).getInputByValue("Continue");
page = (HtmlPage) doClick(button);

validateFinishPage(page, true);

}

@Test
public void cancellation() {

HtmlPage page = launch("io.jans.agama.test.ot.flow3", null);

//click on the cancellation button
HtmlButton button = page.getForms().get(0).getButtonByName("_abort");
page = (HtmlPage) doClick(button);

validateFinishPage(page, true);

}

}
@@ -0,0 +1,37 @@
package io.jans.agama.test;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

import org.testng.annotations.Test;

public class VariableSurvivalTest extends BaseTest {

@Test
public void agamaValues() {
run("io.jans.agama.test.vars_and_rrf.agamaValues", 2);
}

@Test
public void javaValues() {
run("io.jans.agama.test.vars_and_rrf.javaValues1", 5);
}

private void run(String qname, int submissions) {

HtmlPage page = launch(qname, null);
for (int i = 0; i < submissions; i++) {
page = moveForward(page);
}
validateFinishPage(page, true);

}

private HtmlPage moveForward(HtmlPage page) {
//click on the "Continue" button
HtmlSubmitInput button = page.getForms().get(0).getInputByValue("Continue");
return (HtmlPage) doClick(button);
}

}
@@ -0,0 +1,6 @@
Flow io.jans.agama.test.broken.flow1
Basepath ""

Log "Lizard on dove"

//No finish. This will crash
@@ -0,0 +1,4 @@
Flow io.jans.agama.test.broken.flow2
Basepath ""

Log null.x // This will crash
@@ -0,0 +1,6 @@
Flow io.jans.agama.test.broken.flow3
Basepath ""

a=[ 1, 2, 3]
y = "two"
Log a[y] // This will crash
@@ -0,0 +1,10 @@
Flow io.jans.agama.test.broken.parent
Basepath ""

| E1 = Trigger io.jans.agama.test.broken.flow1
| E2 = Trigger io.jans.agama.test.broken.flow2

When E1 is null or E2 is null
Finish false

Finish true //all flows should have thrown error
@@ -0,0 +1,6 @@
Flow io.jans.agama.test.broken.sub.flow3
Basepath ""

Trigger io.jans.agama.test.broken.flow3

Finish false
@@ -0,0 +1,9 @@
Flow io.jans.agama.test.broken.sub.parent
Basepath ""

| E = Trigger io.jans.agama.test.broken.sub.flow3

When E is null
Finish false

Finish true //flow should have thrown error
@@ -0,0 +1,7 @@
Flow io.jans.agama.test.ot.flow1
Basepath "ot"

o = RRF "page.ftl"
//o should be an empty map at this point
o = { success: true, data: o }
Finish o
@@ -0,0 +1,11 @@
Flow io.jans.agama.test.ot.flow2
Basepath "ot"

obj = Trigger io.jans.agama.test.ot.flow1
Override templates "ot/page.ftl" "cust/mypage.ftlh"

When obj.data.flavor is null
Finish false

// if the template override worked as expected, execution should reach this point
Finish true
@@ -0,0 +1,10 @@
Flow io.jans.agama.test.ot.flow3
Basepath "ot"

obj = Trigger io.jans.agama.test.ot.flow1
Override templates "ot/page.ftl" "cust/cancel.ftlh"

When obj.aborted is true and obj.data.flavor is not null
Finish true

Finish false
@@ -0,0 +1,50 @@
//This flow tests if basic Agama variables are properly serialized/deserialized before/after RRF usage
Flow io.jans.agama.test.vars_and_rrf.agamaValues
Basepath ""

str = "string"
bool = true
number = 1000
list = [ str, bool, number ]
map = { str: str, bool: bool, number: number, list: list }

obj = { name: str }
RRF "ot/page.ftl" obj

//Ensure variables remain intact

When str is not "string" or bool is not true or number is not 1000
or list.length is not 3
Log "Any of str, bool, number, or list variables were lost"
Finish false

When map is null or map.str is not str or map.bool is not bool or
map.number is not number or map.list.length is not 3
Log "Something in the map variable was lost"
Finish false

When obj is null or obj.name is not str
Log "Something in the obj variable was lost"
Finish false

obj = null

RRF "ot/page.ftl"

//Ensure variables remain intact

When str is not "string" or bool is not true or number is not 1000
or list.length is not 3
Log "Any of str, bool, number, or list variables were lost"
Finish false

When map is null or map.str is not str or map.bool is not bool or
map.number is not number or map.list.length is not 3
Log "Something in the map variable was lost"
Finish false

When obj is not null
Log "obj was not nullified"
Finish false

Finish true
@@ -0,0 +1,51 @@
//This flow tests if some Java variables are properly serialized/deserialized before/after RRF usage
Flow io.jans.agama.test.vars_and_rrf.javaValues1
Basepath ""

t1 = Call co.Test#new
t1.id = "QWE"

RRF "ot/page.ftl"

t2 = Call co.Test#new
t2.id = "RTY"

RRF "ot/page.ftl"

s = Call co.Test#sum t1 t2
When s is not "QWERTY"
Log "Something about variables t1 or t2 was lost"
Finish false

list = [ t1, t2 ]
jList = Call java.util.Arrays#asList list
list = null
RRF "ot/page.ftl"

When jList.length is not 2
Finish false

s = Call co.Test#sum jList[0] jList[1]

When s is not "QWERTY"
Log "Something about variables jList was lost"
Finish false

jList = null
| E = Call jList add t1

RRF "ot/page.ftl"

When E is null
Log "Something is wrong with variable E"
Finish false

exname = E.class.name
E2 = Call com.nimbusds.oauth2.sdk.ParseException#new "ASDFG" null E
RRF "ot/page.ftl"

When E2 is null or E2.message is not "ASDFG" or E2.cause.class.name is not exname
Log "Something is wrong with variable E2"
Finish false

Finish true
@@ -1,6 +1,6 @@
package co;

public class Test implements MyInterface {
public class Test implements MyInterface, Serializable {

private String id;

Expand Down
@@ -0,0 +1,11 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<form method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="flavor" value="bitter">
<button type="submit" name="_abort" value="">Let's cancel the subflow</button>
</form>

</body>
</html>
@@ -0,0 +1,11 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<form method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="flavor" value="sweet">
<input type="submit" value="Continue">
</form>

</body>
</html>
@@ -0,0 +1,11 @@
<#ftl output_format="HTML">
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<form method="post" enctype="application/x-www-form-urlencoded">
<input type="submit" value="Continue">
</form>

</body>
</html>