/**
* Tests that files can be accessed.
*/
public void testViewFiles() throws Exception {
// create some files and directories
FileManager fileManager = new FileManager(blog, FileMetaData.BLOG_FILE);
fileManager.createDirectory("/", "a");
fileManager.createDirectory("/", "z");
fileManager.saveFile("/", "y.txt", "Some content");
fileManager.saveFile("/", "b.txt", "Some content");
request.setParameter("path", "/");
request.setParameter("type", FileMetaData.BLOG_FILE);
View view = action.process(request, response);
// check file information available and the right view is returned
assertEquals(FileMetaData.BLOG_FILE, action.getModel().get("type"));
FileMetaData fileMetaData = (FileMetaData)action.getModel().get("directory");
assertEquals("/", fileMetaData.getAbsolutePath());
assertTrue(fileMetaData.isDirectory());
assertEquals("uploadFileToBlog.secureaction", action.getModel().get("uploadAction"));
assertTrue(view instanceof FilesView);
List files = (List)action.getModel().get("files");
assertEquals(4, files.size());
// the files should be in this order
// - a, z, b.txt, y.txt (directories followed by files, both alphabetically)
FileMetaData file = (FileMetaData)files.get(0);
assertEquals("a", file.getName());
assertEquals("/", file.getPath());
assertTrue(file.isDirectory());
file = (FileMetaData)files.get(1);
assertEquals("z", file.getName());
assertEquals("/", file.getPath());
assertTrue(file.isDirectory());
file = (FileMetaData)files.get(2);
assertEquals("b.txt", file.getName());
assertEquals("/", file.getPath());
assertFalse(file.isDirectory());
file = (FileMetaData)files.get(3);
assertEquals("y.txt", file.getName());
assertEquals("/", file.getPath());
assertFalse(file.isDirectory());
// and clean up
fileManager.deleteFile("/", "a");
fileManager.deleteFile("/", "z");
fileManager.deleteFile("/", "y.txt");
fileManager.deleteFile("/", "b.txt");
}