1 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 UserFormTest 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 UserFormTest( String name ) { 50 super( name ); 51 } 52 53 public void setUp() throws Exception { 54 super.setUp(); 55 56 ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) ); 57 58 TestData.createUsers(); 59 } 60 61 public void tearDown() 62 throws 63 Exception { 64 super.tearDown(); 65 } 66 67 public void testValidateMissingEmail() throws Exception { 68 setRequestPathInfo( "/user" ); 69 addRequestParameter( "action", "saveNew" ); 70 addRequestParameter( "email", "" ); 71 addRequestParameter( "password", "password" ); 72 actionPerform(); 73 74 verifyActionErrors( new String [] { "reg.user.missingemail" } ); 75 } 76 77 public void testValidateInvalidEmail() throws Exception { 78 setRequestPathInfo( "/user" ); 79 addRequestParameter( "action", "saveNew" ); 80 addRequestParameter( "email", "invalid email com" ); 81 addRequestParameter( "password", "password" ); 82 addRequestParameter( "verifypassword", "password" ); 83 actionPerform(); 84 85 verifyActionErrors( new String [] { "reg.user.invalidemail" } ); 86 } 87 88 public void testValidateMissingPassword() throws Exception { 89 setRequestPathInfo( "/user" ); 90 addRequestParameter( "action", "saveNew" ); 91 addRequestParameter( "email", "user1@user1.com" ); 92 addRequestParameter( "password", "" ); 93 actionPerform(); 94 95 verifyActionErrors( new String [] { "reg.user.missingpassword" } ); 96 } 97 98 public void testValidateSaveNewMismatchedPassword() throws Exception { 99 setRequestPathInfo( "/user" ); 100 addRequestParameter( "action", "saveNew" ); 101 addRequestParameter( "email", "user1@user1.com" ); 102 addRequestParameter( "password", "password" ); 103 addRequestParameter( "verifypassword", "mismatchedpassword" ); 104 actionPerform(); 105 106 verifyActionErrors( new String [] { "reg.user.verifypasswordmismatch" } ); 107 } 108 109 public void testValidateSaveNewUserExists() throws Exception { 110 setRequestPathInfo( "/user" ); 111 addRequestParameter( "action", "saveNew" ); 112 addRequestParameter( "email", "test1@methodhead.com" ); 113 addRequestParameter( "password", "password" ); 114 addRequestParameter( "verifypassword", "password" ); 115 actionPerform(); 116 117 verifyActionErrors( new String [] { "reg.user.userExists" } ); 118 } 119 120 public void testValidateSaveMismatchPassword() throws Exception { 121 setRequestPathInfo( "/user" ); 122 addRequestParameter( "action", "save" ); 123 addRequestParameter( "id", "1" ); 124 addRequestParameter( "email", "user1@user1.com" ); 125 addRequestParameter( "password", "password" ); 126 addRequestParameter( "verifypassword", "mismatchpassword" ); 127 actionPerform(); 128 129 verifyActionErrors( new String [] { "reg.user.verifypasswordmismatch" } ); 130 } 131 132 public void testValidateSaveUserExists() throws Exception { 133 setRequestPathInfo( "/user" ); 134 addRequestParameter( "action", "save" ); 135 addRequestParameter( "id", "1" ); 136 addRequestParameter( "email", "test2@methodhead.com" ); 137 addRequestParameter( "password", "" ); 138 addRequestParameter( "verifypassword", "" ); 139 actionPerform(); 140 141 verifyActionErrors( new String [] { "reg.user.userExists" } ); 142 } 143 } 144 | Popular Tags |