~ubuntu-branches/ubuntu/oneiric/libcommons-validator-java/oneiric

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/validator/MultipleTests.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Kumar Appaiah, Varun Hiremath
  • Date: 2007-09-16 00:57:46 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070916005746-r5xwnjm12ng9fbdf
Tags: 1:1.3.1-1
[ Kumar Appaiah ]
* New upstream release.
* New uploaders: Varun Hiremath and Kumar Appaiah, removed Wolfgang Baer
* Use upstream's conf directory for configuration and DTDs.
* Use a custom ant.properties to avoid downloads.
* Use DEB_UPSTREAM_VERSION in rules instead of versions in rules for symlinking.

[ Varun Hiremath ]
* debian/control:
  + Add rhino to Build-Depends-Indep and Depends.
  + Add XS-Vcs-{Svn, Browser} headers.
  + Depend on java-gcj-compat instead of kaffe.
* debian/compat: switch to 5
* Remove debian/patches and remove RELEASE-NOTES.txt in debian/rules.
* Add debian/orig-tar.sh to remove CRLF line terminators from upstream files.
* debian/rules: implement get-orig-source
* debian/watch: switch to version 3 and call debian/orig-tar.sh

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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 $
3
 
 * $Revision: 1.15 $
4
 
 * $Date: 2004/02/21 17:10:30 $
5
 
 *
6
 
 * ====================================================================
7
 
 * Copyright 2001-2004 The Apache Software Foundation
8
 
 *
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
12
 
 *
13
 
 *     http://www.apache.org/licenses/LICENSE-2.0
14
 
 *
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.
20
 
 */
21
 
 
22
 
 
23
 
package org.apache.commons.validator;
24
 
 
25
 
import java.io.IOException;
26
 
 
27
 
import junit.framework.Test;
28
 
import junit.framework.TestSuite;
29
 
 
30
 
import org.xml.sax.SAXException;
31
 
 
32
 
/**
33
 
 * Performs Validation Test.
34
 
 */
35
 
public class MultipleTests extends TestCommon {
36
 
 
37
 
   /**
38
 
    * The key used to retrieve the set of validation
39
 
    * rules from the xml file.
40
 
    */
41
 
   protected static String FORM_KEY = "nameForm";
42
 
 
43
 
   /**
44
 
    * The key used to retrieve the validator action.
45
 
    */
46
 
   protected static String ACTION = "required";
47
 
 
48
 
 
49
 
 
50
 
   public MultipleTests(String name) {
51
 
       super(name);
52
 
   }
53
 
 
54
 
   /**
55
 
    * Start the tests.
56
 
    *
57
 
    * @param theArgs the arguments. Not used
58
 
    */
59
 
   public static void main(String[] theArgs) {
60
 
       junit.awtui.TestRunner.main(new String[] {MultipleTests.class.getName()});
61
 
   }
62
 
 
63
 
   /**
64
 
    * @return a test suite (<code>TestSuite</code>) that includes all methods
65
 
    *         starting with "test"
66
 
    */
67
 
   public static Test suite() {
68
 
       // All methods starting with "test" will be executed in the test suite.
69
 
       return new TestSuite(MultipleTests.class);
70
 
   }
71
 
 
72
 
   /**
73
 
    * Load <code>ValidatorResources</code> from
74
 
    * validator-multipletest.xml.
75
 
    */
76
 
   protected void setUp() throws IOException, SAXException {
77
 
      // Load resources
78
 
      loadResources("validator-multipletest.xml");
79
 
   }
80
 
 
81
 
   protected void tearDown() {
82
 
   }
83
 
 
84
 
   /**
85
 
    * With nothing provided, we should fail both because both are required.
86
 
    */
87
 
   public void testBothBlank() throws ValidatorException {
88
 
      // Create bean to run test on.
89
 
      NameBean name = new NameBean();
90
 
 
91
 
      // Construct validator based on the loaded resources
92
 
      // and the form key
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);
97
 
 
98
 
      // Get results of the validation.
99
 
      ValidatorResults results = null;
100
 
 
101
 
      // throws ValidatorException,
102
 
      // but we aren't catching for testing
103
 
      // since no validation methods we use
104
 
      // throw this
105
 
      results = validator.validate();
106
 
 
107
 
      assertNotNull("Results are null.", results);
108
 
 
109
 
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
110
 
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
111
 
 
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));
115
 
 
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"));
120
 
   }
