You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/06/01 22:00:04 UTC

svn commit: r1130280 - in /oodt/branches/protocol/protocol-api/src: main/bin/ main/java/org/apache/oodt/cas/protocol/action/ main/java/org/apache/oodt/cas/protocol/auth/ main/java/org/apache/oodt/cas/protocol/config/ main/java/org/apache/oodt/cas/proto...

Author: bfoster
Date: Wed Jun  1 20:00:03 2011
New Revision: 1130280

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

- improved unit-tests and documentation

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

Added:
    oodt/branches/protocol/protocol-api/src/main/bin/
    oodt/branches/protocol/protocol-api/src/main/bin/protocol
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java   (with props)
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java   (with props)
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java   (with props)
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java   (with props)
Modified:
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/BasicVerifyAction.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/auth/Authentication.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/BasicAuthentication.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/NoAuthentication.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/ProtocolConfig.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/SpringProtocolConfig.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/system/ProtocolManager.java
    oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/verify/BasicProtocolVerifier.java
    oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml
    oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml
    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/auth/TestBasicAuthentication.java
    oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
    oodt/branches/protocol/protocol-api/src/testdata/test-protocol-config.xml

Added: oodt/branches/protocol/protocol-api/src/main/bin/protocol
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/bin/protocol?rev=1130280&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/bin/protocol (added)
+++ oodt/branches/protocol/protocol-api/src/main/bin/protocol Wed Jun  1 20:00:03 2011
@@ -0,0 +1,13 @@
+#!/bin/csh
+
+set args
+
+if ( $#args > 0 ) then
+	set args = "$*"
+endif
+
+${JAVA_HOME}/bin/java \
+	-Djava.ext.dirs=../lib \
+	-Djava.util.logging.config.file=../etc/logging.properties \
+	-Dorg.apache.oodt.cas.protocol.manager.config.file=../policy/protocol-config.xml \
+   	org.apache.oodt.cas.protocol.system.CLProtocolManager ${args}
\ No newline at end of file

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/BasicVerifyAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/BasicVerifyAction.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/BasicVerifyAction.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/action/BasicVerifyAction.java Wed Jun  1 20:00:03 2011
@@ -34,18 +34,20 @@ public class BasicVerifyAction extends P
 	private ProtocolVerifier verifier;
 	private ProtocolFactory factory;
 	
+	private boolean lastVerificationResult;
+	
 	@Override
 	public void performAction(ProtocolManager protocolManager) throws Exception {
 		if (factory != null) {
 			Protocol protocol = factory.newInstance();
-			if (verifier.verify(protocol, getSite(), getAuthentication())) {
+			if (lastVerificationResult = verifier.verify(protocol, getSite(), getAuthentication())) {
 				LOG.info("Protocol '" + protocol.getClass().getCanonicalName() + "' PASSED verification!");
 			} else {
 				LOG.severe("Protocol '" + protocol.getClass().getCanonicalName() + "' FAILED verification!");
 			}
 		} else {
 			Protocol protocol = protocolManager.getProtocolBySite(getSite(), getAuthentication(), verifier);
-			if (protocol != null) {
+			if (lastVerificationResult = protocol != null) {
 				LOG.info("Protocol '" + protocol.getClass().getCanonicalName() + "' PASSED verification!");
 			} else {
 				LOG.info("No Protocol determined, FAILED verification!");				
@@ -61,4 +63,7 @@ public class BasicVerifyAction extends P
 		this.factory = factory;
 	}
 	
+	protected boolean getLastVerificationResults() {
+		return lastVerificationResult;
+	}
 }

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=1130280&r1=1130279&r2=1130280&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 Wed Jun  1 20:00:03 2011
@@ -19,6 +19,7 @@ package org.apache.oodt.cas.protocol.act
 //JDK imports
 import java.io.File;
 import java.net.URI;
+import java.net.URISyntaxException;
 
 //OODT imports
 import org.apache.oodt.cas.protocol.Protocol;
@@ -32,26 +33,40 @@ import org.apache.oodt.cas.protocol.syst
  */
 public class DownloadAction extends ProtocolAction {
 	
-	private String urlString;
-	private String toDir;
+	protected URI uri;
+	protected String toDir;
+	protected Protocol usedProtocol;
 	
 	public void performAction(ProtocolManager protocolManager) throws Exception {
-		URI uri = new URI(urlString);
-		Protocol protocol = protocolManager.getProtocolBySite(
-				new URI(uri.getScheme(), uri.getHost(), null, null),
-				getAuthentication(),
-				null);
-		protocol.get(new ProtocolFile(uri.getPath(), false),
-				(toDir != null ? new File(toDir).getAbsoluteFile() : new File(
-						".").getAbsoluteFile()));
+		usedProtocol = createProtocol(protocolManager);
+		ProtocolFile fromFile = createProtocolFile();
+		String toFilename = fromFile.equals(ProtocolFile.ROOT)
+				|| fromFile.getName().isEmpty() ? uri.getHost() : fromFile
+				.getName();
+		File toFile = (toDir != null) ? new File(toDir, toFilename) : new File(toFilename);
+		usedProtocol.get(fromFile, toFile.getAbsoluteFile());
 	}
 	
-	public void setUrl(String urlString) {
-		this.urlString = urlString;
+	public void setUrl(String urlString) throws URISyntaxException {
+		uri = new URI(urlString);
 	}
 	
 	public void setToDir(String toDir) {
 		this.toDir = toDir;
 	}
 
+	protected Protocol getUsedProtocol() {
+		return usedProtocol;
+	}
+	
+	protected ProtocolFile createProtocolFile() throws URISyntaxException {
+		return new ProtocolFile(uri.getPath(), false);
+	}
+	
+	protected Protocol createProtocol(ProtocolManager protocolManager) throws URISyntaxException {
+		return protocolManager.getProtocolBySite(
+				new URI(uri.getScheme(), uri.getHost(), null, null),
+				getAuthentication(),
+				null);
+	}
 }

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/Authentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/Authentication.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/Authentication.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/Authentication.java Wed Jun  1 20:00:03 2011
@@ -26,5 +26,5 @@ public interface Authentication {
 	public String getUser();
 	
 	public String getPass();
-	
+
 }

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/BasicAuthentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/BasicAuthentication.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/BasicAuthentication.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/BasicAuthentication.java Wed Jun  1 20:00:03 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.oodt.cas.protocol.auth;
 
+import org.apache.commons.lang.Validate;
+
 /**
  * Basic username and password {@link Authentication}
  * 
@@ -28,6 +30,8 @@ public class BasicAuthentication impleme
 	private String pass;
 	
 	public BasicAuthentication(String user, String pass) {
+		Validate.notNull(user, "NULL user not allowed");
+		Validate.notNull(pass, "NULL pass not allowed");
 		this.user = user;
 		this.pass = pass;
 	}
@@ -39,5 +43,4 @@ public class BasicAuthentication impleme
 	public String getPass() {
 		return pass;
 	}
-
 }

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/NoAuthentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/NoAuthentication.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/NoAuthentication.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/auth/NoAuthentication.java Wed Jun  1 20:00:03 2011
@@ -24,10 +24,11 @@ package org.apache.oodt.cas.protocol.aut
 public class NoAuthentication implements Authentication {
 
 	public String getUser() {
-		return null;
+		return "";
 	}
 
 	public String getPass() {
-		return null;
+		return "";
 	}
+
 }

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/ProtocolConfig.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/ProtocolConfig.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/ProtocolConfig.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/ProtocolConfig.java Wed Jun  1 20:00:03 2011
@@ -31,6 +31,8 @@ import org.apache.oodt.cas.protocol.syst
  */
 public interface ProtocolConfig {
 
+	public List<ProtocolFactory> getAllFactories();
+	
 	public List<ProtocolFactory> getFactoriesBySite(URI site);
 	
 }

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/SpringProtocolConfig.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/SpringProtocolConfig.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/SpringProtocolConfig.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/config/SpringProtocolConfig.java Wed Jun  1 20:00:03 2011
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 
 //Spring imports
+import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.protocol.ProtocolFactory;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
@@ -39,6 +40,7 @@ public class SpringProtocolConfig implem
 	protected Map<String, List<ProtocolFactory>> factoryMap;
 	
 	public SpringProtocolConfig(String configFile) {
+		Validate.notNull(configFile, "SpringProtocolConfig configFile cannnot be NULL");
 		factoryMap = new HashMap<String, List<ProtocolFactory>>();
 		FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext(configFile);
 		Collection<ProtocolFactory> protocolFactories = appContext.getBeansOfType(ProtocolFactory.class).values();
@@ -52,7 +54,16 @@ public class SpringProtocolConfig implem
 		}
 	}
 	
+	public List<ProtocolFactory> getAllFactories() {
+		ArrayList<ProtocolFactory> factories = new ArrayList<ProtocolFactory>();
+		for (List<ProtocolFactory> groupOfFactories : factoryMap.values()) {
+			factories.addAll(groupOfFactories);
+		}
+		return factories;
+	}
+	
 	public List<ProtocolFactory> getFactoriesBySite(URI site) {
+		Validate.notNull(site, "URI site cannot be NULL");
 		List<ProtocolFactory> factories = factoryMap.get(site.getScheme());
 		if (factories == null) {
 			factories = new ArrayList<ProtocolFactory>();

Modified: oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/system/ProtocolManager.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/system/ProtocolManager.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/system/ProtocolManager.java (original)
+++ oodt/branches/protocol/protocol-api/src/main/java/org/apache/oodt/cas/protocol/system/ProtocolManager.java Wed Jun  1 20:00:03 2011
@@ -17,6 +17,7 @@
 package org.apache.oodt.cas.protocol.system;
 
 //OODT imports
+import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.protocol.auth.Authentication;
 import org.apache.oodt.cas.protocol.config.ProtocolConfig;
 import org.apache.oodt.cas.protocol.verify.ProtocolVerifier;
@@ -26,6 +27,7 @@ import org.apache.oodt.cas.protocol.Prot
 //JDK imports
 import java.net.URI;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
@@ -42,6 +44,7 @@ public class ProtocolManager {
 	private Map<URI, ProtocolFactory> verifiedMap;
 	
     public ProtocolManager(ProtocolConfig protocolConfig) {
+    	Validate.notNull(protocolConfig, "protocolConfig must not be NULL");
     	this.protocolConfig = protocolConfig;
     	verifiedMap = new HashMap<URI, ProtocolFactory>();
     }
@@ -50,15 +53,40 @@ public class ProtocolManager {
     	return protocolConfig;
     }
     
+    public List<ProtocolFactory> getFactories() {
+    	return protocolConfig.getAllFactories();
+    }
+    
+    /**
+     * Determines/creates the appropriate {@link Protocol} for the given site and {@link Authentication}.
+     * {@link ProtocolVerifier} is run and the first {@link Protocol} to pass its verification, will be
+     * returned already connected to the given site.  If a {@link Protocol} is returned once for a given
+     * site/Authentication combination, then it will be remember next time this method is called an
+     * {@link ProtocolVerifier} will not be run (assumed pass).
+     * 
+     * @param site The URI for which a {@link Protocol} will be created
+     * @param auth The connection {@link Authentication} to be used to connect to the given site
+     * @param verifier The {@link ProtocolVerifier} which any {@link Protocol} must pass to be returned 
+     * 			as the approved {@link Protocol} for the given site and {@link Authentication}; may be null,
+     * 			in which case as long as the {@link Protocol} can connect to the site it is considered a pass
+     * 			as will be returned
+     * @return A verified {@link Protocol} for the given site and {@link Authentication}, otherwise null if
+     * 	no {@link Protocol} could be determined.
+     */
     public Protocol getProtocolBySite(URI site, Authentication auth, ProtocolVerifier verifier) {
     	if (verifiedMap.containsKey(site)) {
     		return verifiedMap.get(site).newInstance();
     	} else {
     		for (ProtocolFactory factory : protocolConfig.getFactoriesBySite(site)) {
+    			Protocol protocol = null;
     			try {
-    				Protocol protocol = factory.newInstance();
+    				protocol = factory.newInstance();
     				if (verifier == null || verifier.verify(protocol, site, auth)) {
     					verifiedMap.put(site, factory);
+    					if (protocol.connected()) {
+    						protocol.close();
+    					}
+    					protocol.connect(site.getHost(), auth);
     					return protocol;
     				}
     			} catch (Exception e) {
@@ -72,7 +100,17 @@ public class ProtocolManager {
     	}
     }
     
-    public void setProtocol(URI site, ProtocolFactory factory) {
+    /**
+     * 
+     * @param site
+     * @param auth
+     * @param factory
+     * @throws IllegalArgumentException if any of the arguments are null
+     */
+    public void setProtocol(URI site, Authentication auth, ProtocolFactory factory) {
+    	Validate.notNull(site, "site must not be NULL");
+    	Validate.notNull(auth, "auth must not be NULL");
+    	Validate.notNull(factory, "factory must not be NULL");
     	verifiedMap.put(site, factory);
     }
 }

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=1130280&r1=1130279&r2=1130280&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 Wed Jun  1 20:00:03 2011
@@ -74,6 +74,8 @@ public class BasicProtocolVerifier imple
                     + protocol.getClass().getCanonicalName()
                     + " failed compatibility test : " + e.getMessage(), e);
             return false;
+        } finally {
+        	try { protocol.close(); } catch (Exception e) {}
         }
         return true;
     }

Modified: oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml (original)
+++ oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-action-beans.xml Wed Jun  1 20:00:03 2011
@@ -12,6 +12,6 @@
 
 	<bean class="org.apache.oodt.commons.spring.postprocessor.SetIdBeanPostProcessor"/>
 
-	<bean id="download" class="org.apache.oodt.cas.protocol.action.DownloadAction"/>
+	<bean id="Download" class="org.apache.oodt.cas.protocol.action.DownloadAction"/>
 	
 </beans>
\ No newline at end of file

Modified: oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml (original)
+++ oodt/branches/protocol/protocol-api/src/main/resources/policy/protocol-cmd-line-beans.xml Wed Jun  1 20:00:03 2011
@@ -58,7 +58,7 @@
 	</bean>
 	
 	<bean id="url" lazy-init="true" class="org.apache.oodt.commons.option.CmdLineOption">
-		<property name="shortOption" value="u"/>
+		<property name="shortOption" value="url"/>
 		<property name="longOption" value="url"/>
 		<property name="description" value="URL to download"/>
 		<property name="hasArgs" value="true"/>

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=1130280&r1=1130279&r2=1130280&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 Wed Jun  1 20:00:03 2011
@@ -18,6 +18,7 @@ package org.apache.oodt.cas.protocol;
 
 //JDK imports
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -36,9 +37,18 @@ public class MockProtocol implements Pro
 	private ProtocolFile cwd;
 	private String factoryId;
 	
+	private List<ProtocolFile> deletedFiles;
+	private List<ProtocolFile> putFiles;
+	private List<ProtocolFile> getFiles;
+	private int timesConnected;
+	
 	public MockProtocol(String factoryId) {
 		connected = false;
 		this.factoryId = factoryId;
+		deletedFiles = new ArrayList<ProtocolFile>();
+		putFiles = new ArrayList<ProtocolFile>();
+		getFiles = new ArrayList<ProtocolFile>();
+		timesConnected = 0;
 	}
 	
 	public String getFactoryId() {
@@ -48,6 +58,14 @@ public class MockProtocol implements Pro
 	public void connect(String host, Authentication authentication)
 			throws ProtocolException {
 		connected = true;
+		deletedFiles.clear();
+		putFiles.clear();
+		getFiles.clear();
+		timesConnected++;
+	}
+	
+	public int getTimesConnected() {
+		return timesConnected;
 	}
 
 	public void close() throws ProtocolException {
@@ -64,12 +82,20 @@ public class MockProtocol implements Pro
 
 	public void get(ProtocolFile fromFile, File toFile)
 			throws ProtocolException {
-		//do nothing
+		getFiles.add(fromFile);
 	}
 
+	public List<ProtocolFile> getGetFiles() {
+		return getFiles;
+	}
+	
 	public void put(File fromFile, ProtocolFile toFile)
 			throws ProtocolException {
-		//do nothing
+		putFiles.add(toFile);
+	}
+	
+	public List<ProtocolFile> getPutFiles() {
+		return putFiles;
 	}
 
 	public ProtocolFile pwd() throws ProtocolException {
@@ -81,7 +107,11 @@ public class MockProtocol implements Pro
 	}
 
 	public void delete(ProtocolFile file) throws ProtocolException {
-		//do nothing
+		deletedFiles.add(file);
+	}
+	
+	public List<ProtocolFile> getDeletedFiles() {
+		return deletedFiles;
 	}
 
 }

Added: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java?rev=1130280&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java (added)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java Wed Jun  1 20:00:03 2011
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.action;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+
+/**
+ * Mock class for {@ProtocolAction}.
+ * 
+ * @author bfoster
+ */
+public class MockProtocolAction extends ProtocolAction {
+
+	@Override
+	public void performAction(ProtocolManager protocolManager) throws Exception {}
+
+}

Propchange: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/MockProtocolAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java?rev=1130280&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java (added)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java Wed Jun  1 20:00:03 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.action;
+
+//JUnit imports
+import java.net.URI;
+
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.auth.Authentication;
+import org.apache.oodt.cas.protocol.config.MockSpringProtocolConfig;
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+import org.apache.oodt.cas.protocol.verify.ProtocolVerifier;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link BasicVerifyAction}
+ * 
+ * @author bfoster
+ */
+public class TestBasicVerifyAction extends TestCase {
+
+	public void testVerification() throws Exception {
+		BasicVerifyAction bva = new BasicVerifyAction();
+		bva.setSite("http://localhost");
+		bva.setVerifier(new ProtocolVerifier() {
+			public boolean verify(Protocol protocol, URI site,
+					Authentication auth) {
+				return auth != null && site.toString().equals("http://localhost");
+			}
+		});
+		bva.performAction(new ProtocolManager(new MockSpringProtocolConfig()));
+		assertTrue(bva.getLastVerificationResults());
+	}
+	
+}

Propchange: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestBasicVerifyAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java?rev=1130280&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java (added)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java Wed Jun  1 20:00:03 2011
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.action;
+
+//JUnit imports
+import java.net.URISyntaxException;
+
+import org.apache.oodt.cas.protocol.MockProtocol;
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.ProtocolFile;
+import org.apache.oodt.cas.protocol.config.MockSpringProtocolConfig;
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link DownloadAction}.
+ * 
+ * @author bfoster
+ */
+public class TestDownloadAction extends TestCase {
+	
+	private ProtocolManager pm;
+	
+	@Override
+	public void setUp() {
+		pm = new ProtocolManager(new MockSpringProtocolConfig());
+	}
+	
+	public void testCreateProtocol() throws URISyntaxException {
+		DownloadAction da = new DownloadAction();
+		da.setUrl("http://localhost/some/file");
+		Protocol protocol = da.createProtocol(pm);
+		assertNotNull(protocol);
+		assertTrue(protocol instanceof MockProtocol);
+		assertEquals("http1", ((MockProtocol) protocol).getFactoryId());
+	}
+	
+	public void testCreateProtocolFile() throws URISyntaxException {
+		DownloadAction da = new DownloadAction();
+		da.setUrl("http://localhost/some/file");
+		ProtocolFile file = da.createProtocolFile();
+		assertNotNull(file);
+		assertEquals("/some/file", file.getPath());
+		assertFalse(file.isRelative());
+		assertFalse(file.isDir());
+	}
+	
+	public void testFileDownload() throws Exception {
+		DownloadAction da = new DownloadAction();
+		da.setUrl("http://localhost/some/file");
+		da.performAction(new ProtocolManager(new MockSpringProtocolConfig()));
+		assertNotNull(da.getUsedProtocol());
+		assertTrue(da.getUsedProtocol() instanceof MockProtocol);
+		assertEquals(1, ((MockProtocol) da.getUsedProtocol()).getGetFiles().size());
+		assertEquals("/some/file", ((MockProtocol) da.getUsedProtocol()).getGetFiles().get(0).getPath());
+	}
+}

Propchange: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestDownloadAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java?rev=1130280&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java (added)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java Wed Jun  1 20:00:03 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.action;
+
+//JUnit imports
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ProtocolAction}.
+ * 
+ * @author bfoster
+ */
+public class TestProtocolAction extends TestCase {
+
+	public void testInitialState() throws URISyntaxException {
+		MockProtocolAction action = new MockProtocolAction();
+		action.setId("id");
+		action.setUser("user");
+		action.setPass("pass");
+		action.setSite("http://some-site");
+		assertEquals("id", action.getId());
+		assertEquals("user", action.getAuthentication().getUser());
+		assertEquals("pass", action.getAuthentication().getPass());
+		assertEquals("http://some-site", action.getSite().toString());
+	}
+}

Propchange: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/action/TestProtocolAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java (original)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java Wed Jun  1 20:00:03 2011
@@ -32,4 +32,18 @@ public class TestBasicAuthentication ext
 		assertEquals("pass", auth.getPass());
 	}
 	
+	public void testNullCase() {
+		try {
+			new BasicAuthentication(null, "pass");
+			fail("Should have thrown IllegalArgumentException");
+		}catch (IllegalArgumentException e) {}
+		try {
+			new BasicAuthentication("user", null);
+			fail("Should have thrown IllegalArgumentException");
+		}catch (IllegalArgumentException e) {}
+		try {
+			new BasicAuthentication(null, null);
+			fail("Should have thrown IllegalArgumentException");
+		}catch (IllegalArgumentException e) {}
+	}
 }

Modified: oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java (original)
+++ oodt/branches/protocol/protocol-api/src/test/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java Wed Jun  1 20:00:03 2011
@@ -28,8 +28,8 @@ public class TestNoAuthentication extend
 
 	public void testInitialState() {
 		NoAuthentication auth = new NoAuthentication();
-		assertNull(auth.getUser());
-		assertNull(auth.getPass());
+		assertEquals("", auth.getUser());
+		assertEquals("", auth.getPass());
 	}
 	
 }

Modified: oodt/branches/protocol/protocol-api/src/testdata/test-protocol-config.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-api/src/testdata/test-protocol-config.xml?rev=1130280&r1=1130279&r2=1130280&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-api/src/testdata/test-protocol-config.xml (original)
+++ oodt/branches/protocol/protocol-api/src/testdata/test-protocol-config.xml Wed Jun  1 20:00:03 2011
@@ -30,7 +30,7 @@
 		<property name="schema" value="sftp"/>
 	</bean>
 	
-	<bean id="http" class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+	<bean id="http1" class="org.apache.oodt.cas.protocol.MockProtocolFactory">
 		<property name="schema" value="http"/>
 	</bean>