You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/03/06 17:32:39 UTC

cvs commit: jakarta-slide/testsuite/testsuite/junit Tprocessor.dtd

juergen     02/03/06 08:32:38

  Modified:    testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor
                        TProcessors.java
               testsuite/testsuite/junit Tprocessor.dtd
  Log:
  added the possibility to define (and specify) a var definition at the response body, e.g. <body varDefinition="XXXX" varPath="multistatus/response/href" >
  
  Revision  Changes    Path
  1.15      +100 -54   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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TProcessors.java	5 Mar 2002 10:21:01 -0000	1.14
  +++ TProcessors.java	6 Mar 2002 16:32:38 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java,v 1.14 2002/03/05 10:21:01 juergen Exp $
  - * $Revision: 1.14 $
  - * $Date: 2002/03/05 10:21:01 $
  + * $Header: /home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java,v 1.15 2002/03/06 16:32:38 juergen Exp $
  + * $Revision: 1.15 $
  + * $Date: 2002/03/06 16:32:38 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * Main class to performe a test case and check and report the results
    *
    * @author Software AG
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public class TProcessors {
       
  @@ -527,21 +527,22 @@
               
               client.executeMethod(method);
               client.endSession();
  -//          System.out.println("Status Code "+ m.getStatusCode());
  -//          System.out.println("Status Text "+ m.getStatusText());
  +            //          System.out.println("Status Code "+ m.getStatusCode());
  +            //          System.out.println("Status Text "+ m.getStatusText());
               
               
  -//          if (method instanceof PropFindMethod) {
  -//              System.out.println("###################");
  -//              System.out.println("###################");
  -//              System.out.println("###################");
  -//              if (((PropFindMethod)method).getResponseDocument() != null) System.out.println("body " + getElementString(((PropFindMethod)method).getResponseDocument().getDocumentElement()));
  -//              System.out.println("###################");
  -//              System.out.println("###################");
  -//              System.out.println("###################");
  -//          }
  +            //          if (method instanceof PropFindMethod) {
  +            //              System.out.println("###################");
  +            //              System.out.println("###################");
  +            //              System.out.println("###################");
  +            //              if (((PropFindMethod)method).getResponseDocument() != null) System.out.println("body " + getElementString(((PropFindMethod)method).getResponseDocument().getDocumentElement()));
  +            //              System.out.println("###################");
  +            //              System.out.println("###################");
  +            //              System.out.println("###################");
  +            //          }
               
  -            fillAutomatedVariables(method);
  +            
  +            fillVariables(method, elt.getChild("response").getChild("body"));
               
               result = (responseAssert(method, elt));
               
  @@ -608,7 +609,7 @@
        * @return true if the file name is valid
        */
       private  boolean checkFileName(String name){
  -//      System.out.println("Checking " + name + " = " + new File(name).isFile());
  +        //      System.out.println("Checking " + name + " = " + new File(name).isFile());
           return new File(name).isFile();
       }
       
  @@ -671,28 +672,28 @@
           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);
  +            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();
               }
               
  -            result = output.toString();
  -            input.close();
  -            output.close();
  -            
  -        }
  -        catch (Exception e) {
  -            e.printStackTrace();
  -        }
  -        
               
           }
           return result;
  @@ -762,7 +763,7 @@
        * @param List
        */
       private  HttpMethod fillMethodName(Element methodElement, HttpMethod method)
  -     throws Exception {
  +        throws Exception {
           StringTokenizer st = new StringTokenizer(replaceKnownVariable(methodElement));
           method = HttpMethodFactory(st.nextToken(), st.nextToken());
           return method;
  @@ -1097,37 +1098,75 @@
       
       
       
  +    /**
  +     *
  +     */
  +    private void fillVariables (HttpMethod m, Element body) {
  +        if (m instanceof XMLResponseMethodBase){
  +            fillAutomatedVariables((XMLResponseMethodBase)m);
  +            fillSpecifiedVariable((XMLResponseMethodBase)m, body);
  +        }
  +    }
  +    
       
       
       
       /**
        *
        */
  -    private void fillAutomatedVariables (HttpMethod m) {
  -        List possibleAutomatedVariables;
  +    private void fillSpecifiedVariable (XMLResponseMethodBase m, Element body) {
           
  -        if (m instanceof XMLResponseMethodBase){
  +        if (body == null) return;  // no body, nothing to fill
  +        
  +        try {
               
  -            try{
  +            String searchPattern = body.getAttributeValue("varPath");
  +            String varName = body.getAttributeValue("varDefinition");
  +            if ((searchPattern != null) && (varName != null) && m.getResponseDocument() != null){
                   
  -                List possible = xdavConfiguration.getPropertyList("automatedVariables", m.getName());
  -                Iterator iter = possible.iterator();
  -                while (iter.hasNext()){
  -                    String searchPattern = (String)iter.next();
  -                    if (((XMLResponseMethodBase)m).getResponseDocument() != null){
  -                        fillAutomatedVariables(findElementList(new org.jdom.input.DOMBuilder().build(((XMLResponseMethodBase)m).getResponseDocument().getDocumentElement()),
  -                                                               searchPattern));
  -                    }
  +                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();
               }
  +            
  +            
  +        } 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()){
  +                String searchPattern = (String)iter.next();
  +                if (((XMLResponseMethodBase)m).getResponseDocument() != null){
  +                    fillAutomatedVariables(findElementList(getMethodElement(m), searchPattern));
  +                }
  +            }
  +            
  +            
  +        } catch(Exception e){
  +            e.printStackTrace();
  +        }
  +        
  +    }
  +    
  +    
  +    
  +    
       private void fillAutomatedVariables (List valueList) {
           Iterator iter = valueList.iterator();
           while (iter.hasNext()){
  @@ -1140,6 +1179,13 @@
       }
       
       
  +    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();
  @@ -1190,7 +1236,7 @@
       
       private InputStream expectedResponseAsStream(Element element)
           throws Exception {
  -            
  +        
           Element expectedResponse = element.getChild("response").getChild("body");
           InputStream result = null;
           if (binaryReadRequest(expectedResponse)) {
  @@ -1340,7 +1386,7 @@
        * If the method name is not known, null is returned
        */
       public static HttpMethod HttpMethodFactory(String methodName, String path)
  -     throws Exception {
  +        throws Exception {
           HttpMethod result = HttpMethodFactory(methodName);
           if (result != null){
               result.setPath(path);
  
  
  
  1.4       +1 -0      jakarta-slide/testsuite/testsuite/junit/Tprocessor.dtd
  
  Index: Tprocessor.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/testsuite/testsuite/junit/Tprocessor.dtd,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Tprocessor.dtd	25 Feb 2002 10:00:10 -0000	1.3
  +++ Tprocessor.dtd	6 Mar 2002 16:32:38 -0000	1.4
  @@ -38,6 +38,7 @@
   <!ELEMENT body (#PCDATA)>
   <!ATTLIST body
   	varDefinition CDATA #IMPLIED
  +	varPath CDATA #IMPLIED
   	varUsage CDATA #IMPLIED
   	fileReference CDATA #IMPLIED
   	fileEncoding CDATA #IMPLIED
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>