121
 
 
122
 
   /**
123
 
    * If the first name fails required, and the second test fails int, we should get two errors.
124
 
    */
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");
130
 
 
131
 
      // Construct validator based on the loaded resources
132
 
      // and the form key
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);
137
 
 
138
 
      // Get results of the validation.
139
 
      ValidatorResults results = null;
140
 
 
141
 
      results = validator.validate();
142
 
 
143
 
      assertNotNull("Results are null.", results);
144
 
 
145
 
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
146
 
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
147
 
 
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));
151
 
 
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"));
155
 
   }
156
 
 
157
 
   /**
158
 
    * If the first name is there, and the last name fails int, we should get one error.
159
 
    */
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");
165
 
 
166
 
      // Construct validator based on the loaded resources
167
 
      // and the form key
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);
172
 
 
173
 
      // Get results of the validation.
174
 
      ValidatorResults results = null;
175
 
 
176
 
      results = validator.validate();
177
 
 
178
 
      assertNotNull("Results are null.", results);
179
 
 
180
 
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
181
 
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
182
 
 
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));
186
 
 
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"));
190
 
   }
191
 
 
192
 
   /**
193
 
    * If first name is ok and last name is ok and is an int, no errors.
194
 
    */
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");
200
 
 
201
 
      // Construct validator based on the loaded resources
202
 
      // and the form key
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);
207
 
 
208
 
      // Get results of the validation.
209
 
      ValidatorResults results = null;
210
 
 
211
 
      results = validator.validate();
212
 
 
213
 
      assertNotNull("Results are null.", results);
214
 
 
215
 
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
216
 
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
217
 
 
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));
221
 
 
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"));
225
 
   }
226
 
 
227
 
   /**
228
 
    * If middle name is not there, then the required dependent test should fail.
229
 
    * No other tests should run
230
 
    *
231
 
    * @throws ValidatorException
232
 
    */
233
 
   public void testFailingFirstDependentValidator() throws ValidatorException {
234
 
       // Create bean to run test on.
235
 
       NameBean name = new NameBean();
236
 
 
237
 
       // Construct validator based on the loaded resources
238
 
       // and the form key
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);
243
 
 
244
 
       // Get results of the validation.
245
 
       ValidatorResults results = null;
246
 
 
247
 
       results = validator.validate();
248
 
 
249
 
       assertNotNull("Results are null.", results);
250
 
 
251
 
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
252
 
 
253
 
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
254
 
 
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"));
257
 
 
258
 
       assertTrue("Middle Name ValidatorResult should not contain the 'int' action.", !middleNameResult.containsAction("int"));
259
 
 
260
 
       assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
261
 
   }
262
 
 
263
 
   /**
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
266
 
    * run.
267
 
    *
268
 
    * @throws ValidatorException
269
 
    */
270
 
   public void testFailingNextDependentValidator() throws ValidatorException {
271
 
       // Create bean to run test on.
272
 
       NameBean name = new NameBean();
273
 
       name.setMiddleName("TEST");
274
 
 
275
 
       // Construct validator based on the loaded resources
276
 
       // and the form key
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);
281
 
 
282
 
       // Get results of the validation.
283
 
       ValidatorResults results = null;
284
 
 
285
 
       results = validator.validate();
286
 
 
287
 
       assertNotNull("Results are null.", results);
288
 
 
289
 
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
290
 
 
291
 
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
292
 
 
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"));
295
 
 
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"));
298
 
 
299
 
       assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
300
 
   }
301
 
 
302
 
   /**
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.
305
 
    *
306
 
    * @throws ValidatorException
307
 
    */
308
 
   public void testPassingDependentsFailingMain() throws ValidatorException {
309
 
       // Create bean to run test on.
310
 
       NameBean name = new NameBean();
311
 
       name.setMiddleName("-2534");
312
 
 
313
 
       // Construct validator based on the loaded resources
314
 
       // and the form key
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);
319
 
 
320
 
       // Get results of the validation.
321
 
       ValidatorResults results = null;
322
 
 
323
 
       results = validator.validate();
324
 
 
325
 
       assertNotNull("Results are null.", results);
326
 
 
327
 
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
328
 
 
329
 
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
330
 
 
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"));
333
 
 
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"));
336
 
 
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"));
339
 
   }
340
 
 
341
 
   /**
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.
344
 
    *
345
 
    * @throws ValidatorException
346
 
    */
