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 re...@apache.org on 2001/01/21 21:34:59 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests TestDOMUtils.java

remm        01/01/21 12:34:59

  Modified:    src/webdav/client/src/org/apache/webdav/cmd Main.java
               src/webdav/client/src/org/apache/webdav/lib
                        WebdavClient.java
               src/webdav/client/src/org/apache/webdav/lib/methods
                        GetMethod.java
               src/webdav/client/src/org/apache/webdav/lib/tests
                        TestCookie.java
               src/webdav/client/src/org/apache/webdav/lib/util/tests
                        TestDOMUtils.java
  Log:
  - Updated tests to JUnit 3.5. I don't think there should be a main method in the
    test classes instead, since the JUnit API for running it seems to be a moving
    target (it's easier to update the scripts in only one place).
  - Merge API patches submitted by Sung-Gu Park. The startSession() call no
    longer throws IOException, which can cause some compilation errors in
    programs which are using the API (although they are very easy to fix).
  - Modify the GetMethod so that you can specify the local temp file to use.
    Also URL enocde the file path. That patch was submitted by Sung-Gu Park.
  
  Revision  Changes    Path
  1.6       +4 -14     jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Main.java	2000/12/20 01:24:19	1.5
  +++ Main.java	2001/01/21 20:34:56	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v 1.5 2000/12/20 01:24:19 daveb Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/12/20 01:24:19 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/cmd/Main.java,v 1.6 2001/01/21 20:34:56 remm Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/01/21 20:34:56 $
    *
    * ====================================================================
    *
  @@ -83,7 +83,7 @@
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class Main {
   
  @@ -640,20 +640,10 @@
               // Ready for interactive commandline
               ready = true;
           
  -        } catch (UnknownHostException uhe) { 
  -            uhe.getMessage();
  -            System.err.println
  -                ("Unable to connect to remote host: Unknown Host ");
  -            System.exit(1);
           } catch (IllegalArgumentException iae) {
               iae.getMessage();
               System.err.println
                   ("Unable to connect to remote host: Out of Port");
  -            System.exit(1);
  -        } catch (ConnectException ce) {
  -            ce.getMessage();
  -            System.err.println
  -                ("Unable to connect to remote host: Connection refused");
               System.exit(1);
           } catch( Exception se ) {
               System.out.println("Error on startup: " + se + "\n");
  
  
  
  1.18      +49 -7     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java
  
  Index: WebdavClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- WebdavClient.java	2001/01/13 16:34:46	1.17
  +++ WebdavClient.java	2001/01/21 20:34:57	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.17 2001/01/13 16:34:46 remm Exp $
  - * $Revision: 1.17 $
  - * $Date: 2001/01/13 16:34:46 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavClient.java,v 1.18 2001/01/21 20:34:57 remm Exp $
  + * $Revision: 1.18 $
  + * $Date: 2001/01/21 20:34:57 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import java.text.SimpleDateFormat;
   import java.net.Socket;
   import java.net.UnknownHostException;
  +import java.net.URL;
   import org.apache.webdav.lib.methods.WebdavMethod;
   
   /**
  @@ -105,6 +106,25 @@
           new SimpleDateFormat(DATE_FORMAT);
       
       
  +    // ----------------------------------------------------------- Constructors
  +    
  +    
  +    public WebdavClient() {
  +        startSession();
  +    }
  +    
  +    
  +    public WebdavClient(URL url) {
  +        startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort());
  +    }
  +    
  +    
  +    public WebdavClient(URL url, String user, String password) {
  +        this(url);
  +        setCredentials(new Credentials(user, password));
  +    }
  +    
  +    
       // ----------------------------------------------------- Instance Variables
       
       
  @@ -198,6 +218,30 @@
       }
       
       
  +    /**
  +     * Get the session host.
  +     */
  +    public String getHost() {
  +        return sessionHost;
  +    }
  +    
  +    
  +    /**
  +     * Get the session port.
  +     */
  +    public int getPort() {
  +        return sessionPort;
  +    }
  +    
  +    
  +    /**
  +     * Get the state for lock information.
  +     */
  +    public State getState() {
  +        return state;
  +    }
  +    
  +    
       // --------------------------------------------------------- Public Methods
       
       
  @@ -351,8 +395,7 @@
       /**
        * Start a session.
        */
  -    public void startSession() 
  -        throws IOException {
  +    public void startSession() {
           
           state = new State();
           this.sessionHost = "localhost";
  @@ -364,8 +407,7 @@
       /**
        * Start a session.
        */
  -    public void startSession(String host, int port) 
  -        throws UnknownHostException, IOException {
  +    public void startSession(String host, int port) {
           
           if (debug > 0)
               System.out.println("Start session : Host:" + host 
  
  
  
  1.5       +70 -5     jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java
  
  Index: GetMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GetMethod.java	2000/12/11 02:06:00	1.4
  +++ GetMethod.java	2001/01/21 20:34:58	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v 1.4 2000/12/11 02:06:00 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/12/11 02:06:00 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/methods/GetMethod.java,v 1.5 2001/01/21 20:34:58 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/01/21 20:34:58 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   
   import java.io.*;
   import java.util.*;
  +import java.net.URLEncoder;
   import org.apache.webdav.lib.State;
   import org.apache.webdav.lib.Header;
   import org.apache.webdav.lib.WebdavStatus;
  @@ -74,6 +75,7 @@
    * GET Method.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  + * @author Sung-Gu Park
    */
   public class GetMethod
       extends WebdavMethodBase {
  @@ -129,6 +131,30 @@
       }
       
       
  +   /**
  +     * Method constructor.
  +     */
  +    public GetMethod(String path, String tempDir, String tempFile) {
  +        this(path);
  +        useDisk = true;
  +        setTempDir(tempDir);
  +        setTempFile(tempFile);
  +    }
  +
  +   /**
  +     * Method constructor.
  +     */
  +    public GetMethod(String path, boolean useDisk, String tempDir,
  +                     String tempFile) {
  +        this(path);
  +        setUseDisk(useDisk);
  +        if (useDisk) {
  +            setTempDir(tempDir);
  +            setTempFile(tempFile);
  +        }
  +    }
  +    
  +    
       // ----------------------------------------------------- Instance Variables
       
       
  @@ -156,6 +182,12 @@
       protected String tempDir = TEMP_DIR;
       
       
  +    /**
  +     * Temporary file to use.
  +     */
  +    protected String tempFile = null;
  +    
  +    
       // ------------------------------------------------------------- Properties
       
       
  @@ -209,6 +241,25 @@
       }
       
       
  +    /**
  +     * Temporary file setter.
  +     *
  +     * @param tempFile New value of tempFile
  +     */
  +    public void setTempFile(String tempFile) {
  +        checkNotUsed();
  +        this.tempFile = tempFile;
  +    }
  +    
  +    
  +    /**
  +     * Temporary file getter.
  +     */
  +    public String getTempFile() {
  +        return tempFile;
  +    }
  +    
  +    
       // --------------------------------------------------------- Public Methods
       
       
  @@ -290,9 +341,21 @@
               // Create a temporary file on the HD
               File dir = new File(tempDir);
               dir.mkdirs();
  +            
  +            String tempFileName = null;
  +            if (tempFile == null) {
  +                String encodedPath = URLEncoder.encode(getPath());
  +                int length = encodedPath.length();
  +                if (length > 240) {
  +                    encodedPath = encodedPath.substring(length - 200, length);
  +                }
  +                tempFileName = System.currentTimeMillis() + "-" 
  +                    + encodedPath + ".tmp";
  +            } else {
  +                tempFileName = tempFile;
  +            }
               
  -            String tempFileName = tempDir + getPath().hashCode() + ".tmp";
  -            fileData = new File(tempFileName);
  +            fileData = new File(tempDir, tempFileName);
               out = new FileOutputStream(fileData);
               
           } else {
  @@ -312,6 +375,8 @@
           
           if (!useDisk)
               memoryData = ((ByteArrayOutputStream) out).toByteArray();
  +        
  +        out.close();
           
       }
       
  
  
  
  1.2       +8 -7      jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/tests/TestCookie.java
  
  Index: TestCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/tests/TestCookie.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCookie.java	2000/12/21 04:22:39	1.1
  +++ TestCookie.java	2001/01/21 20:34:58	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/tests/TestCookie.java,v 1.1 2000/12/21 04:22:39 bcholmes Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/12/21 04:22:39 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/tests/TestCookie.java,v 1.2 2001/01/21 20:34:58 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/01/21 20:34:58 $
    *
    * ====================================================================
    *
  @@ -68,7 +68,7 @@
   
   import junit.ui.TestRunner;
   
  -import junit.util.StandardTestSuiteLoader;
  +import junit.runner.StandardTestSuiteLoader;
   
   import org.apache.webdav.lib.Cookie;
   import org.apache.webdav.lib.Header;
  @@ -78,7 +78,7 @@
    * Test cases for Cookie
    *
    * @author BC Holmes
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class TestCookie extends TestCase {
   
  @@ -97,11 +97,12 @@
           return new TestSuite(TestCookie.class);
       }
   
  -
  +/*
       public static void main(String[] args) {
           new TestRunner().start(new String[] { TestCookie.class.getName() },
                                  new StandardTestSuiteLoader());
       }
  +*/
   
       /**
        * Test basic parse (with various spacings
  @@ -177,4 +178,4 @@
   
           assert("Webdav exception should have been caught", exception != null);
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.5       +7 -7      jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests/TestDOMUtils.java
  
  Index: TestDOMUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests/TestDOMUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestDOMUtils.java	2000/12/10 05:07:55	1.4
  +++ TestDOMUtils.java	2001/01/21 20:34:59	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests/TestDOMUtils.java,v 1.4 2000/12/10 05:07:55 bcholmes Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/12/10 05:07:55 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/util/tests/TestDOMUtils.java,v 1.5 2001/01/21 20:34:59 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/01/21 20:34:59 $
    *
    * ====================================================================
    *
  @@ -81,9 +81,9 @@
   
   import junit.framework.*;
   
  -import junit.ui.TestRunner;
  +import junit.textui.TestRunner;
   
  -import junit.util.StandardTestSuiteLoader;
  +import junit.runner.StandardTestSuiteLoader;
   
   /**
    * Testcases for DOMUtils
  @@ -127,12 +127,12 @@
           return new TestSuite(TestDOMUtils.class);
       }
   
  -
  +/*
       public static void main(String[] args) {
           new TestRunner().start(new String[] { TestDOMUtils.class.getName() },
                                  new StandardTestSuiteLoader());
       }
  -
  +*/
   /*
       public void testIsDOM2Compliant() throws Exception {
           DocumentBuilderFactory factory =