public abstract class SAFSTestLevelException
extends java.lang.RuntimeException
TestCycle
, TestSuite
or TestCase
to indicate the failures/errors of a certain test level.SAFSTestLevelFailure
or SAFSTestLevelError
.
This Exception will be caught by AspectTestLevel
, but we don't throw it out anymore,
instead we return a null for the original method. If the original method doesn't require a return value, it is OK;
but if the original method needs a return value, there will be a AopInvocationException. At this situation user can set
the field returnObj
and it will be used for original method as return value. Below is an example:
//With this annotation, this method will be intercepted by our "spring aspect"AspectTestLevel
. @TestCase //an integer value is required as return value public int testAPIForHtml(String browser) throws Throwable{ int fail = 0; String mapID = "BogusHtml.map"; String counterID = StringUtils.getMethodName(0, true); SAFSTestLevelError testLevelError = new SAFSTestLevelError(); if(Misc.SetApplicationMap(mapID)){ }else{ String errorMsg = "Fail to load map '"+mapID+"', cannot test in browser '"+browser+"'!"; Logging.LogTestFailure(counterID+errorMsg); testLevelError.addError("SetApplicationMap Failed.", errorMsg, "MAPERR"); } if(fail > 0){ Logging.LogTestFailure(counterID + " reports "+ fail +" UNEXPECTED test failures!"); //Set the field 'returnObj' so thatAspectTestLevel
can return it for this method as "return value". testLevelError.setReturnObj(fail); throw testLevelError; }else{ Logging.LogTestSuccess(counterID + " did not report any UNEXPECTED test failures!"); } return fail; }
Modifier and Type | Class and Description |
---|---|
static class |
SAFSTestLevelException.TestLevelMessage |
Modifier and Type | Field and Description |
---|---|
protected java.util.List<SAFSTestLevelException.TestLevelMessage> |
messages
Hold the errors/failures thrown out with this exception.
|
protected java.lang.Object |
returnObj
Hold the object to return for annotation handling.
|
Constructor and Description |
---|
SAFSTestLevelException() |
SAFSTestLevelException(java.lang.String message,
java.lang.String details,
java.lang.String type) |
Modifier and Type | Method and Description |
---|---|
protected void |
addMessage(java.lang.String message,
java.lang.String details,
java.lang.String type,
java.lang.StackTraceElement errorTrace) |
protected java.util.List<SAFSTestLevelException.TestLevelMessage> |
getMessages() |
java.lang.Object |
getReturnObj() |
void |
setReturnObj(java.lang.Object returnObj) |
protected java.util.List<SAFSTestLevelException.TestLevelMessage> messages
protected java.lang.Object returnObj
AspectTestLevel
to add some extra operations
around an annotated method, sometimes when the original method throws an exception
SAFSTestLevelError
/, we catch them in "spring aspect"
AspectTestLevel
but we don't throw it out again, instead we return a null
for the original method. If the original method doesn't require a return value, it is
OK; but if the original method needs a return value, there will be a AopInvocationException.
At this situation, we can set this field when we create the exception in the original method,
and our "spring aspect" AspectTestLevel
will return this field for original method.public SAFSTestLevelException()
public SAFSTestLevelException(java.lang.String message, java.lang.String details, java.lang.String type)
protected void addMessage(java.lang.String message, java.lang.String details, java.lang.String type, java.lang.StackTraceElement errorTrace)
protected java.util.List<SAFSTestLevelException.TestLevelMessage> getMessages()
public java.lang.Object getReturnObj()
public void setReturnObj(java.lang.Object returnObj)
Copyright © SAS Institute. All Rights Reserved.