347
 
   public void testPassingDependentsPassingMain() throws ValidatorException {
348
 
       // Create bean to run test on.
349
 
       NameBean name = new NameBean();
350
 
       name.setMiddleName("2534");
351
 
 
352
 
       // Construct validator based on the loaded resources
353
 
       // and the form key
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);
358
 
 
359
 
       // Get results of the validation.
360
 
       ValidatorResults results = null;
361
 
 
362
 
       results = validator.validate();
363
 
 
364
 
       assertNotNull("Results are null.", results);
365
 
 
366
 
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
367
 
 
368
 
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
369
 
 
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"));
372
 
 
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"));
375
 
 
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"));
378
 
   }
379
 
}
 
1
/*
 
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
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
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.
 
16
 */
 
17
package org.apache.commons.validator;
 
18
 
 
19
import java.io.IOException;
 
20
 
 
21
import junit.framework.Test;
 
22
import junit.framework.TestSuite;
 
23
 
 
24
import org.xml.sax.SAXException;
 
25
 
 
26
/**
 
27
 * Performs Validation Test.
 
28
 *
 
29
 * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
 
30
 */
 
31
public class MultipleTests extends TestCommon {
 
32
 
 
33
   /**
 
34
    * The key used to retrieve the set of validation
 
35
    * rules from the xml file.
 
36
    */
 
37
   protected static String FORM_KEY = "nameForm";
 
38
 
 
39
   /**
 
40
    * The key used to retrieve the validator action.
 
41
    */
 
42
   protected static String ACTION = "required";
 
43
 
 
44
 
 
45
 
 
46
   public MultipleTests(String name) {
 
47
       super(name);
 
48
   }
 
49
 
 
50
   /**
 
51
    * Start the tests.
 
52
    *
 
53
    * @param theArgs the arguments. Not used
 
54
    */
 
55
   public static void main(String[] theArgs) {
 
56
       junit.awtui.TestRunner.main(new String[] {MultipleTests.class.getName()});
 
57
   }
 
58
 
 
59
   /**
 
60
    * @return a test suite (<code>TestSuite</code>) that includes all methods
 
61
    *         starting with "test"
 
62
    */
 
63
   public static Test suite() {
 
64
       // All methods starting with "test" will be executed in the test suite.
 
65
       return new TestSuite(MultipleTests.class);
 
66
   }
 
67
 
 
68
   /**
 
69
    * Load <code>ValidatorResources</code> from
 
70
    * validator-multipletest.xml.
 
71
    */
 
72
   protected void setUp() throws IOException, SAXException {
 
73
      // Load resources
 
74
      loadResources("MultipleTests-config.xml");
 
75
   }
 
76
 
 
77
   protected void tearDown() {
 
78
   }
 
79
 
 
80
   /**
 
81
    * With nothing provided, we should fail both because both are required.
 
82
    */
 
83
   public void testBothBlank() throws ValidatorException {
 
84
      // Create bean to run test on.
 
85
      NameBean name = new NameBean();
 
86
 
 
87
      // Construct validator based on the loaded resources
 
88
      // and the form key
 
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);
 
93
 
 
94
      // Get results of the validation.
 
95
      ValidatorResults results = null;
 
96
 
 
97
      // throws ValidatorException,
 
98
      // but we aren't catching for testing
 
99
      // since no validation methods we use
 
100
      // throw this
 
101
      results = validator.validate();
 
102
 
 
103
      assertNotNull("Results are null.", results);
 
104
 
 
105
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
 
106
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
 
107
 
 
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));
 
111
 
 
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"));
 
116
   }
 
117
 
 
118
   /**
 
119
    * If the first name fails required, and the second test fails int, we should get two errors.
 
120
    */
 
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");
 
126
 
 
127
      // Construct validator based on the loaded resources
 
128
      // and the form key
 
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);
 
133
 
 
134
      // Get results of the validation.
 
135
      ValidatorResults results = null;
 
136
 
 
137
      results = validator.validate();
 
138
 
 
139
      assertNotNull("Results are null.", results);
 
140
 
 
141
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
 
142
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
 
143
 
 
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));
 
147
 
 
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"));
 
151
   }
 
152
 
 
153
   /**
 
154
    * If the first name is there, and the last name fails int, we should get one error.
 
155
    */
 
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");
 
161
 
 
162
      // Construct validator based on the loaded resources
 
163
      // and the form key
 
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);
 
168
 
 
169
      // Get results of the validation.
 
170
      ValidatorResults results = null;
 
171
 
 
172
      results = validator.validate();
 
