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 java.io.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import com.methodhead.auth.*;
031: import com.methodhead.aikp.*;
032: import com.methodhead.sitecontext.*;
033: import com.methodhead.*;
034: import com.methodhead.util.*;
035: import servletunit.struts.*;
036: import org.apache.struts.action.*;
037: import org.apache.cactus.*;
038:
039: public class ViewPageServletTest extends ServletTestCase {
040:
041: ViewPageServlet servlet = null;
042:
043: static {
044: TestUtils.initLogger();
045: }
046:
047: public ViewPageServletTest(String name) {
048: super (name);
049: }
050:
051: public void setUp() throws Exception {
052: super .setUp();
053:
054: ConnectionSingleton.runBatchUpdate(new FileReader(
055: "webapp/WEB-INF/db/transfer-reset.sql"));
056: }
057:
058: public void tearDown() throws Exception {
059: super .tearDown();
060: }
061:
062: public void beginDoGet(WebRequest webRequest) {
063: //
064: // this doesn't really matter since we'll force certain values later
065: //
066: webRequest.setURL("dev.danhensgen.com", "", "", "/page1.shtml",
067: "");
068: }
069:
070: public void testDoGet() throws Exception {
071: TestData.createSiteMap();
072: TestData.createWebappFiles(ServletUtils
073: .getRealFile(request, ""));
074:
075: //
076: // we need to do what the ShimFilter normally would
077: //
078: SiteContext
079: .setContext(request, SiteContext.getDefaultContext());
080: request.setAttribute(ShimGlobals.PAGEALIAS_KEY, "page1");
081:
082: servlet = new ViewPageServlet();
083: servlet.doGet(request, response);
084: }
085:
086: public void endDoGet(WebResponse webResponse) {
087: assertEquals("\nHello from MockModule.display().\n\n",
088: webResponse.getText());
089: }
090:
091: public void beginDoGetPageNotFound(WebRequest webRequest) {
092: //
093: // this doesn't really matter since we'll force certain values later
094: //
095: webRequest.setURL("dev.danhensgen.com", "", "",
096: "/invalid.shtml", "");
097: }
098:
099: public void testDoGetPageNotFound() throws Exception {
100: TestData.createSiteMap();
101: TestData.createWebappFiles(ServletUtils
102: .getRealFile(request, ""));
103:
104: //
105: // we need to do what the ShimFilter normally would
106: //
107: SiteContext
108: .setContext(request, SiteContext.getDefaultContext());
109: request.setAttribute(ShimGlobals.PAGEALIAS_KEY, "invalid");
110:
111: servlet = new ViewPageServlet();
112: servlet.doGet(request, response);
113: }
114:
115: public void endDoGetPageNotFound(WebResponse webResponse) {
116: assertEquals(410, webResponse.getStatusCode());
117: assertTrue(webResponse.getText().indexOf("Page Not Found") > 0);
118: }
119:
120: public void beginDoGetPageNotFoundWithPage(WebRequest webRequest) {
121: //
122: // this doesn't really matter since we'll force certain values later
123: //
124: webRequest.setURL("dev.danhensgen.com", "", "",
125: "/invalid.shtml", "");
126: }
127:
128: public void testDoGetPageNotFoundWithPage() throws Exception {
129: TestData.createPageNotFoundPage();
130: TestData.createWebappFiles(ServletUtils
131: .getRealFile(request, ""));
132:
133: //
134: // we need to do what the ShimFilter normally would
135: //
136: SiteContext
137: .setContext(request, SiteContext.getDefaultContext());
138: request.setAttribute(ShimGlobals.PAGEALIAS_KEY, "invalid");
139:
140: servlet = new ViewPageServlet();
141: servlet.doGet(request, response);
142: }
143:
144: public void endDoGetPageNotFoundWithPage(WebResponse webResponse) {
145: //
146: // we used template3.jsp for the pagenotfound page and it contains this
147: // text
148: //
149: assertEquals(410, webResponse.getStatusCode());
150: assertEquals("This is a template.\n", webResponse.getText());
151: }
152: }
|