KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
25 import java.io.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.auth.*;
31 import com.methodhead.aikp.*;
32 import com.methodhead.sitecontext.*;
33 import com.methodhead.*;
34 import servletunit.struts.*;
35 import org.apache.struts.action.*;
36 import org.apache.cactus.*;
37
38 public class SendPasswordActionTest extends CactusStrutsTestCase {
39
40   User user = null;
41   Role role = null;
42
43   static {
44     TestUtils.initLogger();
45   }
46
47   public SendPasswordActionTest( String JavaDoc name ) {
48     super( name );
49   }
50
51   public void setUp() {
52     try {
53       super.setUp();
54
55       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
56     }
57     catch ( Exception JavaDoc e ) {
58       fail( e.getMessage() );
59     }
60   }
61
62   public void tearDown()
63   throws
64     Exception JavaDoc {
65     super.tearDown();
66   }
67
68   public void testDoSendPasswordForm() {
69     TestData.createUsers();
70
71     SiteContext.setContext( request, TestData.siteContext1 );
72
73     setRequestPathInfo( "/sendPasswordForm" );
74     actionPerform();
75
76     verifyForward( "form" );
77   }
78
79   public void testDoSendPassword() {
80     TestData.createUsers();
81
82     SiteContext.setContext( request, TestData.siteContext1 );
83
84     setRequestPathInfo( "/sendPassword" );
85     addRequestParameter( "email", "test1@methodhead.com" );
86     actionPerform();
87
88     verifyForward( "success" );
89
90     //
91
// test policy should send the message to test1@methodhead.com
92
//
93

94     //
95
// user should still have the same password
96
//
97
user = new User();
98     user.load( new IntKey( 1 ) );
99     assertEquals( "password", user.getString( "password" ) );
100
101     //
102
// should have message
103
//
104
verifyActionMessages( new String JavaDoc[] { "reg.sendpassword.passwordSent" } );
105   }
106
107   public void testDoSendPasswordEncrypted() {
108     System.out.println( "SendPasswordActionTest.testDoSendPasswordEncrypted(): Can't test encrypted passwords with DefaultTransferPolicy." );
109 /*
110     TestData.createUsers();
111     TestPolicy.setPasswordEncrypted( true );
112
113     SiteContext.setContext( request, TestData.siteContext1 );
114
115     setRequestPathInfo( "/sendPassword" );
116     addRequestParameter( "email", "test1@methodhead.com" );
117     actionPerform();
118
119     verifyForward( "success" );
120
121     //
122     // test policy should send the message to test1@methodhead.com
123     //
124
125     //
126     // user should still have a new password
127     //
128     user = new User();
129     user.load( new IntKey( 1 ) );
130     assertTrue( !"password".equals( user.getString( "password" ) ) );
131
132     //
133     // should have message
134     //
135     verifyActionMessages( new String[] { "reg.sendpassword.passwordSent" } );
136 */

137   }
138 }
139
Popular Tags