1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring.parsers.processors;
12
13 import org.mule.config.spring.parsers.PreProcessor;
14
15 import javax.xml.parsers.ParserConfigurationException;
16
17 public class CheckRequiredAttributesTestCase extends AbstractPreProcessorTestCase
18 {
19 public void testSingleSetSingleAttribute() throws ParserConfigurationException
20 {
21 String[][] groups = new String[][] {
22 new String[]{ "a1" }
23 };
24 String text = "must have all attributes for one of the sets: [a1]";
25
26
27 assertBad(groups, "", text);
28
29
30 assertBad(groups, "x", text);
31
32
33 assertOk(groups, "a1");
34 assertOk(groups, "a1 x");
35 assertOk(groups, "x a1");
36 }
37
38 public void testSingleSetMultipleAttributes() throws ParserConfigurationException
39 {
40 String[][] groups = new String[][] {
41 new String[] { "b1", "b2" }
42 };
43 String text = "must have all attributes for one of the sets: [b1, b2]";
44
45
46 assertBad(groups, "", text);
47
48
49 assertBad(groups, "x", text);
50
51
52 assertBad(groups, "b1", text);
53 assertBad(groups, "b2", text);
54
55
56 assertBad(groups, "x b1", text);
57 assertBad(groups, "x b2", text);
58
59
60 assertOk(groups, "b1 b2");
61
62
63 assertOk(groups, "x b1 b2");
64 }
65
66 public void testTwoSetsSingleAttribute() throws ParserConfigurationException
67 {
68 String[][] groups = new String[][] {
69 new String[] { "a1" },
70 new String[] { "b1" }
71 };
72 String text = "must have all attributes for one of the sets: [a1] [b1]";
73
74
75 assertBad(groups, "", text);
76
77
78 assertBad(groups, "x", text);
79 assertBad(groups, "x y", text);
80
81
82 assertOk(groups, "a1");
83 assertOk(groups, "b1");
84
85
86 assertOk(groups, "a1 x");
87 assertOk(groups, "x a1");
88 assertOk(groups, "b1 x");
89 assertOk(groups, "x b1");
90
91
92 assertOk(groups, "a1 b1");
93 }
94
95 public void testTwoSetsEmptySecondSet() throws ParserConfigurationException
96 {
97 String[][] groups = new String[][] {
98 new String[] { "a1" },
99 new String[] {}
100 };
101 String text = "must have all attributes for one of the sets: [a1]";
102
103
104 assertBad(groups, "", text);
105
106
107 assertBad(groups, "x", text);
108 assertBad(groups, "x b1", text);
109
110
111 assertOk(groups, "a1");
112 assertOk(groups, "a1 x");
113 assertOk(groups, "x a1");
114 }
115
116 public void testTwoSetsMultipleAttributes() throws ParserConfigurationException
117 {
118 String[][] groups = new String[][] {
119 new String[] { "a1", "a2" },
120 new String[] { "b1", "b2" }
121 };
122 String text = "must have all attributes for one of the sets: [a1, a2] [b1, b2]";
123
124
125 assertBad(groups, "", text);
126
127
128 assertBad(groups, "x", text);
129
130
131 assertBad(groups, "a1", text);
132 assertBad(groups, "a2", text);
133 assertBad(groups, "b1", text);
134 assertBad(groups, "b2", text);
135 assertBad(groups, "a1 x", text);
136 assertBad(groups, "a2 x", text);
137 assertBad(groups, "b1 x", text);
138 assertBad(groups, "b2 x", text);
139 assertBad(groups, "x a1", text);
140 assertBad(groups, "x a2", text);
141 assertBad(groups, "x b1", text);
142 assertBad(groups, "x b2", text);
143 assertBad(groups, "a1 b1", text);
144
145
146 assertOk(groups, "a1 a2");
147 assertOk(groups, "x a1 a2");
148 assertOk(groups, "a1 x a2");
149 assertOk(groups, "a1 a2 x");
150 assertOk(groups, "b1 b2");
151 assertOk(groups, "x b1 b2");
152 assertOk(groups, "b1 x b2");
153 assertOk(groups, "b1 b2 x");
154
155
156 assertOk(groups, "a1 a2 b1");
157 assertOk(groups, "x a1 a2 b1");
158 assertOk(groups, "a1 x a2 b1");
159 assertOk(groups, "a1 a2 x b1");
160 assertOk(groups, "a1 a2 b1 x");
161 assertOk(groups, "a1 a2 b2");
162 assertOk(groups, "x a1 a2 b2");
163 assertOk(groups, "a1 x a2 b2");
164 assertOk(groups, "a1 a2 x b2");
165 assertOk(groups, "a1 a2 b2 x");
166 assertOk(groups, "b1 b2 a1");
167 assertOk(groups, "x b1 b2 a1");
168 assertOk(groups, "b1 x b2 a1");
169 assertOk(groups, "b1 b2 x a1");
170 assertOk(groups, "b1 b2 a1 x");
171 assertOk(groups, "b1 b2 a2");
172 assertOk(groups, "x b1 b2 a2");
173 assertOk(groups, "b1 x b2 a2");
174 assertOk(groups, "b1 b2 x a2");
175 assertOk(groups, "b1 b2 a2 x");
176 }
177
178 public void testTwoSetsOverlappingAttributes() throws ParserConfigurationException
179 {
180 String[][] groups = new String[][] {
181 new String[] { "a1", "a2" },
182 new String[] { "a1", "b1" }
183 };
184 String text = "must have all attributes for one of the sets: [a1, a2] [a1, b1]";
185
186
187 assertBad(groups, "", text);
188
189
190 assertBad(groups, "x", text);
191
192
193 assertOk(groups, "a1 a2");
194 assertOk(groups, "x a1 a2");
195 assertOk(groups, "a1 x a2");
196 assertOk(groups, "a1 a2 x");
197
198
199 assertOk(groups, "a1 b1");
200 assertOk(groups, "x a1 b1");
201 assertOk(groups, "a1 x b1");
202 assertOk(groups, "a1 b1 x");
203
204
205 assertOk(groups, "a1 a2 b1");
206 }
207
208 public void testRealWorld() throws ParserConfigurationException
209 {
210 String[][] groups = new String[][] {
211 new String[] { "address" },
212 new String[] { "ref" },
213 new String[] { "type", "from" },
214 new String[] { "type", "recipient" }
215 };
216
217 assertOk(groups, "from id name type");
218 }
219
220 protected PreProcessor createCheck(String[][] constraint)
221 {
222 return new CheckRequiredAttributes(constraint);
223 }
224 }