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.SetupActions;
19  import org.figure8.join.util.JoinFormTestCase;
20  
21  import org.apache.struts.action.ActionErrors;
22  /**
23   * This is a test case for testing SetupForm validation method
24   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
25   * @version $Revision: 1.1 $
26   */
27  public class SetupFormTest extends JoinFormTestCase{
28  
29     // Attributes ---------------------------------------------------------------
30  
31     /** The SetupForm to test */
32     protected SetupForm form = new SetupForm();
33  
34  
35     // Public -------------------------------------------------------------------
36  
37     /** Test form sucessfull validation */
38     public void testValidationSuccess(){
39        // Set setup type.
40        setOperation(SetupActions.SETUP_TYPE_OP);
41        form.setSetupType("standard");
42        ActionErrors errors = validateForm();
43        assertEquals("Set setup type validation sucessfull", 0, errors.size());
44        // Set administrator.
45        setOperation(SetupActions.SETUP_ADMIN_OP);
46        form.setAdminName("admin");
47        form.setAdminPassword("password");
48        form.setAdminCPassword("password");
49        form.setAdminFirstname("firstname");
50        form.setAdminLastname("lastname");
51        errors = validateForm();
52        assertEquals("Set administrator validation sucessfull", 0, errors.size());
53     }
54  
55     /** Test difeerent form validation failure reason */
56     public void testValidationFailures(){
57        // Set setup null type.
58        setOperation(SetupActions.SETUP_TYPE_OP);
59        ActionErrors errors = validateForm();
60        assertEquals("Setup type validation fails with no setup type", 1, errors.size());
61        // Set administrator.
62        setOperation(SetupActions.SETUP_ADMIN_OP);
63        errors = validateForm();
64        assertEquals("Set administrator validation fails with no params", 4, errors.size());
65     }
66  
67  
68     // Implementation of JoinFormTestCase ---------------------------------------
69  
70     /** @return A {@link SetupForm} instance */
71     public JoinForm getFormToValidate(){
72        return form;
73     }
74  }