Author: bfoster
Date: Sat Jun 4 02:30:33 2011
New Revision: 1131306
URL: http://svn.apache.org/viewvc?rev=1131306&view=rev
Log:
- formatting
- unit-tests improved
- bug fixes exposed by unit-tests
--------------------
OODT-194
Modified:
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/Protocol.java
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/DownloadAction.java
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/MockProtocol.java
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java
Modified:
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/Protocol.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/Protocol.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/Protocol.java
(original)
+++
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/Protocol.java
Sat Jun 4 02:30:33 2011
@@ -40,6 +40,10 @@ public interface Protocol {
public void cd(ProtocolFile file) throws ProtocolException;
+ public void cdRoot() throws ProtocolException;
+
+ public void cdHome() throws ProtocolException;
+
public void get(ProtocolFile fromFile, File toFile) throws
ProtocolException;
public void put(File fromFile, ProtocolFile toFile) throws
ProtocolException;
Modified:
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
(original)
+++
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/ProtocolFile.java
Sat Jun 4 02:30:33 2011
@@ -16,9 +16,6 @@
*/
package org.apache.oodt.cas.protocol;
-//JDK imports
-import java.io.File;
-
//APACHE imports
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
@@ -32,14 +29,16 @@ public class ProtocolFile {
public static final String SEPARATOR = "/";
- public static final ProtocolFile ROOT = new ProtocolFile(SEPARATOR,
true);
- public static final ProtocolFile HOME = new ProtocolFile(
- new File("").getAbsolutePath(), true);
-
private String path;
private boolean isDir;
-
+ private ProtocolFile parent;
+
public ProtocolFile(String path, boolean isDir) {
+ this(null, path, isDir);
+ }
+
+ public ProtocolFile(ProtocolFile parent, String path, boolean isDir) {
+ this.parent = parent;
this.isDir = isDir;
Validate.notNull(path, "ProtocolFile's path cannot be NULL");
this.path = path.length() > 0 && !path.equals(SEPARATOR) ?
StringUtils
@@ -71,11 +70,7 @@ public class ProtocolFile {
* @return The name of the file this path represents
*/
public String getName() {
- if (this.equals(ROOT) || !path.contains(SEPARATOR)) {
- return path;
- } else {
- return path.substring(path.lastIndexOf(SEPARATOR) + 1);
- }
+ return path.substring(path.lastIndexOf(SEPARATOR) + 1);
}
/**
@@ -94,15 +89,31 @@ public class ProtocolFile {
* @return The parent {@link ProtocolFile}
*/
public ProtocolFile getParent() {
- if (this.equals(ROOT) || !path.contains(SEPARATOR)) {
- return null;
+ if (parent != null) {
+ return parent;
} else {
- return new ProtocolFile(path.substring(0,
- path.lastIndexOf(SEPARATOR)), true);
+ int index = StringUtils.lastIndexOf(path, SEPARATOR);
+ return (index > 0) ? new
ProtocolFile(StringUtils.substring(path, 0, index), true) : null;
}
}
/**
+ * Get Absolute pathed {@link ProtocolFile} version of this {@link
ProtocolFile}.
+ *
+ * @return the absolute pathed version of this {@link ProtocolFile}
+ */
+ public ProtocolFile getAbsoluteFile() {
+ if (this.isRelative()) {
+ ProtocolFile parent = this.getParent();
+ if (parent != null) {
+ return new
ProtocolFile(StringUtils.chomp(parent.getPath(), SEPARATOR)
+ + SEPARATOR + this.getPath(),
this.isDir());
+ }
+ }
+ return this;
+ }
+
+ /**
* {@inheritDoc}
*/
public int hashCode() {
@@ -115,7 +126,9 @@ public class ProtocolFile {
public boolean equals(Object path) {
if (path instanceof ProtocolFile) {
ProtocolFile p = (ProtocolFile) path;
- return (p.getPath().equals(this.getPath()) && p.isDir()
== this.isDir());
+ return (p.getAbsoluteFile().getPath()
+
.equals(this.getAbsoluteFile().getPath()) && p.isDir() == this
+ .isDir());
}
return false;
}
@@ -124,6 +137,6 @@ public class ProtocolFile {
* {@inheritDoc}
*/
public String toString() {
- return path;
+ return "{parent = '" + this.parent + "', path = '" + path + "',
isDir = '" + isDir + "'}";
}
}
Modified:
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/DownloadAction.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/DownloadAction.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/DownloadAction.java
(original)
+++
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/DownloadAction.java
Sat Jun 4 02:30:33 2011
@@ -40,7 +40,7 @@ public class DownloadAction extends Prot
public void performAction(ProtocolManager protocolManager) throws
Exception {
usedProtocol = createProtocol(protocolManager);
ProtocolFile fromFile = createProtocolFile();
- String toFilename = fromFile.equals(ProtocolFile.ROOT)
+ String toFilename = fromFile.equals(ProtocolFile.SEPARATOR)
|| fromFile.getName().isEmpty() ? uri.getHost()
: fromFile
.getName();
File toFile = (toDir != null) ? new File(toDir, toFilename) :
new File(toFilename);
Modified:
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java
(original)
+++
oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java
Sat Jun 4 02:30:33 2011
@@ -55,15 +55,15 @@ public class BasicProtocolVerifier imple
protocol.connect(site.getHost(), auth);
// Test ls, cd, and pwd
- protocol.cd(ProtocolFile.HOME);
+ protocol.cdHome();
ProtocolFile home = protocol.pwd();
protocol.ls();
if (uriTestCdMap.containsKey(site)) {
protocol.cd(uriTestCdMap.get(site));
} else {
- protocol.cd(ProtocolFile.ROOT);
+ protocol.cdHome();
}
- protocol.cd(ProtocolFile.HOME);
+ protocol.cdHome();
// Verify again at home directory
if (home == null || !home.equals(protocol.pwd()))
Modified:
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/MockProtocol.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/MockProtocol.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/MockProtocol.java
(original)
+++
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/MockProtocol.java
Sat Jun 4 02:30:33 2011
@@ -79,6 +79,14 @@ public class MockProtocol implements Pro
public void cd(ProtocolFile file) throws ProtocolException {
cwd = file;
}
+
+ public void cdHome() throws ProtocolException {
+ cwd = new ProtocolFile("", true);
+ }
+
+ public void cdRoot() throws ProtocolException {
+ cwd = new ProtocolFile("/", true);
+ }
public void get(ProtocolFile fromFile, File toFile)
throws ProtocolException {
Modified:
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java
URL:
http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java?rev=1131306&r1=1131305&r2=1131306&view=diff
==============================================================================
---
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java
(original)
+++
oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/TestProtocolFile.java
Sat Jun 4 02:30:33 2011
@@ -33,7 +33,6 @@ public class TestProtocolFile extends Te
String filePath = ProtocolFile.SEPARATOR + "path" +
ProtocolFile.SEPARATOR + "to" + ProtocolFile.SEPARATOR + "file";
ProtocolFile pFile = new ProtocolFile(filePath, false);
assertEquals(filePath, pFile.getPath());
- assertEquals(pFile.getPath(), pFile.toString());
assertEquals("file", pFile.getName());
assertFalse(pFile.isDir());
assertFalse(pFile.isRelative());
@@ -41,25 +40,15 @@ public class TestProtocolFile extends Te
// Test Parent file
String parentPath = ProtocolFile.SEPARATOR + "path" +
ProtocolFile.SEPARATOR + "to";
assertEquals(parentPath, pFile.getParent().getPath());
- assertEquals(pFile.getParent().getPath(),
pFile.getParent().toString());
assertEquals("to", pFile.getParent().getName());
assertTrue(pFile.getParent().isDir());
assertFalse(pFile.getParent().isRelative());
}
- public void testRoot() {
- assertEquals(ProtocolFile.SEPARATOR,
ProtocolFile.ROOT.getPath());
- assertNull(ProtocolFile.ROOT.getParent());
- assertEquals(ProtocolFile.ROOT.getPath(),
ProtocolFile.ROOT.getName());
- assertEquals(ProtocolFile.ROOT.getPath(),
ProtocolFile.ROOT.toString());
- assertTrue(ProtocolFile.ROOT.isDir());
- assertFalse(ProtocolFile.ROOT.isRelative());
- }
-
- public void testHome() {
- assertEquals(new File("").getAbsolutePath(),
ProtocolFile.HOME.getPath());
- assertEquals(ProtocolFile.HOME.getPath(),
ProtocolFile.HOME.toString());
- assertFalse(ProtocolFile.HOME.isRelative());
- assertTrue(ProtocolFile.HOME.isDir());
+ public void testEquals() {
+ assertEquals(new ProtocolFile("/test/directory", true), new
ProtocolFile(
+ new ProtocolFile("/test", true), "directory",
true));
+ assertEquals(new ProtocolFile(new ProtocolFile("/", true),
"repo", true), new ProtocolFile("/repo", true));
+ assertEquals(new ProtocolFile(new ProtocolFile("/", true), "",
true), new ProtocolFile("/", true));
}
}