2
* $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/MultipleTests.java,v 1.15 2004/02/21 17:10:30 rleland Exp $
4
* $Date: 2004/02/21 17:10:30 $
6
* ====================================================================
7
* Copyright 2001-2004 The Apache Software Foundation
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
23
package org.apache.commons.validator;
25
import java.io.IOException;
27
import junit.framework.Test;
28
import junit.framework.TestSuite;
30
import org.xml.sax.SAXException;
33
* Performs Validation Test.
35
public class MultipleTests extends TestCommon {
38
* The key used to retrieve the set of validation
39
* rules from the xml file.
41
protected static String FORM_KEY = "nameForm";
44
* The key used to retrieve the validator action.
46
protected static String ACTION = "required";
50
public MultipleTests(String name) {
57
* @param theArgs the arguments. Not used
59
public static void main(String[] theArgs) {
60
junit.awtui.TestRunner.main(new String[] {MultipleTests.class.getName()});
64
* @return a test suite (<code>TestSuite</code>) that includes all methods
65
* starting with "test"
67
public static Test suite() {
68
// All methods starting with "test" will be executed in the test suite.
69
return new TestSuite(MultipleTests.class);
73
* Load <code>ValidatorResources</code> from
74
* validator-multipletest.xml.
76
protected void setUp() throws IOException, SAXException {
78
loadResources("validator-multipletest.xml");
81
protected void tearDown() {
85
* With nothing provided, we should fail both because both are required.
87
public void testBothBlank() throws ValidatorException {
88
// Create bean to run test on.
89
NameBean name = new NameBean();
91
// Construct validator based on the loaded resources
93
Validator validator = new Validator(resources, FORM_KEY);
94
// add the name bean to the validator as a resource
95
// for the validations to be performed on.
96
validator.setParameter(Validator.BEAN_PARAM, name);
98
// Get results of the validation.
99
ValidatorResults results = null;
101
// throws ValidatorException,
102
// but we aren't catching for testing
103
// since no validation methods we use
105
results = validator.validate();
107
assertNotNull("Results are null.", results);
109
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
110
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
112
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
113
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
114
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
116
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
117
assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
118
assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
119
assertTrue("Last Name ValidatorResults should not contain the 'int' action.", !lastNameResult.containsAction("int"));
123
* If the first name fails required, and the second test fails int, we should get two errors.
125
public void testRequiredFirstNameBlankLastNameShort() throws ValidatorException {
126
// Create bean to run test on.
127
NameBean name = new NameBean();
128
name.setFirstName("");
129
name.setLastName("Test");
131
// Construct validator based on the loaded resources
133
Validator validator = new Validator(resources, FORM_KEY);
134
// add the name bean to the validator as a resource
135
// for the validations to be performed on.
136
validator.setParameter(Validator.BEAN_PARAM, name);
138
// Get results of the validation.
139
ValidatorResults results = null;
141
results = validator.validate();
143
assertNotNull("Results are null.", results);
145
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
146
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
148
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
149
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
150
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
152
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
153
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
154
assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
158
* If the first name is there, and the last name fails int, we should get one error.
160
public void testRequiredLastNameShort() throws ValidatorException {
161
// Create bean to run test on.
162
NameBean name = new NameBean();
163
name.setFirstName("Test");
164
name.setLastName("Test");
166
// Construct validator based on the loaded resources
168
Validator validator = new Validator(resources, FORM_KEY);
169
// add the name bean to the validator as a resource
170
// for the validations to be performed on.
171
validator.setParameter(Validator.BEAN_PARAM, name);
173
// Get results of the validation.
174
ValidatorResults results = null;
176
results = validator.validate();
178
assertNotNull("Results are null.", results);
180
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
181
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
183
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
184
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
185
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
187
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
188
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
189
assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
193
* If first name is ok and last name is ok and is an int, no errors.
195
public void testRequiredLastNameLong() throws ValidatorException {
196
// Create bean to run test on.
197
NameBean name = new NameBean();
198
name.setFirstName("Joe");
199
name.setLastName("12345678");
201
// Construct validator based on the loaded resources
203
Validator validator = new Validator(resources, FORM_KEY);
204
// add the name bean to the validator as a resource
205
// for the validations to be performed on.
206
validator.setParameter(Validator.BEAN_PARAM, name);
208
// Get results of the validation.
209
ValidatorResults results = null;
211
results = validator.validate();
213
assertNotNull("Results are null.", results);
215
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
216
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
218
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
219
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
220
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
222
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
223
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
224
assertTrue("Last Name ValidatorResult for the 'int' action should have passed.", lastNameResult.isValid("int"));
228
* If middle name is not there, then the required dependent test should fail.
229
* No other tests should run
231
* @throws ValidatorException
233
public void testFailingFirstDependentValidator() throws ValidatorException {
234
// Create bean to run test on.
235
NameBean name = new NameBean();
237
// Construct validator based on the loaded resources
239
Validator validator = new Validator(resources, FORM_KEY);
240
// add the name bean to the validator as a resource
241
// for the validations to be performed on.
242
validator.setParameter(Validator.BEAN_PARAM, name);
244
// Get results of the validation.
245
ValidatorResults results = null;
247
results = validator.validate();
249
assertNotNull("Results are null.", results);
251
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
253
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
255
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
256
assertTrue("Middle Name ValidatorResult for the 'required' action should have failed", !middleNameResult.isValid("required"));
258
assertTrue("Middle Name ValidatorResult should not contain the 'int' action.", !middleNameResult.containsAction("int"));
260
assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
264
* If middle name is there but not int, then the required dependent test
265
* should pass, but the int dependent test should fail. No other tests should
268
* @throws ValidatorException
270
public void testFailingNextDependentValidator() throws ValidatorException {
271
// Create bean to run test on.
272
NameBean name = new NameBean();
273
name.setMiddleName("TEST");
275
// Construct validator based on the loaded resources
277
Validator validator = new Validator(resources, FORM_KEY);
278
// add the name bean to the validator as a resource
279
// for the validations to be performed on.
280
validator.setParameter(Validator.BEAN_PARAM, name);
282
// Get results of the validation.
283
ValidatorResults results = null;
285
results = validator.validate();
287
assertNotNull("Results are null.", results);
289
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
291
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
293
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
294
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
296
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
297
assertTrue("Middle Name ValidatorResult for the 'int' action should have failed", !middleNameResult.isValid("int"));
299
assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
303
* If middle name is there and a negative int, then the required and int
304
* dependent tests should pass, but the positive test should fail.
306
* @throws ValidatorException
308
public void testPassingDependentsFailingMain() throws ValidatorException {
309
// Create bean to run test on.
310
NameBean name = new NameBean();
311
name.setMiddleName("-2534");
313
// Construct validator based on the loaded resources
315
Validator validator = new Validator(resources, FORM_KEY);
316
// add the name bean to the validator as a resource
317
// for the validations to be performed on.
318
validator.setParameter(Validator.BEAN_PARAM, name);
320
// Get results of the validation.
321
ValidatorResults results = null;
323
results = validator.validate();
325
assertNotNull("Results are null.", results);
327
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
329
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
331
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
332
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
334
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
335
assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
337
assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
338
assertTrue("Middle Name ValidatorResult for the 'positive' action should have failed", !middleNameResult.isValid("positive"));
342
* If middle name is there and a positve int, then the required and int
343
* dependent tests should pass, and the positive test should pass.
345
* @throws ValidatorException
347
public void testPassingDependentsPassingMain() throws ValidatorException {
348
// Create bean to run test on.
349
NameBean name = new NameBean();
350
name.setMiddleName("2534");
352
// Construct validator based on the loaded resources
354
Validator validator = new Validator(resources, FORM_KEY);
355
// add the name bean to the validator as a resource
356
// for the validations to be performed on.
357
validator.setParameter(Validator.BEAN_PARAM, name);
359
// Get results of the validation.
360
ValidatorResults results = null;
362
results = validator.validate();
364
assertNotNull("Results are null.", results);
366
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
368
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
370
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
371
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
373
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
374
assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
376
assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
377
assertTrue("Middle Name ValidatorResult for the 'positive' action should have passed", middleNameResult.isValid("positive"));
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.validator;
19
import java.io.IOException;
21
import junit.framework.Test;
22
import junit.framework.TestSuite;
24
import org.xml.sax.SAXException;
27
* Performs Validation Test.
29
* @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
31
public class MultipleTests extends TestCommon {
34
* The key used to retrieve the set of validation
35
* rules from the xml file.
37
protected static String FORM_KEY = "nameForm";
40
* The key used to retrieve the validator action.
42
protected static String ACTION = "required";
46
public MultipleTests(String name) {
53
* @param theArgs the arguments. Not used
55
public static void main(String[] theArgs) {
56
junit.awtui.TestRunner.main(new String[] {MultipleTests.class.getName()});
60
* @return a test suite (<code>TestSuite</code>) that includes all methods
61
* starting with "test"
63
public static Test suite() {
64
// All methods starting with "test" will be executed in the test suite.
65
return new TestSuite(MultipleTests.class);
69
* Load <code>ValidatorResources</code> from
70
* validator-multipletest.xml.
72
protected void setUp() throws IOException, SAXException {
74
loadResources("MultipleTests-config.xml");
77
protected void tearDown() {
81
* With nothing provided, we should fail both because both are required.
83
public void testBothBlank() throws ValidatorException {
84
// Create bean to run test on.
85
NameBean name = new NameBean();
87
// Construct validator based on the loaded resources
89
Validator validator = new Validator(resources, FORM_KEY);
90
// add the name bean to the validator as a resource
91
// for the validations to be performed on.
92
validator.setParameter(Validator.BEAN_PARAM, name);
94
// Get results of the validation.
95
ValidatorResults results = null;
97
// throws ValidatorException,
98
// but we aren't catching for testing
99
// since no validation methods we use
101
results = validator.validate();
103
assertNotNull("Results are null.", results);
105
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
106
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
108
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
109
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
110
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
112
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
113
assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
114
assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
115
assertTrue("Last Name ValidatorResults should not contain the 'int' action.", !lastNameResult.containsAction("int"));
119
* If the first name fails required, and the second test fails int, we should get two errors.
121
public void testRequiredFirstNameBlankLastNameShort() throws ValidatorException {
122
// Create bean to run test on.
123
NameBean name = new NameBean();
124
name.setFirstName("");
125
name.setLastName("Test");
127
// Construct validator based on the loaded resources
129
Validator validator = new Validator(resources, FORM_KEY);
130
// add the name bean to the validator as a resource
131
// for the validations to be performed on.
132
validator.setParameter(Validator.BEAN_PARAM, name);
134
// Get results of the validation.
135
ValidatorResults results = null;
137
results = validator.validate();
139
assertNotNull("Results are null.", results);
141
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
142
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
144
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
145
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
146
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
148
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
149
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
150
assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
154
* If the first name is there, and the last name fails int, we should get one error.
156
public void testRequiredLastNameShort() throws ValidatorException {
157
// Create bean to run test on.
158
NameBean name = new NameBean();
159
name.setFirstName("Test");
160
name.setLastName("Test");
162
// Construct validator based on the loaded resources
164
Validator validator = new Validator(resources, FORM_KEY);
165
// add the name bean to the validator as a resource
166
// for the validations to be performed on.
167
validator.setParameter(Validator.BEAN_PARAM, name);
169
// Get results of the validation.
170
ValidatorResults results = null;
172
results = validator.validate();
174
assertNotNull("Results are null.", results);
176
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
177
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
179
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
180
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
181
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
183
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
184
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
185
assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
189
* If first name is ok and last name is ok and is an int, no errors.
191
public void testRequiredLastNameLong() throws ValidatorException {
192
// Create bean to run test on.
193
NameBean name = new NameBean();
194
name.setFirstName("Joe");
195
name.setLastName("12345678");
197
// Construct validator based on the loaded resources
199
Validator validator = new Validator(resources, FORM_KEY);
200
// add the name bean to the validator as a resource
201
// for the validations to be performed on.
202
validator.setParameter(Validator.BEAN_PARAM, name);
204
// Get results of the validation.
205
ValidatorResults results = null;
207
results = validator.validate();
209
assertNotNull("Results are null.", results);
211
ValidatorResult firstNameResult = results.getValidatorResult("firstName");
212
ValidatorResult lastNameResult = results.getValidatorResult("lastName");
214
assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
215
assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
216
assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
218
assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
219
assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
220
assertTrue("Last Name ValidatorResult for the 'int' action should have passed.", lastNameResult.isValid("int"));
224
* If middle name is not there, then the required dependent test should fail.
225
* No other tests should run
227
* @throws ValidatorException
229
public void testFailingFirstDependentValidator() throws ValidatorException {
230
// Create bean to run test on.
231
NameBean name = new NameBean();
233
// Construct validator based on the loaded resources
235
Validator validator = new Validator(resources, FORM_KEY);
236
// add the name bean to the validator as a resource
237
// for the validations to be performed on.
238
validator.setParameter(Validator.BEAN_PARAM, name);
240
// Get results of the validation.
241
ValidatorResults results = null;
243
results = validator.validate();
245
assertNotNull("Results are null.", results);
247
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
249
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
251
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
252
assertTrue("Middle Name ValidatorResult for the 'required' action should have failed", !middleNameResult.isValid("required"));
254
assertTrue("Middle Name ValidatorResult should not contain the 'int' action.", !middleNameResult.containsAction("int"));
256
assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
260
* If middle name is there but not int, then the required dependent test
261
* should pass, but the int dependent test should fail. No other tests should
264
* @throws ValidatorException
266
public void testFailingNextDependentValidator() throws ValidatorException {
267
// Create bean to run test on.
268
NameBean name = new NameBean();
269
name.setMiddleName("TEST");
271
// Construct validator based on the loaded resources
273
Validator validator = new Validator(resources, FORM_KEY);
274
// add the name bean to the validator as a resource
275
// for the validations to be performed on.
276
validator.setParameter(Validator.BEAN_PARAM, name);
278
// Get results of the validation.
279
ValidatorResults results = null;
281
results = validator.validate();
283
assertNotNull("Results are null.", results);
285
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
287
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
289
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
290
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
292
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
293
assertTrue("Middle Name ValidatorResult for the 'int' action should have failed", !middleNameResult.isValid("int"));
295
assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
299
* If middle name is there and a negative int, then the required and int
300
* dependent tests should pass, but the positive test should fail.
302
* @throws ValidatorException
304
public void testPassingDependentsFailingMain() throws ValidatorException {
305
// Create bean to run test on.
306
NameBean name = new NameBean();
307
name.setMiddleName("-2534");
309
// Construct validator based on the loaded resources
311
Validator validator = new Validator(resources, FORM_KEY);
312
// add the name bean to the validator as a resource
313
// for the validations to be performed on.
314
validator.setParameter(Validator.BEAN_PARAM, name);
316
// Get results of the validation.
317
ValidatorResults results = null;
319
results = validator.validate();
321
assertNotNull("Results are null.", results);
323
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
325
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
327
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
328
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
330
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
331
assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
333
assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
334
assertTrue("Middle Name ValidatorResult for the 'positive' action should have failed", !middleNameResult.isValid("positive"));
338
* If middle name is there and a positve int, then the required and int
339
* dependent tests should pass, and the positive test should pass.
341
* @throws ValidatorException
343
public void testPassingDependentsPassingMain() throws ValidatorException {
344
// Create bean to run test on.
345
NameBean name = new NameBean();
346
name.setMiddleName("2534");
348
// Construct validator based on the loaded resources
350
Validator validator = new Validator(resources, FORM_KEY);
351
// add the name bean to the validator as a resource
352
// for the validations to be performed on.
353
validator.setParameter(Validator.BEAN_PARAM, name);
355
// Get results of the validation.
356
ValidatorResults results = null;
358
results = validator.validate();
360
assertNotNull("Results are null.", results);
362
ValidatorResult middleNameResult = results.getValidatorResult("middleName");
364
assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
366
assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
367
assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
369
assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
370
assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
372
assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
373
assertTrue("Middle Name ValidatorResult for the 'positive' action should have passed", middleNameResult.isValid("positive"));