173
 
 
174
      assertNotNull("Results are null.", results);
 
175
 
 
176
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
 
177
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
 
178
 
 
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));
 
182
 
 
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"));
 
186
   }
 
187
 
 
188
   /**
 
189
    * If first name is ok and last name is ok and is an int, no errors.
 
190
    */
 
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");
 
196
 
 
197
      // Construct validator based on the loaded resources
 
198
      // and the form key
 
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);
 
203
 
 
204
      // Get results of the validation.
 
205
      ValidatorResults results = null;
 
206
 
 
207
      results = validator.validate();
 
208
 
 
209
      assertNotNull("Results are null.", results);
 
210
 
 
211
      ValidatorResult firstNameResult = results.getValidatorResult("firstName");
 
212
      ValidatorResult lastNameResult = results.getValidatorResult("lastName");
 
213
 
 
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));
 
217
 
 
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"));
 
221
   }
 
222
 
 
223
   /**
 
224
    * If middle name is not there, then the required dependent test should fail.
 
225
    * No other tests should run
 
226
    *
 
227
    * @throws ValidatorException
 
228
    */
 
229
   public void testFailingFirstDependentValidator() throws ValidatorException {
 
230
       // Create bean to run test on.
 
231
       NameBean name = new NameBean();
 
232
 
 
233
       // Construct validator based on the loaded resources
 
234
       // and the form key
 
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);
 
239
 
 
240
       // Get results of the validation.
 
241
       ValidatorResults results = null;
 
242
 
 
243
       results = validator.validate();
 
244
 
 
245
       assertNotNull("Results are null.", results);
 
246
 
 
247
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
 
248
 
 
249
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
 
250
 
 
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"));
 
253
 
 
254
       assertTrue("Middle Name ValidatorResult should not contain the 'int' action.", !middleNameResult.containsAction("int"));
 
255
 
 
256
       assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
 
257
   }
 
258
 
 
259
   /**
 
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
 
262
    * run.
 
263
    *
 
264
    * @throws ValidatorException
 
265
    */
 
266
   public void testFailingNextDependentValidator() throws ValidatorException {
 
267
       // Create bean to run test on.
 
268
       NameBean name = new NameBean();
 
269
       name.setMiddleName("TEST");
 
270
 
 
271
       // Construct validator based on the loaded resources
 
272
       // and the form key
 
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);
 
277
 
 
278
       // Get results of the validation.
 
279
       ValidatorResults results = null;
 
280
 
 
281
       results = validator.validate();
 
282
 
 
283
       assertNotNull("Results are null.", results);
 
284
 
 
285
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
 
286
 
 
287
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
 
288
 
 
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"));
 
291
 
 
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"));
 
294
 
 
295
       assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
 
296
   }
 
297
 
 
298
   /**
 
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.
 
301
    *
 
302
    * @throws ValidatorException
 
303
    */
 
304
   public void testPassingDependentsFailingMain() throws ValidatorException {
 
305
       // Create bean to run test on.
 
306
       NameBean name = new NameBean();
 
307
       name.setMiddleName("-2534");
 
308
 
 
309
       // Construct validator based on the loaded resources
 
310
       // and the form key
 
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);
 
315
 
 
316
       // Get results of the validation.
 
317
       ValidatorResults results = null;
 
318
 
 
319
       results = validator.validate();
 
320
 
 
321
       assertNotNull("Results are null.", results);
 
322
 
 
323
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
 
324
 
 
325
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
 
326
 
 
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"));
 
329
 
 
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"));
 
332
 
 
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"));
 
335
   }
 
336
 
 
337
   /**
 
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.
 
340
    *
 
341
    * @throws ValidatorException
 
342
    */
 
343
   public void testPassingDependentsPassingMain() throws ValidatorException {
 
344
       // Create bean to run test on.
 
345
       NameBean name = new NameBean();
 
346
       name.setMiddleName("2534");
 
347
 
 
348
       // Construct validator based on the loaded resources
 
349
       // and the form key
 
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);
 
354
 
 
355
       // Get results of the validation.
 
356
       ValidatorResults results = null;
 
357
 
 
358
       results = validator.validate();
 
359
 
 
360
       assertNotNull("Results are null.", results);
 
361
 
 
362
       ValidatorResult middleNameResult = results.getValidatorResult("middleName");
 
363
 
 
364
       assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
 
365
 
 
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"));
 
368
 
 
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"));
 
371
 
 
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"));
 
374
   }
 
375
}