KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > admin > FileManagerModuleTest


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.modules.admin;
14
15 import java.io.File JavaDoc;
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 /**
25  * DOCUMENT ME!
26  *
27  * @author cburkey
28  */

29 public class FileManagerModuleTest extends BaseTestCase
30 {
31
32     public FileManagerModuleTest(String JavaDoc inName)
33     {
34         super(inName);
35     }
36     
37     protected FileManagerModule getFileManagerModule()
38     {
39         return (FileManagerModule) getFixture().getModuleManager().getModule( "Page" );
40     }
41
42     /**
43      * DOCME
44      *
45      * @throws Exception DOCME
46      */

47     public void testCopy() throws Exception JavaDoc
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 JavaDoc origFile = getRealFile("/withcontentpath.xml");
60         assertTrue(origFile.exists());
61
62         File JavaDoc origXConfFile = getRealFile("/withcontentpath.xconf");
63         assertTrue(origXConfFile.exists());
64
65         File JavaDoc newFile = getRealFile("/subdir/withcontentpath-copy.html");
66         //File newXConfFile = getRealFile("/subdir/withcontentpath-copy.xconf");
67

68         assertTrue(newFile.exists());
69         //assertTrue(newXConfFile.exists());
70
}
71
72     public void testShortCopy() throws Exception JavaDoc
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 JavaDoc newFile = getRealFile("/normal-copy.htm");
84         assertTrue( newFile.exists() );
85         
86     }
87     
88     /**
89      * DOCME
90      *
91      * @throws Exception DOCME
92      */

93     public void testMove() throws Exception JavaDoc
94     {
95         String JavaDoc origPath = "/normal-copy.html";
96         String JavaDoc 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 JavaDoc origFile = getRealFile(origPath);
108         //File origXConfFile = getRealFile("withcontentpath.xconf");
109
File JavaDoc newFile = getRealFile(newPath);
110         //File newXConfFile = getRealFile("withcontentpath-copy.xconf");
111
assertTrue(newFile.exists());
112         //assertTrue(newXConfFile.exists());
113
assertTrue(!origFile.exists());
114         //assertTrue(!origXConfFile.exists());
115

116         // Move the file back, if the move worked.
117
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 JavaDoc
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 JavaDoc getRealFile(String JavaDoc inPath) throws Exception JavaDoc
136     {
137         return new File JavaDoc(getRoot(), inPath);
138     }
139
140     protected void tearDown() throws Exception JavaDoc
141     {
142         FileUtils utils = new FileUtils();
143         utils.deleteAll(getRealFile("/subdir"));
144     }
145 }
146
Popular Tags