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.MessageActions;
19  import org.figure8.join.util.JoinFormTestCase;
20  
21  import org.apache.struts.action.ActionErrors;
22  /**
23   * This is a test case for testing MessageForm validation and setter methods.
24   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
25   * @version $Revision: 1.1 $
26   */
27  public class MessageFormTest extends JoinFormTestCase{
28  
29     // Attributes ---------------------------------------------------------------
30  
31     /** The MessageForm to test */
32     protected MessageForm form = new MessageForm();
33  
34  
35     // Public -------------------------------------------------------------------
36  
37     /** Test form sucessfull validation */
38     public void testValidationSuccess(){
39        // Load message operation.
40        setOperation(MessageActions.LOAD_OP);
41        form.setIdStr("123");
42        ActionErrors errors = validateForm();
43        assertTrue("Load operation validation sucessfull", errors.isEmpty());
44     }
45  
46     /** Test different form validation failure reason */
47     public void testValidationFailures(){
48        // Save message operation.
49        setOperation(MessageActions.SAVE_OP);
50        ActionErrors errors = validateForm();
51        assertEquals("Load op. validation fails with no title, content, publication and expiry date", 4, errors.size());
52     }
53  
54  
55     // Implementation of JoinFormTestCase ---------------------------------------
56  
57     /** @return A {@link MessageForm} instance */
58     public JoinForm getFormToValidate(){
59        return form;
60     }
61  }