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.util.JoinFormTestCase;
18  import org.figure8.join.control.JoinForm;
19  import org.figure8.join.control.action.EnvironmentMappingActions;
20  import org.figure8.join.businessobjects.environment.LogicalEnvironment;
21  import org.figure8.join.businessobjects.environment.PhysicalEnvironment;
22  import org.figure8.join.businessobjects.environment.EnvironmentMapping;
23  
24  import org.apache.struts.action.ActionErrors;
25  import org.apache.commons.beanutils.PropertyUtils;
26  /**
27   * JUnit test case for testing EnvironmentMappingForm validation and setter methods.
28   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29   * @version Revision$
30   */
31  public class EnvironmentMappingFormTest extends JoinFormTestCase{
32  
33     // Attributes ---------------------------------------------------------------
34  
35     /** The EnvironmentMappingForm to test */
36     protected EnvironmentMappingForm form = new EnvironmentMappingForm();
37  
38  
39     // Public -------------------------------------------------------------------
40  
41     /** Test form sucessfull validation */
42     public void testValidationSuccess(){
43        // Create mapping operation.
44        setOperation(EnvironmentMappingActions.CREATE_OP);
45        form.setLogicalEnvKey("key01");
46        form.setPhysicalEnvKey("key02");
47        ActionErrors errors = validateForm();
48        assertTrue("Create operation validation successfull", errors.isEmpty());
49     }
50  
51     /** Test different form validation failure reason */
52     public void testValidationFailures(){
53        // Create mapping operation.
54        setOperation(EnvironmentMappingActions.CREATE_OP);
55        ActionErrors errors = validateForm();
56        assertEquals("Create op. validation fails with no param", 2, errors.size());
57        // Add logical env param.
58        form.setLogicalEnvKey("key01");
59        errors = validateForm();
60        assertEquals("Create op. validation fails with 1 param", 1, errors.size());
61     }
62  
63     /** Test the copy of properties from domain object to form */
64     public void testPropertiesCopy(){
65        // Create a new mapping.
66        LogicalEnvironment logicalEnv = new LogicalEnvironment();
67        PhysicalEnvironment physicalEnv = new PhysicalEnvironment();
68        EnvironmentMapping mapping = new EnvironmentMapping(logicalEnv, physicalEnv);
69        mapping.close();
70        try{
71           // Copy into form the step properties.
72           PropertyUtils.copyProperties(form, mapping);
73        }
74        catch (Exception e){
75           fail("The properties copy failed with: " + e.getMessage());
76        }
77        // Assert.
78        assertEquals("StartDate of form is the same as Mapping", mapping.getStartDate(), form.getStartDate());
79        assertEquals("EndDate of form is the same as Mapping", mapping.getEndDate(), form.getEndDate());
80     }
81  
82  
83     // Implementation of JoinFormTestCase ---------------------------------------
84  
85     /** @return A {@link EnvironmentMappingForm} instance */
86     public JoinForm getFormToValidate(){
87        return form;
88     }
89  }