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 org.apache.cactus.*;
030: import javax.servlet.jsp.tagext.*;
031: import javax.servlet.jsp.*;
032: import com.methodhead.sitecontext.*;
033: import com.methodhead.*;
034:
035: public class HeadTagTest extends JspTestCase {
036:
037: static {
038: TestUtils.initLogger();
039: TestUtils.initDb();
040: }
041:
042: public HeadTagTest(String name) {
043: super (name);
044: }
045:
046: protected void setUp() {
047: //setLogLevel( Level.DEBUG );
048: try {
049: request.setAttribute(SiteContext.SITECONTEXT_KEY,
050: SiteContext.getDefaultContext());
051: } catch (Exception e) {
052: fail(e.getMessage());
053: }
054: }
055:
056: protected void tearDown() {
057: }
058:
059: public void testHeadViewPage() {
060: try {
061: HeadTag tag = null;
062: Page page = null;
063:
064: page = new Page();
065: page.setString("title", "Test Page");
066: request.setAttribute(ShimGlobals.PAGE_KEY, page);
067: tag = new HeadTag();
068: tag.setPageContext(pageContext);
069:
070: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
071: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
072:
073: } catch (Exception e) {
074: e.printStackTrace();
075: fail();
076: }
077: }
078:
079: public void endHeadViewPage(WebResponse response) {
080: String output = response.getText();
081: assertEquals(
082: "<head>\n"
083: + "<base href=\"http://localhost:8082/transfercm-test/\"/>\n"
084: + "<title>Test Page</title>\n" + "</head>\n",
085: output);
086: }
087:
088: public void testHeadViewPageAltTitleAndMeta() {
089: try {
090: HeadTag tag = null;
091: Page page = null;
092:
093: page = new Page();
094: page.setString("title", "Test Page");
095: page.setString("alttitle", "altTest Page");
096: page.setString("metadescription", "metadescription");
097: page.setString("metakeywords", "metakeywords");
098: request.setAttribute(ShimGlobals.PAGE_KEY, page);
099: tag = new HeadTag();
100: tag.setPageContext(pageContext);
101:
102: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
103: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
104:
105: } catch (Exception e) {
106: e.printStackTrace();
107: fail();
108: }
109: }
110:
111: public void endHeadViewPageAltTitleAndMeta(WebResponse response) {
112: String output = response.getText();
113: assertEquals(
114: "<head>\n"
115: + "<base href=\"http://localhost:8082/transfercm-test/\"/>\n"
116: + "<title>altTest Page</title>\n"
117: + "<meta name=\"description\" content=\"metadescription\"/>\n"
118: + "<meta name=\"keywords\" content=\"metakeywords\"/>\n"
119: + "</head>\n", output);
120: }
121:
122: public void testHeadEditPage() {
123: try {
124: HeadTag tag = null;
125: Page page = null;
126:
127: page = new Page();
128: page.setString("title", "Test Page");
129: request.setAttribute(ShimGlobals.PAGE_KEY, page);
130: session.setAttribute(ShimGlobals.MODE_KEY,
131: ShimGlobals.MODE_EDIT);
132: tag = new HeadTag();
133: tag.setPageContext(pageContext);
134:
135: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
136: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
137:
138: } catch (Exception e) {
139: e.printStackTrace();
140: fail();
141: }
142: }
143:
144: public void endHeadEditPage(WebResponse response) {
145: //
146: // should get domain specified by site context in base tag when we're logged in
147: //
148: String output = response.getText();
149: assertEquals(
150: "<head>\n"
151: + "<base href=\"http://DEFAULT:8082/transfercm-test/\"/>\n"
152: + "<title>Test Page</title>\n" + "</head>\n",
153: output);
154: }
155:
156: public void testHeadDefine() {
157: try {
158: HeadTag tag = null;
159:
160: request.setAttribute(ShimGlobals.PANELMAP_KEY,
161: new HashMap());
162: tag = new HeadTag();
163: tag.setPageContext(pageContext);
164:
165: assertEquals(Tag.SKIP_BODY, tag.doStartTag());
166: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
167:
168: } catch (Exception e) {
169: e.printStackTrace();
170: fail();
171: }
172: }
173:
174: public void testHeadRichEditPage() {
175: try {
176: HeadTag tag = null;
177: Page page = null;
178: Panel panel = null;
179:
180: page = new Page();
181: page.setString("title", "Test Page");
182: panel = new Panel();
183: panel.setName("body");
184: panel.setModuleClass("com.methodhead.shim.MockModule");
185: page.addPanel(panel);
186: request.setAttribute(ShimGlobals.EDITPANEL_KEY, "body");
187: session.setAttribute(ShimGlobals.MODE_KEY,
188: ShimGlobals.MODE_EDIT);
189: request.setAttribute(ShimGlobals.PAGE_KEY, page);
190: tag = new HeadTag();
191: tag.setPageContext(pageContext);
192:
193: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
194: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
195:
196: } catch (Exception e) {
197: e.printStackTrace();
198: fail();
199: }
200: }
201:
202: public void endHeadRichEditPage(WebResponse response) {
203: //
204: // should get domain specified by site context in base tag when we're logged in
205: //
206: String output = response.getText();
207: assertEquals(
208: "<head>\n"
209: + "<base href=\"http://DEFAULT:8082/transfercm-test/\"/>\n"
210: + "<title>Test Page</title>\n" + "</head>\n",
211: output);
212: }
213:
214: public void testHeadWithSiteContextPath() throws Exception {
215: TestData.createSiteContexts();
216:
217: HeadTag tag = null;
218: Page page = null;
219:
220: //
221: // set site context to something with a path
222: //
223: request.setAttribute(SiteContext.SITECONTEXT_KEY,
224: TestData.siteContext3);
225:
226: page = new Page();
227: page.setString("title", "Test Page");
228: request.setAttribute(ShimGlobals.PAGE_KEY, page);
229:
230: tag = new HeadTag();
231: tag.setPageContext(pageContext);
232:
233: assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
234: assertEquals(Tag.EVAL_PAGE, tag.doEndTag());
235: }
236:
237: public void endHeadWithSiteContextPath(WebResponse response) {
238: String output = response.getText();
239: assertEquals(
240: "<head>\n"
241: + "<base href=\"http://localhost:8082/transfercm-test/path/\"/>\n"
242: + "<title>Test Page</title>\n" + "</head>\n",
243: output);
244: }
245: }
|