Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Add tests for EGL serialization and deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Feb 14, 2024
1 parent b35634c commit 45c2e6b
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 0 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ okhttpVersion=4.12.0
jvmVersion=1.8
rpgParserVersion=2.1.42
javaModuleVersion=0.9.15
eglParserVersion=0.0.1
10 changes: 10 additions & 0 deletions starlasu-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val lionwebVersion = extra["lionwebVersion"]
val kolasuVersion = extra["kolasuVersion"]
val rpgParserVersion = extra["rpgParserVersion"]
val javaModuleVersion = extra["javaModuleVersion"]
val eglParserVersion = extra["eglParserVersion"]

val githubUser = (
project.findProperty("starlasu.github.user")
Expand All @@ -36,6 +37,14 @@ repositories {
password = githubToken
}
}
maven {
name = project.name
url = uri("https://maven.pkg.github.com/Strumenta/kolasu-EGL-langmodule")
credentials {
username = githubUser
password = githubToken
}
}
}

dependencies {
Expand All @@ -46,6 +55,7 @@ dependencies {
implementation("com.strumenta.langmodules.kolasu-java-langmodule:ast:$javaModuleVersion")
testImplementation(kotlin("test-junit5"))
testImplementation("com.strumenta:rpg-parser:$rpgParserVersion")
testImplementation("com.strumenta.langmodules.kolasu-EGL-langmodule:ast:$eglParserVersion")
testImplementation("com.strumenta:rpg-parser-symbol-resolution:$rpgParserVersion")
testImplementation("commons-io:commons-io:2.7")
testImplementation("org.slf4j:slf4j-simple:1.7.30")
Expand Down
34 changes: 34 additions & 0 deletions starlasu-demo/src/test/kotlin/EGLLionWebConversion.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.strumenta.egl.ast.EglCompilationUnit
import com.strumenta.egl.ast.kLanguage
import com.strumenta.egl.parser.EGLKolasuParser
import com.strumenta.kolasu.parsing.ParsingResult
import org.apache.commons.io.input.BOMInputStream
import java.io.InputStream
import kotlin.test.Ignore
import kotlin.test.Test

class EGLLionWebConversion : AbstractLionWebConversion<EglCompilationUnit>(kLanguage) {

override fun parse(inputStream: InputStream): ParsingResult<EglCompilationUnit> {
val parser = EGLKolasuParser()
return parser.parse(inputStream)
}

@Test
fun sqlBatch() {
val inputStream = this.javaClass.getResourceAsStream("/egl/SQLBatch.egl") ?: throw IllegalStateException()
checkSerializationAndDeserialization(inputStream)
}

@Test
fun `rosetta-code-count-examples-1`() {
val inputStream = this.javaClass.getResourceAsStream("/egl/rosetta-code-count-examples-1.egl") ?: throw IllegalStateException()
checkSerializationAndDeserialization(inputStream)
}

@Test
fun `rosetta-code-count-examples-2`() {
val inputStream = this.javaClass.getResourceAsStream("/egl/rosetta-code-count-examples-2.egl") ?: throw IllegalStateException()
checkSerializationAndDeserialization(inputStream)
}
}
123 changes: 123 additions & 0 deletions starlasu-demo/src/test/resources/egl/SQLBatch.egl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.CompanyB.CustomerPackage;
program SQLBatch type basicProgram

dept Department;

function main()
try
clearTable();
loadTable();
getRow();
updateRow();
getAllRows();
forceRecordNotFound();
forceSQLException();
onException (ex SQLException)
sqlFailure();
onException (ex AnyException)
anyFailure( ex );
end
end

function getRow( )
setVariation ( "Get row from department table" );
getDept("D100");
end

function updateRow()
set dept empty;
setVariation ( "Update department table" );
dept.id = "T100";
get dept forUpdate;
if ( dept is noRecordFound )
sqlFailure();
else
dept.description = "Test Engineers";
replace dept;
commit();
end
getDept( "T100" );
end

function getAllRows()
setVariation ( "Get all departments" );
dept.id = " ";
open deptSet for dept;
foreach ( dept )
showDept();
end
end

function clearTable()
setVariation ( "Clear all rows from department table" );
dept.id = " ";
execute delete
#sql{
delete from DEPARTMENT_TABLE
where
id >= :dept.id
} for dept;
commit();
end

function forceRecordNotFound()
setVariation( "Try to get a department that is not in the table");
getDept("B100");
end

function forceSQLException()
setVariation("Force an sql exception by dropping a non-existent table");
prepare dropStmt from "DROP TABLE NOT_A_TABLE";
execute dropStmt;
end

function loadTable()
setVariation ( "Load department table" );
addDept("A100","Architects","AM0001");
addDept("D100","Developers","DM0001");
addDept("T100","Testers","TM0001");
addDept("M100","Managers","MM0001");
commit();
end

function addDept( deptNo string, desc String, manager string )
dept.id = deptNo;
dept.description = desc;
dept.manager = manager;
add dept;
end

function getDept( id string )
set dept empty;
dept.id = id;
get dept;
showDept();
end

function showDept()
if ( dept is noRecordFound )
writeStdOut ( "Department " + dept.id + " not found." );
else
writeStdOut( "Department " + dept.id +
" description: " + dept.description );
end
end

function setVariation ( desc string )
writeStdOut ( "Variation = " + desc );
end

function sqlFailure()
writeStdOut ( "SQL Exception, SQL code =
" + sysVar.sqlData.sqlCode
+ ", SQL state: " + sysVar.sqlData.sqlstate );
rollback();
end

function anyFailure( ex AnyException )
writeStdOut ( "Unexpected Exception, Error code = " + ex.messageID );
writeStdOut ( ex.message );
rollback();
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.eglexamples.client;

import org.eclipse.edt.rui.widgets.*;

handler RosettaCodeHandler type RUIhandler{initialUI =[ui], title = "Rosetta Code Tasks and Counts"}

ui GridLayout{columns = 3, rows = 4, cellPadding = 4, children = [ b1, dg1, l1, l2, l3, l4 ]};

b1 Button{ layoutData = new GridLayoutData{ row = 1, column = 1 }, text = "Go!", onClick = b1_onClick };
l1 TextLabel{ layoutData = new GridLayoutData{ row = 1, column = 2 }, text = "Total Tasks:" };
l2 TextLabel{ layoutData = new GridLayoutData{ row = 1, column = 3 }, text = "0" };

l3 TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 2 }, text = "Total Implementations:" };
l4 TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 3 }, text = "0" };

