On 17/11/06, Steve Feehan <[EMAIL PROTECTED]> wrote:
On Fri, Nov 17, 2006 at 11:39:56AM +0000, sebb wrote:
> The Regex Post-Processor can be applied to Headers, but this feature
> has not yet been applied to the Response Assertion, sorry.
>
> It's a useful feature - just no-one has got round to implementing it yet.
>
> I've added a Bugzilla enhancement request so it does not get forgotten.
>
> As a work-round, you could use the BeanShell Assertion to get access
> to the Headers.
Even with my incredibly weak Java skills I was able to get something
simple to work. Does this look sane?
Looks OK.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
if (ResponseCode.equals("200")) {
// NOTE: the ResponseHeaders are a String with embedded newlines.
// I wasn't able to use the ^ or $ anchors in my regex. If this
// were required perhaps the string could be split into an array of
// strings?
You need to use the modifier (?m) which allows ^ and $ to match
embbeded lines. Either add it to the String below:
String p = "X-Cache: HIT";
String p = "(?m)X-Cache: HIT";
or add the appropriate flag to the compile method call:
Pattern pattern = Pattern.compile(p);
Pattern pattern = Pattern.compile(p, java.util.regex.Pattern.MULTILINE);
Matcher matcher = pattern.matcher(ResponseHeaders);
if (!matcher.find()) {
Failure = true ;
FailureMessage = "The " + p +
" header was not present in response headers.\n" +
ResponseHeaders;
}
} else {
Failure = true;
FailureMessage = "Error: HTTP Response code " + ResponseCode;
}
Thanks!
--
Steve Feehan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]