juergen     2002/12/16 07:48:29

  Modified:    
testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor
                        TProcessors.java StreamResponseBodyAssert.java
  Log:
  Adaptions to the new Slide API (and commons http api).
  
  Revision  Changes    Path
  1.42      +47 -30    
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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TProcessors.java  27 Nov 2002 13:47:02 -0000      1.41
  +++ TProcessors.java  16 Dec 2002 15:48:29 -0000      1.42
  @@ -77,7 +77,6 @@
   import java.io.UnsupportedEncodingException;
   import java.util.ArrayList;
   import java.util.Date;
  -import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.List;
  @@ -88,6 +87,8 @@
   import org.apache.commons.httpclient.Header;
   import org.apache.commons.httpclient.HttpClient;
   import org.apache.commons.httpclient.HttpMethod;
  +import org.apache.commons.httpclient.HttpState;
  +import org.apache.commons.httpclient.UsernamePasswordCredentials;
   import org.apache.slide.testsuite.testtools.tutil.TArgs;
   import org.apache.slide.testsuite.testtools.tutil.XConf;
   import org.apache.util.URLUtil;
  @@ -100,6 +101,7 @@
   import org.apache.webdav.lib.methods.DeleteMethod;
   import org.apache.webdav.lib.methods.GetMethod;
   import org.apache.webdav.lib.methods.HeadMethod;
  +import org.apache.webdav.lib.methods.HttpRequestBodyMethodBase;
   import org.apache.webdav.lib.methods.LabelMethod;
   import org.apache.webdav.lib.methods.LockMethod;
   import org.apache.webdav.lib.methods.MkWorkspaceMethod;
  @@ -238,6 +240,25 @@
        */
       public static void main(String[] args)
       {
  +
  +
  +//        {
  +//        HttpClient client = new HttpClient();
  +//        HttpState state = new WebdavState();
  +//        Credentials cred = new UsernamePasswordCredentials("guest", "guest");
  +//        client.startSession("tamino.demozone.softwareag.com", 80);
  +//        state.setCredentials(null, cred);
  +//        client.setState(state);
  +//        HeadMethod method = new 
HeadMethod("/taminowebdavserver/yourstore/PictureDemo");
  +//            try {
  +//                client.executeMethod(method);
  +//                client.endSession();
  +//            } catch (java.io.IOException e) {
  +//                e.printStackTrace();
  +//            }
  +//        }
  +
  +
           if (!mainExecuter(args, null, null)) {
               System.exit (-1);
           }
  @@ -554,19 +575,13 @@
   
           HttpClient client = new HttpClient();
           WebdavState state = new WebdavState();
  -        state.setAuthenticateToken("Basic realm=xxx"); // currently only basic is 
supported
  -        state.setURLDecodingCharset(defaultUrlEncoding);
  -        state.setURLEncodingCharset(defaultUrlEncoding);
  +        Credentials cred = new UsernamePasswordCredentials(user, password);
  +//        state.setURLDecodingCharset(defaultUrlEncoding);
  +//        state.setURLEncodingCharset(defaultUrlEncoding);
           client.startSession((String)startUp.get("host"),
  -                                ((Integer)startUp.get("port") ).intValue(),
  -                            new Credentials(user, password));
  +                            ((Integer)startUp.get("port") ).intValue());
  +        state.setCredentials(null, cred);
           client.setState(state);
  -        if (tracingRequest.indexOf("client") != (-1)) {
  -            client.setDebug(100);
  -        }
  -        else {
  -            client.setDebug(0);
  -        }
   
           //              System.out.println("############### user " + user);
           //              System.out.println("############### pwd  " + password);
  @@ -893,7 +908,7 @@
        */
       private  HttpMethod fillHeader (Element header, HttpMethod method){
           Header headerToSet = getResponseHeader(header);
  -        method.setHeader(headerToSet.getName(), headerToSet.getValue());
  +        method.setRequestHeader(headerToSet.getName(), headerToSet.getValue());
           return method;
       }
   
  @@ -915,18 +930,20 @@
           if (method instanceof PutMethod && binaryReadRequest(element)) {
               File input = new File(getFileReferenceName(element));
               if (!input.exists()) throw new Exception("File " + 
getFileReferenceName(element) + " does not exist");
  -            method.setHeader("Content-Length", ""+input.length());
  -            ((PutMethod)method).sendData(input);
  +            method.setRequestHeader("Content-Length", ""+input.length());
  +            ((PutMethod)method).setRequestBody(input);
           }
           else {
               try {
                   String source = replaceKnownVariable(element);
                   if (method instanceof PutMethod) {
                       byte[] input = source.getBytes(getFileEncoding(element));
  -                    method.setHeader("Content-Length", ""+input.length);
  -                    ((PutMethod)method).sendData(input);
  +                    method.setRequestHeader("Content-Length", ""+input.length);
  +                    ((PutMethod)method).setRequestBody(input);
                   } else {
  -                    method.setQuery(source);
  +                    if (method instanceof HttpRequestBodyMethodBase) {
  +                        ((HttpRequestBodyMethodBase)method).setRequestBody(source);
  +                    }
                   }
               }
               catch (UnsupportedEncodingException e) { throw new 
Exception(e.toString());}
  @@ -1077,19 +1094,19 @@
   
               Header  headToMatch      = (Header) header.next();
               boolean oneHeaderMatched = allowHeaders.contains(headToMatch.getName()) 
||  // head to be compared
  -                verifyOneHeader(headToMatch, m.getHeaders());     // compare it
  +                verifyOneHeader(headToMatch, m.getResponseHeaders());     // 
compare it
   
               if (!oneHeaderMatched){
                   if (result) {
                       xmlresult.writeElementStart("headerErrors");
                   }
  -                if (m.getHeader(headToMatch.getName()) == null){
  +                if (m.getResponseHeader(headToMatch.getName()) == null){
                       xmlresult.writeElement("nonExistingHeader", "name", 
headToMatch.getName(), headToMatch.getValue().trim());
                   }
                   else{
                       xmlresult.writeElementStart("nonMatchingHeader",  "name", 
headToMatch.getName());
                       xmlresult.writeElement("expectedValue", 
headToMatch.getValue().trim());
  -                    xmlresult.writeElement("receivedValue", 
m.getHeader(headToMatch.getName()).getValue().trim());
  +                    xmlresult.writeElement("receivedValue", 
m.getResponseHeader(headToMatch.getName()).getValue().trim());
                       xmlresult.writeElementEnd("nonMatchingHeader");
                   }
               }
  @@ -1107,10 +1124,10 @@
   
   
   
  -    private boolean  verifyOneHeader(Header h, Enumeration enum){
  +    private boolean  verifyOneHeader(Header h, Header[] headers){
           boolean result = false;
  -        while(enum.hasMoreElements()){
  -            Header temp1 = ((Header) enum.nextElement());
  +        for (int counter=0; counter<headers.length; counter++) {
  +            Header temp1 = (Header) headers[counter];
               String hName1 = temp1.getName();
               String hValue1 = temp1.getValue();
               if(hName1.equalsIgnoreCase(h.getName()) &&
  @@ -1248,7 +1265,7 @@
                   String varName = headerElement.getAttributeValue("varDefinition");
                   if (varName != null && !varName.trim().equals("")) {
                       String headerName = 
getResponseHeader(headerElement.getText()).getName();
  -                    Header h = m.getHeader(headerName);
  +                    Header h = m.getResponseHeader(headerName);
                       String varValue ;
                       if (h != null) varValue = h.getValue();
                       else           varValue = "header " + headerName + " not found";
  @@ -1457,7 +1474,7 @@
           } else if (m instanceof UpdateMethod){
               result = new UpdateAssert ((XMLResponseMethodBase) m, 
expectedResponseAsDOM(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes);
           } else if (m instanceof GetMethod){
  -            if (m.getHeader("Content-Type") == null || 
!m.getHeader("Content-Type").getValue().equals("text/xml")) {
  +            if (m.getResponseHeader("Content-Type") == null || 
!m.getResponseHeader("Content-Type").getValue().equals("text/xml")) {
                   result = new GetAssert ( m, 
expectedResponseAsStream(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes);
               } else {
                   result = new GetXMLAssert ( m, 
expectedResponseAsStream(expectedResponseElement), xdavConfiguration, xmlresult, 
expectedResponseCodes);
  
  
  
  1.10      +5 -8      
jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/StreamResponseBodyAssert.java
  
  Index: StreamResponseBodyAssert.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/StreamResponseBodyAssert.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StreamResponseBodyAssert.java     27 Nov 2002 13:47:02 -0000      1.9
  +++ StreamResponseBodyAssert.java     16 Dec 2002 15:48:29 -0000      1.10
  @@ -99,11 +99,8 @@
   
           this.method = method;
           this.expectedBody = expectedBody;
  -        // ugly quick hack to read the body
           try {
  -            if (method.hasResponseBody() && method instanceof GetMethod) {
  -                this.receivedBody = ((GetMethod)method).getData();
  -            }
  +                this.receivedBody = method.getResponseBodyAsStream();
           }
           catch (Exception e) {
               e.printStackTrace();
  
  
  

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

Reply via email to