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.io.*;
025: import java.sql.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import com.methodhead.sitecontext.*;
031: import com.methodhead.*;
032: import org.apache.cactus.*;
033: import javax.servlet.jsp.tagext.*;
034: import javax.servlet.jsp.*;
035:
036: public class BodyTagTest extends JspTestCase {
037:
038: static {
039: TestUtils.initLogger();
040: TestUtils.initDb();
041: }
042:
043: public BodyTagTest(String name) {
044: super (name);
045: }
046:
047: protected void setUp() {
048: //setLogLevel( Level.DEBUG );
049: try {
050: ConnectionSingleton.runBatchUpdate(new FileReader(
051: "webapp/WEB-INF/db/transfer-reset.sql"));
052: TestData.createSiteContexts();
053: SiteContext.setContext(request, TestData.siteContext1);
054: } catch (Exception e) {
055: fail(e.getMessage());
056: }
057: }
058:
059: protected void tearDown() {
060: }
061:
062: public void testBodyDisplay() {
063: try {
064: BodyTag tag = null;
065:
066: tag = new com.methodhead.shim.BodyTag();
067: tag.setPageContext(pageContext);
068:
069: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
070: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
071:
072: tag.setOnload("onLoad()");
073:
074: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
075: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
076: } catch (Exception e) {
077: e.printStackTrace();
078: fail();
079: }
080: }
081:
082: public void endBodyDisplay(WebResponse response) {
083: String output = response.getText();
084: assertEquals(
085: "<body>\n</body>\n<body onload=\"onLoad()\">\n</body>\n",
086: output);
087: }
088:
089: public void testBodyDisplayWithAttributes() {
090: try {
091: BodyTag tag = null;
092:
093: tag = new com.methodhead.shim.BodyTag();
094: tag.setPageContext(pageContext);
095:
096: tag.setOnload("onload");
097: tag.setId("id");
098: tag.setStyleClass("class");
099: tag.setLang("lang");
100: tag.setDir("dir");
101: tag.setTitle("title");
102: tag.setStyle("style");
103: tag.setBgcolor("bgcolor");
104: tag.setOnunload("onunload");
105: tag.setOnclick("onclick");
106: tag.setOnmousedown("onmousedown");
107: tag.setOnmouseup("onmouseup");
108: tag.setOnmouseover("onmouseover");
109: tag.setOnmousemove("onmousemove");
110: tag.setOnmouseout("onmouseout");
111: tag.setOnkeypress("onkeypress");
112: tag.setOnkeydown("onkeydown");
113: tag.setOnkeyup("onkeyup");
114:
115: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
116: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
117: } catch (Exception e) {
118: e.printStackTrace();
119: fail();
120: }
121: }
122:
123: public void endBodyDisplayWithAttributes(WebResponse response) {
124: String output = response.getText();
125: assertEquals("<body " + "onload=\"onload\" " + "id=\"id\" "
126: + "class=\"class\" " + "lang=\"lang\" "
127: + "dir=\"dir\" " + "title=\"title\" "
128: + "style=\"style\" " + "bgcolor=\"bgcolor\" "
129: + "onunload=\"onunload\" " + "onclick=\"onclick\" "
130: + "onmousedown=\"onmousedown\" "
131: + "onmouseup=\"onmouseup\" "
132: + "onmouseover=\"onmouseover\" "
133: + "onmousemove=\"onmousemove\" "
134: + "onmouseout=\"onmouseout\" "
135: + "onkeypress=\"onkeypress\" "
136: + "onkeydown=\"onkeydown\" " + "onkeyup=\"onkeyup\""
137: + ">\n</body>\n", output);
138: }
139:
140: public void testBodyEdit() {
141: try {
142: BodyTag tag = null;
143:
144: session.setAttribute(ShimGlobals.MODE_KEY,
145: ShimGlobals.MODE_EDIT);
146: tag = new com.methodhead.shim.BodyTag();
147: tag.setPageContext(pageContext);
148:
149: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
150: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
151:
152: tag.setOnload("onLoad()");
153: tag.setOnbeforeunload("onBeforeUnload()");
154:
155: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
156: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
157: } catch (Exception e) {
158: e.printStackTrace();
159: fail();
160: }
161: }
162:
163: public void endBodyEdit(WebResponse response) {
164: String html = "<body>\n"
165: + "<script type=\"text/javascript\" src=\"approot/js/menu-config.js\"></script>\n"
166: + "\n"
167: + "</body>\n"
168: + "<body onload=\"onLoad()\" onbeforeunload=\"onBeforeUnload()\">\n"
169: + "<script type=\"text/javascript\" src=\"approot/js/menu-config.js\"></script>\n"
170: + "\n" + "</body>\n";
171:
172: String output = response.getText();
173:
174: assertEquals(html, output);
175: }
176:
177: public void testBodyRichEdit() {
178: try {
179: BodyTag tag = null;
180:
181: request.setAttribute(ShimGlobals.MODE_KEY,
182: ShimGlobals.MODE_RICHEDIT);
183: tag = new com.methodhead.shim.BodyTag();
184: tag.setPageContext(pageContext);
185:
186: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
187: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
188:
189: tag.setOnload("onLoad()");
190: tag.setOnbeforeunload("onBeforeunload()");
191:
192: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
193: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
194: } catch (Exception e) {
195: e.printStackTrace();
196: fail();
197: }
198: }
199:
200: public void endBodyRichEdit(WebResponse response) {
201: String output = response.getText();
202: assertEquals(
203: "<body onload=\"window.parent.init()\" onbeforeunload=\"return window.parent.toolbarFrame.onBeforeUnload()\">\n</body>\n<body onload=\"onLoad(),window.parent.init()\" onbeforeunload=\"return window.parent.toolbarFrame.onBeforeUnload()\">\n</body>\n",
204: output);
205: }
206: }
|