You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bs...@apache.org on 2007/10/25 02:17:43 UTC

svn commit: r588091 - in /commons/proper/validator/trunk/src/test: java/org/apache/commons/validator/ java/org/apache/commons/validator/routines/ resources/org/apache/commons/validator/routines/

Author: bspeakmon
Date: Wed Oct 24 17:17:42 2007
New Revision: 588091

URL: http://svn.apache.org/viewvc?rev=588091&view=rev
Log:
- VALIDATOR-203/VALIDATOR-242: copy tests and resources from old Email/URL validators to routines package
- make ResultPair public so routines tests can use it

Added:
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
    commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/
    commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml
Modified:
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ResultPair.java

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ResultPair.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ResultPair.java?rev=588091&r1=588090&r2=588091&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ResultPair.java (original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/ResultPair.java Wed Oct 24 17:17:42 2007
@@ -21,7 +21,7 @@
  *
  * @version $Revision$ $Date$
  */
- class ResultPair {
+ public class ResultPair {
       public String item;
       public boolean valid;
 

Added: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java?rev=588091&view=auto
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java (added)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java Wed Oct 24 17:17:42 2007
@@ -0,0 +1,439 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.validator.*;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+
+/**
+ * Performs Validation Test for e-mail validations.
+ *
+ *
+ * @version $Revision: 493905 $ $Date: 2007-01-07 18:11:38 -0800 (Sun, 07 Jan 2007) $
+ */
+public class EmailValidatorTest extends AbstractCommonTest {
+
+    /**
+     * 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.
+    */
+   protected static String ACTION = "email";
+
+
+   public EmailValidatorTest(String name) {
+       super(name);
+   }
+
+   /**
+    * Start the tests.
+    *
+    * @param theArgs the arguments. Not used
+    */
+   public static void main(String[] theArgs) {
+       junit.awtui.TestRunner.main(new String[] {EmailValidatorTest.class.getName()});
+   }
+
+   /**
+    * @return a test suite (<code>TestSuite</code>) that includes all methods
+    *         starting with "test"
+    */
+   public static Test suite() {
+       // All methods starting with "test" will be executed in the test suite.
+       return new TestSuite(EmailValidatorTest.class);
+   }
+
+   /**
+    * Load <code>ValidatorResources</code> from
+    * validator-regexp.xml.
+    */
+   protected void setUp() throws IOException, SAXException {
+      loadResources("EmailValidatorTest-config.xml");
+   }
+
+   protected void tearDown() {
+   }
+
+   /**
+    * Tests the e-mail validation.
+    */
+   public void testEmail() throws ValidatorException {
+      // Create bean to run test on.
+      ValueBean info = new ValueBean();
+
+      info.setValue("jsmith@apache.org");
+      valueTest(info, true);
+   }
+
+   /**
+    * Tests the email validation with numeric domains.
+    */
+    public void testEmailWithNumericAddress() throws ValidatorException {
+        ValueBean info = new ValueBean();
+        info.setValue("someone@[216.109.118.76]");
+        valueTest(info, true);
+        info.setValue("someone@yahoo.com");
+        valueTest(info, true);
+    }
+
+    /**
+     * 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.");
+        valueTest(info, false);
+
+        info.setValue("jsmith@apache.c");
+        valueTest(info, false);
+
+        info.setValue("someone@yahoo.museum");
+        valueTest(info, true);
+
+        info.setValue("someone@yahoo.mu-seum");
+        valueTest(info, false);
+    }
+
+   /**
+    * <p>Tests the e-mail validation with a dash in
+    * the address.</p>
+    */
+   public void testEmailWithDash() throws ValidatorException {
+      // Create bean to run test on.
+      ValueBean info = new ValueBean();
+
+      info.setValue("andy.noble@data-workshop.com");
+      valueTest(info, true);
+
+      info.setValue("andy-noble@data-workshop.-com");
+       valueTest(info, false);
+       info.setValue("andy-noble@data-workshop.c-om");
+       valueTest(info,false);
+       info.setValue("andy-noble@data-workshop.co-m");
+       valueTest(info, false);
+
+
+   }
+
+   /**
+    * Tests the e-mail validation with a dot at the end of
+    * the address.
+    */
+   public void testEmailWithDotEnd() throws ValidatorException {
+      // Create bean to run test on.
+      ValueBean info = new ValueBean();
+
+      info.setValue("andy.noble@data-workshop.com.");
+      valueTest(info, false);
+
+   }
+
+    /**
+     * Tests the e-mail validation with an RCS-noncompliant character in
+     * the address.
+     */
+    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);
+
+        // The ' character is valid in an email username.
+        info.setValue("andy.o'reilly@data-workshop.com");
+        valueTest(info, true);
+
+        // But not in the domain name.
+        info.setValue("andy@o'reilly.data-workshop.com");
+        valueTest(info, false);
+
+        info.setValue("foo+bar@i.am.not.in.us.example.com");
+        valueTest(info, true);
+    }
+
+   /**
+    * 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);
+        info.setValue("joeblow@apache,org");
+        valueTest(info, false);
+
+    }
+
+   /**
+    * Tests the email validation with spaces.
+    */
+    public void testEmailWithSpaces() throws ValidatorException {
+        ValueBean info = new ValueBean();
+        info.setValue("joeblow @apache.org");
+        valueTest(info, false);
+        info.setValue("joeblow@ apache.org");
+        valueTest(info, false);
+        info.setValue(" joeblow@apache.org");
+        valueTest(info, true);
+        info.setValue("joeblow@apache.org ");
+        valueTest(info, true);
+        info.setValue("joe blow@apache.org ");
+        valueTest(info, false);
+        info.setValue("joeblow@apa che.org ");
+        valueTest(info, false);
+
+    }
+
+   /**
+    * Tests the email validation with ascii control characters.
+    * (i.e. Ascii chars 0 - 31 and 127)
+    */
+    public void testEmailWithControlChars() throws ValidatorException {
+        EmailValidator validator = new EmailValidator();
+        for (char c = 0; c < 32; c++) {
+            assertFalse("Test control char " + ((int)c), validator.isValid("foo" + c + "bar@domain.com"));
+        }
+        assertFalse("Test control char 127", validator.isValid("foo" + ((char)127) + "bar@domain.com"));
+    }
+
+    /**
+     * Write this test according to parts of RFC, as opposed to the type of character
+     * that is being tested.
+     *
+     * <p><b>FIXME</b>: This test fails so disable it with a leading _ for 1.1.4 release.
+     * The real solution is to fix the email parsing.
+     *
+     * @throws ValidatorException
+     */
+    public void _testEmailUserName() throws ValidatorException {
+        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");
+        valueTest(info, true);
+        info.setValue("joe_@apache.org");
+        valueTest(info, true);
+
+        //UnQuoted Special characters are invalid
+
+        info.setValue("joe.@apache.org");
+        valueTest(info, false);
+        info.setValue("joe+@apache.org");
+        valueTest(info, false);
+        info.setValue("joe!@apache.org");
+        valueTest(info, false);
+        info.setValue("joe*@apache.org");
+        valueTest(info, false);
+        info.setValue("joe'@apache.org");
+        valueTest(info, false);
+        info.setValue("joe(@apache.org");
+        valueTest(info, false);
+        info.setValue("joe)@apache.org");
+        valueTest(info, false);
+        info.setValue("joe,@apache.org");
+        valueTest(info, false);
+        info.setValue("joe%45@apache.org");
+        valueTest(info, false);
+        info.setValue("joe;@apache.org");
+        valueTest(info, false);
+        info.setValue("joe?@apache.org");
+        valueTest(info, false);
+        info.setValue("joe&@apache.org");
+        valueTest(info, false);
+        info.setValue("joe=@apache.org");
+        valueTest(info, false);
+
+        //Quoted Special characters are valid
+        info.setValue("\"joe.\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe+\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe!\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe*\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe'\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe(\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe)\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe,\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe%45\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe;\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe?\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe&\"@apache.org");
+        valueTest(info, true);
+        info.setValue("\"joe=\"@apache.org");
+        valueTest(info, true);
+
+    }
+
+    /**
+     * 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.
+     */
+    ResultPair[] testEmailFromPerl = {
+        new ResultPair("abigail@example.com", true),
+        new ResultPair("abigail@example.com ", true),
+        new ResultPair(" abigail@example.com", true),
+        new ResultPair("abigail @example.com ", true),
+        new ResultPair("*@example.net", true),
+        new ResultPair("\"\\\"\"@foo.bar", true),
+        new ResultPair("fred&barny@example.com", true),
+        new ResultPair("---@example.com", true),
+        new ResultPair("foo-bar@example.net", true),
+        new ResultPair("\"127.0.0.1\"@[127.0.0.1]", true),
+        new ResultPair("Abigail <ab...@example.com>", true),
+        new ResultPair("Abigail<ab...@example.com>", true),
+        new ResultPair("Abigail<@a...@example.com>", true),
+        new ResultPair("\"This is a phrase\"<ab...@example.com>", true),
+        new ResultPair("\"Abigail \"<ab...@example.com>", true),
+        new ResultPair("\"Joe & J. Harvey\" <example @Org>", true),
+        new ResultPair("Abigail <abigail @ example.com>", true),
+        new ResultPair("Abigail made this <  abigail   @   example  .    com    >", true),
+        new ResultPair("Abigail(the bitch)@example.com", true),
+        new ResultPair("Abigail <abigail @ example . (bar) com >", true),
+        new ResultPair("Abigail < (one)  abigail (two) @(three)example . (bar) com (quz) >", true),
+        new ResultPair("Abigail (foo) (((baz)(nested) (comment)) ! ) < (one)  abigail (two) @(three)example . (bar) com (quz) >", true),
+        new ResultPair("Abigail <ab...@example.com>", true),
+        new ResultPair("Abigail <ab...@example.com> ", true),
+        new ResultPair("(foo) abigail@example.com", true),
+        new ResultPair("abigail@example.com (foo)", true),
+        new ResultPair("\"Abi\\\"gail\" <ab...@example.com>", true),
+        new ResultPair("abigail@[example.com]", true),
+        new ResultPair("abigail@[exa\\[ple.com]", true),
+        new ResultPair("abigail@[exa\\]ple.com]", true),
+        new ResultPair("\":sysmail\"@  Some-Group. Some-Org", true),
+        new ResultPair("Muhammed.(I am  the greatest) Ali @(the)Vegas.WBA", true),
+        new ResultPair("mailbox.sub1.sub2@this-domain", true),
+        new ResultPair("sub-net.mailbox@sub-domain.domain", true),
+        new ResultPair("name:;", true),
+        new ResultPair("':;", true),
+        new ResultPair("name:   ;", true),
+        new ResultPair("Alfred Neuman <Ne...@BBN-TENEXA>", true),
+        new ResultPair("Neuman@BBN-TENEXA", true),
+        new ResultPair("\"George, Ted\" <Sh...@Group.Arpanet>", true),
+        new ResultPair("Wilt . (the  Stilt) Chamberlain@NBA.US", true),
+        new ResultPair("Cruisers:  Port@Portugal, Jones@SEA;", true),
+        new ResultPair("$@[]", true),
+        new ResultPair("*()@[]", true),
+        new ResultPair("\"quoted ( brackets\" ( a comment )@example.com", true),
+        new ResultPair("\"Joe & J. Harvey\"\\x0D\\x0A     <ddd\\@ Org>", true),
+        new ResultPair("\"Joe &\\x0D\\x0A J. Harvey\" <ddd \\@ Org>", true),
+        new ResultPair("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 ResultPair("   Just a string", false),
+        new ResultPair("string", false),
+        new ResultPair("(comment)", false),
+        new ResultPair("()@example.com", false),
+        new ResultPair("fred(&)barny@example.com", false),
+        new ResultPair("fred\\ barny@example.com", false),
+        new ResultPair("Abigail <abi gail @ example.com>", false),
+        new ResultPair("Abigail <ab...@example.com>", false),
+        new ResultPair("Abigail <ab...@example.com>", false),
+        new ResultPair("\"Abi\"gail\" <ab...@example.com>", false),
+        new ResultPair("abigail@[exa]ple.com]", false),
+        new ResultPair("abigail@[exa[ple.com]", false),
+        new ResultPair("abigail@[exaple].com]", false),
+        new ResultPair("abigail@", false),
+        new ResultPair("@example.com", false),
+        new ResultPair("phrase: abigail@example.com abigail@example.com ;", false),
+        new ResultPair("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
+     *
+     * FIXME This test fails so disable it with a leading _ for 1.1.4 release.
+     * The real solution is to fix the email parsing.
+     */
+    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.
+    *
+    * @param info	Value to run test on.
+    * @param passed	Whether or not the test is expected to pass.
+    */
+   private void valueTest(ValueBean info, boolean passed) throws ValidatorException {
+      // Construct validator based on the loaded resources
+      // and the form key
+      Validator validator = new Validator(resources, FORM_KEY);
+      // add the name bean to the validator as a resource
+      // for the validations to be performed on.
+      validator.setParameter(Validator.BEAN_PARAM, info);
+
+      // Get results of the validation.
+      ValidatorResults results = null;
+
+      // throws ValidatorException,
+      // but we aren't catching for testing
+      // since no validation methods we use
+      // throw this
+      results = validator.validate();
+
+      assertNotNull("Results are null.", results);
+
+      ValidatorResult result = results.getValidatorResult("value");
+
+      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)));
+    }
+}

Added: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java?rev=588091&view=auto
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java (added)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java Wed Oct 24 17:17:42 2007
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.validator.ResultPair;
+
+/**
+ * Performs Validation Test for url validations.
+ *
+ * @version $Revision: 493905 $ $Date: 2007-01-07 18:11:38 -0800 (Sun, 07 Jan 2007) $
+ */
+public class UrlValidatorTest extends TestCase {
+
+   private boolean printStatus = false;
+   private boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using.
+
+   public UrlValidatorTest(String testName) {
+      super(testName);
+   }
+
+   public static Test suite() {
+      return new TestSuite(UrlValidatorTest.class);
+   }
+
+   protected void setUp() {
+      for (int index = 0; index < testPartsIndex.length - 1; index++) {
+         testPartsIndex[index] = 0;
+      }
+   }
+
+   protected void tearDown() {
+   }
+
+   public void testIsValid() {
+    	testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
+    	setUp();
+    	int options =
+    		UrlValidator.ALLOW_2_SLASHES
+    			+ UrlValidator.ALLOW_ALL_SCHEMES
+    			+ UrlValidator.NO_FRAGMENTS;
+
+    	testIsValid(testUrlPartsOptions, options);
+   }
+
+   public void testIsValidScheme() {
+      if (printStatus) {
+         System.out.print("\n testIsValidScheme() ");
+      }
+      String[] schemes = {"http", "gopher"};
+      //UrlValidator urlVal = new UrlValidator(schemes,false,false,false);
+      UrlValidator urlVal = new UrlValidator(schemes, 0);
+      for (int sIndex = 0; sIndex < testScheme.length; sIndex++) {
+         ResultPair testPair = testScheme[sIndex];
+         boolean result = urlVal.isValidScheme(testPair.item);
+         assertEquals(testPair.item, testPair.valid, result);
+         if (printStatus) {
+            if (result == testPair.valid) {
+               System.out.print('.');
+            } else {
+               System.out.print('X');
+            }
+         }
+      }
+      if (printStatus) {
+         System.out.println();
+      }
+
+   }
+
+   /**
+    * Create set of tests by taking the testUrlXXX arrays and
+    * running through all possible permutations of their combinations.
+    *
+    * @param testObjects Used to create a url.
+    */
+   public void testIsValid(Object[] testObjects, int options) {
+      UrlValidator urlVal = new UrlValidator(null, options);
+      assertTrue(urlVal.isValid("http://www.google.com"));
+      assertTrue(urlVal.isValid("http://www.google.com/"));
+      int statusPerLine = 60;
+      int printed = 0;
+      if (printIndex)  {
+         statusPerLine = 6;
+      }
+      do {
+         StringBuffer testBuffer = new StringBuffer();
+         boolean expected = true;
+         for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
+            int index = testPartsIndex[testPartsIndexIndex];
+            ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex];
+            testBuffer.append(part[index].item);
+            expected &= part[index].valid;
+         }
+         String url = testBuffer.toString();
+         boolean result = urlVal.isValid(url);
+         assertEquals(url, expected, result);
+         if (printStatus) {
+            if (printIndex) {
+               System.out.print(testPartsIndextoString());
+            } else {
+               if (result == expected) {
+                  System.out.print('.');
+               } else {
+                  System.out.print('X');
+               }
+            }
+            printed++;
+            if (printed == statusPerLine) {
+               System.out.println();
+               printed = 0;
+            }
+         }
+      } while (incrementTestPartsIndex(testPartsIndex, testObjects));
+      if (printStatus) {
+         System.out.println();
+      }
+   }
+
+   public void testValidator202() {
+       String[] schemes = {"http","https"};
+       UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
+       urlValidator.isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log");
+   }
+
+   public void testValidator204() {
+       String[] schemes = {"http","https"};
+       UrlValidator urlValidator = new UrlValidator(schemes);
+       assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
+   }
+
+   static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
+      boolean carry = true;  //add 1 to lowest order part.
+      boolean maxIndex = true;
+      for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) {
+         int index = testPartsIndex[testPartsIndexIndex];
+         ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex];
+         if (carry) {
+            if (index < part.length - 1) {
+               index++;
+               testPartsIndex[testPartsIndexIndex] = index;
+               carry = false;
+            } else {
+               testPartsIndex[testPartsIndexIndex] = 0;
+               carry = true;
+            }
+         }
+         maxIndex &= (index == (part.length - 1));
+      }
+
+
+      return (!maxIndex);
+   }
+
+   private String testPartsIndextoString() {
+      StringBuffer carryMsg = new StringBuffer("{");
+      for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
+         carryMsg.append(testPartsIndex[testPartsIndexIndex]);
+         if (testPartsIndexIndex < testPartsIndex.length - 1) {
+            carryMsg.append(',');
+         } else {
+            carryMsg.append('}');
+         }
+      }
+      return carryMsg.toString();
+
+   }
+
+   public void testValidateUrl() {
+      assertTrue(true);
+   }
+
+   /**
+    * Only used to debug the unit tests.
+    * @param argv
+    */
+   public static void main(String[] argv) {
+
+      UrlValidatorTest fct = new UrlValidatorTest("url test");
+      fct.setUp();
+      fct.testIsValid();
+      fct.testIsValidScheme();
+   }
+   //-------------------- Test data for creating a composite URL
+   /**
+    * The data given below approximates the 4 parts of a URL
+    * <scheme>://<authority><path>?<query> except that the port number
+    * is broken out of authority to increase the number of permutations.
+    * A complete URL is composed of a scheme+authority+port+path+query,
+    * all of which must be individually valid for the entire URL to be considered
+    * valid.
+    */
+   ResultPair[] testUrlScheme = {new ResultPair("http://", true),
+                               new ResultPair("ftp://", true),
+                               new ResultPair("h3t://", true),
+                               new ResultPair("3ht://", false),
+                               new ResultPair("http:/", false),
+                               new ResultPair("http:", false),
+                               new ResultPair("http/", false),
+                               new ResultPair("://", false),
+                               new ResultPair("", true)};
+
+   ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true),
+                                  new ResultPair("go.com", true),
+                                  new ResultPair("go.au", true),
+                                  new ResultPair("0.0.0.0", true),
+                                  new ResultPair("255.255.255.255", true),
+                                  new ResultPair("256.256.256.256", false),
+                                  new ResultPair("255.com", true),
+                                  new ResultPair("1.2.3.4.5", false),
+                                  new ResultPair("1.2.3.4.", false),
+                                  new ResultPair("1.2.3", false),
+                                  new ResultPair(".1.2.3.4", false),
+                                  new ResultPair("go.a", false),
+                                  new ResultPair("go.a1a", true),
+                                  new ResultPair("go.1aa", false),
+                                  new ResultPair("aaa.", false),
+                                  new ResultPair(".aaa", false),
+                                  new ResultPair("aaa", false),
+                                  new ResultPair("", false)
+   };
+   ResultPair[] testUrlPort = {new ResultPair(":80", true),
+                             new ResultPair(":65535", true),
+                             new ResultPair(":0", true),
+                             new ResultPair("", true),
+                             new ResultPair(":-1", false),
+                             new ResultPair(":65636", true),
+                             new ResultPair(":65a", false)
+   };
+   ResultPair[] testPath = {new ResultPair("/test1", true),
+                          new ResultPair("/t123", true),
+                          new ResultPair("/$23", true),
+                          new ResultPair("/..", false),
+                          new ResultPair("/../", false),
+                          new ResultPair("/test1/", true),
+                          new ResultPair("", true),
+                          new ResultPair("/test1/file", true),
+                          new ResultPair("/..//file", false),
+                          new ResultPair("/test1//file", false)
+   };
+   //Test allow2slash, noFragment
+   ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true),
+                                    new ResultPair("/t123", true),
+                                    new ResultPair("/$23", true),
+                                    new ResultPair("/..", false),
+                                    new ResultPair("/../", false),
+                                    new ResultPair("/test1/", true),
+                                    new ResultPair("/#", false),
+                                    new ResultPair("", true),
+                                    new ResultPair("/test1/file", true),
+                                    new ResultPair("/t123/file", true),
+                                    new ResultPair("/$23/file", true),
+                                    new ResultPair("/../file", false),
+                                    new ResultPair("/..//file", false),
+                                    new ResultPair("/test1//file", true),
+                                    new ResultPair("/#/file", false)
+   };
+
+   ResultPair[] testUrlQuery = {new ResultPair("?action=view", true),
+                              new ResultPair("?action=edit&mode=up", true),
+                              new ResultPair("", true)
+   };
+
+   Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery};
+   Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery};
+   int[] testPartsIndex = {0, 0, 0, 0, 0};
+
+   //---------------- Test data for individual url parts ----------------
+   ResultPair[] testScheme = {new ResultPair("http", true),
+                            new ResultPair("ftp", false),
+                            new ResultPair("httpd", false),
+                            new ResultPair("telnet", false)};
+
+
+}

