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.auth.*;
031: import com.methodhead.sitecontext.*;
032: import com.methodhead.tree.*;
033: import com.methodhead.*;
034: import servletunit.struts.*;
035: import org.apache.struts.action.*;
036: import org.apache.cactus.*;
037:
038: public class HomeActionTest extends CactusStrutsTestCase {
039:
040: TestSite site_ = null;
041: SiteContext siteContext1_ = null;
042: SiteContext siteContext2_ = null;
043:
044: FoldingTreeNode root = null;
045: SiteMapTree tree = null;
046:
047: private void createData() {
048: site_ = new TestSite();
049: site_.createPages();
050: site_.createLinks();
051: site_.createSiteMap();
052:
053: ShimUtils.setUpShimSession(request, SiteContext
054: .getDefaultContext());
055:
056: siteContext1_ = new SiteContext();
057: siteContext1_.getDomains().add("methodhead.com");
058: siteContext1_.saveNew();
059:
060: siteContext2_ = new SiteContext();
061: siteContext2_.getDomains().add("danhensgen.com");
062: siteContext2_.saveNew();
063: }
064:
065: static {
066: TestUtils.initLogger();
067: TestUtils.initDb();
068: }
069:
070: public HomeActionTest(String name) {
071: super (name);
072: }
073:
074: public void setUp() {
075: try {
076: super .setUp();
077:
078: ConnectionSingleton.runBatchUpdate(new FileReader(
079: "webapp/WEB-INF/db/transfer-reset.sql"));
080:
081: TestData.createUsers();
082: AuthUtil.setUser(request, TestData.user1);
083: } catch (Exception e) {
084: fail(e.getMessage());
085: }
086: }
087:
088: public void tearDown() throws Exception {
089: super .tearDown();
090: ShimUtils.tearDownShimSession(request);
091: session.getServletContext().removeAttribute(
092: ShimGlobals.SITEMAPMAP_KEY);
093: }
094:
095: public void testDoHome() {
096: try {
097: ShimUtils.setUpShimSession(request, SiteContext
098: .getDefaultContext());
099:
100: setRequestPathInfo("/home");
101: actionPerform();
102:
103: verifyForward("form");
104: } catch (Exception e) {
105: e.printStackTrace();
106: fail();
107: }
108: }
109:
110: public void testDoHomeWithHomePage() {
111: try {
112: createData();
113:
114: setRequestPathInfo("/home");
115: actionPerform();
116:
117: verifyForwardPath("/editPage.do?id=1");
118: } catch (Exception e) {
119: e.printStackTrace();
120: fail();
121: }
122: }
123:
124: public void testDoHomeNoSiteContext() {
125: try {
126: setRequestPathInfo("/home");
127: actionPerform();
128:
129: verifyForward("form");
130: } catch (Exception e) {
131: e.printStackTrace();
132: fail();
133: }
134: }
135:
136: public void testDoOpenLink() {
137: try {
138: createData();
139:
140: tree = ShimUtils.getSiteMapTree(request);
141: root = (FoldingTreeNode) tree.getRoot();
142: assertTrue(!root.getOpened());
143:
144: setRequestPathInfo("/link");
145: addRequestParameter("open", "" + root.hashCode());
146: actionPerform();
147:
148: verifyForwardPath("/siteMap.do");
149:
150: assertTrue(root.getOpened());
151:
152: setRequestPathInfo("/link");
153: addRequestParameter("close", "" + root.hashCode());
154: actionPerform();
155:
156: verifyForwardPath("/siteMap.do");
157:
158: assertTrue(!root.getOpened());
159: } catch (Exception e) {
160: e.printStackTrace();
161: fail();
162: }
163: }
164:
165: public void testDoSwitch() {
166: try {
167: createData();
168:
169: setRequestPathInfo("/switch");
170: addRequestParameter("id", "" + siteContext2_.getInt("id"));
171: actionPerform();
172:
173: verifyForwardPath("/home.do");
174:
175: assertEquals(siteContext2_, SiteContext.getContext(request));
176: assertNotNull(ShimUtils.getSiteMapTree(request));
177: } catch (Exception e) {
178: e.printStackTrace();
179: fail();
180: }
181: }
182:
183: public void testDoSiteMap() {
184: try {
185: createData();
186:
187: setRequestPathInfo("/siteMap");
188: actionPerform();
189:
190: verifyForward("form");
191: } catch (Exception e) {
192: e.printStackTrace();
193: fail();
194: }
195: }
196: }
|