001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.components;
006:
007: import com.opensymphony.xwork.Action;
008: import com.opensymphony.xwork.ActionContext;
009: import com.opensymphony.xwork.ActionSupport;
010: import com.opensymphony.xwork.util.OgnlValueStack;
011:
012: import junit.framework.TestCase;
013:
014: /**
015: * test case for AbstractRichtexteditorConnector
016: *
017: * @author tm_jee
018: * @version $Date: 2006-02-17 16:21:02 +0100 (Fri, 17 Feb 2006) $ $Id: AbstractRichtexteditorConnectorTest.java 2199 2006-02-17 15:21:02Z tmjee $
019: */
020: public class AbstractRichtexteditorConnectorTest extends TestCase {
021:
022: private MockRichtexteditorConnector action;
023:
024: public void testBrowseGetFolders() throws Exception {
025: action.setCommand("GetFolders");
026: action.setType("Image"); // Image, Link or Flash (according to FCK specs)
027: action.setCurrentFolder("/");
028: action.setServerPath("/myserver/path/");
029: action._Folder = new AbstractRichtexteditorConnector.Folder[] {
030: new AbstractRichtexteditorConnector.Folder("folder1"),
031: new AbstractRichtexteditorConnector.Folder("folder2") };
032:
033: String resultName = action.browse();
034:
035: assertEquals(ActionContext.getContext().get(
036: "__richtexteditorCommand"), "GetFolders");
037: assertEquals(ActionContext.getContext().get(
038: "__richtexteditorType"), "Image");
039: assertEquals(ActionContext.getContext().get(
040: "__richtexteditorFolderPath"), "/");
041: assertEquals(ActionContext.getContext().get(
042: "__richtexteditorServerPath"),
043: "/calculated/myserver/path/");
044: assertEquals(ActionContext.getContext().get(
045: "__richtexteditorGetFolders"), action._Folder);
046: assertTrue(action.isCalculateServerPathCalled);
047: assertTrue(action.isGetFoldersCalled);
048: assertFalse(action.isCreateFolderCalled);
049: assertFalse(action.isFileUploadCalled);
050: assertFalse(action.isGetFoldersAndFilesCalled);
051: assertFalse(action.isUnknownCommandCalled);
052: assertEquals(resultName,
053: AbstractRichtexteditorConnector.GET_FOLDERS);
054: }
055:
056: public void testBrowseGetFoldersAndFiles() throws Exception {
057: action.setCommand("GetFoldersAndFiles");
058: action.setType("Link");
059: action.setCurrentFolder("/currFolder");
060: action.setServerPath("/myserver/path2/");
061: action._FoldersAndFiles = new AbstractRichtexteditorConnector.FoldersAndFiles(
062: new AbstractRichtexteditorConnector.Folder[] {
063: new AbstractRichtexteditorConnector.Folder(
064: "folder1"),
065: new AbstractRichtexteditorConnector.Folder(
066: "folder2") },
067: new AbstractRichtexteditorConnector.File[] {
068: new AbstractRichtexteditorConnector.File(
069: "file1", 10l),
070: new AbstractRichtexteditorConnector.File(
071: "file2", 20l) });
072:
073: String resultName = action.browse();
074:
075: assertEquals(ActionContext.getContext().get(
076: "__richtexteditorCommand"), "GetFoldersAndFiles");
077: assertEquals(ActionContext.getContext().get(
078: "__richtexteditorType"), "Link");
079: assertEquals(ActionContext.getContext().get(
080: "__richtexteditorFolderPath"), "/currFolder");
081: assertEquals(ActionContext.getContext().get(
082: "__richtexteditorServerPath"),
083: "/calculated/myserver/path2/");
084: assertEquals(ActionContext.getContext().get(
085: "__richtexteditorGetFoldersAndFiles"),
086: action._FoldersAndFiles);
087: assertTrue(action.isCalculateServerPathCalled);
088: assertFalse(action.isGetFoldersCalled);
089: assertFalse(action.isCreateFolderCalled);
090: assertFalse(action.isFileUploadCalled);
091: assertTrue(action.isGetFoldersAndFilesCalled);
092: assertFalse(action.isUnknownCommandCalled);
093: assertEquals(resultName,
094: AbstractRichtexteditorConnector.GET_FOLDERS_AND_FILES);
095: }
096:
097: public void testBrowseCreateFolder() throws Exception {
098: action.setCommand("CreateFolder");
099: action.setType("Flash");
100: action.setCurrentFolder("/currFolder1");
101: action.setServerPath("/myserver/path3/");
102: action._CreateFolderResult = AbstractRichtexteditorConnector.CreateFolderResult.NO_ERRORS;
103:
104: String resultName = action.browse();
105:
106: assertEquals(ActionContext.getContext().get(
107: "__richtexteditorCommand"), "CreateFolder");
108: assertEquals(ActionContext.getContext().get(
109: "__richtexteditorType"), "Flash");
110: assertEquals(ActionContext.getContext().get(
111: "__richtexteditorFolderPath"), "/currFolder1");
112: assertEquals(ActionContext.getContext().get(
113: "__richtexteditorServerPath"),
114: "/calculated/myserver/path3/");
115: assertEquals(ActionContext.getContext().get(
116: "__richtexteditorCreateFolder"),
117: action._CreateFolderResult);
118: assertTrue(action.isCalculateServerPathCalled);
119: assertFalse(action.isGetFoldersCalled);
120: assertTrue(action.isCreateFolderCalled);
121: assertFalse(action.isFileUploadCalled);
122: assertFalse(action.isGetFoldersAndFilesCalled);
123: assertFalse(action.isUnknownCommandCalled);
124: assertEquals(resultName,
125: AbstractRichtexteditorConnector.CREATE_FOLDER);
126: }
127:
128: public void testBrowseFileUpload() throws Exception {
129: action.setCommand("FileUpload");
130: action._FileUploadResult = AbstractRichtexteditorConnector.FileUploadResult
131: .uploadComplete();
132:
133: String resultName = action.browse();
134:
135: assertEquals(ActionContext.getContext().get(
136: "__richtexteditorCommand"), "FileUpload");
137: assertEquals(ActionContext.getContext().get(
138: "__richtexteditorFileUpload"), action._FileUploadResult);
139: assertFalse(action.isCalculateServerPathCalled);
140: assertFalse(action.isGetFoldersCalled);
141: assertFalse(action.isCreateFolderCalled);
142: assertTrue(action.isFileUploadCalled);
143: assertFalse(action.isGetFoldersAndFilesCalled);
144: assertFalse(action.isUnknownCommandCalled);
145: assertEquals(resultName,
146: AbstractRichtexteditorConnector.FILE_UPLOAD);
147: }
148:
149: public void testFileUpload() throws Exception {
150: action._FileUploadResult = AbstractRichtexteditorConnector.FileUploadResult
151: .uploadCompleteWithFilenamChanged("newFile.txt");
152:
153: String resultName = action.upload();
154:
155: assertEquals(ActionContext.getContext().get(
156: "__richtexteditorFileUpload"), action._FileUploadResult);
157: assertFalse(action.isCalculateServerPathCalled);
158: assertFalse(action.isGetFoldersCalled);
159: assertFalse(action.isCreateFolderCalled);
160: assertTrue(action.isFileUploadCalled);
161: assertFalse(action.isGetFoldersAndFilesCalled);
162: assertFalse(action.isUnknownCommandCalled);
163: assertEquals(resultName,
164: AbstractRichtexteditorConnector.FILE_UPLOAD);
165: }
166:
167: public void testUnknown() throws Exception {
168: action.setCommand("noSuchCommand");
169:
170: String resultName = action.browse();
171:
172: assertFalse(action.isCalculateServerPathCalled);
173: assertFalse(action.isGetFoldersCalled);
174: assertFalse(action.isCreateFolderCalled);
175: assertFalse(action.isFileUploadCalled);
176: assertFalse(action.isGetFoldersAndFilesCalled);
177: assertTrue(action.isUnknownCommandCalled);
178: assertEquals(resultName, Action.ERROR);
179: }
180:
181: protected void setUp() throws Exception {
182: super .setUp();
183: ActionContext.getContext().setValueStack(new OgnlValueStack());
184: ActionContext.getContext().getContextMap().clear();
185: action = new MockRichtexteditorConnector();
186: }
187:
188: protected void tearDown() throws Exception {
189: super.tearDown();
190: action = null;
191: }
192: }
|