001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import java.util.*;
024: import java.sql.*;
025: import junit.framework.*;
026: import org.apache.log4j.*;
027: import com.methodhead.persistable.*;
028: import com.methodhead.test.*;
029: import com.methodhead.sitecontext.*;
030: import org.apache.cactus.*;
031: import javax.servlet.jsp.tagext.*;
032: import javax.servlet.jsp.*;
033:
034: public class PanelTagTest extends JspTestCase {
035:
036: Panel panel = null;
037: Page page = null;
038: PanelTag tag = null;
039:
040: static {
041: TestUtils.initLogger();
042: TestUtils.initDb();
043: }
044:
045: public PanelTagTest(String name) {
046: super (name);
047: }
048:
049: protected void setUp() {
050: //setLogLevel( Level.DEBUG );
051: try {
052: } catch (Exception e) {
053: fail(e.getMessage());
054: }
055: }
056:
057: protected void tearDown() {
058: }
059:
060: public void testPanelDefine() {
061: try {
062: PanelTag tag = null;
063: Map map = null;
064: PanelConfig panelConfig = null;
065:
066: //
067: // panel tag with only name specified
068: //
069: request.setAttribute(ShimGlobals.PANELMAP_KEY,
070: new HashMap());
071: tag = new PanelTag();
072: tag.setPageContext(pageContext);
073: tag.setName("body");
074:
075: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
076: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
077:
078: map = (Map) request.getAttribute(ShimGlobals.PANELMAP_KEY);
079:
080: assertNotNull(map);
081: assertEquals(1, map.keySet().size());
082:
083: panelConfig = (PanelConfig) map.get("body");
084:
085: assertNotNull(panelConfig);
086: assertEquals("body", panelConfig.getName());
087: assertEquals(ShimGlobals.DEFAULT_MODULE, panelConfig
088: .getDefaultModule());
089:
090: //
091: // another panel (in the same request) with default module specified
092: //
093: tag = new PanelTag();
094: tag.setPageContext(pageContext);
095: tag.setName("header");
096: tag.setDefaultModule("com.methodhead.shim.SomeModule");
097:
098: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
099: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
100:
101: map = (Map) request.getAttribute(ShimGlobals.PANELMAP_KEY);
102:
103: assertNotNull(map);
104: assertEquals(2, map.keySet().size());
105:
106: panelConfig = (PanelConfig) map.get("header");
107:
108: assertNotNull(panelConfig);
109: assertEquals("header", panelConfig.getName());
110: assertEquals("com.methodhead.shim.SomeModule", panelConfig
111: .getDefaultModule());
112: } catch (Exception e) {
113: e.printStackTrace();
114: fail();
115: }
116: }
117:
118: public void testPanelDisplay() {
119: try {
120: Panel panel = null;
121: Page page = null;
122: PanelTag tag = null;
123:
124: panel = new Panel();
125: panel.setName("body");
126: panel.setModuleClass("com.methodhead.shim.MockModule");
127: panel.setModule(new MockModule());
128: page = new Page();
129: page.addPanel(panel);
130: request.setAttribute(ShimGlobals.PAGE_KEY, page);
131: tag = new PanelTag();
132: tag.setPageContext(pageContext);
133: tag.setName("body");
134:
135: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
136: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
137: } catch (Exception e) {
138: e.printStackTrace();
139: fail();
140: }
141: }
142:
143: public void endPanelDisplay(WebResponse response) {
144: String output = response.getText();
145: assertEquals("Hello from MockModule.display().\n", output);
146: }
147:
148: public void testPanelDisplayMissingPanel() {
149: try {
150: Panel panel = null;
151: Page page = null;
152: PanelTag tag = null;
153:
154: page = new Page();
155: request.setAttribute(ShimGlobals.PAGE_KEY, page);
156: tag = new PanelTag();
157: tag.setPageContext(pageContext);
158: tag.setName("body");
159:
160: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
161: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
162: } catch (Exception e) {
163: e.printStackTrace();
164: fail();
165: }
166: }
167:
168: public void endPanelDisplayMissingPanel(WebResponse response) {
169: String output = response.getText();
170: assertEquals(
171: "This panel is not set; please contact the webmaster.\n",
172: output);
173: }
174:
175: public void testPanelEdit() {
176: try {
177: Panel panel = null;
178: Page page = null;
179: PanelTag tag = null;
180:
181: panel = new Panel();
182: panel.setName("body");
183: panel.setModuleClass("com.methodhead.shim.MockModule");
184: panel.setModule(new MockModule());
185: page = new Page();
186: page.setInt("id", 666);
187: page.addPanel(panel);
188: request.setAttribute(ShimGlobals.PAGE_KEY, page);
189: session.setAttribute(ShimGlobals.MODE_KEY,
190: ShimGlobals.MODE_EDIT);
191: SiteContext.setContext(request, SiteContext
192: .getDefaultContext());
193: tag = new PanelTag();
194: tag.setPageContext(pageContext);
195: tag.setName("body");
196: MockModule.setConfigurable(false);
197: MockModule.setEditable(false);
198:
199: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
200: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
201:
202: MockModule.setConfigurable(true);
203:
204: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
205: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
206:
207: MockModule.setConfigurable(false);
208: MockModule.setEditable(true);
209:
210: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
211: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
212:
213: MockModule.setConfigurable(true);
214:
215: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
216: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
217:
218: tag.setName("missingpanel");
219:
220: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
221: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
222: } catch (Exception e) {
223: e.printStackTrace();
224: fail();
225: }
226: }
227:
228: public void endPanelEdit(WebResponse response) {
229: String output = response.getText();
230:
231: assertEquals(
232: "Hello from MockModule.display().\n"
233: + "<a href=\"configurePanelForm.do?pageid=666&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a> <a href=\"configureModule.do?pageid=666&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" src=\"approot/images/panel_configure.gif\"></a>\nHello from MockModule.display().\n\n"
234: + "<a href=\"configurePanelForm.do?pageid=666&panel=body\"><img title=\"Panel\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a> <a href=\"editPanel.do?pageid=666&panel=body\"><img border=0 align=\"middle\" src=\"approot/images/panel_edit.gif\"></a>\nHello from MockModule.display().\n\n"
235: + "<a href=\"configurePanelForm.do?pageid=666&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a> <a href=\"configureModule.do?pageid=666&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" src=\"approot/images/panel_configure.gif\"></a> <a href=\"editPanel.do?pageid=666&panel=body\"><img title=\"Edit\" border=0 align=\"middle\" src=\"approot/images/panel_edit.gif\"></a>\nHello from MockModule.display().\n\n"
236: + "<a href=\"configurePanelForm.do?pageid=666&panel=missingpanel\"><img title=\"Select Module\" border=0 align=\"middle\" src=\"approot/images/panel_module.gif\"></a>\nThis panel is not set; please contact the webmaster.\n\n",
237: output);
238: }
239:
240: public void testPanelPreview() {
241: try {
242: Panel panel = null;
243: Page page = null;
244: PanelTag tag = null;
245:
246: panel = new Panel();
247: panel.setName("body");
248: panel.setModuleClass("com.methodhead.shim.MockModule");
249: panel.setModule(new MockModule());
250: page = new Page();
251: page.setInt("id", 666);
252: page.addPanel(panel);
253: request.setAttribute(ShimGlobals.PAGE_KEY, page);
254: request.setAttribute(ShimGlobals.PREVIEW_KEY, "true");
255: session.setAttribute(ShimGlobals.MODE_KEY,
256: ShimGlobals.MODE_EDIT);
257: tag = new PanelTag();
258: tag.setPageContext(pageContext);
259: tag.setName("body");
260:
261: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
262: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
263: } catch (Exception e) {
264: e.printStackTrace();
265: fail();
266: }
267: }
268:
269: public void endPanelPreview(WebResponse response) {
270: String output = response.getText();
271: assertEquals("Hello from MockModule.display().\n", output);
272: }
273:
274: public void testPanelRichEdit() {
275: try {
276: Panel panel = null;
277: Page page = null;
278: PanelTag tag = null;
279:
280: page = new Page();
281: page.setInt("id", 666);
282: panel = new Panel();
283: panel.setName("body");
284: panel.setModuleClass("com.methodhead.shim.MockModule");
285: panel.setModule(new MockModule());
286: page.addPanel(panel);
287: panel = new Panel();
288: panel.setName("footer");
289: panel.setModuleClass("com.methodhead.shim.MockModule");
290: panel.setModule(new MockModule());
291: page.addPanel(panel);
292: request.setAttribute(ShimGlobals.PAGE_KEY, page);
293: request.setAttribute(ShimGlobals.MODE_KEY,
294: ShimGlobals.MODE_RICHEDIT);
295: session.setAttribute(ShimGlobals.MODE_KEY,
296: ShimGlobals.MODE_EDIT);
297: request.setAttribute(ShimGlobals.EDITPANEL_KEY, "body");
298: tag = new PanelTag();
299: tag.setPageContext(pageContext);
300: tag.setName("body");
301:
302: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
303: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
304:
305: tag = new PanelTag();
306: tag.setPageContext(pageContext);
307: tag.setName("footer");
308:
309: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
310: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
311: } catch (Exception e) {
312: e.printStackTrace();
313: fail();
314: }
315: }
316:
317: public void endPanelRichEdit(WebResponse response) {
318: String output = response.getText();
319: assertEquals(
320: "<div id=\"editableDiv\">\nHello from MockModule.display().\n</div>\n"
321: + "Hello from MockModule.display().\n", output);
322: }
323: }
|