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.reg;
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.sitecontext.*;
031: import com.methodhead.auth.*;
032: import com.methodhead.*;
033: import servletunit.struts.*;
034: import org.apache.struts.action.*;
035: import org.apache.struts.util.*;
036: import org.apache.cactus.*;
037:
038: public class UserFormTest extends CactusStrutsTestCase {
039:
040: List list = null;
041: LabelValueBean labelValue = null;
042: DynaActionForm form = null;
043: User user = null;
044:
045: static {
046: TestUtils.initLogger();
047: }
048:
049: public UserFormTest(String name) {
050: super (name);
051: }
052:
053: public void setUp() throws Exception {
054: super .setUp();
055:
056: ConnectionSingleton.runBatchUpdate(new FileReader(
057: "webapp/WEB-INF/db/transfer-reset.sql"));
058:
059: TestData.createUsers();
060: }
061:
062: public void tearDown() throws Exception {
063: super .tearDown();
064: }
065:
066: public void testValidateMissingEmail() throws Exception {
067: setRequestPathInfo("/user");
068: addRequestParameter("action", "saveNew");
069: addRequestParameter("email", "");
070: addRequestParameter("password", "password");
071: actionPerform();
072:
073: verifyActionErrors(new String[] { "reg.user.missingemail" });
074: }
075:
076: public void testValidateInvalidEmail() throws Exception {
077: setRequestPathInfo("/user");
078: addRequestParameter("action", "saveNew");
079: addRequestParameter("email", "invalid email com");
080: addRequestParameter("password", "password");
081: addRequestParameter("verifypassword", "password");
082: actionPerform();
083:
084: verifyActionErrors(new String[] { "reg.user.invalidemail" });
085: }
086:
087: public void testValidateMissingPassword() throws Exception {
088: setRequestPathInfo("/user");
089: addRequestParameter("action", "saveNew");
090: addRequestParameter("email", "user1@user1.com");
091: addRequestParameter("password", "");
092: actionPerform();
093:
094: verifyActionErrors(new String[] { "reg.user.missingpassword" });
095: }
096:
097: public void testValidateSaveNewMismatchedPassword()
098: throws Exception {
099: setRequestPathInfo("/user");
100: addRequestParameter("action", "saveNew");
101: addRequestParameter("email", "user1@user1.com");
102: addRequestParameter("password", "password");
103: addRequestParameter("verifypassword", "mismatchedpassword");
104: actionPerform();
105:
106: verifyActionErrors(new String[] { "reg.user.verifypasswordmismatch" });
107: }
108:
109: public void testValidateSaveNewUserExists() throws Exception {
110: setRequestPathInfo("/user");
111: addRequestParameter("action", "saveNew");
112: addRequestParameter("email", "test1@methodhead.com");
113: addRequestParameter("password", "password");
114: addRequestParameter("verifypassword", "password");
115: actionPerform();
116:
117: verifyActionErrors(new String[] { "reg.user.userExists" });
118: }
119:
120: public void testValidateSaveMismatchPassword() throws Exception {
121: setRequestPathInfo("/user");
122: addRequestParameter("action", "save");
123: addRequestParameter("id", "1");
124: addRequestParameter("email", "user1@user1.com");
125: addRequestParameter("password", "password");
126: addRequestParameter("verifypassword", "mismatchpassword");
127: actionPerform();
128:
129: verifyActionErrors(new String[] { "reg.user.verifypasswordmismatch" });
130: }
131:
132: public void testValidateSaveUserExists() throws Exception {
133: setRequestPathInfo("/user");
134: addRequestParameter("action", "save");
135: addRequestParameter("id", "1");
136: addRequestParameter("email", "test2@methodhead.com");
137: addRequestParameter("password", "");
138: addRequestParameter("verifypassword", "");
139: actionPerform();
140:
141: verifyActionErrors(new String[] { "reg.user.userExists" });
142: }
143: }
|