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.auth.*;
031: import com.methodhead.sitecontext.*;
032: import com.methodhead.aikp.*;
033: import com.methodhead.*;
034: import com.methodhead.transfer.*;
035: import servletunit.struts.*;
036: import org.apache.struts.action.*;
037: import org.apache.cactus.*;
038:
039: public class UserActionTest extends CactusStrutsTestCase {
040:
041: DynaActionForm form = null;
042: List list = null;
043: String[] strings = null;
044: User user = null;
045: Contact contact = null;
046: Role role = null;
047:
048: static {
049: TestUtils.initLogger();
050: TestUtils.initDb();
051: }
052:
053: public UserActionTest(String name) {
054: super (name);
055: }
056:
057: public void setUp() {
058: try {
059: super .setUp();
060: ConnectionSingleton.runBatchUpdate(new FileReader(
061: "webapp/WEB-INF/db/transfer-reset.sql"));
062:
063: TestData.createUsers();
064: AuthUtil.setUser(request, TestData.user1);
065: } catch (Exception e) {
066: fail(e.getMessage());
067: }
068: }
069:
070: public void tearDown() throws Exception {
071: super .tearDown();
072: }
073:
074: public void testPopulateForm() {
075: try {
076:
077: setRequestPathInfo("/user");
078: addRequestParameter("action", "edit");
079: addRequestParameter("id", "1");
080: actionPerform();
081:
082: verifyInputForward();
083:
084: form = (DynaActionForm) getActionForm();
085:
086: assertEquals("User1", form.get("firstname"));
087: assertEquals("", form.get("middlename"));
088: assertEquals("BBB", form.get("lastname"));
089: assertEquals("", form.get("company"));
090: assertEquals("", form.get("address1"));
091: assertEquals("", form.get("address2"));
092: assertEquals("", form.get("city"));
093: assertEquals("", form.get("state"));
094: assertEquals("", form.get("zip"));
095: assertEquals("", form.get("country"));
096: assertEquals("", form.get("phone"));
097: assertEquals("", form.get("fax"));
098: assertEquals("test1@methodhead.com", form.get("email"));
099: assertEquals("", form.get("url"));
100: assertEquals("", form.get("password"));
101: assertEquals("", form.get("verifypassword"));
102: } catch (Exception e) {
103: e.printStackTrace();
104: fail();
105: }
106: }
107:
108: public void testPopulatePersistable() {
109: try {
110:
111: setRequestPathInfo("/user");
112: addRequestParameter("action", "save");
113: addRequestParameter("id", "1");
114: addRequestParameter("email", "user1@user1.com");
115: addRequestParameter("firstname", "User1Updated");
116: actionPerform();
117:
118: verifyForwardPath("/user.do?action=list");
119:
120: user = new User();
121: user.load(new IntKey(1));
122: assertEquals("User1Updated", user.getContact().getString(
123: "firstname"));
124: } catch (Exception e) {
125: e.printStackTrace();
126: fail();
127: }
128: }
129:
130: public void testDoList() {
131: try {
132: setRequestPathInfo("/user");
133: addRequestParameter("action", "list");
134: actionPerform();
135:
136: verifyForward("list");
137:
138: form = (DynaActionForm) getActionForm();
139: list = (List) form.get("list");
140: assertEquals(3, list.size());
141:
142: user = (User) list.get(0);
143: assertEquals(3, user.getInt("id"));
144:
145: user = (User) list.get(1);
146: assertEquals(1, user.getInt("id"));
147: role = (Role) user.getRoles().get(0);
148: assertEquals(DefaultTransferPolicy.ROLE_SYSADMIN, role
149: .getName());
150:
151: user = (User) list.get(2);
152: assertEquals(2, user.getInt("id"));
153: } catch (Exception e) {
154: e.printStackTrace();
155: fail();
156: }
157: }
158: }
|