dg1 DataGrid{ layoutData = new GridLayoutData{ row = 3, column = 1, horizontalSpan = 3 },
pageSize = 10, showScrollbar = true,
columns = [ new DataGridColumn{name = "title", displayName = "Task", width=220},
new DataGridColumn{name = "count", displayName = "Count", width=100} ] };

cmcontinue string?;
title string?;
allTasks Task[];

restBindingTasks IHttp? = new HttpRest{
restType = eglx.rest.ServiceType.TrueRest,
request.uri = "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=1&format=json"};

restBindingPageDetail IHttp? = new HttpRest{
restType = eglx.rest.ServiceType.TrueRest,
request.uri = "http://rosettacode.org/mw/index.php"};

function b1_onClick(event Event in)
call ProxyFunctions.listTasks("") using restBindingTasks
returning to listTasksCallBack onException exceptionHandler;
end

function listTasksCallBack(retResult RosettaCodeJSON in)
title = retResult.query.categorymembers[1].title;
cmcontinue = retResult.queryContinue.categorymembers.cmcontinue;

call ProxyFunctions.fetchPageDetail(title) using restBindingPageDetail
returning to pageDetailCallBack onException exceptionHandler;
end

function pageDetailCallBack(pageResults string in)
count int = countSubstring("=={{header", pageResults);
allTasks.appendElement(new Task { title = title, count = count });
l2.text = l2.text as int + 1;
l4.text = l4.text as int + count;

if(cmcontinue != null)
call ProxyFunctions.listTasks(cmcontinue) using restBindingTasks
returning to listTasksCallBack onException exceptionHandler;
else
dg1.data = allTasks as any[];
end
end

function countSubstring(substr string in, str string in) returns(int)
if(str.length() > 0 and substr.length() > 0)
return (str.length() - str.replaceStr(subStr, "").length()) / subStr.length();
else
return 0;
end
end

function exceptionHandler(exp AnyException in)
end

end

record Task
title string;
count int;
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.eglexamples.client;

library ProxyFunctions

function listTasks(continueLocation String in) returns (RosettaCodeJSON) {
@Rest{method = _GET, uriTemplate = "&cmcontinue={continueLocation}",
requestFormat = None, responseFormat = JSON}
}
end

function fetchPageDetail(title String in) returns (String) {
@Rest{method = _GET, uriTemplate = "?title={title}&action=raw",
requestFormat = None, responseFormat = None}
}
end

end

record RosettaCodeJSON
query Query;
queryContinue QueryContinue{JSONName = "query-continue"};
end

record Query
categorymembers Categorymembers[];
end

record Categorymembers
cmcontinue string?;
pageid int?;
ns int?;
title string?;
end

record QueryContinue
categorymembers Categorymembers;
end

0 comments on commit 45c2e6b

Please sign in to comment.