1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.config;
22
23 import junit.framework.TestCase;
24
25
26
27
28
29
30
31
32 public class TestFormPropertyConfig extends TestCase {
33 public void testBasicInherit()
34 throws Exception {
35 FormPropertyConfig base =
36 new FormPropertyConfig("base", "java.lang.String[]", "", 10);
37 String baseCount = "10";
38
39 base.setProperty("count", baseCount);
40
41 FormPropertyConfig sub = new FormPropertyConfig();
42
43 sub.setName("base");
44
45 sub.inheritFrom(base);
46
47 assertEquals("Type was not inherited", base.getType(), sub.getType());
48 assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
49 assertEquals("Size was not inherited", base.getSize(), sub.getSize());
50 assertEquals("Arbitrary config property was not inherited", baseCount,
51 sub.getProperty("count"));
52 }
53
54 public void testInheritWithInitialOverride()
55 throws Exception {
56 FormPropertyConfig base =
57 new FormPropertyConfig("base", "java.lang.String", "value");
58
59 FormPropertyConfig sub = new FormPropertyConfig();
60
61 sub.setName("base");
62
63 String initial = "otherValue";
64
65 sub.setInitial(initial);
66
67 sub.inheritFrom(base);
68
69 assertEquals("Type was not inherited", base.getType(), sub.getType());
70 assertEquals("Initial is incorrect", initial, sub.getInitial());
71 assertEquals("Size is incorrect", base.getSize(), sub.getSize());
72 }
73
74 public void testInheritWithTypeOverride()
75 throws Exception {
76 FormPropertyConfig base =
77 new FormPropertyConfig("base", "java.lang.String", "");
78
79 FormPropertyConfig sub = new FormPropertyConfig();
80
81 sub.setName("base");
82 sub.setType("java.lang.Integer");
83
84 sub.inheritFrom(base);
85
86 assertEquals("Type is incorrect", "java.lang.Integer", sub.getType());
87 assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
88 assertEquals("Size is incorrect", base.getSize(), sub.getSize());
89 }
90
91 public void testInheritWithTypeOverride2()
92 throws Exception {
93 FormPropertyConfig base =
94 new FormPropertyConfig("base", "java.lang.String", "");
95
96 FormPropertyConfig sub = new FormPropertyConfig();
97
98 sub.setName("base");
99
100 String type = "java.lang.Integer[]";
101 int size = 10;
102
103 sub.setType(type);
104 sub.setSize(size);
105
106 sub.inheritFrom(base);
107
108 assertEquals("Type is incorrect", type, sub.getType());
109 assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
110 assertEquals("Size is incorrect", size, sub.getSize());
111 }
112
113 public void testInheritWithSizeOverride()
114 throws Exception {
115 FormPropertyConfig base =
116 new FormPropertyConfig("base", "java.lang.String[]", "", 20);
117
118 FormPropertyConfig sub = new FormPropertyConfig();
119
120 sub.setName("base");
121
122 int size = 50;
123
124 sub.setSize(size);
125
126 sub.inheritFrom(base);
127
128 assertEquals("Type was not inherited", base.getType(), sub.getType());
129 assertEquals("Initial is incorrect", base.getInitial(), sub.getInitial());
130 assertEquals("Size is incorrect", size, sub.getSize());
131 }
132 }