Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.jans.agama.test;

import io.jans.agama.dsl.TranspilationResult;
import io.jans.agama.dsl.Transpiler;

import java.nio.file.Files;
import java.nio.file.Paths;

import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
* Code-generation conformance for subflow invocation and web-interaction constructs
* ({@code Trigger}, {@code RRF}, {@code RFAC}). Transpiles the existing pass flows and
* asserts the generated JavaScript emits the corresponding runtime calls:
* {@code triggers_calls.txt} exercises {@code Trigger} (subflow invocation with bubbled-up
* result), and {@code structure.txt} exercises {@code RRF} (render-reply-fetch) and
* {@code RFAC} (redirect-fetch-at-callback). {@link ValidFlowsTest} only checks that these
* flows parse.
*/
public class WebInteractionTest {

private String passFlow(String fileName) throws Exception {
return Files.readString(Paths.get("target/test-classes/pass", fileName));
}

@Test
public void transpile_triggersFlow_generatesSubflowCall() throws Exception {
TranspilationResult result = Transpiler.transpile("flow", passFlow("triggers_calls.txt"));
assertNotNull(result);
String code = result.getCode();
assertNotNull(code);

assertTrue(code.contains("_flowCall("), "Trigger should generate a subflow call");
assertTrue(code.contains("_it.bubbleUp"), "an unassigned Trigger should bubble up the subflow result");
}

@Test
public void transpile_structureFlow_generatesWebInteractionCalls() throws Exception {
TranspilationResult result = Transpiler.transpile("flow", passFlow("structure.txt"));
assertNotNull(result);
String code = result.getCode();
assertNotNull(code);

assertTrue(code.contains("_renderReplyFetch("), "RRF should generate a render-reply-fetch call");
assertTrue(code.contains("_redirectFetchAtCallback("), "RFAC should generate a redirect-fetch-at-callback call");
}
}
6 changes: 6 additions & 0 deletions agama/transpiler/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
</classes>
</test>

<test name="Web interaction" enabled="true">
<classes>
<class name="io.jans.agama.test.WebInteractionTest" />
</classes>
</test>

</suite>