Added: commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml?rev=588091&view=auto
==============================================================================
--- commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml (added)
+++ commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml Wed Oct 24 17:17:42 2007
@@ -0,0 +1,34 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE form-validation PUBLIC
+     "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.4.0//EN"
+     "http://commons.apache.org/dtds/validator_1_4_0.dtd">
+     
+<form-validation>
+   <global>
+      <validator name="email"
+                 classname="org.apache.commons.validator.GenericValidatorImpl"
+                 method="validateEmail"
+                 methodParams="java.lang.Object,org.apache.commons.validator.Field"
+                 msg=""/>
+   </global>
+   <formset>
+      <form name="emailForm">
+         <field property="value" depends="email"/>
+      </form>
+   </formset>   
+</form-validation>



Re: [validator] svn commit: r588091 - in /commons/proper/validator/trunk/src/test: java/org/apache/commons/validator/ java/org/apache/commons/validator/routines/ resources/org/apache/commons/validator/routines/

Posted by Rahul Akolkar <ra...@gmail.com>.
On 10/24/07, bspeakmon@apache.org <bs...@apache.org> wrote:
> Author: bspeakmon
> Date: Wed Oct 24 17:17:42 2007
> New Revision: 588091
>
> URL: http://svn.apache.org/viewvc?rev=588091&view=rev
> Log:
> - VALIDATOR-203/VALIDATOR-242: copy tests and resources from old Email/URL validators to routines package
> - make ResultPair public so routines tests can use it
>
> Added:
>     commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
>     commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
>     commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/
>     commons/proper/validator/trunk/src/test/resources/org/apache/commons/validator/routines/EmailValidatorTest-config.xml
<snip/>

Still missing svn props.

-Rahul

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org