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.sitecontext.*;
031: import com.methodhead.*;
032: import com.methodhead.auth.*;
033: import servletunit.struts.*;
034: import org.apache.struts.action.*;
035: import org.apache.cactus.*;
036:
037: public class LoginActionTest extends CactusStrutsTestCase {
038:
039: SiteContext siteContext = null;
040:
041: static {
042: TestUtils.initLogger();
043: TestUtils.initDb();
044: }
045:
046: public LoginActionTest(String name) {
047: super (name);
048: }
049:
050: public void setUp() {
051: try {
052: super .setUp();
053:
054: ConnectionSingleton.runBatchUpdate(new FileReader(
055: "webapp/WEB-INF/db/transfer-reset.sql"));
056:
057: TestData.createUsers();
058: } catch (Exception e) {
059: fail(e.getMessage());
060: }
061: }
062:
063: public void tearDown() throws Exception {
064: super .tearDown();
065: }
066:
067: public void testDoLoginNoSite() throws Exception {
068: //
069: // log in to no site
070: //
071: setRequestPathInfo("/login");
072: addRequestParameter("login", "test1@methodhead.com");
073: addRequestParameter("password", "password");
074: addRequestParameter("site", "");
075: actionPerform();
076:
077: verifyForward("loggedIn");
078:
079: assertNull(SiteContext.getContext(request));
080: assertNull(session.getAttribute(ShimGlobals.SITEMAPTREE_KEY));
081: }
082:
083: public void testDoLoginSite() throws Exception {
084: //
085: // log in to a site, no path
086: //
087: setRequestPathInfo("/login");
088: addRequestParameter("login", "test2@methodhead.com");
089: addRequestParameter("password", "password");
090: addRequestParameter("site", "site1.com");
091: actionPerform();
092:
093: verifyForward("loggedIn");
094:
095: siteContext = SiteContext.getContext(request);
096: assertNotNull(siteContext);
097: assertEquals(TestData.siteContext1, siteContext);
098: assertNotNull(session.getAttribute(ShimGlobals.SITEMAPTREE_KEY));
099: }
100:
101: public void testDoLoginSiteWithPath() throws Exception {
102: //
103: // log into site with path
104: //
105: setRequestPathInfo("/login");
106: addRequestParameter("login", "test3@methodhead.com");
107: addRequestParameter("password", "password");
108: addRequestParameter("site", "site3.com/path");
109: actionPerform();
110:
111: verifyForward("loggedIn");
112:
113: siteContext = SiteContext.getContext(request);
114: assertNotNull(siteContext);
115: assertEquals(TestData.siteContext3, siteContext);
116: assertNotNull(session.getAttribute(ShimGlobals.SITEMAPTREE_KEY));
117: }
118: }
|