This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for EGL serialization and deserialization
- Loading branch information
1 parent
b35634c
commit 45c2e6b
Showing
6 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ okhttpVersion=4.12.0 | |
jvmVersion=1.8 | ||
rpgParserVersion=2.1.42 | ||
javaModuleVersion=0.9.15 | ||
eglParserVersion=0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
76 changes: 76 additions & 0 deletions
76
starlasu-demo/src/test/resources/egl/rosetta-code-count-examples-1.egl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
37 changes: 37 additions & 0 deletions
37
starlasu-demo/src/test/resources/egl/rosetta-code-count-examples-2.egl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |