|
From: <ian...@us...> - 2007-07-03 17:16:58
|
Revision: 210
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=210&view=rev
Author: iansmith
Date: 2007-07-03 10:16:54 -0700 (Tue, 03 Jul 2007)
Log Message:
-----------
I'm a bit frightened because the editor is claiming that I
should commit some of the prefs files but all I did was select
version 1.4 syntax checking. Sigh. I'm not going to try to not commit those changes for now.
I added more specifications to my sync tool. This tool is
currently semantically broken because it looks for spaces
rather than templates, but that will be easily fixed.
Modified Paths:
--------------
spaces/trunk/src/com/ogoglio/spacesync/SyncTool.java
spaces/trunk/src/com/ogoglio/spacesync/SyncToolSpec.java
Modified: spaces/trunk/src/com/ogoglio/spacesync/SyncTool.java
===================================================================
--- spaces/trunk/src/com/ogoglio/spacesync/SyncTool.java 2007-07-03 02:33:29 UTC (rev 209)
+++ spaces/trunk/src/com/ogoglio/spacesync/SyncTool.java 2007-07-03 17:16:54 UTC (rev 210)
@@ -31,7 +31,7 @@
public List listSpacesToSynchronize(String dir) {
File f = new File(dir);
- List<File> result = new ArrayList<File>();
+ List result = new ArrayList();
if (!f.exists() || !f.isDirectory() || !f.canRead()) {
return null;
@@ -52,7 +52,7 @@
}
public List candidatesDirsFromCriticalDirs(String path1, String path2) {
- List<String> result = new ArrayList<String>();
+ List result = new ArrayList();
result.add(path1 + File.separatorChar + "spaces");
result.add(path1 + File.separatorChar + ".spaces");
result.add(path2 + File.separatorChar + "spaces");
@@ -91,7 +91,8 @@
abort(ABORT_BAD_PW);
return; //if you don't understand why this is here, don't mess with it
}
- if (findUsersSpaces()==null) {
+ List spaceNames = findUsersSpaces();
+ if (spaceNames==null) {
abort(ABORT_NO_SPACES);
return; //if you don't understand why this is here, don't mess with it
}
Modified: spaces/trunk/src/com/ogoglio/spacesync/SyncToolSpec.java
===================================================================
--- spaces/trunk/src/com/ogoglio/spacesync/SyncToolSpec.java 2007-07-03 02:33:29 UTC (rev 209)
+++ spaces/trunk/src/com/ogoglio/spacesync/SyncToolSpec.java 2007-07-03 17:16:54 UTC (rev 210)
@@ -1,24 +1,32 @@
package com.ogoglio.spacesync;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import com.agical.rmock.extension.junit.RMockTestCase;
+import com.ogoglio.client.WebAPIAuthenticator;
public class SyncToolSpec extends RMockTestCase {
- public SyncTool mock;
+ public SyncTool mock; //we use this in every spec
+
+ public static final String SVC="http://transmutable.gov",USER="doofus",PW="somepw";
+ public static final String[] CMD_LINE_ARGS = { USER, PW, SVC};
public void setUp() {
mock=(SyncTool)mock(SyncTool.class);
}
-
- public void testLookForDirsInCWDAndHomeWithRightNameReturningOnlyNamesOfSpaces() {
- List<String> fakeCandidateList = new ArrayList<String>();
+ private List createFakeList(int numberOfFakeItems,String prefix) {
+ List result = new ArrayList();
+ for (int i=0; i<numberOfFakeItems;++i) { result.add(prefix+i);}
+ return result;
+ }
+ public void testLookForDirsInCWDAndHomeWithRightNameReturningOnlyNamesOfDirs() {
int ITERS=4;
- for (int i=0; i<ITERS;++i) { fakeCandidateList.add("better not exist on disk)");}
+ List fakeDirList = createFakeList(ITERS,"dir");
beginSection(s.ordered("set of directories checked"));
{
@@ -26,7 +34,7 @@
modify().forward();
mock.candidatesDirsFromCriticalDirs("cwd","home dir");
- modify().args(is.NOT_NULL,is.NOT_NULL).returnValue(fakeCandidateList);
+ modify().args(is.NOT_NULL,is.NOT_NULL).returnValue(fakeDirList);
mock.listSpacesToSynchronize("points to a dir");
modify().args(is.NOT_NULL);
@@ -57,4 +65,59 @@
public void testForgotServiceURI() throws IOException, URISyntaxException {
checkWrongNumberOfArgs(2);
}
+
+ public void checkAuthorizationSequence(String cookieValue)
+ throws IOException, URISyntaxException {
+ WebAPIAuthenticator authMock=(WebAPIAuthenticator)mock(WebAPIAuthenticator.class,"authMock");
+
+ beginSection(s.ordered("startup ordering of param and auth checks"));
+ {
+ mock.start(CMD_LINE_ARGS);
+ modify().forward();
+
+ mock.getAuthenticator();
+ modify().returnValue(authMock);
+
+ authMock.authenticate(new URI(SVC), USER, PW);
+ modify().returnValue(cookieValue);
+ }
+ endSection();
+ }
+ public void testBadUsernameOrPasswordForService() throws IOException, URISyntaxException {
+ checkAuthorizationSequence(null);
+
+ mock.abort(SyncTool.ABORT_BAD_PW);
+
+ startVerification();
+ mock.start(CMD_LINE_ARGS);
+ }
+
+ //basically test that all the startup crap completes ok so we can get started testing that spaces
+ //actually can sync
+ public void testSyncSpaceCalledOnceForEachSpaceName() throws IOException, URISyntaxException{
+ List fakeMagicDirs= createFakeList(2,"dir");
+ List fakeSpaces = createFakeList(2,"space");
+
+ checkAuthorizationSequence("someCookieSoAuthOK");
+
+ beginSection(s.ordered("order of looking in dirs makes sense"));
+ {
+ mock.findUsersSpaces();
+ modify().forward();
+
+ mock.candidatesDirsFromCriticalDirs("really CWD", "really $HOME");
+ modify().args(is.instanceOf(String.class).and(is.NOT_NULL),is.instanceOf(String.class).and(is.NOT_NULL));
+ modify().returnValue(fakeMagicDirs);
+
+ mock.listSpacesToSynchronize((String)fakeMagicDirs.get(0));
+ modify().returnValue(null);
+
+ mock.listSpacesToSynchronize((String)fakeMagicDirs.get(1));
+ modify().returnValue(fakeSpaces);
+ }
+ endSection();
+
+ startVerification();
+ mock.start(CMD_LINE_ARGS);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|