Permalink
Browse files

Don't eat the body before we compare it

  • Loading branch information...
1 parent d312093 commit 34b285c60827530e60e0316409e8c82e65063182 David Kowis committed Nov 20, 2013
@@ -13,18 +13,6 @@ class InstrumentedMatchRule implements MatchRule {
def requestValidations = []
- def dumpRequest(Request r) {
- println("Request:")
- def lines = [
- "URI: ${r.uri}",
- "METHOD: ${r.method}",
- "HEADERS: ${r.headers.collect { k,v -> "$k: $v"} join ", "}",
- "BODY: ${r.bodyAsText.input.getText()}"
- ]
- lines.each { l ->
- println("\t" + l)
- }
- }
@Override
boolean isMatch(Request a, Request b) {
@@ -33,34 +21,24 @@ class InstrumentedMatchRule implements MatchRule {
rv.call(b)
}
- //Does doing this eat all the text and ruin it?
- println("REQUEST SENT:")
- dumpRequest(a)
- println("REQUEST RECORDED:")
- dumpRequest(b)
def current = counter.incrementAndGet()
println("Matching attempt: ${current}")
println("A request class: ${a.getClass()}")
println("B request class: ${b.getClass()}")
if(a.getUri() == b.getUri() && a.getMethod() == b.getMethod()) {
//Same method and URI, lets do a body comparison
+ //Can only consume the body once, once it's gone it's gone.
def aBody = a.getBodyAsText().getInput().getText()
def bBody = b.getBodyAsText().getInput().getText()
//Ideally in the real world, we'd parse the XML or the JSON and compare the ASTs instead
// of just comparing the body strings, so that meaningless whitespace doesn't mean anything
- println("aBody: " + aBody)
- println("bBody: " + bBody)
+ println("aBody: |" + aBody + "|")
+ println("bBody: |" + bBody + "|")
- def bytesMatch = ByteStreams.equal(a.getBodyAsBinary(), b.getBodyAsBinary())
def textMatch = aBody.equals(bBody)
- if(bytesMatch != textMatch){
- println("HOW DID THIS NOT BE THE SAME?!!?!")
- }
-
-
//Right now, lets just compare the bodies also
return textMatch
} else {

0 comments on commit 34b285c

Please sign in to comment.