Matt/ groovysample

Test update to see if the vim outline gets picked up.

    1   
    2 #!/usr/bin/env groovy
    3 
    4 import org.apache.commons.lang.StringUtils;
    5 import org.custommonkey.xmlunit.*;
    6 
    7 //Ignore whitespace on XML tests
    8 XMLUnit.setIgnoreWhitespace(true)
    9 
   10 parseURL = new URL(args[0])
   11 target = args[1]
   12 errorList = [:]
   13 
   14 parseURL.withReader( { reader ->
   15                 int stateCounter = 0
   16                 String line = ""
   17 
   18                 errorGroup = []
   19                 lineNumber = 0
   20 
   21                 //The pattern is line #, throw away, input, throw away, expected, throw away, received
   22                 while( (line = reader.readLine()) != null ) {
   23                         if([1,3,5].contains(stateCounter)) {
   24 
   25                         }
   26                         else if(stateCounter == 0) {
   27                                 line = ( line =~ /Line (.*?):/ )[0][1]
   28                                 println("--Found : " + line)
   29                                 lineNumber = line
   30                         }       
   31                         else if(stateCounter == 2) {
   32                                 errorGroup << line
   33                         }       
   34                         else if(stateCounter == 4) {
   35                                 errorGroup << line
   36                         }       
   37                         else if(stateCounter == 6) {
   38                                 errorGroup << line
   39                         }
   40 
   41                         if(stateCounter == 6) {
   42                                 errorList[lineNumber] = errorGroup
   43                                 errorGroup = []
   44                                 stateCounter = 0
   45                         }
   46                         else {
   47                                 stateCounter++  
   48                         }
   49                 }
   50         }
   51 )
   52 
   53 println("--l to list, q to quit, # to select")
   54 
   55 consoleInput = new BufferedReader(new InputStreamReader(System.in))
   56 
   57 consoleInput.each { choice ->
   58         if(choice == "l") {
   59                 errorList.each { k , v ->
   60                         println("--Line : " + k)
   61                 }                       
   62         } else if(choice == "q") {
   63                 return
   64         } else if (errorList.containsKey(choice)) {
   65                 group = errorList[choice]
   66                 println("--Using : " + choice)
   67                 request = group[0]
   68                 expected = group[1]
   69                 found = group[2]
   70 
   71                 requestXml = new XmlParser().parseText(request)
   72                 expectedXml = new XmlParser().parseText(expected)
   73 
   74                 printer = new XmlNodePrinter()          
   75 
   76                 println("---- Request : ")
   77                 printer.print(requestXml)
   78 
   79                 println("---- Expected : ")
   80                 printer.print(expectedXml)
   81 
   82                 expectedFoundDiff = new Diff(expected, found)
   83                 if( expectedFoundDiff.identical() ) {
   84                         println("--Expected and found were the same, something's wrong with this script")
   85                 }
   86                 else {
   87                         println("--Expected / Found diff")
   88                         detailedExpectedFoundDiff = new DetailedDiff(expectedFoundDiff)
   89                         detailedExpectedFoundDiff.getAllDifferences().each { item -> println(item) }
   90                 }
   91 
   92                 version = (request =~ /.* version="(.*?)"/ )[0][1]
   93                 version = "IQ411MRT:$version"
   94 
   95                 URL targetUrl = new URL(target)
   96                 conn = targetUrl.openConnection()
   97                 conn.setRequestMethod("POST")
   98                 conn.setDoOutput(true)                  
   99                 conn.setRequestProperty("API_VERSION", version)
  100                 OutputStreamWriter writer = new OutputStreamWriter(conn.outputStream)
  101                 writer.write(request)
  102                 writer.flush()
  103                 writer.close()
  104                 conn.connect()
  105                 
  106                 response = conn.content.text
  107                 
  108                 expectedResponseDiff = new Diff(expected, response)
  109                 if( expectedResponseDiff.identical() ) {
  110                         println("--Expected and response were the same");
  111                 }
  112                 else {
  113                         println("--Expected / Response diff")
  114                         detailedDiff = new DetailedDiff(expectedResponseDiff)
  115                         detailedDiff.getAllDifferences().each { item -> println(item) }
  116                 }               
  117                 
  118                 foundResponseDiff = new Diff(found, response)
  119                 if( foundResponseDiff.identical() ) {
  120                         println("--Found and response were the same");
  121                 }
  122                 else {
  123                         println("--Found / Response diff")
  124                         println("---- Reponse :")
  125                         printer.print(new XmlParser().parseText(response))
  126                         println("---- Found :")
  127                         printer.print(new XmlParser().parseText(found))
  128                         detailedDiff = new DetailedDiff(foundResponseDiff)
  129                         detailedDiff.getAllDifferences().each { item -> println(item) }
  130                 }               
  131         }
  132         else {
  133                 println("--'l' is your only option.  You typed : " + choice)
  134         }
  135 }