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.sitecontext;
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 servletunit.struts.*;
031: import org.apache.struts.action.*;
032: import org.apache.cactus.*;
033: import com.methodhead.auth.*;
034: import com.methodhead.aikp.*;
035: import com.methodhead.*;
036:
037: public class SiteContextActionTest extends CactusStrutsTestCase {
038:
039: private SiteContext siteContext = null;
040: private DynaActionForm form = null;
041: private List list = null;
042:
043: static {
044: TestUtils.initLogger();
045: }
046:
047: public SiteContextActionTest(String name) {
048: super (name);
049: }
050:
051: public void setUp() {
052: try {
053: super .setUp();
054:
055: ConnectionSingleton.runBatchUpdate(new FileReader(
056: "webapp/WEB-INF/db/transfer-reset.sql"));
057:
058: TestData.createUsers();
059: AuthUtil.setUser(request, TestData.user1);
060: } catch (Exception e) {
061: fail(e.getMessage());
062: }
063: }
064:
065: public void tearDown() throws Exception {
066: super .tearDown();
067: }
068:
069: public void testPopulateForm() {
070: try {
071: setRequestPathInfo("/siteContext");
072: addRequestParameter("action", "edit");
073: addRequestParameter("id", ""
074: + TestData.siteContext2.get("id"));
075: actionPerform();
076:
077: verifyInputForward();
078:
079: form = (DynaActionForm) getActionForm();
080: assertEquals("site2.com\nwww.site2.com", form
081: .get("domainsText"));
082: assertEquals("", form.get("path"));
083: } catch (Exception e) {
084: e.printStackTrace();
085: fail();
086: }
087: }
088:
089: public void testPopulatePersistable() {
090: try {
091: setRequestPathInfo("/siteContext");
092: addRequestParameter("action", "save");
093: addRequestParameter("id", ""
094: + TestData.siteContext1.get("id"));
095: addRequestParameter("domainsText", "newsite1.com");
096: addRequestParameter("path", "test");
097: actionPerform();
098:
099: siteContext = new SiteContext();
100: assertTrue(siteContext.loadForDomainAndPath("newsite1.com",
101: "test"));
102: assertEquals(TestData.siteContext1.get("id"), siteContext
103: .get("id"));
104: } catch (Exception e) {
105: e.printStackTrace();
106: fail();
107: }
108: }
109:
110: public void testDoList() {
111: try {
112: setRequestPathInfo("/siteContext");
113: addRequestParameter("action", "list");
114: actionPerform();
115:
116: verifyForward("list");
117:
118: form = (DynaActionForm) getActionForm();
119:
120: list = (List) form.get("list");
121: assertEquals(4, list.size());
122:
123: siteContext = (SiteContext) list.get(0);
124: assertEquals(1, siteContext.getDomains().size());
125: assertEquals("DEFAULT", siteContext.getDomains().get(0));
126:
127: siteContext = (SiteContext) list.get(1);
128: assertEquals(1, siteContext.getDomains().size());
129: assertEquals("site1.com", siteContext.getDomains().get(0));
130:
131: siteContext = (SiteContext) list.get(2);
132: assertEquals("site2.com", siteContext.getDomains().get(0));
133: assertEquals(2, siteContext.getDomains().size());
134: assertEquals("www.site2.com", siteContext.getDomains().get(
135: 1));
136:
137: siteContext = (SiteContext) list.get(3);
138: assertEquals(1, siteContext.getDomains().size());
139: assertEquals("site3.com", siteContext.getDomains().get(0));
140: assertEquals("path", siteContext.getString("path"));
141: } catch (Exception e) {
142: e.printStackTrace();
143: fail();
144: }
145: }
146:
147: public void testDoCancelSave() {
148: setRequestPathInfo("/siteContext");
149: addRequestParameter("action", "save");
150: addRequestParameter("cancel", "Cancel");
151: addRequestParameter("id", "" + TestData.siteContext1.get("id"));
152: addRequestParameter("domainsText", "danhensgen.com");
153: addRequestParameter("path", "test");
154: actionPerform();
155:
156: verifyForwardPath("/siteContext.do?action=list");
157: }
158:
159: public void testDoCancelDelete() {
160: setRequestPathInfo("/siteContext");
161: addRequestParameter("action", "delete");
162: addRequestParameter("cancel", "Cancel");
163: addRequestParameter("id", "" + TestData.siteContext1.get("id"));
164: addRequestParameter("domainsText", "danhensgen.com");
165: addRequestParameter("path", "test");
166: actionPerform();
167:
168: verifyInputForward();
169: }
170: }
|