KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > reg > RolesFormTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.reg;
22
23 import java.util.*;
24 import java.io.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.sitecontext.*;
31 import com.methodhead.auth.*;
32 import com.methodhead.*;
33 import servletunit.struts.*;
34 import org.apache.struts.action.*;
35 import org.apache.struts.util.*;
36 import org.apache.cactus.*;
37
38 public class RolesFormTest extends CactusStrutsTestCase {
39
40   List list = null;
41   LabelValueBean labelValue = null;
42   DynaActionForm form = null;
43   User user = null;
44
45   static {
46     TestUtils.initLogger();
47   }
48
49   public RolesFormTest( String JavaDoc name ) {
50     super( name );
51   }
52
53   public void setUp() {
54     try {
55       super.setUp();
56
57       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
58     }
59     catch ( Exception JavaDoc e ) {
60       fail( e.getMessage() );
61     }
62   }
63
64   public void tearDown()
65   throws
66     Exception JavaDoc {
67     super.tearDown();
68   }
69
70   public void testReset() {
71     TestData.createUsers();
72
73     setRequestPathInfo( "/rolesForm" );
74     addRequestParameter( "action", "new" );
75     actionPerform();
76
77     form = ( DynaActionForm )getActionForm();
78
79     //
80
// verify test roles
81
//
82
list = ( List )form.get( "roleOptions" );
83     assertEquals( 3, list.size() );
84
85     labelValue = ( LabelValueBean )list.get( 0 );
86     assertEquals( "System Administrator", labelValue.getLabel() );
87     assertEquals( "ROLE_SYSADMIN", labelValue.getValue() );
88
89     labelValue = ( LabelValueBean )list.get( 1 );
90     assertEquals( "Site Administrator", labelValue.getLabel() );
91     assertEquals( "ROLE_SITEADMIN", labelValue.getValue() );
92
93     labelValue = ( LabelValueBean )list.get( 2 );
94     assertEquals( "Webmaster", labelValue.getLabel() );
95     assertEquals( "ROLE_WEBMASTER", labelValue.getValue() );
96
97     //
98
// verify test sites
99
//
100
list = ( List )form.get( "siteOptions" );
101     assertEquals( 5, list.size() );
102
103     labelValue = ( LabelValueBean )list.get( 0 );
104     assertEquals( "Select...", labelValue.getLabel() );
105     assertEquals( "", labelValue.getValue() );
106
107     labelValue = ( LabelValueBean )list.get( 1 );
108     assertEquals( "DEFAULT", labelValue.getLabel() );
109     assertEquals( "0", labelValue.getValue() );
110
111     labelValue = ( LabelValueBean )list.get( 2 );
112     assertEquals( "site1.com", labelValue.getLabel() );
113     assertEquals( "1", labelValue.getValue() );
114
115     labelValue = ( LabelValueBean )list.get( 3 );
116     assertEquals( "site2.com", labelValue.getLabel() );
117     assertEquals( "2", labelValue.getValue() );
118
119     labelValue = ( LabelValueBean )list.get( 4 );
120     assertEquals( "site3.com/path", labelValue.getLabel() );
121     assertEquals( "3", labelValue.getValue() );
122   }
123 }
124
Popular Tags