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.StatusActions;
19 import org.figure8.join.businessobjects.commons.Status;
20 import org.figure8.join.util.JoinFormTestCase;
21
22 import org.apache.commons.beanutils.PropertyUtils;
23 import org.apache.struts.action.ActionErrors;
24 /**
25 * This is a test case for testing StatusForm validation and setter methods.
26 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
27 * @version $Revision: 1.1 $
28 */
29 public class StatusFormTest extends JoinFormTestCase{
30
31
32
33 /** The StatusForm to test */
34 protected StatusForm form = new StatusForm();
35
36
37
38
39 /** Test form sucessfull validation */
40 public void testValidationSuccess(){
41
42 setOperation(StatusActions.LOAD_OP);
43 form.setIdStr("1");
44 ActionErrors errors = validateForm();
45 assertTrue("Load operation validation sucessfull", errors.isEmpty());
46 assertEquals("Validation convert string to long", 1, form.getId());
47
48 setOperation(StatusActions.SAVE_OP);
49 form.setKey("key");
50 form.setLabel("label");
51 form.setTerminalStr("true");
52 form.setCancelledStr("false");
53 errors = validateForm();
54 assertTrue("Save operation validation sucessfull", errors.isEmpty());
55 assertTrue("Validation convert string to boolean", form.isTerminal());
56 assertFalse("Validation convert stirng to boolean", form.isCancelled());
57 }
58
59 /** Test different form validation failure reason */
60 public void testValidationFailures(){
61
62 setOperation(StatusActions.LOAD_OP);
63 ActionErrors errors = validateForm();
64 assertEquals("Load op. validation fails with no id", 1, errors.size());
65 assertEquals("Load op. validation fails with required id", "errors.required[label.global.id]", errors.get().next().toString());
66
67 setOperation(StatusActions.SAVE_OP);
68 form.setKey("key");
69 errors = validateForm();
70 assertEquals("Save op. validation fails with no label", 1, errors.size());
71 assertEquals("Save op. validation fails with required position", "errors.required[label.status.label]", errors.get().next().toString());
72
73 form.setLabel("label");
74 form.setTerminalStr("true");
75 form.setCancelledStr("true");
76 errors = validateForm();
77 assertEquals("Save op. validation fails with invalid value", 1, errors.size());
78 assertEquals("Save op. validation fails with invalid value", "errors.invalid[label.status.cancelled]", errors.get().next().toString());
79 }
80
81 /** Test the copy of properties from domain object to form */
82 public void testPropertiesCopy(){
83
84 Status status = new Status("key", "label", "type");
85 status.setTerminal(true);
86 status.setCancelled(false);
87 try{
88
89 PropertyUtils.copyProperties(form, status);
90 }
91 catch (Exception e){
92 fail("The properties copy failed with: " + e.getMessage());
93 }
94
95 assertEquals("Key of form is the same as Status", "label", form.getLabel());
96 assertEquals("Label of form is the same as Status", "label", form.getLabel());
97 assertEquals("Type of form is the same as Status", "type", form.getType());
98 assertTrue("Terminal flag of form is the same as Status", form.isTerminal());
99 assertFalse("Cancelled flag fo form is the same as Status", form.isCancelled());
100 }
101
102
103
104
105 /** @return A {@link StatusForm} instance */
106 public JoinForm getFormToValidate(){
107 return form;
108 }
109 }