Author: bfoster
Date: Sat Jun  4 02:31:41 2011
New Revision: 1131308

URL: http://svn.apache.org/viewvc?rev=1131308&view=rev
Log:

- formatting
- unit-tests improved
- bug fixes exposed by unit-tests

--------------------
OODT-194

Modified:
    
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
    
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
    
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java
    
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpFile.java
    
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
    
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java

Modified: 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
 Sat Jun  4 02:31:41 2011
@@ -34,20 +34,18 @@ public class HttpFile extends ProtocolFi
        private static final long serialVersionUID = -7780059889413081800L;
 
        private URL link;
-       private HttpFile parent;
 
-       public HttpFile(String virtualPath, boolean isDir, URL link, HttpFile 
parent) {
-               super(virtualPath, isDir);
+       public HttpFile(String virtualPath, boolean isDir, URL link) {
+               this(null, virtualPath, isDir, link);
+       }
+       
+       public HttpFile(HttpFile parent, String virtualPath, boolean isDir, URL 
link) {
+               super(parent, virtualPath, isDir);
                Validate.notNull(link, "URL link must not be NULL");
                this.link = link;
-               this.parent = parent;
        }
 
        public URL getLink() {
                return this.link;
        }
-
-       public ProtocolFile getParent() {
-               return this.parent;
-       }
 }

Modified: 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
 Sat Jun  4 02:31:41 2011
@@ -63,7 +63,7 @@ public class HttpProtocol implements Pro
        HttpFile httpFile = null;
        if (!(file instanceof HttpFile)) {
                URL link = HttpUtils.resolveUri(currentFile.getLink().toURI(), 
file.getPath()).toURL();
-                       httpFile = new HttpFile(file.getPath(), file.isDir(), 
link, null);
+                       httpFile = new HttpFile(link.getPath(), file.isDir(), 
link);
       } else {
         httpFile = (HttpFile) file;
       }
@@ -78,13 +78,21 @@ public class HttpProtocol implements Pro
           + e.getMessage(), e);
     }
   }
