2008-04-30 19:38:36 +08:00
|
|
|
// Sample BeanShell Assertion script
|
|
|
|
|
// Derived from http://www.mail-archive.com/jmeter-user@jakarta.apache.org/msg05597.html
|
|
|
|
|
|
|
|
|
|
if (ResponseCode != null && ResponseCode.equals ("200") == false )
|
|
|
|
|
{
|
|
|
|
|
// this is standard stuff
|
|
|
|
|
Failure=true ;
|
|
|
|
|
FailureMessage ="Response code was not a 200 response code it was " + ResponseCode + "." ;
|
|
|
|
|
print ( "the return code is " + ResponseCode); // this goes to stdout
|
|
|
|
|
log.warn( "the return code is " + ResponseCode); // this goes to the JMeter log file
|
|
|
|
|
} else {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// non standard stuff where BeanShell assertion will be really powerful .
|
|
|
|
|
// in my example I just test the size , but you could extend it further
|
|
|
|
|
// to actually test the content against another file.
|
|
|
|
|
byte [] arr = (byte[]) ResponseData ;
|
|
|
|
|
// print ( arr.length ) ; // use this to determine the size
|
|
|
|
|
if (arr != null && arr.length != 25218)
|
|
|
|
|
{
|
|
|
|
|
Failure= true ;
|
|
|
|
|
FailureMessage = "The response data size was not as expected" ;
|
|
|
|
|
}
|
|
|
|
|
else if ( arr == null )
|
|
|
|
|
{
|
|
|
|
|
Failure= true ;
|
|
|
|
|
FailureMessage = "The response data size was null" ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch ( Throwable t )
|
|
|
|
|
{
|
|
|
|
|
print ( t ) ;
|
|
|
|
|
log.warn("Error: ",t);
|
|
|
|
|
}
|
2007-07-04 07:23:51 +08:00
|
|
|
}
|