You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rl...@apache.org on 2004/01/19 15:11:34 UTC
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator TestPair.java EmailTest.java UrlTest.java
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("jsmith@apache.org");
- valueTest(info, true);
-
- info.setValue("jsmith@apache.com");
- valueTest(info, true);
-
- info.setValue("jsmith@apache.net");
- valueTest(info, true);
-
- info.setValue("jsmith@apache.info");
- valueTest(info, true);
-
- info.setValue("jsmith@apache.infoo");
- valueTest(info, false);
-
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ info.setValue("jsmith@apache.org");
+ valueTest(info, true);
+
+ info.setValue("jsmith@apache.com");
+ valueTest(info, true);
+
+ info.setValue("jsmith@apache.net");
+ valueTest(info, true);
+
+ info.setValue("jsmith@apache.info");
+ valueTest(info, true);
+
+ info.setValue("jsmith@apache.infoo");
+ valueTest(info, false);
+
info.setValue("jsmith@apache.");
valueTest(info, false);
-
+
info.setValue("jsmith@apache.c");
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("andy.noble@\u008fdata-workshop.com");
- valueTest(info, false);
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ info.setValue("andy.noble@\u008fdata-workshop.com");
+ valueTest(info, false);
// The ' character is valid in an email address.
- info.setValue("andy.o'reilly@data-workshop.com");
- valueTest(info, true);
-
+ info.setValue("andy.o'reilly@data-workshop.com");
+ valueTest(info, true);
+
info.setValue("foo+bar@i.am.not.in.us.example.com");
valueTest(info, true);
}
@@ -215,11 +215,11 @@
* Tests the email validation with commas.
*/
public void testEmailWithCommas() throws ValidatorException {
- ValueBean info = new ValueBean();
- info.setValue("joeblow@apa,che.org");
- valueTest(info, false);
- info.setValue("joeblow@apache.o,rg");
- valueTest(info, false);
+ ValueBean info = new ValueBean();
+ info.setValue("joeblow@apa,che.org");
+ valueTest(info, false);
+ info.setValue("joeblow@apache.o,rg");
+ valueTest(info, false);
info.setValue("joeblow@apache,org");
valueTest(info, false);
@@ -231,9 +231,9 @@
* @throws ValidatorException
*/
public void testEmailUserName() throws ValidatorException {
- ValueBean info = new ValueBean();
- info.setValue("joe1blow@apache.org");
- valueTest(info, true);
+ ValueBean info = new ValueBean();
+ info.setValue("joe1blow@apache.org");
+ valueTest(info, true);
info.setValue("joe$blow@apache.org");
valueTest(info, true);
info.setValue("joe-@apache.org");
@@ -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("abigail@example.com", true),
+ new TestPair("abigail@example.com ", true),
+ new TestPair(" abigail@example.com", true),
+ new TestPair("abigail @example.com ", true),
+ new TestPair("*@example.net", true),
+ new TestPair("\"\\\"\"@foo.bar", true),
+ new TestPair("fred&barny@example.com", true),
+ new TestPair("---@example.com", true),
+ new TestPair("foo-bar@example.net", true),
+ new TestPair("\"127.0.0.1\"@[127.0.0.1]", true),
+ new TestPair("Abigail <ab...@example.com>", true),
+ new TestPair("Abigail<ab...@example.com>", true),
+ new TestPair("Abigail<@a...@example.com>", true),
+ new TestPair("\"This is a phrase\"<ab...@example.com>", true),
+ new TestPair("\"Abigail \"<ab...@example.com>", 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 <ab...@example.com>", true),
+ new TestPair("Abigail <ab...@example.com> ", true),
+ new TestPair("(foo) abigail@example.com", true),
+ new TestPair("abigail@example.com (foo)", true),
+ new TestPair("\"Abi\\\"gail\" <ab...@example.com>", true),
+ new TestPair("abigail@[example.com]", true),
+ new TestPair("abigail@[exa\\[ple.com]", true),
+ new TestPair("abigail@[exa\\]ple.com]", true),
+ new TestPair("\":sysmail\"@ Some-Group. Some-Org", true),
+ new TestPair("Muhammed.(I am the greatest) Ali @(the)Vegas.WBA", true),
+ new TestPair("mailbox.sub1.sub2@this-domain", true),
+ new TestPair("sub-net.mailbox@sub-domain.domain", true),
+ new TestPair("name:;", true),
+ new TestPair("':;", true),
+ new TestPair("name: ;", true),
+ new TestPair("Alfred Neuman <Ne...@BBN-TENEXA>", true),
+ new TestPair("Neuman@BBN-TENEXA", true),
+ new TestPair("\"George, Ted\" <Sh...@Group.Arpanet>", true),
+ new TestPair("Wilt . (the Stilt) Chamberlain@NBA.US", true),
+ new TestPair("Cruisers: Port@Portugal, Jones@SEA;", true),
+ new TestPair("$@[]", 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 <Wh...@Cordon-Bleu>,\\x0D\\x0A" +
+ " Childs\\@WGBH.Boston, \"Galloping Gourmet\"\\@\\x0D\\x0A" +
+ " ANT.Down-Under (Australian National Television),\\x0D\\x0A" +
+ " Cheapie\\@Discount-Liquors;", true),
+ new TestPair(" Just a string", false),
+ new TestPair("string", false),
+ new TestPair("(comment)", false),
+ new TestPair("()@example.com", false),
+ new TestPair("fred(&)barny@example.com", false),
+ new TestPair("fred\\ barny@example.com", false),
+ new TestPair("Abigail <abi gail @ example.com>", false),
+ new TestPair("Abigail <ab...@example.com>", false),
+ new TestPair("Abigail <ab...@example.com>", false),
+ new TestPair("\"Abi\"gail\" <ab...@example.com>", false),
+ new TestPair("abigail@[exa]ple.com]", false),
+ new TestPair("abigail@[exa[ple.com]", false),
+ new TestPair("abigail@[exaple].com]", false),
+ new TestPair("abigail@", false),
+ new TestPair("@example.com", false),
+ new TestPair("phrase: abigail@example.com abigail@example.com ;", false),
+ new TestPair("invalid�char@example.com", 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 apache@apache.org.
*
* 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org