1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.control.form;
16
17 import org.figure8.join.control.JoinForm;
18 import org.figure8.join.control.action.LoginAction;
19 import org.figure8.join.util.JoinFormTestCase;
20
21 import org.apache.struts.action.ActionErrors;
22 /**
23 * This is a test case for testing LoginForm validation method.
24 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
25 * @version $Revision: 1.1 $
26 */
27 public class LoginFormTest extends JoinFormTestCase{
28
29
30
31 /** The LoginForm to use */
32 protected LoginForm form = new LoginForm();
33
34
35
36
37 /** Test form sucessfull validation */
38 public void testValidationSuccess(){
39 setOperation(LoginAction.ENTER_OP);
40 form.setLogin("login");
41 form.setPassword("password");
42 ActionErrors errors = validateForm();
43 assertEquals("Form validation is sucessfull", 0, errors.size());
44 }
45
46 /** Test different form validation failures */
47 public void testValidationFailures(){
48 setOperation(LoginAction.ENTER_OP);
49
50 ActionErrors errors = validateForm();
51 assertEquals("Validation fails with no login nor password", 2, errors.size());
52
53 form.setLogin("");
54 form.setPassword("");
55 errors = validateForm();
56 assertEquals("Validation fails with empty login and password", 2, errors.size());
57 System.err.println(errors.get());
58
59 form.setLogin(null);
60 form.setPassword("password");
61 errors = validateForm();
62 assertEquals("Validation fails with null login", 1, errors.size());
63 assertEquals("Validation fails with null login", "errors.required[label.user.login]", errors.get().next().toString());
64
65 form.setLogin("login");
66 form.setPassword(null);
67 errors = validateForm();
68 assertEquals("Validation fails with null password", 1, errors.size());
69 assertEquals("Validation fails with null password", "errors.required[label.user.password]", errors.get().next().toString());
70 }
71
72
73
74
75 /** @return A {@link LoginForm} instance */
76 public JoinForm getFormToValidate(){
77 return form;
78 }
79 }