pnever      2003/08/29 05:51:09

  Modified:    
testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor
                        TProcessors.java
  Log:
  Fixed minor bug
  
  Revision  Changes    Path
  1.69      +411 -422  
jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java
  
  Index: TProcessors.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- TProcessors.java  27 Aug 2003 15:48:32 -0000      1.68
  +++ TProcessors.java  29 Aug 2003 12:51:08 -0000      1.69
  @@ -135,66 +135,66 @@
    * @version $Revision$
    */
   public class TProcessors {
  -
  -
  -
  +    
  +    
  +    
       /** Table for startup parameter */
       Hashtable startUp = null;
  -
  -
  +    
  +    
       /** home */
       String xdavhome;
  -
  +    
       /** port */
       String port;
  -
  +    
       /** host */
       String host;
  -
  +    
       /** user */
       String defaultUser;
  -
  +    
       /** password */
       String defaultPassword;
  -
  -
  +    
  +    
       /** url encoding */
       String defaultUrlEncoding;
  -
  -
  +    
  +    
       /** Tracing required */
       String tracingRequest;
  -
  -
  +    
  +    
       /** hold all the variable defined **/
       KnownVariablesHashtable knownVariables = new KnownVariablesHashtable();
  -
  -
  +    
  +    
       /** holds all configuration **/
       XConf xdavConfiguration = null;
  -
  +    
       /** specify where to write the xml results **/
       private XMLOutput xmlresult = new XMLOutput(System.out);
  -
  +    
       /** count all executed test elements **/
       private long testElementsExecuted = 0;
  -
  +    
       /** count all executed test elements **/
       private long testElementsExecutedWithError = 0;
  -
  +    
       /** The absolute path name of the execute input file **/
       private String globalAbsolutePath = null;
  -
  -
  +    
  +    
       /** The absolute path name of the execute input file **/
       private String globalTestFileName = null;
  -
  +    
       /**
        * Constructor
        */
  -
  +    
       public  TProcessors (){
  -
  +        
           xdavhome = System.getProperty("xdav.home");
           host = System.getProperty("xdav.host");
           port = System.getProperty("xdav.port");
  @@ -202,7 +202,7 @@
           defaultPassword = System.getProperty("xdav.password");
           defaultUrlEncoding = System.getProperty("xdav.urlencoding");
           tracingRequest = System.getProperty("xdav.tracingRequest",  "none");
  -
  +        
           if (defaultUrlEncoding == null) {
               defaultUrlEncoding = "UTF-8";
           }
  @@ -224,31 +224,30 @@
               System.out.println("xdav.port is not set!");
               throw new Error("xdav.port is not set!");
           }
  -
  +        
           // Set some defaults
           startUp = new Hashtable();
           startUp.put("host", host);
           startUp.put("port", new Integer(port));
  -
  -
  +        
  +        
           try { xdavConfiguration = new XConf(new File(xdavhome +
                                                            File.separator + 
"testsuite"+
                                                            File.separator + "junit"+
                                                            File.separator + 
"tprocessor.xml")); }
           catch (Exception e) { e.printStackTrace(); }
  -
  -
  +        
  +        
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * main method
        */
  -    public static void main(String[] args)
  -    {
  -
  -
  +    public static void main(String[] args) {
  +        
  +        
           //      for (int threadCounter=1; threadCounter <= 20; threadCounter++) {
           //          threadsToExceute.add(new Thread(new 
Runner(item.getChildren().iterator(), Thread.currentThread()), "parallelThread-" + 
(threadsToExceute.size()+1)));
           //          {
  @@ -279,8 +278,8 @@
           //              } catch (java.io.IOException e) {e.printStackTrace();}
           //          }
           //      }
  -
  -
  +        
  +        
   //
           //        for (int i=0; i<10000; i++)
           //        {
  @@ -304,50 +303,49 @@
           //            }
           //        }
           //            System.exit (-1);
  -
  -
  +        
  +        
           if (!mainExecuter(args, null, null)) {
               System.exit (-1);
           }
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       /**
        * main executer method to be called from outside
        */
  -    public static boolean mainExecuter(String[] args, java.io.PrintStream 
xmlresult, int[] counters)
  -    {
  -
  -
  +    public static boolean mainExecuter(String[] args, java.io.PrintStream 
xmlresult, int[] counters) {
  +        
  +        
           String stestName = "";
           boolean result = true;
           TArgs arg = new TArgs (args);
  -
  -
  +        
  +        
           TProcessors tp = new TProcessors();
           if(!tp.processStartUp( args )){
               System.exit(-1);
           }
  -
  +        
           if (arg.isOptionSet ("name")) {
               stestName = arg.get ("name");
           }
           else {
               return false;
           }
  -
  -
  +        
  +        
           //      System.out.println("Can read this file: "+ testName.canRead()+ 
"***" +testName.length());
           //      System.out.println("Can get the name of this file: "+ 
testName.getName());
  -
  -
  +        
  +        
           if (!tp.executeTestCase( new File (stestName), xmlresult )) {
               result = false;
           }
  -
  +        
           if (counters != null) {
               counters[0] ++;
               if (!result) counters[1] ++;
  @@ -355,17 +353,17 @@
               //          System.out.println("$$$$$$$$$$$ processed cases err " + 
counters[1]);
               //          System.out.println("");
           }
  -
  -
  -
  +        
  +        
  +        
           return result;
       }
  -
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
  +    
       /**
        * Process the initial args passed to the Class.<br>
        * Currently this should consist of:<br>
  @@ -379,86 +377,83 @@
        */
       private boolean processStartUp( String[] args ){
           boolean ready = false;
  -
  -
  +        
  +        
           TArgs arg = new TArgs (args);
  -
  +        
           if (arg.isOptionSet ("help")) {
  -
  +            
               printStartUsage();
               return false;
           }
           if (arg.isOptionSet("host")){
  -
  -
  +            
  +            
               startUp.put("host", arg.get("host"));
  -
  +            
               ready = true;
           }
           if(arg.isOptionSet("port")){
               int val;
  -            try
  -            {
  +            try {
                   val = Integer.parseInt( arg.get("port") );
               }
  -            catch ( NumberFormatException ne )
  -            {
  +            catch ( NumberFormatException ne ) {
                   printStartUsage();
                   return false;
               }
               startUp.put("port", new Integer(val) );
  -
  -
  +            
  +            
               ready = true;
           }
  -
  -
  +        
  +        
           if (arg.isOptionSet( "name" ) ){
               ready = true;
           }
  -
  -
  +        
  +        
           return ready;
       }
       /**
        * Print the commands options from startup
        */
  -    private static void printStartUsage()
  -    {
  -
  +    private static void printStartUsage() {
  +        
           System.out.println("XDAV Tprocessor Startup args:");
           System.out.println("  -name <The name of testcase, full path should be 
given>");
           System.out.println("  -host <host to connect to>");
           System.out.println("  -port <post to conect on>");
           System.out.println("  -help");
  -
  -
  +        
  +        
       }
       // -------------------------------------------------------- Private Methods
  -
  +    
       /**
        * Construct a document (tree) out of given XML file. Execute testStep given in 
the
        * file
        * @param WeddavClient client, File
        */
  -
  +    
       private boolean executeTestCase( File testfile, PrintStream xmlresultPar ){
           boolean result= true;
           long time = System.currentTimeMillis();
  -
  +        
           if (xmlresultPar != null){
               this.xmlresult = new XMLOutput(xmlresultPar);
           }
  -
  -
  +        
  +        
           System.out.println("");
           System.out.println(new Date() + " Starting test case: " + 
testfile.getAbsolutePath());
  -
  +        
           xmlresult.writeRootElementStart("testCase");
           xmlresult.writeElement("fileName", testfile.getAbsolutePath());
  -
  +        
           try{
  -            globalTestFileName = testfile.getAbsolutePath();
  +            globalTestFileName = testfile.getName();
               globalAbsolutePath = testfile.getParent();
               //          globalAbsolutePath = testfile.;
               result = exceuteStepOrRepeater(new 
SAXBuilder(true).build(testfile).getRootElement().getChildren().iterator());
  @@ -469,37 +464,37 @@
           } catch( Exception e ) {
               e.printStackTrace();
           }
  -
  -
  +        
  +        
           xmlresult.writeElement("result",  
((testElementsExecutedWithError!=0)?"ERROR":"Success"));
           xmlresult.writeElement("time",  ((System.currentTimeMillis() - time)));
           xmlresult.writeElement("testElementCount",  testElementsExecuted);
           xmlresult.writeElement("testElementErrors",  testElementsExecutedWithError);
           xmlresult.writeRootElementEnd("testCase");
           xmlresult.flush();
  -
  -
  +        
  +        
           if (testElementsExecutedWithError!=0) System.out.println(new Date() + " 
FAILED test case: " + testfile.getAbsolutePath());
           //      System.out.println("Ending test case: " + 
testfile.getAbsolutePath());
           //      System.out.println("");
           //      try {System.in.read();} catch (Exception e) {}
  -
  -
  -
  +        
  +        
  +        
           return testElementsExecutedWithError==0;
  -
  +        
       }
  -
  -
  +    
  +    
       private boolean exceuteStepOrRepeater(Iterator items) {
           boolean result           = true;
           Vector  threadsToExceute = new Vector(10);
           Vector  cleanUpThreads   = new Vector(10);
  -
  +        
           try {
  -
  +            
               result = exceuteStepOrRepeater(items, threadsToExceute, cleanUpThreads);
  -
  +            
               // now execute all collected threads in parallel
               for (int i = 0 ; i<threadsToExceute.size(); i++) {
                   ((Thread)threadsToExceute.elementAt(i)).start();
  @@ -507,7 +502,7 @@
               for (int i = 0 ; i<threadsToExceute.size(); i++) {
                   ((Thread)threadsToExceute.elementAt(i)).join();
               }
  -
  +            
               // now do the clean up tasks
               // now execute all collected threads in parallel
               for (int i = 0 ; i<cleanUpThreads.size(); i++) {
  @@ -520,20 +515,20 @@
           catch (Exception e){
               e.printStackTrace();
           }
  -
  +        
           return result;
  -
  +        
       }
  -
  -
  -
  +    
  +    
  +    
       private boolean exceuteStepOrRepeater(Iterator items, Vector threadsToExceute, 
Vector cleanUpThreads) {
           HttpClientExtended client = new HttpClientExtended(defaultUser, 
defaultPassword);
  -
  +        
           return exceuteStepOrRepeater(items, threadsToExceute, cleanUpThreads, 
client);
       }
  -
  -
  +    
  +    
       private boolean checkCondition(Element conditionContainer, String condition) 
throws Exception {
           if (condition == null) return false;
           String evaluatedCondition = replaceKnownVariable(conditionContainer, 
condition, "x=x");
  @@ -543,12 +538,12 @@
           String rightSide = expression.nextToken();
           return leftSide.equals(rightSide);
       }
  -
  -
  -
  +    
  +    
  +    
       private boolean exceuteStepOrRepeater(Iterator items, Vector threadsToExceute, 
Vector cleanUpThreads, HttpClientExtended client) {
           boolean result = true;
  -
  +        
           try {
               while(items.hasNext()){
                   Element item = (Element) items.next();
  @@ -591,17 +586,17 @@
                       System.out.println("#########################");
                   }
               }
  -
  -
  +            
  +            
           }
           catch (Exception e){
               e.printStackTrace();
           }
  -
  +        
           return result;
       }
  -
  -
  +    
  +    
       private void assignVariables(List varDefinitions ){
           if (varDefinitions != null) {
               Iterator iter = varDefinitions.iterator();
  @@ -612,52 +607,51 @@
               }
           }
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       /**
        * Execute a given request for a testStep
        * @param Element
        */
  -
  +    
       private boolean executeStep(Element elt, HttpClientExtended client ){
  -
  +        
           boolean result      = false;
           long time           = System.currentTimeMillis();
           HttpMethod method   = null;
  -
  +        
           // initialise user and password
           knownVariables.put("user", defaultUser);
           knownVariables.put("password", defaultPassword);
  -
  +        
           assignVariables(elt.getChildren("assign"));
  -
  +        
           String user       = replaceKnownVariable(elt.getChild("user"), defaultUser);
           String password   = replaceKnownVariable(elt.getChild("password"), 
defaultPassword);
  -
  +        
           // set user and password to the computed values
           knownVariables.put("user", user);
           knownVariables.put("password", password);
  -
  +        
           // create a new client, iff the user id has changed, else use the current 
HttpClient
           if (!client.getUser().equals(user)) {
               client = new HttpClientExtended(user, password);
           }
  -
  -
  +        
  +        
           //              System.out.println("############### user " + user);
           //              System.out.println("############### pwd  " + password);
  -
  +        
           xmlresult.writeElementStart("exceuteStep");
  -
  +        
           try{
  -
  +            
               try {
                   method = executeRequest(elt.getChild("request"));
  -                String fileName = 
globalTestFileName.substring(globalAbsolutePath.length()+1);
  -                method.setRequestHeader("User-Agent", "Jakarta Slide TProcessor " + 
URLUtil.URLEncode(fileName,"UTF-8"));
  +                method.setRequestHeader("User-Agent", "Jakarta Slide TProcessor " + 
URLUtil.URLEncode(globalTestFileName,"UTF-8"));
               } catch (Exception e) {
                   if (method != null) {
                       xmlresult.writeElement("method", method.getName());
  @@ -665,28 +659,26 @@
                       throw e;
                   }
               }
  -
  +            
               if (method == null){
                   System.out.println("#########################");
                   System.out.println("Method pointer is null = " + 
getElementString(elt.getChild("request")) );
                   System.out.println("#########################");
                   return false;
               }
  -
  +            
               xmlresult.writeElement("method", method.getName());
               xmlresult.writeElement("url", 
URLUtil.URLEncode(method.getPath(),"UTF-8"));
  -
  -//            client.setConnectionTimeout(100000);
  -//            if (elt.getChild("maxDuration") != null) {
  -//                client.setConnectionTimeout(new 
Integer(elt.getChild("maxDuration").getAttributeValue("time")).intValue());
  -//            }
  -
  +            
  +            //            client.setConnectionTimeout(100000);
  +            //            if (elt.getChild("maxDuration") != null) {
  +            //                client.setConnectionTimeout(new 
Integer(elt.getChild("maxDuration").getAttributeValue("time")).intValue());
  +            //            }
  +            
               final int MAX = 50;
               int i;
  -            for (i = 0; true; i++)
  -            {
  -                try
  -                {
  +            for (i = 0; true; i++) {
  +                try {
                       client.executeMethod(method);
                       break;
                   }
  @@ -708,8 +700,8 @@
               }
               //          System.out.println("Status Code "+ m.getStatusCode());
               //          System.out.println("Status Text "+ m.getStatusText());
  -
  -
  +            
  +            
               //          if (method instanceof PropFindMethod) {
               //              System.out.println("###################");
               //              System.out.println("###################");
  @@ -719,47 +711,47 @@
               //              System.out.println("###################");
               //              System.out.println("###################");
               //          }
  -
  -
  +            
  +            
               fillVariables(method, elt.getChild("response"));
  -
  +            
               result = (responseAssert(method, elt));
  -
  -
  +            
  +            
               method.releaseConnection();
  -
  -
  +            
  +            
           }catch(Exception e){
               xmlresult.writeException( e );
               e.printStackTrace();
           }
  -
  +        
           if (!result) testElementsExecutedWithError ++;
           testElementsExecuted ++;
  -
  -
  +        
  +        
           xmlresult.writeElement("result", (!result?"ERROR":"Success"));
           xmlresult.writeElement("time",  ((System.currentTimeMillis() - time)));
           xmlresult.writeElementEnd("exceuteStep");
  -
  -
  +        
  +        
           return result;
       }
  -
  +    
       /**
        * Constructs from request the method associated to the given request
        * @param Element
        */
  -
  +    
       private HttpMethod executeRequest(Element request) throws Exception {
           HttpMethod method = null;
           List list = request.getChildren();
           Iterator items = list.iterator();
  -
  -
  +        
  +        
           while(items.hasNext()){
               Element item = (Element) items.next();
  -
  +            
               if(item.getName().equals("command")){
                   method = fillMethodName(item, method);
               }
  @@ -768,12 +760,12 @@
               } else if(item.getName().equals("body")){
                   method = fillBody(item, method);
               }
  -
  +            
           }
           return(method);
       }
  -
  -
  +    
  +    
       /**
        * This method is used to replace variables in a element
        * @param element the element to replacement should be applied
  @@ -782,8 +774,8 @@
       private  String replaceKnownVariable(Element element){
           return replaceKnownVariable(element, null);
       }
  -
  -
  +    
  +    
       /**
        * This method checks if a name points to a valid file
        * @param fileName
  @@ -793,9 +785,9 @@
           //      System.out.println("Checking " + name + " = " + new 
File(name).isFile());
           return new File(name).isFile();
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * This method returns the name of a valid file
        * @param name is the possibly unqualified file name
  @@ -809,8 +801,8 @@
           }
           return result;
       }
  -
  -
  +    
  +    
       /**
        * This method returns the name of a valid file
        * @param name is the possibly unqualified file name
  @@ -827,9 +819,9 @@
           }
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * This method returns the name of a valid file
        * @param name is the possibly unqualified file name
  @@ -840,8 +832,8 @@
           if (result == null || result.equals("")) result = "UTF-8";
           return result;
       }
  -
  -
  +    
  +    
       /**
        * This method is used to replace variables in a string
        * @param element the element to replacement should be applied
  @@ -852,34 +844,34 @@
           String result = body.getText();
           String fileName = getFileReferenceName(body);
           if (fileName != null) {
  -
  +            
               try {
  -
  +                
                   Reader input  = new BufferedReader(
                       new InputStreamReader(
                                                         new 
FileInputStream(fileName), getFileEncoding(body)));
                   StringWriter output = new StringWriter();
                   char[] buffer = new char[1024];
                   int numberOfBytesRead;
  -
  +                
                   while ((numberOfBytesRead=input.read(buffer)) > 0) {
                       output.write (buffer, 0, numberOfBytesRead);
                   }
  -
  +                
                   result = output.toString();
                   input.close();
                   output.close();
  -
  +                
               }
               catch (Exception e) {
                   e.printStackTrace();
               }
  -
  -
  +            
  +            
           }
           return result;
       }
  -
  +    
       /**
        * This method is used to replace variables in a string
        * @param element the element to replacement should be applied
  @@ -890,8 +882,8 @@
           if (element == null) return defaultValue;
           return replaceKnownVariable(element, getBodyValue(element), defaultValue);
       }
  -
  -
  +    
  +    
       /**
        * This method is used to replace variables in a string. If a variable value 
uses other variables
        * those variables are subsituted too.
  @@ -901,11 +893,11 @@
        * @return String the value of the element, with all applied replacements, if 
element is null return defaultValue
        */
       private  String replaceKnownVariable(Element element, String line, String 
defaultValue){
  -
  +        
           if (element == null) return defaultValue;
  -
  +        
           if (element.getAttributeValue("varUsage") != null && 
!element.getAttributeValue("varUsage").equals("")){
  -
  +            
               if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
                   String varName = "varUsage";  // default
                   line = replace(line, "%"+varName+"%", computeVarValue(element, 
element.getAttributeValue("varUsage")));
  @@ -930,11 +922,11 @@
        * @return String the value of the element, with all applied replacements, if 
element is null return defaultValue
        */
       private  String doReplaceKnownVariable(Element element, String line, String 
defaultValue){
  -
  +        
           if (element == null) return defaultValue;
  -
  +        
           if (element.getAttributeValue("varUsage") != null && 
!element.getAttributeValue("varUsage").equals("")){
  -
  +            
               if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
                   String varName = "varUsage";  // default
                   line = replace(line, "%"+varName+"%", 
knownVariables.get(element.getAttributeValue("varUsage")));
  @@ -950,9 +942,9 @@
           }
           return line;
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * This method computes for a given variable name the value. If the value 
contains
        * additional variable references, these are resolved to their values
  @@ -967,10 +959,10 @@
           }
           return result;
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * This method is used to replace variables in a string
        * @param line the string which will be modified
  @@ -979,7 +971,7 @@
        * @return value of line, with all applied replacements
        */
       public static String replace(String line, String pattern, String value){
  -
  +        
           while (line.indexOf(pattern) != -1){
               line = line.substring(0, line.indexOf(pattern)) +
                   value +
  @@ -988,10 +980,10 @@
           //      System.out.println("#### Replaced " + pattern + " with " + value + 
" --> " + line);
           return line;
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * This method is used to find out the name of the Resquest Method
        * @param List
  @@ -1003,10 +995,10 @@
           method.setRequestHeader("Content-Length", "0");
           return method;
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * This method is used to set the Header in request Method
        * @param List
  @@ -1018,11 +1010,11 @@
           if (name.equalsIgnoreCase("destination")) {
               value = URLUtil.URLEncode(value, "utf-8");
           }
  -
  +        
           method.setRequestHeader(name, value);
           return method;
       }
  -
  +    
       private  boolean binaryReadRequest(Element element) {
           String fileReference = getFileReferenceName(element);
           String fileEncoding = element.getAttributeValue("fileEncoding");
  @@ -1030,9 +1022,9 @@
               (fileEncoding == null || fileEncoding.equals("binary"));
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * This method is used to set the Header in request Method
        * @param List
  @@ -1065,16 +1057,16 @@
               catch (UnsupportedEncodingException e) { throw new 
Exception(e.toString());}
           }
           return method;
  -
  +        
       }
  -
  -
  -
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
  +    
  +    
  +    
       /**
        * This method is used to return body as String
        * @param String
  @@ -1083,28 +1075,28 @@
           boolean firstPart = false;
           boolean secondPart = false;
           Iterator header = responseHeader(elt.getChild("response"));
  -
  -
  +        
  +        
           List expectedResponseCodes = 
responseStatus(elt.getChild("response").getChildText("command"));
  -
  +        
           if (expectedResponseCodes != null && !expectedResponseCodes.contains(new 
Integer(m.getStatusCode()))) {
  -
  +            
               xmlresult.writeElementStart("responseError");
               xmlresult.writeElement("receivedValue", 
WebdavStatus.getStatusText(m.getStatusCode()) +
                                          "   " + m.getStatusCode());
               xmlresult.writeElement("expectedValue", 
getStatusText(expectedResponseCodes) +
                                          "   " + expectedResponseCodes);
               xmlresult.writeElementEnd("responseError");
  -
  +            
               if (m instanceof XMLResponseMethodBase && m.getStatusCode()==207 ) {
                   System.out.println("#################");
                   
System.out.println(getElementString(((XMLResponseMethodBase)m).getResponseDocument().getDocumentElement()));
                   System.out.println("#################");
               }
  -
  +            
               return false;
           }
  -
  +        
           // a received response code of 404 will not compare the headers
           ResponseBodyAssert methodAssert = assertFactory(m, elt, 
expectedResponseCodes);
           secondPart = (m.getStatusCode() == 404 && expectedResponseCodes != null &&
  @@ -1112,40 +1104,40 @@
                             expectedResponseCodes.contains(new Integer(404)))
               ||
               responseHeaderAssert(m, elt, header);
  -
  +        
           firstPart  = (methodAssert!=null)?methodAssert.assertResponseBody():true;
  -
  -
  +        
  +        
           return ( firstPart && secondPart);
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * This method is used to set the Header in request Method
        * @param List
        */
       private  String getStatusText (List responseCodes){
  -
  +        
           String result = "";
  -
  +        
           Iterator iter = responseCodes.iterator();
           while (iter.hasNext()) {
               result = result + " " + 
WebdavStatus.getStatusText(((Integer)iter.next()).intValue());
           }
  -
  +        
           return result;
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * This method is used to set the Header in request Method
        * @param String
        */
       private  Header getResponseHeader (String headerString){
  -
  +        
           Header result = new Header();
           String name;
           String value;
  @@ -1158,15 +1150,15 @@
               value = headerString.substring(size+1);
           }
           value = value.trim();
  -
  +        
           result.setName(name);
           result.setValue(value);
  -
  +        
           return result;
  -
  +        
       }
  -
  -
  +    
  +    
       /**
        * This method is used to set the Header in request Method
        * @param Element
  @@ -1174,7 +1166,7 @@
       private  Header getResponseHeader (Element headerElement){
           return getResponseHeader(replaceKnownVariable(headerElement));
       }
  -
  +    
       /**
        * This method is used to return body as String
        * @param String
  @@ -1182,21 +1174,21 @@
       private boolean  responseHeaderAssert(HttpMethod m, Element elt, Iterator 
header){
           boolean result = false;
           try{
  -
  +            
               result = verifyHeader(xdavConfiguration.getPropertyList 
("excludedHeaderProperties", m.getName()), m, header);
  -
  +            
           }catch(Exception e){
               e.printStackTrace();
           }
  -
  -
  +        
  +        
           return result;
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       /**
        * This method is used to check if all the given headers are returned by the 
WebDav method
        * @param String
  @@ -1204,11 +1196,11 @@
       private boolean  verifyHeader(List allowHeaders, HttpMethod m, Iterator header){
           boolean result = true;
           while (header.hasNext()){
  -
  +            
               Header  headToMatch      = (Header) header.next();
               boolean oneHeaderMatched = allowHeaders.contains(headToMatch.getName()) 
||  // head to be compared
                   verifyOneHeader(headToMatch, 
m.getResponseHeader(headToMatch.getName()));                                        // 
compare it
  -
  +            
               if (!oneHeaderMatched){
                   if (result) {
                       xmlresult.writeElementStart("headerErrors");
  @@ -1223,20 +1215,20 @@
                       xmlresult.writeElementEnd("nonMatchingHeader");
                   }
               }
  -
  +            
               result = result && oneHeaderMatched;
  -
  +            
           }
           if (!result) {
               xmlresult.writeElementEnd("headerErrors");
           }
           return result;
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       private boolean  verifyOneHeader(Header expected, Header received){
           boolean result = false;
           result = received != null &&
  @@ -1244,9 +1236,9 @@
                    compareOneHeader(expected, received));
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       private boolean  compareOneHeader(Header expected, Header received){
           boolean result = false;
           if (expected.getName().equals("Allow") || expected.getName().equals("DAV")) 
{
  @@ -1256,9 +1248,9 @@
           }
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       private boolean  compareCommaSeperatedListHeader(Header expected, Header 
received){
           boolean result = false;
           HashSet expList = tokeniseCommaList(expected.getValue());
  @@ -1273,19 +1265,18 @@
           }
           return result;
       }
  -
  +    
       private HashSet tokeniseCommaList(String value){
           HashSet result = new HashSet();
           StringTokenizer iter = new StringTokenizer(value, ",");
  -        while (iter.hasMoreElements())
  -        {
  +        while (iter.hasMoreElements()) {
               String element = ((String)iter.nextElement()).trim();
               result.add(element);
           }
           return result;
       }
  -
  -
  +    
  +    
       private Iterator responseHeader(Element response){
           ArrayList result = new ArrayList();
           Iterator iter = response.getChildren("header").iterator();
  @@ -1295,11 +1286,11 @@
           }
           return result.iterator();
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       public static List responseStatus (String response){
           List result = new ArrayList();
           if (response.equals("*")) return null;
  @@ -1319,44 +1310,44 @@
           }
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
   //
  -
  -
  +    
  +    
       /**
        *
        */
       public static String getElementString (org.w3c.dom.Element e) {
           return getElementString(new org.jdom.input.DOMBuilder().build(e));
       }
  -
  -
  +    
  +    
       /**
        *
        */
       public static String getElementString (Element e) {
           XMLOutputter out = new XMLOutputter("  ", true);
           String result = null;
  -
  +        
           if (e == null) return "null";
  -
  +        
           try {
               result = out.outputString (e);
           }
           catch (Exception ex) {}
  -
  +        
           return result;
       }
  -
  +    
       /**
        * Extract from expected response it body
        */
       protected  Element getElementFromString (String  input){
  -
  +        
           if (input == null) return null;
  -
  +        
           Element result = null;
           //      System.out.println("######");
           //      System.out.println("######" + element);
  @@ -1364,11 +1355,11 @@
           //      System.out.println("");
           //      System.out.println("");
           //      System.out.println("");
  -
  +        
           if (input.trim().equals("")) return null;
  -
  +        
           try {
  -
  +            
               result = (new SAXBuilder().build(new 
StringReader(input.trim()))).getRootElement();
           }
           catch (Exception e){
  @@ -1377,12 +1368,12 @@
               System.out.println("#####################");
               e.printStackTrace();
           }
  -
  +        
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        *
        */
  @@ -1393,26 +1384,26 @@
               fillSpecifiedVariable((XMLResponseMethodBase)m, 
responseElement.getChild("body"));
           }
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        *
        */
       private void fillSpecifiedCommandHeaderVariable (HttpMethod m, Element 
responseElement) {
  -
  +        
           if (responseElement == null) return;  // no response, nothing to fill
  -
  +        
           try {
  -
  +            
               // fill the command variable, if present
               String varName = 
responseElement.getChild("command").getAttributeValue("varDefinition");
               if (varName != null && !varName.trim().equals("")) {
                   String responseCode = new Integer(m.getStatusCode()).toString();
                   knownVariables.put(varName, responseCode);
               }
  -
  +            
               // fill the header variable, if present
               Iterator iter = responseElement.getChildren("header").iterator();
               while (iter.hasNext()) {
  @@ -1427,49 +1418,49 @@
                       knownVariables.put(varName, varValue);
                   }
               }
  -
  +            
           } catch(Exception e){
               e.printStackTrace();
           }
  -
  +        
       }
       /**
        *
        */
       private void fillSpecifiedVariable (XMLResponseMethodBase m, Element body) {
  -
  +        
           if (body == null) return;  // no body, nothing to fill
  -
  +        
           try {
  -
  +            
               String searchPattern = body.getAttributeValue("varPath");
               String varName = body.getAttributeValue("varDefinition");
               if ((searchPattern != null) && (varName != null) && 
m.getResponseDocument() != null){
  -
  +                
                   String varValue = "";
                   Iterator iter = findElementList(getMethodElement(m), 
searchPattern).iterator();
                   while (iter.hasNext()) {
                       varValue = ((Element)iter.next()).getText();
                   }
  -
  +                
                   knownVariables.put(varName, varValue); // store only the very last 
ocuurence
  -
  +                
               }
  -
  -
  +            
  +            
           } catch(Exception e){
               e.printStackTrace();
           }
  -
  +        
       }
  -
  +    
       /**
        *
        */
       private void fillAutomatedVariables (XMLResponseMethodBase m) {
  -
  +        
           try {
  -
  +            
               List possible = xdavConfiguration.getPropertyList("automatedVariables", 
m.getName());
               Iterator iter = possible.iterator();
               while (iter.hasNext()){
  @@ -1478,17 +1469,17 @@
                       fillAutomatedVariables(findElementList(getMethodElement(m), 
searchPattern));
                   }
               }
  -
  -
  +            
  +            
           } catch(Exception e){
               e.printStackTrace();
           }
  -
  +        
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       private void fillAutomatedVariables (List valueList) {
           Iterator iter = valueList.iterator();
           while (iter.hasNext()){
  @@ -1496,24 +1487,24 @@
               String varName  = "automaticVariable" + (knownVariables.size()-2);
               String varValue = e.getText();
               knownVariables.put(varName, varValue);
  -
  +            
           }
       }
  -
  -
  +    
  +    
       private Element getMethodElement(XMLResponseMethodBase m) {
           return new 
org.jdom.input.DOMBuilder().build(m.getResponseDocument().getDocumentElement());
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       private List findElementList (Element rootElement, String key) {
  -
  +        
           List result = new ArrayList();
  -
  +        
           if (key == null || key.equals("")) return result;
  -
  +        
           if (rootElement.getName().equals(key)) {
               Element e = rootElement;
               if (key.equals("href")) {
  @@ -1524,29 +1515,29 @@
               return result;
           }
           if (key.indexOf("/") == -1) return result;
  -
  +        
           String head = key.substring(0, key.indexOf("/"));
           String tail = key.substring(key.indexOf("/")+1);
           String child = null;
  -
  +        
           //      System.out.println("@@@@@@@@@ xml   "  + rootElement.getName());
  -
  +        
           if (!rootElement.getName().equals(head)) {
               return result;
           }
  -
  +        
           if (tail.indexOf("/") == (-1)){
               child = tail;
           }
           else{
               child = tail.substring(0, tail.indexOf("/"));
           }
  -
  +        
           //      System.out.println("@@@@@@@@@ head  "  + head);
           //      System.out.println("@@@@@@@@@ child "  + child);
           //      System.out.println("@@@@@@@@@ tail  "  + tail);
  -
  -
  +        
  +        
           Iterator iter = rootElement.getChildren().iterator();
           while (iter.hasNext()){
               Element e = (Element)iter.next();
  @@ -1555,19 +1546,19 @@
           }
           return result;
       }
  -
  -
  +    
  +    
       private Element expectedResponseAsDOM(Element expectedResponse) {
           return getElementFromString(expectedResponseAsString(expectedResponse));
       }
  -
  -
  +    
  +    
       private InputStream expectedResponseAsStream(Element element) throws Exception {
  -
  +        
           Element expectedResponse = element.getChild("response").getChild("body");
           if (expectedResponse == null) return null;
  -
  -
  +        
  +        
           InputStream result = null;
           if (binaryReadRequest(expectedResponse)) {
               result = new FileInputStream(getFileReferenceName(expectedResponse));
  @@ -1579,36 +1570,36 @@
           }
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       private String expectedResponseAsString(Element expectedResponse) {
           if (expectedResponse.getChild("response").getChild("body") != null) {
               return 
replaceKnownVariable(expectedResponse.getChild("response").getChild("body"));
           }
           return null;
       }
  -
  -
  -
  +    
  +    
  +    
       private ResponseBodyAssert assertFactory(HttpMethod m, Element 
expectedResponseElement, List expectedResponseCodes) throws Exception {
  -
  +        
           // check for the wildcard
           String expectedResponseString = 
expectedResponseAsString(expectedResponseElement);
           if (expectedResponseString == null || expectedResponseString.equals("*")) 
return null;
  -
  +        
           ResponseBodyAssert result = null;
           if(m instanceof PropFindMethod){
               result = new PropfindAssert((XMLResponseMethodBase) m, 
expectedResponseAsDOM(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes);
           } else if (m instanceof SearchMethod){
               boolean sortingRequired = true;
  -
  +            
               if (expectedResponseElement.getChild("response").getChild("body") != 
null &&
                   
expectedResponseElement.getChild("response").getChild("body").getAttributeValue("nosorting")
 != null &&
                   
expectedResponseElement.getChild("response").getChild("body").getAttributeValue("nosorting").equalsIgnoreCase("true"))
 {
                   sortingRequired = false;
               }
  -
  +            
               result = new SearchAssert((XMLResponseMethodBase) m, 
expectedResponseAsDOM(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes, sortingRequired);
           } else if (m instanceof LockMethod){
               result = new LockAssert((XMLResponseMethodBase) m, 
expectedResponseAsDOM(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes);
  @@ -1647,9 +1638,9 @@
           }
           return result;
       }
  -
  -
  -
  +    
  +    
  +    
       /**
        * Factory method to return a method object based on the methodName.
        * If the method name is not known, null is returned
  @@ -1742,10 +1733,10 @@
               throw new Exception("Method " + methodName + " does not exist");
           return result;
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**
        * Factory method to return a method object based on the methodName.
        * If the method name is not known, null is returned
  @@ -1758,11 +1749,11 @@
           }
           return result;
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       /**************************************************************/
       /* Inner class to help the thread to execute the function     */
       /**************************************************************/
  @@ -1782,11 +1773,11 @@
               knownVariables.removeEnvironment();
           }
       }
  -
  -
  -
  -
  -
  +    
  +    
  +    
  +    
  +    
       /**************************************************************/
       /* Inner class to contain all variable sorted by thread name  */
       /**************************************************************/
  @@ -1794,7 +1785,7 @@
           private Hashtable knownVarsByThread = new Hashtable();
           public String get(String key) {
               String    result = "";
  -
  +            
               if (key.startsWith("globalVariable") ||
                   key.equals("host")||
                   key.equals("port")||
  @@ -1851,9 +1842,9 @@
               return getEnvironment(Thread.currentThread());
           }
       }
  -
  -
  -
  +    
  +    
  +    
       /**************************************************************/
       /* Inner class to have a HashMap act as a stack too           */
       /**************************************************************/
  @@ -1876,26 +1867,24 @@
               return super.remove(stack.pop());
           }
       }
  -
  -
  -
  -
  +    
  +    
  +    
  +    
       /**************************************************************/
       /* Inner class to have some more function on HttpClient       */
       /**************************************************************/
       private class HttpClientExtended extends HttpClient {
           private String user = null;
  -
  -        public void setUser(String user)
  -        {
  +        
  +        public void setUser(String user) {
               this.user = user;
           }
  -
  -        public String getUser()
  -        {
  +        
  +        public String getUser() {
               return user;
           }
  -
  +        
           private HttpClientExtended (String user, String password){
               super();
               //            System.out.println("####### " + 
Thread.currentThread().getName() + " : Creating client " + user);
  @@ -1910,7 +1899,7 @@
               setState(state);
               //        client.setPreEmptiveAuthentication(true);  for later use [jpl]
           }
  -
  +        
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to