rleland 2004/01/19 06:11:34
Modified: validator/src/test/org/apache/commons/validator
EmailTest.java UrlTest.java
Added: validator/src/test/org/apache/commons/validator
TestPair.java
Log:
Add test for email address comments
Revision Changes Path
1.23 +134 -46
jakarta-commons/validator/src/test/org/apache/commons/validator/EmailTest.java
Index: EmailTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/EmailTest.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- EmailTest.java 11 Jan 2004 23:30:21 -0000 1.22
+++ EmailTest.java 19 Jan 2004 14:11:33 -0000 1.23
@@ -72,12 +72,12 @@
* Performs Validation Test for e-mail validations.
*/
public class EmailTest extends TestCommon {
-
- /**
- * The key used to retrieve the set of validation
- * rules from the xml file.
- */
- protected static String FORM_KEY = "emailForm";
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "emailForm";
/**
* The key used to retrieve the validator action.
@@ -133,27 +133,27 @@
* Tests the e-mail validation.
*/
public void testEmailExtension() throws ValidatorException {
- // Create bean to run test on.
- ValueBean info = new ValueBean();
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, true);
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, true);
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, true);
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, true);
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, false);
-
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, true);
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, true);
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, true);
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, true);
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, false);
+
info.setValue("[EMAIL PROTECTED]");
valueTest(info, false);
-
+
info.setValue("[EMAIL PROTECTED]");
valueTest(info, false);
}
@@ -193,20 +193,20 @@
}
/**
- * <p>Tests the e-mail validation with an RCS-noncompliant character in
+ * <p>Tests the e-mail validation with an RCS-noncompliant character in
* the address.</p>
*/
public void testEmailWithBogusCharacter() throws ValidatorException {
- // Create bean to run test on.
- ValueBean info = new ValueBean();
-
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, false);
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, false);
// The ' character is valid in an email address.
- info.setValue("andy.o'[EMAIL PROTECTED]");
- valueTest(info, true);
-
+ info.setValue("andy.o'[EMAIL PROTECTED]");
+ valueTest(info, true);
+
info.setValue("[EMAIL PROTECTED]");
valueTest(info, true);
}
@@ -215,11 +215,11 @@
* Tests the email validation with commas.
*/
public void testEmailWithCommas() throws ValidatorException {
- ValueBean info = new ValueBean();
- info.setValue("[EMAIL PROTECTED],che.org");
- valueTest(info, false);
- info.setValue("[EMAIL PROTECTED],rg");
- valueTest(info, false);
+ ValueBean info = new ValueBean();
+ info.setValue("[EMAIL PROTECTED],che.org");
+ valueTest(info, false);
+ info.setValue("[EMAIL PROTECTED],rg");
+ valueTest(info, false);
info.setValue("[EMAIL PROTECTED],org");
valueTest(info, false);
@@ -231,9 +231,9 @@
* @throws ValidatorException
*/
public void testEmailUserName() throws ValidatorException {
- ValueBean info = new ValueBean();
- info.setValue("[EMAIL PROTECTED]");
- valueTest(info, true);
+ ValueBean info = new ValueBean();
+ info.setValue("[EMAIL PROTECTED]");
+ valueTest(info, true);
info.setValue("[EMAIL PROTECTED]");
valueTest(info, true);
info.setValue("[EMAIL PROTECTED]");
@@ -300,7 +300,95 @@
}
+ /**
+ * These test values derive directly from RFC 822 &
+ * Mail::RFC822::Address & RFC::RFC822::Address perl test.pl
+ * For traceability don't combine these test values with other tests.
+ */
+ TestPair[] testEmailFromPerl = {
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED] ", true),
+ new TestPair(" [EMAIL PROTECTED]", true),
+ new TestPair("abigail @example.com ", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("\"\\\"\"@foo.bar", true),
+ new TestPair("fred&[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("\"127.0.0.1\"@[127.0.0.1]", true),
+ new TestPair("Abigail <[EMAIL PROTECTED]>", true),
+ new TestPair("Abigail<[EMAIL PROTECTED]>", true),
+ new TestPair("Abigail<@a,@b,@c:[EMAIL PROTECTED]>", true),
+ new TestPair("\"This is a phrase\"<[EMAIL PROTECTED]>", true),
+ new TestPair("\"Abigail \"<[EMAIL PROTECTED]>", true),
+ new TestPair("\"Joe & J. Harvey\" <example @Org>", true),
+ new TestPair("Abigail <abigail @ example.com>", true),
+ new TestPair("Abigail made this < abigail @ example . com >",
true),
+ new TestPair("Abigail(the bitch)@example.com", true),
+ new TestPair("Abigail <abigail @ example . (bar) com >", true),
+ new TestPair("Abigail < (one) abigail (two) @(three)example . (bar) com
(quz) >", true),
+ new TestPair("Abigail (foo) (((baz)(nested) (comment)) ! ) < (one) abigail
(two) @(three)example . (bar) com (quz) >", true),
+ new TestPair("Abigail <abigail(fo\\(o)@example.com>", true),
+ new TestPair("Abigail <abigail(fo\\)o)@example.com> ", true),
+ new TestPair("(foo) [EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED] (foo)", true),
+ new TestPair("\"Abi\\\"gail\" <[EMAIL PROTECTED]>", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("\":sysmail\"@ Some-Group. Some-Org", true),
+ new TestPair("Muhammed.(I am the greatest) Ali @(the)Vegas.WBA", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("name:;", true),
+ new TestPair("':;", true),
+ new TestPair("name: ;", true),
+ new TestPair("Alfred Neuman <[EMAIL PROTECTED]>", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("\"George, Ted\" <[EMAIL PROTECTED]>", true),
+ new TestPair("Wilt . (the Stilt) [EMAIL PROTECTED]", true),
+ new TestPair("Cruisers: [EMAIL PROTECTED], [EMAIL PROTECTED];", true),
+ new TestPair("[EMAIL PROTECTED]", true),
+ new TestPair("*()@[]", true),
+ new TestPair("\"quoted ( brackets\" ( a comment )@example.com", true),
+ new TestPair("\"Joe & J. Harvey\"\\x0D\\x0A <ddd\\@ Org>", true),
+ new TestPair("\"Joe &\\x0D\\x0A J. Harvey\" <ddd \\@ Org>", true),
+ new TestPair("Gourmets: Pompous Person <[EMAIL PROTECTED]>,\\x0D\\x0A" +
+ " [EMAIL PROTECTED], \"Galloping Gourmet\"[EMAIL PROTECTED]" +
+ " ANT.Down-Under (Australian National Television),\\x0D\\x0A" +
+ " [EMAIL PROTECTED];", true),
+ new TestPair(" Just a string", false),
+ new TestPair("string", false),
+ new TestPair("(comment)", false),
+ new TestPair("()@example.com", false),
+ new TestPair("fred(&)[EMAIL PROTECTED]", false),
+ new TestPair("fred\\ [EMAIL PROTECTED]", false),
+ new TestPair("Abigail <abi gail @ example.com>", false),
+ new TestPair("Abigail <abigail(fo(o)@example.com>", false),
+ new TestPair("Abigail <abigail(fo)o)@example.com>", false),
+ new TestPair("\"Abi\"gail\" <[EMAIL PROTECTED]>", false),
+ new TestPair("[EMAIL PROTECTED]", false),
+ new TestPair("[EMAIL PROTECTED]", false),
+ new TestPair("[EMAIL PROTECTED]", false),
+ new TestPair("abigail@", false),
+ new TestPair("@example.com", false),
+ new TestPair("phrase: [EMAIL PROTECTED] [EMAIL PROTECTED] ;", false),
+ new TestPair("[EMAIL PROTECTED]", false)
+ };
+ /**
+ * Write this test based on perl Mail::RFC822::Address
+ * which takes its example email address directly from RFC822
+ *
+ * @throws ValidatorException
+ */
+ public void testEmailFromPerl() throws ValidatorException {
+ ValueBean info = new ValueBean();
+ for (int index = 0; index < testEmailFromPerl.length; index++) {
+ info.setValue(testEmailFromPerl[index].item);
+ valueTest(info, testEmailFromPerl[index].valid);
+ }
+ }
/**
* Utlity class to run a test on a value.
@@ -332,5 +420,5 @@
assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
assertTrue("Value "+info.getValue()+" ValidatorResult should contain the '" +
ACTION +"' action.", result.containsAction(ACTION));
assertTrue("Value "+info.getValue()+"ValidatorResult for the '" + ACTION +"'
action should have " + (passed ? "passed" : "failed") + ".", (passed ?
result.isValid(ACTION) : !result.isValid(ACTION)));
- }
+ }
}
1.8 +3 -12
jakarta-commons/validator/src/test/org/apache/commons/validator/UrlTest.java
Index: UrlTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/UrlTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UrlTest.java 11 Jan 2004 23:30:21 -0000 1.7
+++ UrlTest.java 19 Jan 2004 14:11:33 -0000 1.8
@@ -69,15 +69,6 @@
* Performs Validation Test for url validations.
*/
public class UrlTest extends TestCase {
- class TestPair {
- public String item;
- public boolean valid;
-
- public TestPair(String item, boolean valid) {
- this.item = item;
- this.valid = valid; //Weather the individual part of url is valid.
- }
- }
private boolean printStatus = false;
private boolean printIndex = false;//print index that indicates current
scheme,host,port,path, query test were using.
1.1
jakarta-commons/validator/src/test/org/apache/commons/validator/TestPair.java
Index: TestPair.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestPair.java,v
1.1 2004/01/19 14:11:33 rleland Exp $
* $Revision: 1.1 $
* $Date: 2004/01/19 14:11:33 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names, "Apache", "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
/**
* Groups tests and expected results.
*/
package org.apache.commons.validator;
class TestPair {
public String item;
public boolean valid;
public TestPair(String item, boolean valid) {
this.item = item;
this.valid = valid; //Weather the individual part of url is valid.
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]