KickJava   Java API By Example, From Geeks To Geeks.

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


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 PasswordFormTest 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 PasswordFormTest( String JavaDoc name ) {
50     super( name );
51   }
52
53   public void setUp() throws Exception JavaDoc {
54     super.setUp();
55
56     ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
57
58     TestData.createUsers();
59     AuthUtil.setUser( request, TestData.user1 );
60   }
61
62   public void tearDown()
63   throws
64     Exception JavaDoc {
65     super.tearDown();
66   }
67
68   public void testValidatePasswordMissingPassword() throws Exception JavaDoc {
69     setRequestPathInfo( "/password" );
70     addRequestParameter( "oldpassword", "" );
71     addRequestParameter( "password", "" );
72     addRequestParameter( "verifypassword", "" );
73     actionPerform();
74
75     verifyActionErrors( new String JavaDoc[] { "reg.password.missingpassword", "reg.password.missingoldpassword", "reg.password.missingverifypassword" } );
76   }
77
78   public void testValidatePasswordIncorrectOldPassword() throws Exception JavaDoc {
79     setRequestPathInfo( "/password" );
80     addRequestParameter( "oldpassword", "incorrectpassword" );
81     addRequestParameter( "password", "newpassword" );
82     addRequestParameter( "verifypassword", "newpassword" );
83     actionPerform();
84
85     verifyActionErrors( new String JavaDoc[] { "reg.password.incorrectoldpassword" } );
86   }
87
88   public void testValidatePasswordMismatchedPassword() throws Exception JavaDoc {
89     setRequestPathInfo( "/password" );
90     addRequestParameter( "oldpassword", "password" );
91     addRequestParameter( "password", "newpassword" );
92     addRequestParameter( "verifypassword", "mismatchedpassword" );
93     actionPerform();
94
95     verifyActionErrors( new String JavaDoc[] { "reg.password.verifypasswordmismatch" } );
96   }
97
98   public void testValidatePasswordEncryptedMissingPassword() throws Exception JavaDoc {
99     setRequestPathInfo( "/password" );
100     addRequestParameter( "oldpassword", "" );
101     addRequestParameter( "password", "" );
102     addRequestParameter( "verifypassword", "" );
103     actionPerform();
104
105     verifyActionErrors( new String JavaDoc[] { "reg.password.missingpassword", "reg.password.missingoldpassword", "reg.password.missingverifypassword" } );
106   }
107
108   public void testValidatePasswordEncryptedIncorrectOldPassword() throws Exception JavaDoc {
109     setRequestPathInfo( "/password" );
110     addRequestParameter( "oldpassword", "incorrectpassword" );
111     addRequestParameter( "password", "newpassword" );
112     addRequestParameter( "verifypassword", "newpassword" );
113     actionPerform();
114
115     verifyActionErrors( new String JavaDoc[] { "reg.password.incorrectoldpassword" } );
116   }
117
118   public void testValidatePasswordEncryptedMismatchedPassword() throws Exception JavaDoc {
119     setRequestPathInfo( "/password" );
120     addRequestParameter( "oldpassword", "password" );
121     addRequestParameter( "password", "newpassword" );
122     addRequestParameter( "verifypassword", "mismatchedpassword" );
123     actionPerform();
124
125     verifyActionErrors( new String JavaDoc[] { "reg.password.verifypasswordmismatch" } );
126   }
127
128   public void testValidatePasswordEncrypted() throws Exception JavaDoc {
129     setRequestPathInfo( "/password" );
130     addRequestParameter( "oldpassword", "password" );
131     addRequestParameter( "password", "newpassword" );
132     addRequestParameter( "verifypassword", "newpassword" );
133     actionPerform();
134
135     verifyNoActionErrors();
136   }
137 }
138
Popular Tags