Clover coverage report - Cactus 1.4 for J2EE API 13
Coverage timestamp: Sun Aug 25 2002 18:02:10 BST
file stats: LOC: 153   Methods: 6
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebTestResultParser.java 60% 91.3% 100% 87.1%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.client;
 3   
 import org.apache.cactus.WebTestResult;
 4   
 
 5   
 /** 
 6   
  * Parse a string representing a Test result and transform it into a 
 7   
  * <code>WebTestResult</code> object. 
 8   
  * 
 9   
  * @see WebTestResult 
 10   
  * 
 11   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 12   
  * 
 13   
  * @version $Id: WebTestResultParser.java,v 1.5 2002/07/21 12:09:16 vmassol Exp $ 
 14   
  */
 15   
 public class WebTestResultParser {
 16   
   /** 
 17   
        * Parsed exception class name 
 18   
        */
 19   
   protected String exceptionClassname;
 20   
   /** 
 21   
        * Parsed exception message 
 22   
        */
 23   
   protected String exceptionMessage;
 24   
   /** 
 25   
        * Parsed exception stack trace 
 26   
        */
 27   
   protected String exceptionStacktrace;
 28   
   /** 
 29   
        * Parse a string and transform it into a <code>WebTestResult</code> object. 
 30   
        * 
 31   
        * @param theData the string to parse 
 32   
        * @return the <code>WebTestResult</code> object corresponding to the data 
 33   
        *         string 
 34   
        * @exception ParsingException if an error happens during parsing 
 35   
        */
 36  66
   public WebTestResult parse(String theData) throws ParsingException {
 37  66
     String buffer;
 38  66
     WebTestResult result;
 39  66
     buffer = this.readRootElement(theData);
 40  66
     if (buffer.length() == 0) {
 41  61
       result = new WebTestResult();
 42   
     } else {
 43  5
       buffer = this.readExceptionClassname(buffer);
 44  5
       buffer = this.readExceptionMessage(buffer);
 45  5
       buffer = this.readExceptionStacktrace(buffer);
 46  5
       result = new WebTestResult(this.exceptionClassname, this.exceptionMessage, 
 47   
           this.exceptionStacktrace);
 48   
     } 
 49  66
     return result;
 50   
   } 
 51   
 
 52   
   /** 
 53   
        * Read the {@link WebTestResult#XML_ROOT_ELEMENT} portion. 
 54   
        * 
 55   
        * @param theData the string buffer to parse 
 56   
        * @return the string buffer minus what has been read 
 57   
        * @exception ParsingException if an error happens during parsing 
 58   
        */
 59  70
   protected String readRootElement(String theData) throws ParsingException {
 60  70
     String startRootString = "<webresult>";
 61  70
     String endRootString = "</webresult>";
 62  70
     String buffer;
 63  70
     String trimmedData = theData.trim();
 64  70
     if (trimmedData.startsWith(startRootString) && trimmedData.endsWith(endRootString)) {
 65  70
       buffer = trimmedData.substring(startRootString.length(), 
 66   
           trimmedData.length() - endRootString.length());
 67   
     } else {
 68  0
       throw new ParsingException("Not a valid response");
 69   
     } 
 70  70
     return buffer;
 71   
   } 
 72   
 
 73   
   /** 
 74   
        * Read the {@link WebTestResult#XML_EXCEPTION_CLASSNAME_ATTRIBUTE} portion 
 75   
        * and extract the exception classname. 
 76   
        * 
 77   
        * @param theData the string buffer to parse 
 78   
        * @return the string buffer minus what has been read 
 79   
        * @exception ParsingException if an error happens during parsing 
 80   
        */
 81  7
   protected String readExceptionClassname(String theData) throws ParsingException {
 82  7
     String startString = "<exception classname=\"";
 83  7
     String endString = "</exception>";
 84  7
     String buffer;
 85  7
     if (theData.startsWith(startString) && theData.endsWith(endString)) {
 86  7
       int pos = theData.indexOf('\"', startString.length());
 87  7
       this.exceptionClassname = theData.substring(startString.length(), pos);
 88  7
       buffer = theData.substring(startString.length() + this.exceptionClassname.length() + 2, 
 89   
           theData.length() - endString.length());
 90   
     } else {
 91  0
       throw new ParsingException("Not a valid response");
 92   
     } 
 93  7
     return buffer;
 94   
   } 
 95   
 
 96   
   /** 
 97   
        * Read the {@link WebTestResult#XML_EXCEPTION_MESSAGE_ELEMENT} portion 
 98   
        * and extract the exception message. 
 99   
        * 
 100   
        * @param theData the string buffer to parse 
 101   
        * @return the string buffer minus what has been read 
 102   
        * @exception ParsingException if an error happens during parsing 
 103   
        */
 104  6
   protected String readExceptionMessage(String theData) throws ParsingException {
 105  6
     String startString = "<message><![CDATA[";
 106  6
     String endString = "]]></message>";
 107  6
     String buffer;
 108  6
     if (theData.startsWith(startString)) {
 109  6
       int pos = theData.indexOf(endString, startString.length());
 110  6
       this.exceptionMessage = theData.substring(startString.length(), pos);
 111  6
       buffer = theData.substring(pos + endString.length());
 112   
     } else {
 113  0
       throw new ParsingException("Not a valid response");
 114   
     } 
 115  6
     return buffer;
 116   
   } 
 117   
 
 118   
   /** 
 119   
        * Read the {@link WebTestResult#XML_EXCEPTION_STACKTRACE_ELEMENT} portion 
 120   
        * and extract the exception stacktrace. 
 121   
        * 
 122   
        * @param theData the string buffer to parse 
 123   
        * @return the string buffer minus what has been read 
 124   
        * @exception ParsingException if an error happens during parsing 
 125   
        */
 126  5
   protected String readExceptionStacktrace(String theData) throws ParsingException {
 127  5
     String startString = "<stacktrace><![CDATA[";
 128  5
     String endString = "]]></stacktrace>";
 129  5
     String buffer;
 130  5
     if (theData.startsWith(startString)) {
 131  5
       int pos = theData.indexOf(endString, startString.length());
 132  5
       this.exceptionStacktrace = theData.substring(startString.length(), pos);
 133  5
       buffer = theData.substring(pos + endString.length());
 134   
     } else {
 135  0
       throw new ParsingException("Not a valid response");
 136   
     } 
 137  5
     return buffer;
 138   
   } 
 139   
 
 140   
   /** 
 141   
    * Parse a string representing a Test result and transform it into a 
 142   
    * <code>WebTestResult</code> object. 
 143   
    * 
 144   
    * @see WebTestResult 
 145   
    * 
 146   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 147   
    * 
 148   
    * @version $Id: WebTestResultParser.java,v 1.5 2002/07/21 12:09:16 vmassol Exp $ 
 149   
    */
 150  70
   public WebTestResultParser() {
 151  70
     super();
 152   
   } 
 153   
 }