FsAdaptorTest
diff --git a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
index c12f3b3..f957bde 100644
--- a/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
+++ b/src/com/google/enterprise/adaptor/fs/FsAdaptor.java
@@ -149,6 +149,11 @@
}
}
+ @VisibleForTesting
+ FsAdaptor(FileDelegate delegate) {
+ this.delegate = delegate;
+ }
+
@Override
public void initConfig(Config config) {
config.addKey(CONFIG_SRC, null);
@@ -445,6 +450,7 @@
response.setContentType("text/html; charset=" + CHARSET.name());
// TODO(ejona): Get locale from request.
return new HtmlResponseWriter(writer, context.getDocIdEncoder(),
+
Locale.ENGLISH);
}
@@ -454,7 +460,8 @@
return file.toFile().getName();
}
- private boolean isSupportedPath(Path p) throws IOException {
+ @VisibleForTesting
+ boolean isSupportedPath(Path p) throws IOException {
return delegate.isRegularFile(p) || delegate.isDirectory(p);
}
@@ -462,7 +469,8 @@
* Verifies that the file is a descendant of the root directory,
* and that it, nor none of its ancestors, is hidden.
*/
- private boolean isVisibleDescendantOfRoot(Path doc) throws IOException {
+ @VisibleForTesting
+ boolean isVisibleDescendantOfRoot(Path doc) throws IOException {
for (Path file = doc; file != null; file = file.getParent()) {
if (delegate.isHidden(file)) {
if (doc.equals(file)) {
diff --git a/test/com/google/enterprise/adaptor/fs/FsAdaptorTest.java b/test/com/google/enterprise/adaptor/fs/FsAdaptorTest.java
index 539b74b..1430991 100644
--- a/test/com/google/enterprise/adaptor/fs/FsAdaptorTest.java
+++ b/test/com/google/enterprise/adaptor/fs/FsAdaptorTest.java
@@ -16,6 +16,8 @@
import static org.junit.Assert.*;
+import com.google.enterprise.adaptor.fs.MockDirectoryBuilder.ConfigureFile;
+
import org.junit.*;
import org.junit.rules.ExpectedException;
@@ -23,15 +25,75 @@
/** Test cases for {@link FsAdaptor}. */
public class FsAdaptorTest {
+ private MockDirectoryBuilder builder;
+ private MockFileDelegate delegate;
+ private FsAdaptor adaptor;
+ private Config config;
+
+ @Override
+ protected void setUp() {
+ builder = new MockDirectoryBuilder();
+ delegate = new MockFileDelegate(builder);
+ adaptor = new FsAdaptor(delegate);
+ config = new Config();
+ adaptor.initConfig(config);
+ }
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testGetPathName() throws Exception {
- TestHelper.assumeOsIsWindows();
- FsAdaptor adaptor = new FsAdaptor();
assertEquals("share", adaptor.getPathName(Paths.get("\\\\host/share/")));
assertEquals("folder2",
adaptor.getPathName(Paths.get("C:/folder1/folder2/")));
+ assertEquals("foo.text",
+ adaptor.getPathName(Paths.get("C:/folder1/foo.txt")));
+ assertEquals("bug-test", adaptor.getPathName(Paths.get("\\\\\brwsr-xp.gdc-psl.net/bug-test/")));
}
+
+ @Test
+ public void testIsSupportedPath() throws Exception {
+ ConfigureFile configureFile = new ConfigureFile() {
+ public boolean configure(MockFile file) {
+ if ("link".equals(file.getName())) {
+ file.setIsDirectory(false);
+ file.setIsRegularFile(false);
+ return false;
+ }
+ return true;
+ }
+ };
+ builder.addDir(configureFile, null, "/root", "foo", "link", "bar");
+
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root")));
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root/foo")));
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root/bar")));
+ assertFalse(adaptor.isSupportedPath(delegate.getPath("/root/link")));
+ }
+ /*
+ @Test
+ public void testIsVisibleDescendantOfRoot() throws Exception {
+ ConfigureFile configureFile = new ConfigureFile() {
+ public boolean configure(MockFile file) {
+ if ("hidden".equals(file.getName())) {
+ file.setIsHidden(true);
+ return false;
+ }
+ return true;
+ }
+ };
+ MockFile root = builder.addDir(null, "/", "foo");
+ builder.addDir(configureFile, root, "dir1", "bar", "hidden");
+ MockFile dir2 = builder.addDir(configureFile, root, "dir2", "baz");
+ builder.addDir(configureFile, dir2, "hidden", "foobar");
+
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root")));
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root/foo")));
+ assertTrue(adaptor.isSupportedPath(delegate.getPath("/root/bar")));
+ assertFalse(adaptor.isSupportedPath(delegate.getPath("/root/link")));
+ }
+
+ */
+
}