1 64 65 package com.jcorporate.expresso.services.controller.tests; 66 67 import com.jcorporate.expresso.core.controller.ControllerResponse; 68 import com.jcorporate.expresso.core.controller.Input; 69 import com.jcorporate.expresso.core.controller.Transition; 70 import com.jcorporate.expresso.services.test.ControllerTestCase; 71 import com.jcorporate.expresso.services.test.ControllerTestSuite; 72 import junit.framework.TestSuite; 73 import org.apache.cactus.WebRequest; 74 75 76 83 84 public class LoginControllerTest extends ControllerTestCase { 85 86 93 public LoginControllerTest(String testName) throws Exception { 94 super(testName, com.jcorporate.expresso.services.controller.SimpleLoginController.class); 95 } 96 97 98 104 public static void main(String [] args) throws Exception { 105 junit.textui.TestRunner.run(suite()); 106 } 107 108 109 118 public static TestSuite suite() throws Exception { 119 ControllerTestSuite cts = new ControllerTestSuite(); 120 cts.addReadOnlySchemaDependency(com.jcorporate.expresso.core.ExpressoSchema.class); 121 cts.addTestSuite(LoginControllerTest.class); 122 123 return cts; 124 } 125 126 127 138 139 public void beginPromptState(WebRequest theRequest) throws Exception { 140 super.setupParameters("promptLogin", theRequest); 141 } 142 143 144 150 public void testPromptState() throws Exception { 151 ControllerResponse response = super.controllerProcess(); 152 assertTrue("Must get a non-null ControllerResponse Object", response != null); 153 154 Input i = response.getInput("dbContext"); 155 assertTrue("Must have a dbContext Input Object", i != null); 156 157 verifyLoginForm(response); 158 159 } 160 161 168 private void verifyLoginForm(ControllerResponse response) throws Exception { 169 Input i = response.getInput("LoginName"); 170 assertTrue("Must have a LoginName Input Object", i != null); 171 172 i = response.getInput("Password"); 173 assertTrue("Must have a Password Input Object", i != null); 174 175 i = response.getInput("Remember"); 176 assertTrue("Must have a Remember Input Object", i != null); 177 178 Transition t = response.getTransition("processLogin"); 179 assertTrue("Must have a processLogin Transition Object", t != null); 180 181 t = response.getTransition("processLogin"); 182 assertTrue("Must have a promptRegister Transition Object", t != null); 183 184 } 185 186 187 196 public void beginPromptStateLoggedIn(WebRequest theRequest) throws Exception { 197 super.setupParameters("promptLogin", theRequest); 198 super.logIn(theRequest); 199 } 200 201 public void testPromptStateLoggedIn() throws Exception { 202 ControllerResponse response = super.controllerProcess(); 203 assertTrue("Must get a non-null ControllerResponse Object", response != null); 204 205 verifyLoginForm(response); 206 209 } 210 211 212 219 public void beginTestBadLogin(WebRequest theRequest) throws Exception { 220 super.setupParameters("processLogin", theRequest); 221 theRequest.addParameter("LoginName", "dummyFalsePassword"); 222 } 223 224 225 public void testTestBadLogin() throws Exception { 226 ControllerResponse response = super.controllerProcess(); 227 assertTrue("Must get a non-null ControllerResponse Object", response != null); 228 229 verifyLoginForm(response); 233 234 assertTrue("Must have login error message for bad login attempt", 235 response.getErrors().size() > 0); 236 } 237 238 245 public void beginPromptChangePasswordState(WebRequest theRequest) throws Exception { 246 super.setupParameters("promptChangePassword", theRequest); 247 super.logIn(theRequest); 248 } 249 250 255 public void testPromptChangePasswordState() throws Exception { 256 ControllerResponse response = super.controllerProcess(); 257 258 assertTrue("Must get a non-null ControllerResponse Object", response != null); 259 Input i = response.getInput("oldPassword"); 260 assertTrue("Old Password Input Must Exist", i != null); 261 262 i = response.getInput("Password"); 263 assertTrue("New Password Input Must Exist", i != null); 264 265 i = response.getInput("password_verify"); 266 assertTrue("Password Verify Input Must Exist", i != null); 267 268 Transition t = response.getTransition("processChangePassword"); 269 assertTrue("Process Change Password Transition must exist", t != null); 270 271 } 272 } | Popular Tags |