2
* $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/EmailTest.java,v 1.25 2004/03/30 02:42:06 dgraham Exp $
4
* $Date: 2004/03/30 02:42:06 $
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.
22
package org.apache.commons.validator;
24
import java.io.IOException;
26
import junit.framework.Test;
27
import junit.framework.TestSuite;
29
import org.xml.sax.SAXException;
32
* Performs Validation Test for e-mail validations.
34
public class EmailTest extends TestCommon {
37
* The key used to retrieve the set of validation
38
* rules from the xml file.
40
protected static String FORM_KEY = "emailForm";
43
* The key used to retrieve the validator action.
45
protected static String ACTION = "email";
48
public EmailTest(String name) {
55
* @param theArgs the arguments. Not used
57
public static void main(String[] theArgs) {
58
junit.awtui.TestRunner.main(new String[] {EmailTest.class.getName()});
62
* @return a test suite (<code>TestSuite</code>) that includes all methods
63
* starting with "test"
65
public static Test suite() {
66
// All methods starting with "test" will be executed in the test suite.
67
return new TestSuite(EmailTest.class);
71
* Load <code>ValidatorResources</code> from
72
* validator-regexp.xml.
74
protected void setUp() throws IOException, SAXException {
75
loadResources("validator-regexp.xml");
78
protected void tearDown() {
82
* Tests the e-mail validation.
84
public void testEmail() throws ValidatorException {
85
// Create bean to run test on.
86
ValueBean info = new ValueBean();
88
info.setValue("jsmith@apache.org");
89
valueTest(info, true);
93
* Tests the e-mail validation.
95
public void testEmailExtension() throws ValidatorException {
96
// Create bean to run test on.
97
ValueBean info = new ValueBean();
99
info.setValue("jsmith@apache.org");
100
valueTest(info, true);
102
info.setValue("jsmith@apache.com");
103
valueTest(info, true);
105
info.setValue("jsmith@apache.net");
106
valueTest(info, true);
108
info.setValue("jsmith@apache.info");
109
valueTest(info, true);
111
info.setValue("jsmith@apache.infoo");
112
valueTest(info, false);
114
info.setValue("jsmith@apache.");
115
valueTest(info, false);
117
info.setValue("jsmith@apache.c");
118
valueTest(info, false);
122
* <p>Tests the e-mail validation with a dash in
125
public void testEmailWithDash() throws ValidatorException {
126
// Create bean to run test on.
127
ValueBean info = new ValueBean();
129
info.setValue("andy.noble@data-workshop.com");
130
valueTest(info, true);
132
info.setValue("andy-noble@data-workshop.-com");
133
valueTest(info, true);
134
info.setValue("andy-noble@data-workshop.c-om");
135
valueTest(info,true);
136
info.setValue("andy-noble@data-workshop.co-m");
137
valueTest(info, true);
143
* <p>Tests the e-mail validation with a dot at the end of
146
public void testEmailWithDotEnd() throws ValidatorException {
147
// Create bean to run test on.
148
ValueBean info = new ValueBean();
150
info.setValue("andy.noble@data-workshop.com.");
151
valueTest(info, false);
156
* <p>Tests the e-mail validation with an RCS-noncompliant character in
159
public void testEmailWithBogusCharacter() throws ValidatorException {
160
// Create bean to run test on.
161
ValueBean info = new ValueBean();
163
info.setValue("andy.noble@\u008fdata-workshop.com");
164
valueTest(info, false);
166
// The ' character is valid in an email address.
167
info.setValue("andy.o'reilly@data-workshop.com");
168
valueTest(info, true);
170
info.setValue("foo+bar@i.am.not.in.us.example.com");
171
valueTest(info, true);
175
* Tests the email validation with commas.
177
public void testEmailWithCommas() throws ValidatorException {
178
ValueBean info = new ValueBean();
179
info.setValue("joeblow@apa,che.org");
180
valueTest(info, false);
181
info.setValue("joeblow@apache.o,rg");
182
valueTest(info, false);
183
info.setValue("joeblow@apache,org");
184
valueTest(info, false);
189
* Write this test according to parts of RFC, as opposed to the type of character
190
* that is being tested.
191
* @throws ValidatorException
193
* FIXME This test fails so disable it with a leading _ for 1.1.2 release.
194
* The real solution is to fix the email parsing.
196
public void _testEmailUserName() throws ValidatorException {
197
ValueBean info = new ValueBean();
198
info.setValue("joe1blow@apache.org");
199
valueTest(info, true);
200
info.setValue("joe$blow@apache.org");
201
valueTest(info, true);
202
info.setValue("joe-@apache.org");
203
valueTest(info, true);
204
info.setValue("joe_@apache.org");
205
valueTest(info, true);
207
//UnQuoted Special characters are invalid
209
info.setValue("joe.@apache.org");
210
valueTest(info, false);
211
info.setValue("joe+@apache.org");
212
valueTest(info, false);
213
info.setValue("joe!@apache.org");
214
valueTest(info, false);
215
info.setValue("joe*@apache.org");
216
valueTest(info, false);
217
info.setValue("joe'@apache.org");
218
valueTest(info, false);
219
info.setValue("joe(@apache.org");
220
valueTest(info, false);
221
info.setValue("joe)@apache.org");
222
valueTest(info, false);
223
info.setValue("joe,@apache.org");
224
valueTest(info, false);
225
info.setValue("joe%45@apache.org");
226
valueTest(info, false);
227
info.setValue("joe;@apache.org");
228
valueTest(info, false);
229
info.setValue("joe?@apache.org");
230
valueTest(info, false);
231
info.setValue("joe&@apache.org");
232
valueTest(info, false);
233
info.setValue("joe=@apache.org");
234
valueTest(info, false);
236
//Quoted Special characters are valid
237
info.setValue("\"joe.\"@apache.org");
238
valueTest(info, true);
239
info.setValue("\"joe+\"@apache.org");
240
valueTest(info, true);
241
info.setValue("\"joe!\"@apache.org");
242
valueTest(info, true);
243
info.setValue("\"joe*\"@apache.org");
244
valueTest(info, true);
245
info.setValue("\"joe'\"@apache.org");
246
valueTest(info, true);
247
info.setValue("\"joe(\"@apache.org");
248
valueTest(info, true);
249
info.setValue("\"joe)\"@apache.org");
250
valueTest(info, true);
251
info.setValue("\"joe,\"@apache.org");
252
valueTest(info, true);
253
info.setValue("\"joe%45\"@apache.org");
254
valueTest(info, true);
255
info.setValue("\"joe;\"@apache.org");
256
valueTest(info, true);
257
info.setValue("\"joe?\"@apache.org");
258
valueTest(info, true);
259
info.setValue("\"joe&\"@apache.org");
260
valueTest(info, true);
261
info.setValue("\"joe=\"@apache.org");
262
valueTest(info, true);
267
* These test values derive directly from RFC 822 &
268
* Mail::RFC822::Address & RFC::RFC822::Address perl test.pl
269
* For traceability don't combine these test values with other tests.
271
TestPair[] testEmailFromPerl = {
272
new TestPair("abigail@example.com", true),
273
new TestPair("abigail@example.com ", true),
274
new TestPair(" abigail@example.com", true),
275
new TestPair("abigail @example.com ", true),
276
new TestPair("*@example.net", true),
277
new TestPair("\"\\\"\"@foo.bar", true),
278
new TestPair("fred&barny@example.com", true),
279
new TestPair("---@example.com", true),
280
new TestPair("foo-bar@example.net", true),
281
new TestPair("\"127.0.0.1\"@[127.0.0.1]", true),
282
new TestPair("Abigail <abigail@example.com>", true),
283
new TestPair("Abigail<abigail@example.com>", true),
284
new TestPair("Abigail<@a,@b,@c:abigail@example.com>", true),
285
new TestPair("\"This is a phrase\"<abigail@example.com>", true),
286
new TestPair("\"Abigail \"<abigail@example.com>", true),
287
new TestPair("\"Joe & J. Harvey\" <example @Org>", true),
288
new TestPair("Abigail <abigail @ example.com>", true),
289
new TestPair("Abigail made this < abigail @ example . com >", true),
290
new TestPair("Abigail(the bitch)@example.com", true),
291
new TestPair("Abigail <abigail @ example . (bar) com >", true),
292
new TestPair("Abigail < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
293
new TestPair("Abigail (foo) (((baz)(nested) (comment)) ! ) < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
294
new TestPair("Abigail <abigail(fo\\(o)@example.com>", true),
295
new TestPair("Abigail <abigail(fo\\)o)@example.com> ", true),
296
new TestPair("(foo) abigail@example.com", true),
297
new TestPair("abigail@example.com (foo)", true),
298
new TestPair("\"Abi\\\"gail\" <abigail@example.com>", true),
299
new TestPair("abigail@[example.com]", true),
300
new TestPair("abigail@[exa\\[ple.com]", true),
301
new TestPair("abigail@[exa\\]ple.com]", true),
302
new TestPair("\":sysmail\"@ Some-Group. Some-Org", true),
303
new TestPair("Muhammed.(I am the greatest) Ali @(the)Vegas.WBA", true),
304
new TestPair("mailbox.sub1.sub2@this-domain", true),
305
new TestPair("sub-net.mailbox@sub-domain.domain", true),
306
new TestPair("name:;", true),
307
new TestPair("':;", true),
308
new TestPair("name: ;", true),
309
new TestPair("Alfred Neuman <Neuman@BBN-TENEXA>", true),
310
new TestPair("Neuman@BBN-TENEXA", true),
311
new TestPair("\"George, Ted\" <Shared@Group.Arpanet>", true),
312
new TestPair("Wilt . (the Stilt) Chamberlain@NBA.US", true),
313
new TestPair("Cruisers: Port@Portugal, Jones@SEA;", true),
314
new TestPair("$@[]", true),
315
new TestPair("*()@[]", true),
316
new TestPair("\"quoted ( brackets\" ( a comment )@example.com", true),
317
new TestPair("\"Joe & J. Harvey\"\\x0D\\x0A <ddd\\@ Org>", true),
318
new TestPair("\"Joe &\\x0D\\x0A J. Harvey\" <ddd \\@ Org>", true),
319
new TestPair("Gourmets: Pompous Person <WhoZiWhatZit\\@Cordon-Bleu>,\\x0D\\x0A" +
320
" Childs\\@WGBH.Boston, \"Galloping Gourmet\"\\@\\x0D\\x0A" +
321
" ANT.Down-Under (Australian National Television),\\x0D\\x0A" +
322
" Cheapie\\@Discount-Liquors;", true),
323
new TestPair(" Just a string", false),
324
new TestPair("string", false),
325
new TestPair("(comment)", false),
326
new TestPair("()@example.com", false),
327
new TestPair("fred(&)barny@example.com", false),
328
new TestPair("fred\\ barny@example.com", false),
329
new TestPair("Abigail <abi gail @ example.com>", false),
330
new TestPair("Abigail <abigail(fo(o)@example.com>", false),
331
new TestPair("Abigail <abigail(fo)o)@example.com>", false),
332
new TestPair("\"Abi\"gail\" <abigail@example.com>", false),
333
new TestPair("abigail@[exa]ple.com]", false),
334
new TestPair("abigail@[exa[ple.com]", false),
335
new TestPair("abigail@[exaple].com]", false),
336
new TestPair("abigail@", false),
337
new TestPair("@example.com", false),
338
new TestPair("phrase: abigail@example.com abigail@example.com ;", false),
339
new TestPair("invalid�char@example.com", false)
343
* Write this test based on perl Mail::RFC822::Address
344
* which takes its example email address directly from RFC822
346
* @throws ValidatorException
348
* FIXME This test fails so disable it with a leading _ for 1.1.2 release.
349
* The real solution is to fix the email parsing.
351
public void _testEmailFromPerl() throws ValidatorException {
352
ValueBean info = new ValueBean();
353
for (int index = 0; index < testEmailFromPerl.length; index++) {
354
info.setValue(testEmailFromPerl[index].item);
355
valueTest(info, testEmailFromPerl[index].valid);
360
* Utlity class to run a test on a value.
362
* @param info Value to run test on.
363
* @param passed Whether or not the test is expected to pass.
365
private void valueTest(ValueBean info, boolean passed) throws ValidatorException {
366
// Construct validator based on the loaded resources
368
Validator validator = new Validator(resources, FORM_KEY);
369
// add the name bean to the validator as a resource
370
// for the validations to be performed on.
371
validator.setParameter(Validator.BEAN_PARAM, info);
373
// Get results of the validation.
374
ValidatorResults results = null;
376
// throws ValidatorException,
377
// but we aren't catching for testing
378
// since no validation methods we use
380
results = validator.validate();
382
assertNotNull("Results are null.", results);
384
ValidatorResult result = results.getValidatorResult("value");
386
assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
387
assertTrue("Value "+info.getValue()+" ValidatorResult should contain the '" + ACTION +"' action.", result.containsAction(ACTION));
388
assertTrue("Value "+info.getValue()+"ValidatorResult for the '" + ACTION +"' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
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 for e-mail validations.
30
* @version $Revision: 478560 $ $Date: 2006-11-23 13:09:27 +0000 (Thu, 23 Nov 2006) $
32
public class EmailTest extends TestCommon {
35
* The key used to retrieve the set of validation
36
* rules from the xml file.
38
protected static String FORM_KEY = "emailForm";
41
* The key used to retrieve the validator action.
43
protected static String ACTION = "email";
46
public EmailTest(String name) {
53
* @param theArgs the arguments. Not used
55
public static void main(String[] theArgs) {
56
junit.awtui.TestRunner.main(new String[] {EmailTest.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(EmailTest.class);
69
* Load <code>ValidatorResources</code> from
70
* validator-regexp.xml.
72
protected void setUp() throws IOException, SAXException {
73
loadResources("EmailTest-config.xml");
76
protected void tearDown() {
80
* Tests the e-mail validation.
82
public void testEmail() throws ValidatorException {
83
// Create bean to run test on.
84
ValueBean info = new ValueBean();
86
info.setValue("jsmith@apache.org");
87
valueTest(info, true);
91
* Tests the email validation with numeric domains.
93
public void testEmailWithNumericAddress() throws ValidatorException {
94
ValueBean info = new ValueBean();
95
info.setValue("someone@[216.109.118.76]");
96
valueTest(info, true);
97
info.setValue("someone@yahoo.com");
98
valueTest(info, true);
102
* Tests the e-mail validation.
104
public void testEmailExtension() throws ValidatorException {
105
// Create bean to run test on.
106
ValueBean info = new ValueBean();
108
info.setValue("jsmith@apache.org");
109
valueTest(info, true);
111
info.setValue("jsmith@apache.com");
112
valueTest(info, true);
114
info.setValue("jsmith@apache.net");
115
valueTest(info, true);
117
info.setValue("jsmith@apache.info");
118
valueTest(info, true);
120
info.setValue("jsmith@apache.");
121
valueTest(info, false);
123
info.setValue("jsmith@apache.c");
124
valueTest(info, false);
126
info.setValue("someone@yahoo.museum");
127
valueTest(info, true);
129
info.setValue("someone@yahoo.mu-seum");
130
valueTest(info, false);
134
* <p>Tests the e-mail validation with a dash in
137
public void testEmailWithDash() throws ValidatorException {
138
// Create bean to run test on.
139
ValueBean info = new ValueBean();
141
info.setValue("andy.noble@data-workshop.com");
142
valueTest(info, true);
144
info.setValue("andy-noble@data-workshop.-com");
145
valueTest(info, false);
146
info.setValue("andy-noble@data-workshop.c-om");
147
valueTest(info,false);
148
info.setValue("andy-noble@data-workshop.co-m");
149
valueTest(info, false);
155
* Tests the e-mail validation with a dot at the end of
158
public void testEmailWithDotEnd() throws ValidatorException {
159
// Create bean to run test on.
160
ValueBean info = new ValueBean();
162
info.setValue("andy.noble@data-workshop.com.");
163
valueTest(info, false);
168
* Tests the e-mail validation with an RCS-noncompliant character in
171
public void testEmailWithBogusCharacter() throws ValidatorException {
172
// Create bean to run test on.
173
ValueBean info = new ValueBean();
175
info.setValue("andy.noble@\u008fdata-workshop.com");
176
valueTest(info, false);
178
// The ' character is valid in an email username.
179
info.setValue("andy.o'reilly@data-workshop.com");
180
valueTest(info, true);
182
// But not in the domain name.
183
info.setValue("andy@o'reilly.data-workshop.com");
184
valueTest(info, false);
186
info.setValue("foo+bar@i.am.not.in.us.example.com");
187
valueTest(info, true);
191
* Tests the email validation with commas.
193
public void testEmailWithCommas() throws ValidatorException {
194
ValueBean info = new ValueBean();
195
info.setValue("joeblow@apa,che.org");
196
valueTest(info, false);
197
info.setValue("joeblow@apache.o,rg");
198
valueTest(info, false);
199
info.setValue("joeblow@apache,org");
200
valueTest(info, false);
205
* Tests the email validation with spaces.
207
public void testEmailWithSpaces() throws ValidatorException {
208
ValueBean info = new ValueBean();
209
info.setValue("joeblow @apache.org");
210
valueTest(info, false);
211
info.setValue("joeblow@ apache.org");
212
valueTest(info, false);
213
info.setValue(" joeblow@apache.org");
214
valueTest(info, true);
215
info.setValue("joeblow@apache.org ");
216
valueTest(info, true);
217
info.setValue("joe blow@apache.org ");
218
valueTest(info, false);
219
info.setValue("joeblow@apa che.org ");
220
valueTest(info, false);
225
* Tests the email validation with ascii control characters.
226
* (i.e. Ascii chars 0 - 31 and 127)
228
public void testEmailWithControlChars() throws ValidatorException {
229
EmailValidator validator = new EmailValidator();
230
for (char c = 0; c < 32; c++) {
231
assertFalse("Test control char " + ((int)c), validator.isValid("foo" + c + "bar@domain.com"));
233
assertFalse("Test control char 127", validator.isValid("foo" + ((char)127) + "bar@domain.com"));
237
* Write this test according to parts of RFC, as opposed to the type of character
238
* that is being tested.
240
* <p><b>FIXME</b>: This test fails so disable it with a leading _ for 1.1.4 release.
241
* The real solution is to fix the email parsing.
243
* @throws ValidatorException
245
public void _testEmailUserName() throws ValidatorException {
246
ValueBean info = new ValueBean();
247
info.setValue("joe1blow@apache.org");
248
valueTest(info, true);
249
info.setValue("joe$blow@apache.org");
250
valueTest(info, true);
251
info.setValue("joe-@apache.org");
252
valueTest(info, true);
253
info.setValue("joe_@apache.org");
254
valueTest(info, true);
256
//UnQuoted Special characters are invalid
258
info.setValue("joe.@apache.org");
259
valueTest(info, false);
260
info.setValue("joe+@apache.org");
261
valueTest(info, false);
262
info.setValue("joe!@apache.org");
263
valueTest(info, false);
264
info.setValue("joe*@apache.org");
265
valueTest(info, false);
266
info.setValue("joe'@apache.org");
267
valueTest(info, false);
268
info.setValue("joe(@apache.org");
269
valueTest(info, false);
270
info.setValue("joe)@apache.org");
271
valueTest(info, false);
272
info.setValue("joe,@apache.org");
273
valueTest(info, false);
274
info.setValue("joe%45@apache.org");
275
valueTest(info, false);
276
info.setValue("joe;@apache.org");
277
valueTest(info, false);
278
info.setValue("joe?@apache.org");
279
valueTest(info, false);
280
info.setValue("joe&@apache.org");
281
valueTest(info, false);
282
info.setValue("joe=@apache.org");
283
valueTest(info, false);
285
//Quoted Special characters are valid
286
info.setValue("\"joe.\"@apache.org");
287
valueTest(info, true);
288
info.setValue("\"joe+\"@apache.org");
289
valueTest(info, true);
290
info.setValue("\"joe!\"@apache.org");
291
valueTest(info, true);
292
info.setValue("\"joe*\"@apache.org");
293
valueTest(info, true);
294
info.setValue("\"joe'\"@apache.org");
295
valueTest(info, true);
296
info.setValue("\"joe(\"@apache.org");
297
valueTest(info, true);
298
info.setValue("\"joe)\"@apache.org");
299
valueTest(info, true);
300
info.setValue("\"joe,\"@apache.org");
301
valueTest(info, true);
302
info.setValue("\"joe%45\"@apache.org");
303
valueTest(info, true);
304
info.setValue("\"joe;\"@apache.org");
305
valueTest(info, true);
306
info.setValue("\"joe?\"@apache.org");
307
valueTest(info, true);
308
info.setValue("\"joe&\"@apache.org");
309
valueTest(info, true);
310
info.setValue("\"joe=\"@apache.org");
311
valueTest(info, true);
316
* These test values derive directly from RFC 822 &
317
* Mail::RFC822::Address & RFC::RFC822::Address perl test.pl
318
* For traceability don't combine these test values with other tests.
320
TestPair[] testEmailFromPerl = {
321
new TestPair("abigail@example.com", true),
322
new TestPair("abigail@example.com ", true),
323
new TestPair(" abigail@example.com", true),
324
new TestPair("abigail @example.com ", true),
325
new TestPair("*@example.net", true),
326
new TestPair("\"\\\"\"@foo.bar", true),
327
new TestPair("fred&barny@example.com", true),
328
new TestPair("---@example.com", true),
329
new TestPair("foo-bar@example.net", true),
330
new TestPair("\"127.0.0.1\"@[127.0.0.1]", true),
331
new TestPair("Abigail <abigail@example.com>", true),
332
new TestPair("Abigail<abigail@example.com>", true),
333
new TestPair("Abigail<@a,@b,@c:abigail@example.com>", true),
334
new TestPair("\"This is a phrase\"<abigail@example.com>", true),
335
new TestPair("\"Abigail \"<abigail@example.com>", true),
336
new TestPair("\"Joe & J. Harvey\" <example @Org>", true),
337
new TestPair("Abigail <abigail @ example.com>", true),
338
new TestPair("Abigail made this < abigail @ example . com >", true),
339
new TestPair("Abigail(the bitch)@example.com", true),
340
new TestPair("Abigail <abigail @ example . (bar) com >", true),
341
new TestPair("Abigail < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
342
new TestPair("Abigail (foo) (((baz)(nested) (comment)) ! ) < (one) abigail (two) @(three)example . (bar) com (quz) >", true),
343
new TestPair("Abigail <abigail(fo\\(o)@example.com>", true),
344
new TestPair("Abigail <abigail(fo\\)o)@example.com> ", true),
345
new TestPair("(foo) abigail@example.com", true),
346
new TestPair("abigail@example.com (foo)", true),
347
new TestPair("\"Abi\\\"gail\" <abigail@example.com>", true),
348
new TestPair("abigail@[example.com]", true),
349
new TestPair("abigail@[exa\\[ple.com]", true),
350
new TestPair("abigail@[exa\\]ple.com]", true),
351
new TestPair("\":sysmail\"@ Some-Group. Some-Org", true),
352
new TestPair("Muhammed.(I am the greatest) Ali @(the)Vegas.WBA", true),
353
new TestPair("mailbox.sub1.sub2@this-domain", true),
354
new TestPair("sub-net.mailbox@sub-domain.domain", true),
355
new TestPair("name:;", true),
356
new TestPair("':;", true),
357
new TestPair("name: ;", true),
358
new TestPair("Alfred Neuman <Neuman@BBN-TENEXA>", true),
359
new TestPair("Neuman@BBN-TENEXA", true),
360
new TestPair("\"George, Ted\" <Shared@Group.Arpanet>", true),
361
new TestPair("Wilt . (the Stilt) Chamberlain@NBA.US", true),
362
new TestPair("Cruisers: Port@Portugal, Jones@SEA;", true),
363
new TestPair("$@[]", true),
364
new TestPair("*()@[]", true),
365
new TestPair("\"quoted ( brackets\" ( a comment )@example.com", true),
366
new TestPair("\"Joe & J. Harvey\"\\x0D\\x0A <ddd\\@ Org>", true),
367
new TestPair("\"Joe &\\x0D\\x0A J. Harvey\" <ddd \\@ Org>", true),
368
new TestPair("Gourmets: Pompous Person <WhoZiWhatZit\\@Cordon-Bleu>,\\x0D\\x0A" +
369
" Childs\\@WGBH.Boston, \"Galloping Gourmet\"\\@\\x0D\\x0A" +
370
" ANT.Down-Under (Australian National Television),\\x0D\\x0A" +
371
" Cheapie\\@Discount-Liquors;", true),
372
new TestPair(" Just a string", false),
373
new TestPair("string", false),
374
new TestPair("(comment)", false),
375
new TestPair("()@example.com", false),
376
new TestPair("fred(&)barny@example.com", false),
377
new TestPair("fred\\ barny@example.com", false),
378
new TestPair("Abigail <abi gail @ example.com>", false),
379
new TestPair("Abigail <abigail(fo(o)@example.com>", false),
380
new TestPair("Abigail <abigail(fo)o)@example.com>", false),
381
new TestPair("\"Abi\"gail\" <abigail@example.com>", false),
382
new TestPair("abigail@[exa]ple.com]", false),
383
new TestPair("abigail@[exa[ple.com]", false),
384
new TestPair("abigail@[exaple].com]", false),
385
new TestPair("abigail@", false),
386
new TestPair("@example.com", false),
387
new TestPair("phrase: abigail@example.com abigail@example.com ;", false),
388
new TestPair("invalid�char@example.com", false)
392
* Write this test based on perl Mail::RFC822::Address
393
* which takes its example email address directly from RFC822
395
* @throws ValidatorException
397
* FIXME This test fails so disable it with a leading _ for 1.1.4 release.
398
* The real solution is to fix the email parsing.
400
public void _testEmailFromPerl() throws ValidatorException {
401
ValueBean info = new ValueBean();
402
for (int index = 0; index < testEmailFromPerl.length; index++) {
403
info.setValue(testEmailFromPerl[index].item);
404
valueTest(info, testEmailFromPerl[index].valid);
409
* Utlity class to run a test on a value.
411
* @param info Value to run test on.
412
* @param passed Whether or not the test is expected to pass.
414
private void valueTest(ValueBean info, boolean passed) throws ValidatorException {
415
// Construct validator based on the loaded resources
417
Validator validator = new Validator(resources, FORM_KEY);
418
// add the name bean to the validator as a resource
419
// for the validations to be performed on.
420
validator.setParameter(Validator.BEAN_PARAM, info);
422
// Get results of the validation.
423
ValidatorResults results = null;
425
// throws ValidatorException,
426
// but we aren't catching for testing
427
// since no validation methods we use
429
results = validator.validate();
431
assertNotNull("Results are null.", results);
433
ValidatorResult result = results.getValidatorResult("value");
435
assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
436
assertTrue("Value "+info.getValue()+" ValidatorResult should contain the '" + ACTION +"' action.", result.containsAction(ACTION));
437
assertTrue("Value "+info.getValue()+"ValidatorResult for the '" + ACTION +"' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));