1 12 13 package com.openedit.modules.admin; 14 15 import java.io.File ; 16 17 import com.openedit.BaseTestCase; 18 import com.openedit.WebPageRequest; 19 import com.openedit.modules.admin.filemanager.FileManagerModule; 20 import com.openedit.page.PageRequestKeys; 21 import com.openedit.util.FileUtils; 22 23 24 29 public class FileManagerModuleTest extends BaseTestCase 30 { 31 32 public FileManagerModuleTest(String inName) 33 { 34 super(inName); 35 } 36 37 protected FileManagerModule getFileManagerModule() 38 { 39 return (FileManagerModule) getFixture().getModuleManager().getModule( "Page" ); 40 } 41 42 47 public void testCopy() throws Exception  48 { 49 WebPageRequest context = getFixture().createPageRequest(); 50 context.setRequestParameter("sourcePath", "/withcontentpath.html"); 51 context.setRequestParameter("destinationPath", "/subdir/withcontentpath-copy.html"); 52 context.setRequestParameter("overwrite", "true"); 53 54 context.putPageValue( PageRequestKeys.USER, getFixture().getUserManager().getUser("admin")); 55 56 57 getFileManagerModule().copyPage(context); 58 59 File origFile = getRealFile("/withcontentpath.xml"); 60 assertTrue(origFile.exists()); 61 62 File origXConfFile = getRealFile("/withcontentpath.xconf"); 63 assertTrue(origXConfFile.exists()); 64 65 File newFile = getRealFile("/subdir/withcontentpath-copy.html"); 66 68 assertTrue(newFile.exists()); 69 } 71 72 public void testShortCopy() throws Exception 73 { 74 75 WebPageRequest context = getFixture().createPageRequest(); 76 context.setRequestParameter("sourcePath", "/normal.html"); 77 context.setRequestParameter("destinationPath", "/normal-copy.htm"); 78 context.setRequestParameter("overwrite", "true"); 79 80 context.putPageValue( PageRequestKeys.USER, getFixture().getUserManager().getUser("admin")); 81 82 getFileManagerModule().copyPage(context); 83 File newFile = getRealFile("/normal-copy.htm"); 84 assertTrue( newFile.exists() ); 85 86 } 87 88 93 public void testMove() throws Exception  94 { 95 String origPath = "/normal-copy.html"; 96 String newPath = "/normal-copy-copy.html"; 97 98 WebPageRequest context = getFixture().createPageRequest(); 99 100 context.setRequestParameter("sourcePath", origPath); 101 context.setRequestParameter("destinationPath", newPath); 102 103 context.putPageValue("user", getFixture().getUserManager().getUser("admin")); 104 105 getFileManagerModule().movePage(context); 106 107 File origFile = getRealFile(origPath); 108 File newFile = getRealFile(newPath); 110 assertTrue(newFile.exists()); 112 assertTrue(!origFile.exists()); 114 116 context.setRequestParameter("sourcePath", newPath); 118 context.setRequestParameter("destinationPath", origPath); 119 getFileManagerModule().movePage(context); 120 origFile = getRealFile(origPath); 121 assertTrue(origFile.exists()); 122 123 124 } 125 126 public void testZip() throws Exception  127 { 128 WebPageRequest context = getFixture().createPageRequest(); 129 context.setRequestParameter("path","/openedit"); 130 FileManagerModule mod = (FileManagerModule) getFixture().getModuleManager().getModule("Page"); 131 mod.forwardToZip(context); 132 assertEquals("/openedit/filemanager/zipdir/openedit.zip?path=/openedit",context.getPageValue("redirect")); 133 } 134 135 protected File getRealFile(String inPath) throws Exception  136 { 137 return new File (getRoot(), inPath); 138 } 139 140 protected void tearDown() throws Exception  141 { 142 FileUtils utils = new FileUtils(); 143 utils.deleteAll(getRealFile("/subdir")); 144 } 145 } 146 | Popular Tags |