View Javadoc

1   /*
2    * $Id: TestFormPropertyConfig.java 376715 2006-02-10 14:51:24Z husted $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.config;
19  
20  import junit.framework.TestCase;
21  
22  /***
23   * Unit tests for the <code>org.apache.struts.config.FormPropertyConfig</code>
24   * class.
25   *
26   * @version $Rev: 376715 $ $Date: 2005-05-21 19:06:53 -0400 (Sat, 21 May 2005)
27   *          $
28   */
29  public class TestFormPropertyConfig extends TestCase {
30      public void testBasicInherit()
31          throws Exception {
32          FormPropertyConfig base =
33              new FormPropertyConfig("base", "java.lang.String[]", "", 10);
34          String baseCount = "10";
35  
36          base.setProperty("count", baseCount);
37  
38          FormPropertyConfig sub = new FormPropertyConfig();
39  
40          sub.setName("base");
41  
42          sub.inheritFrom(base);
43  
44          assertEquals("Type was not inherited", base.getType(), sub.getType());
45          assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
46          assertEquals("Size was not inherited", base.getSize(), sub.getSize());
47          assertEquals("Arbitrary config property was not inherited", baseCount,
48              sub.getProperty("count"));
49      }
50  
51      public void testInheritWithInitialOverride()
52          throws Exception {
53          FormPropertyConfig base =
54              new FormPropertyConfig("base", "java.lang.String", "value");
55  
56          FormPropertyConfig sub = new FormPropertyConfig();
57  
58          sub.setName("base");
59  
60          String initial = "otherValue";
61  
62          sub.setInitial(initial);
63  
64          sub.inheritFrom(base);
65  
66          assertEquals("Type was not inherited", base.getType(), sub.getType());
67          assertEquals("Initial is incorrect", initial, sub.getInitial());
68          assertEquals("Size is incorrect", base.getSize(), sub.getSize());
69      }
70  
71      public void testInheritWithTypeOverride()
72          throws Exception {
73          FormPropertyConfig base =
74              new FormPropertyConfig("base", "java.lang.String", "");
75  
76          FormPropertyConfig sub = new FormPropertyConfig();
77  
78          sub.setName("base");
79          sub.setType("java.lang.Integer");
80  
81          sub.inheritFrom(base);
82  
83          assertEquals("Type is incorrect", "java.lang.Integer", sub.getType());
84          assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
85          assertEquals("Size is incorrect", base.getSize(), sub.getSize());
86      }
87  
88      public void testInheritWithTypeOverride2()
89          throws Exception {
90          FormPropertyConfig base =
91              new FormPropertyConfig("base", "java.lang.String", "");
92  
93          FormPropertyConfig sub = new FormPropertyConfig();
94  
95          sub.setName("base");
96  
97          String type = "java.lang.Integer[]";
98          int size = 10;
99  
100         sub.setType(type);
101         sub.setSize(size);
102 
103         sub.inheritFrom(base);
104 
105         assertEquals("Type is incorrect", type, sub.getType());
106         assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
107         assertEquals("Size is incorrect", size, sub.getSize());
108     }
109 
110     public void testInheritWithSizeOverride()
111         throws Exception {
112         FormPropertyConfig base =
113             new FormPropertyConfig("base", "java.lang.String[]", "", 20);
114 
115         FormPropertyConfig sub = new FormPropertyConfig();
116 
117         sub.setName("base");
118 
119         int size = 50;
120 
121         sub.setSize(size);
122 
123         sub.inheritFrom(base);
124 
125         assertEquals("Type was not inherited", base.getType(), sub.getType());
126         assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
127         assertEquals("Size is incorrect", size, sub.getSize());
128     }
129 }