+  
+  public void cdRoot() {
+       currentFile = parentFile;
+  }
+  
+  public void cdHome() {
+       cdRoot();
+  }
 
   public void connect(String host, Authentication auth)
       throws ProtocolException {
     try {
       URL url = new URL("http://"; + host + "/");
       url.openStream().close();
-      currentFile = parentFile = new HttpFile("/", true, url, null);
+      currentFile = parentFile = new HttpFile("/", true, url);
       isConnected = true;
     } catch (Exception e) {
       throw new ProtocolException("Failed to connect to http://"; + host + " : "
@@ -174,7 +182,7 @@ public class HttpProtocol implements Pro
 
         // If redirection took place, then change the ProtocolFile's URL.
         if (HttpUtils.checkForRedirection(file.getLink(), conn.getURL())) {
-          file = new HttpFile(file.getPath(), file.isDir(), conn.getURL(), 
file);
+          file = new HttpFile(file, file.getPath(), file.isDir(), 
conn.getURL());
         }
 
         // Find links in URL.
@@ -311,8 +319,7 @@ public class HttpProtocol implements Pro
       throw new Exception("Must specify a url to download: --url <url>");
 
     URL url = new URL(urlString);
-    ProtocolFile urlFile = new HttpFile(url.getPath(),
-        false, url, null);
+    ProtocolFile urlFile = new HttpFile(url.getPath(), false, url);
     File toFile = new File(downloadToDir, urlFile.getName());
     toFile = toFile.getAbsoluteFile();
     toFile.createNewFile();

Modified: 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java
 Sat Jun  4 02:31:41 2011
@@ -106,13 +106,13 @@ public class HttpUtils {
                        String link = matcher.group(2).trim();
                        String virtualPath = matcher.group(3).trim();
                        URL url = resolveUri(file.getLink().toURI(), 
link).toURL();
-                       httpFiles.add(new HttpFile(link, isDirectory(url, 
virtualPath), url, file));
+                       httpFiles.add(new HttpFile(file, link, isDirectory(url, 
virtualPath), url));
                }
                matcher = 
LAZY_LINK_PATTERN.matcher(HttpUtils.readUrl(connect(file.getLink())));
                while (matcher.find()) {
                        String link = matcher.group(2).trim();
                        URL url = resolveUri(file.getLink().toURI(), 
link).toURL();
-                       httpFiles.add(new HttpFile(link, isDirectory(url, 
link), url, file));
+                       httpFiles.add(new HttpFile(file, link, isDirectory(url, 
link), url));
                }
                return httpFiles;
        }

Modified: 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpFile.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpFile.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpFile.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpFile.java
 Sat Jun  4 02:31:41 2011
@@ -30,8 +30,8 @@ import junit.framework.TestCase;
 public class TestHttpFile extends TestCase {
 
        public void testInitialState() throws MalformedURLException {
-               HttpFile parent = new HttpFile("/path/to", false, new 
URL("http://some-site";), null);
-               HttpFile file = new HttpFile("/path/to/file", false, new 
URL("http://some-site";), parent);
+               HttpFile parent = new HttpFile("/path/to", false, new 
URL("http://some-site";));
+               HttpFile file = new HttpFile(parent, "/path/to/file", false, 
new URL("http://some-site";));
                assertNotNull(file.getLink());
                assertEquals("http://some-site";, file.getLink().toString());
                assertFalse(file.isDir());
@@ -42,11 +42,11 @@ public class TestHttpFile extends TestCa
        
        public void testNullCase() throws MalformedURLException {
                try {
-                        new HttpFile(null, false, new URL("http://some-site";), 
null);
+                        new HttpFile(null, false, new URL("http://some-site";));
                        fail("Should have thrown an IllegalArgumentException");
                } catch (IllegalArgumentException e) {}
                try {
-                        new HttpFile("/path/to/file", false, null, null);
+                        new HttpFile("/path/to/file", false, null);
                        fail("Should have thrown an IllegalArgumentException");
                } catch (IllegalArgumentException e) {}
        }

Modified: 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
 Sat Jun  4 02:31:41 2011
@@ -65,9 +65,11 @@ public class TestHttpProtocol extends Te
                HttpProtocol httpProtocol = new HttpProtocol();
                httpProtocol.connect("svn.apache.org", new NoAuthentication());
                assertTrue(httpProtocol.connected());
-               ProtocolFile gotoDir = new 
ProtocolFile("repos/asf/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http",
 true);
+               ProtocolFile gotoDir = new ProtocolFile(httpProtocol.pwd(), 
"repos/asf/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http",
 true);
                httpProtocol.cd(gotoDir);
                ProtocolFile currentDir = httpProtocol.pwd();
+               System.out.println(gotoDir.getAbsoluteFile());
+               System.out.println(currentDir.getAbsoluteFile());
                assertEquals(gotoDir, currentDir);
        }
        

Modified: 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
URL: 
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java?rev=1131308&r1=1131307&r2=1131308&view=diff
==============================================================================
--- 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
 (original)
+++ 
oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
 Sat Jun  4 02:31:41 2011
@@ -151,7 +151,7 @@ public class TestHttpUtils extends TestC
        
        public void testFindLinks() throws MalformedURLException, IOException, 
URISyntaxException {
                URL url = new URL(APACHE_SVN_SITE + PARENT_URL_OF_THIS_TEST);
-               HttpFile parent = new HttpFile(PARENT_URL_OF_THIS_TEST, true, 
url, null);
+               HttpFile parent = new HttpFile(PARENT_URL_OF_THIS_TEST, true, 
url);
                HttpURLConnection conn = HttpUtils.connect(url);
                List<HttpFile> httpFiles = HttpUtils.findLinks(parent);
                boolean foundThisTest = false;


Reply via email to