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 com.methodhead.auth.*;
031: import com.methodhead.util.*;
032: import com.methodhead.*;
033: import servletunit.struts.*;
034: import org.apache.struts.action.*;
035: import org.apache.commons.io.*;
036: import org.apache.cactus.*;
037:
038: public class SiteContextFormTest extends CactusStrutsTestCase {
039:
040: private DynaActionForm form = null;
041: private List list = null;
042:
043: static {
044: TestUtils.initLogger();
045: }
046:
047: public SiteContextFormTest(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:
061: //
062: // these directories get created during the test
063: //
064: FileUtils.deleteDirectory(ServletUtils.getRealFile(request,
065: "4"));
066: FileUtils.deleteDirectory(ServletUtils.getRealFile(request,
067: "WEB-INF/resources/4"));
068: } catch (Exception e) {
069: fail(e.getMessage());
070: }
071: }
072:
073: public void tearDown() throws Exception {
074: super .tearDown();
075: }
076:
077: public void testReset() {
078: setRequestPathInfo("/siteContext");
079: addRequestParameter("action", "saveNew");
080: addRequestParameter("domainsText",
081: " danhensgen.com \n\n www.danhensgen.com\n\n ");
082: actionPerform();
083:
084: form = (DynaActionForm) getActionForm();
085: list = (List) form.get("domains");
086: assertEquals(2, list.size());
087:
088: assertEquals("danhensgen.com", list.get(0));
089: assertEquals("www.danhensgen.com", list.get(1));
090: }
091:
092: public void testValidateNoDomains() {
093: //
094: // no domains
095: //
096: setRequestPathInfo("/siteContext");
097: addRequestParameter("action", "saveNew");
098: actionPerform();
099:
100: verifyInputForward();
101: verifyActionErrors(new String[] { "mhf.missingdomains" });
102: }
103:
104: public void testValidateInvalidDomains() {
105: //
106: // invalid domains
107: //
108: setRequestPathInfo("/siteContext");
109: addRequestParameter("action", "saveNew");
110: addRequestParameter("domainsText", "dan hensgen.com");
111: actionPerform();
112:
113: verifyInputForward();
114: verifyActionErrors(new String[] { "mhf.invaliddomain" });
115: }
116:
117: public void testValidateLongDomainName() {
118: //
119: // a long domain name
120: //
121: setRequestPathInfo("/siteContext");
122: addRequestParameter("action", "saveNew");
123: addRequestParameter("domainsText",
124: "0123456789012345678901234567890123456789012345678901234567890123456789.com");
125: actionPerform();
126:
127: verifyInputForward();
128: verifyActionErrors(new String[] { "mhf.invaliddomain" });
129: }
130:
131: public void testExistingDomain() throws Exception {
132: //
133: // an existing domain/path
134: //
135: setRequestPathInfo("/siteContext");
136: addRequestParameter("action", "saveNew");
137: addRequestParameter("domainsText", "site1.com");
138: actionPerform();
139:
140: verifyInputForward();
141: verifyActionErrors(new String[] { "mhf.domainexists" });
142: }
143:
144: public void testValidateExistingDomain2() {
145: //
146: // an existing domain/path, but not the one being saved
147: //
148: setRequestPathInfo("/siteContext");
149: addRequestParameter("action", "save");
150: addRequestParameter("id", "1");
151: addRequestParameter("domainsText", "site2.com");
152: actionPerform();
153:
154: verifyInputForward();
155: verifyActionErrors(new String[] { "mhf.domainexists" });
156: }
157:
158: public void testValidateDashes() {
159: //
160: // dashes should be allowed
161: //
162: setRequestPathInfo("/siteContext");
163: addRequestParameter("action", "saveNew");
164: addRequestParameter("id", "");
165: addRequestParameter("domainsText", "method-head.com");
166: actionPerform();
167:
168: verifyForwardPath("/siteContext.do?action=list");
169: verifyNoActionErrors();
170: }
171: }
|