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 RolesFormTest 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 RolesFormTest(String name) {
050: super (name);
051: }
052:
053: public void setUp() {
054: try {
055: super .setUp();
056:
057: ConnectionSingleton.runBatchUpdate(new FileReader(
058: "webapp/WEB-INF/db/transfer-reset.sql"));
059: } catch (Exception e) {
060: fail(e.getMessage());
061: }
062: }
063:
064: public void tearDown() throws Exception {
065: super .tearDown();
066: }
067:
068: public void testReset() {
069: TestData.createUsers();
070:
071: setRequestPathInfo("/rolesForm");
072: addRequestParameter("action", "new");
073: actionPerform();
074:
075: form = (DynaActionForm) getActionForm();
076:
077: //
078: // verify test roles
079: //
080: list = (List) form.get("roleOptions");
081: assertEquals(3, list.size());
082:
083: labelValue = (LabelValueBean) list.get(0);
084: assertEquals("System Administrator", labelValue.getLabel());
085: assertEquals("ROLE_SYSADMIN", labelValue.getValue());
086:
087: labelValue = (LabelValueBean) list.get(1);
088: assertEquals("Site Administrator", labelValue.getLabel());
089: assertEquals("ROLE_SITEADMIN", labelValue.getValue());
090:
091: labelValue = (LabelValueBean) list.get(2);
092: assertEquals("Webmaster", labelValue.getLabel());
093: assertEquals("ROLE_WEBMASTER", labelValue.getValue());
094:
095: //
096: // verify test sites
097: //
098: list = (List) form.get("siteOptions");
099: assertEquals(5, list.size());
100:
101: labelValue = (LabelValueBean) list.get(0);
102: assertEquals("Select...", labelValue.getLabel());
103: assertEquals("", labelValue.getValue());
104:
105: labelValue = (LabelValueBean) list.get(1);
106: assertEquals("DEFAULT", labelValue.getLabel());
107: assertEquals("0", labelValue.getValue());
108:
109: labelValue = (LabelValueBean) list.get(2);
110: assertEquals("site1.com", labelValue.getLabel());
111: assertEquals("1", labelValue.getValue());
112:
113: labelValue = (LabelValueBean) list.get(3);
114: assertEquals("site2.com", labelValue.getLabel());
115: assertEquals("2", labelValue.getValue());
116:
117: labelValue = (LabelValueBean) list.get(4);
118: assertEquals("site3.com/path", labelValue.getLabel());
119: assertEquals("3", labelValue.getValue());
120: }
121: }
|