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.transfer;
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: import com.methodhead.shim.*;
038: import com.methodhead.res.*;
039: import com.methodhead.reg.*;
040:
041: public class HomeActionTest extends CactusStrutsTestCase {
042:
043: SiteContext siteContext1_ = null;
044: SiteContext siteContext2_ = null;
045: User user1_ = null;
046:
047: FoldingTreeNode root = null;
048: SiteMapTree tree = null;
049:
050: private void createData() {
051:
052: ShimUtils.setUpShimSession(request, SiteContext
053: .getDefaultContext());
054:
055: siteContext1_ = new SiteContext();
056: siteContext1_.getDomains().add("methodhead.com");
057: siteContext1_.saveNew();
058:
059: siteContext2_ = new SiteContext();
060: siteContext2_.getDomains().add("danhensgen.com");
061: siteContext2_.saveNew();
062: }
063:
064: static {
065: TestUtils.initLogger();
066: TestUtils.initDb();
067: }
068:
069: public HomeActionTest(String name) {
070: super (name);
071: }
072:
073: public void setUp() {
074: try {
075: super .setUp();
076:
077: ConnectionSingleton.runBatchUpdate(new FileReader(
078: "webapp/WEB-INF/db/transfer-reset.sql"));
079:
080: user1_ = new User();
081: user1_.getRoles().add(DefaultTransferPolicy.ROLE_SYSADMIN);
082:
083: AuthUtil.setUser(request, user1_);
084: } catch (Exception e) {
085: fail(e.getMessage());
086: }
087: }
088:
089: public void tearDown() throws Exception {
090: super .tearDown();
091: ShimUtils.tearDownShimSession(request);
092: session.getServletContext().removeAttribute(
093: ShimGlobals.SITEMAPMAP_KEY);
094: }
095:
096: public void testDoSwitch() {
097: try {
098: TestData.createUsers();
099: AuthUtil.setUser(request, TestData.user1);
100:
101: session.setAttribute(ResGlobals.FILETREE_KEY,
102: new FileTree());
103:
104: setRequestPathInfo("/switch");
105: addRequestParameter("id", "2");
106: actionPerform();
107:
108: verifyForwardPath("/home.do");
109:
110: assertNull(session.getAttribute(ResGlobals.FILETREE_KEY));
111: } catch (Exception e) {
112: e.printStackTrace();
113: fail();
114: }
115: }
116: }
|