-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-5197 test cases for query listener exception handling and async …
…scopes
- Loading branch information
Showing
1 changed file
with
163 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 |
---|---|---|
@@ -0,0 +1,163 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" { | ||
|
||
function afterAll(){ | ||
structDelete( request, "ldev5187"); | ||
structDelete( server, "ldev5187_applicationName"); | ||
}; | ||
|
||
function run( testResults , testBox ) { | ||
describe( title="Testcase for LDEV-5187", body = function() { | ||
|
||
it(title = "check query listener before exception", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
expect(function(){ | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
before=function (caller,args) { | ||
//systemOutput("before listener throw", true); | ||
throw "throw in before listener"; | ||
return arguments; | ||
} | ||
} { | ||
echo("select a from q"); | ||
}; | ||
}).toThrow("application","","throw in before listener"); | ||
}); | ||
|
||
it(title = "check query listener after exception", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
expect(function(){ | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
after=function (caller,args) { | ||
//systemOutput("after listener throw", true); | ||
throw "throw in after listener"; | ||
return arguments; | ||
} | ||
} { | ||
echo("select a from q"); | ||
}; | ||
}).toThrow("application","","throw in after listener"); | ||
}); | ||
|
||
it(title = "check query listener after exception, with error listener", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
expect(function(){ | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
after=function (caller,args) { | ||
//systemOutput("before listener throw", true); | ||
throw "throw in after listener"; | ||
return arguments; | ||
}, | ||
error=function (caller,args) { | ||
//systemOutput("in error listener", true); | ||
throw "throw in error listener"; | ||
return arguments; | ||
} | ||
} { | ||
echo("select a from q"); | ||
}; | ||
}).toThrow("application","","throw in error listener"); | ||
}); | ||
|
||
it(title = "check query error listener", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
expect(function(){ | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
before=function (caller,args) { | ||
args.sql = "select I am going to error"; | ||
return arguments; | ||
}, | ||
error=function (caller,args) { | ||
//systemOutput("in error listener", true); | ||
throw "throw in error listener"; | ||
return arguments; | ||
} | ||
} { | ||
echo("select a from q"); | ||
}; | ||
}).toThrow("application","","throw in error listener"); | ||
}); | ||
|
||
it(title = "check query listener scopes", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
application name="ldev5187"; | ||
request.ldev5187 = true; | ||
application.ldev5187 = true; | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
before=function (caller,args) { | ||
if (!structKeyExists( request, "ldev5187" ) ) throw "missing request scope"; | ||
if (!structKeyExists( application, "ldev5187" ) ) throw "missing application scope"; | ||
//systemOutput("Good! before listener has scopes", true); | ||
return arguments; | ||
}, | ||
after=function (caller,args) { | ||
if (!structKeyExists( request, "ldev5187" ) ) throw "missing request scope"; | ||
if (!structKeyExists( application, "ldev5187" ) ) throw "missing application scope"; | ||
//systemOutput("Good! after listener has scopes", true); | ||
return arguments; | ||
} | ||
} { | ||
echo("select a from q"); | ||
}; | ||
expect(qry.a).toBe( "" ); | ||
structDelete(request, "ldev5187"); | ||
structDelete(application, "ldev5187"); | ||
}); | ||
|
||
it(title = "check query error listener scopes, async=false", body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
application name="ldev5187"; | ||
request.ldev5187 = true; | ||
application.ldev5187 = true; | ||
query name="local.qry" dbtype="query" | ||
listener={ | ||
error=function (caller,args) { | ||
if (!structKeyExists( request, "ldev5187" ) ) throw "missing request scope"; | ||
if (!structKeyExists( application, "ldev5187" ) ) throw "missing application scope"; | ||
//systemOutput("Good! error listener has scopes", true); | ||
} | ||
} { | ||
echo("select a from missing"); | ||
}; | ||
structDelete( request, "ldev5187" ); | ||
structDelete( application, "ldev5187" ); | ||
}); | ||
|
||
it(title = "check query error listener scopes, async=true", skip=true, body = function( currentSpec ) { | ||
var q = queryNew("a"); | ||
application name="ldev5187"; | ||
request.ldev5187 = true; | ||
application.ldev5187 = true; | ||
server.ldev5187_applicationName = ""; | ||
query async=true name="local.qry" dbtype="query" | ||
listener={ | ||
error=function (caller,args) { | ||
systemOutput("In async error listener has scopes", true); | ||
if (!structKeyExists( request, "ldev5187" ) ){ | ||
systemOutput("Bad! async error listener missing request scope", true); | ||
throw "missing request scope"; | ||
} | ||
if (!structKeyExists( application, "ldev5187" ) ) { | ||
server.ldev5187_applicationName = getApplicationSettings().name; | ||
systemOutput("Bad! async error listener missing correct application scope [#server.ldev5187_applicationName#]", true); | ||
throw "missing application scope"; | ||
} | ||
systemOutput("Good! async error listener has scopes", true); | ||
} | ||
} { | ||
echo("select a from missing"); | ||
}; | ||
sleep(200); | ||
expect( server.ldev5187_applicationName ).toBe( "ldev5187" ); | ||
structDelete( request, "ldev5187"); | ||
structDelete( application, "ldev5187"); | ||
structDelete( server, "ldev5187_applicationName"); | ||
}); | ||
|
||
}); | ||
} | ||
} |