entry = i.next();
+ String key = entry.getKey();
+ Object value = entry.getValue();
+
+ if (value instanceof Msg) {
+ results.put(key, ((Msg) value).clone());
+ } else if (value instanceof Arg) {
+ results.put(key, ((Arg) value).clone());
+ } else if (value instanceof Var) {
+ results.put(key, ((Var) value).clone());
+ } else {
+ results.put(key, value);
+ }
+ }
+ return results;
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/main/java/org/apache/commons/validator/util/package.html b/Java-base/commons-validator/src/src/main/java/org/apache/commons/validator/util/package.html
new file mode 100644
index 000000000..ce4613baa
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/java/org/apache/commons/validator/util/package.html
@@ -0,0 +1,26 @@
+
+
+
+Package Documentation for org.apache.commons.validator.util Package
+
+
+
+This package contains utility classes used by Commons Validator.
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/digester-rules.xml b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/digester-rules.xml
new file mode 100644
index 000000000..50fde7796
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/digester-rules.xml
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0.dtd
new file mode 100644
index 000000000..6dfb90b28
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0.dtd
@@ -0,0 +1,262 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0_1.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0_1.dtd
new file mode 100644
index 000000000..f5211690b
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_0_1.dtd
@@ -0,0 +1,261 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1.dtd
new file mode 100644
index 000000000..671e74094
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1.dtd
@@ -0,0 +1,308 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1_3.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1_3.dtd
new file mode 100644
index 000000000..8dce2b888
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_1_3.dtd
@@ -0,0 +1,328 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_2_0.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_2_0.dtd
new file mode 100644
index 000000000..58d5adc4d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_2_0.dtd
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_3_0.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_3_0.dtd
new file mode 100644
index 000000000..f644aeb59
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_3_0.dtd
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_4_0.dtd b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_4_0.dtd
new file mode 100644
index 000000000..b446ab71a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/main/resources/org/apache/commons/validator/resources/validator_1_4_0.dtd
@@ -0,0 +1,253 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/resources/download_validator.cgi b/Java-base/commons-validator/src/src/site/resources/download_validator.cgi
new file mode 100755
index 000000000..495cde12d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/resources/download_validator.cgi
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Just call the standard mirrors.cgi script. It will use download.html
+# as the input template.
+exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $*
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/site/resources/images/logo.png b/Java-base/commons-validator/src/src/site/resources/images/logo.png
new file mode 100644
index 000000000..9ed617e29
Binary files /dev/null and b/Java-base/commons-validator/src/src/site/resources/images/logo.png differ
diff --git a/Java-base/commons-validator/src/src/site/site.xml b/Java-base/commons-validator/src/src/site/site.xml
new file mode 100644
index 000000000..0b65f7e9d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/site.xml
@@ -0,0 +1,51 @@
+
+
+
+
+ Commons Validator
+ /images/logo.png
+ /index.html
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/building.xml b/Java-base/commons-validator/src/src/site/xdoc/building.xml
new file mode 100644
index 000000000..f0a90bcab
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/building.xml
@@ -0,0 +1,75 @@
+
+
+
+
+ Building
+ Commons Documentation Team
+
+
+
+
+
+ Commons Validator uses Maven or
+ Ant as a build system.
+
+
+
+
+
+ To build a jar file, change into Validator's root directory and run
+ maven jar
.
+ The result will be in the "target" subdirectory.
+
+
+ To build the Javadocs, run maven javadoc
.
+ The result will be in "target/docs/apidocs".
+
+
+ To build the full website, run maven site
.
+
+ The result will be in "target/docs".
+
+
+ Further details can be found in the
+ commons build instructions .
+
+
+
+
+
+ To build a jar file and the javadocs, change into Validator's root directory
+ and run ant dist
.
+ The result will be in the "dist" subdirectory.
+
+
+
+
+
+
+ Nightly Builds
+ are built once a day from the current SVN HEAD. These are provided purely for test purposes and are NOT
+ official releases of the Apache Software Foundation - Released versions of Commons Validator are
+ available here .
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/community.xml b/Java-base/commons-validator/src/src/site/xdoc/community.xml
new file mode 100644
index 000000000..51b810d1d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/community.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+ Community
+
+
+
+
+
+ The Apache Wiki is a Wiki run by Apache for the Apache community. The Validator Wiki home page is
+ here .
+
+
+ Anyone is welcome to create new content about Validator providing that they
+ observe the usual rules of netiquette.
+
+
+
+
+
+ Struts Console is a free
+ standalone Java Swing application for managing
+ Struts related configuration files, including Commons Validator config files.
+ Struts Console also plugs into several popular Java IDEs for seamless
+ management of config files from one central development tool.
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/download_validator.xml b/Java-base/commons-validator/src/src/site/xdoc/download_validator.xml
new file mode 100644
index 000000000..ec80f4bac
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/download_validator.xml
@@ -0,0 +1,154 @@
+
+
+
+
+
+ Download Apache Commons Validator
+ Apache Commons Documentation Team
+
+
+
+
+
+ We recommend you use a mirror to download our release
+ builds, but you must verify the integrity of
+ the downloaded files using signatures downloaded from our main
+ distribution directories. Recent releases (48 hours) may not yet
+ be available from all the mirrors.
+
+
+
+ You are currently using [preferred] . If you
+ encounter a problem with this mirror, please select another
+ mirror. If all mirrors are failing, there are backup
+ mirrors (at the end of the mirrors list) that should be
+ available.
+
+ [if-any logo] [end]
+
+
+
+
+
+ It is essential that you
+ verify the integrity
+ of downloaded files, preferably using the PGP
signature (*.asc
files);
+ failing that using the MD5
hash (*.md5
checksum files).
+
+
+ The KEYS
+ file contains the public PGP keys used by Apache Commons developers
+ to sign releases.
+
+
+
+
+
+
+ Older releases can be obtained from the archives.
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/index.xml b/Java-base/commons-validator/src/src/site/xdoc/index.xml
new file mode 100644
index 000000000..8616296a3
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/index.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+ Commons Validator
+
+
+
+
+
+
+
+ A common issue when receiving data either electronically or from
+ user input is verifying the integrity of the data. This work is
+ repetitive and becomes even more complicated when different sets
+ of validation rules need to be applied to the same set of data based
+ on locale. Error messages may also vary by locale.
+ This package addresses some of these issues to
+ speed development and maintenance of validation rules.
+
+
+
+
+
+
+
+ Validator provides two distinct sets of functionality:
+
+ A configurable (typically XML) validation engine
+ Reusable "primitive" validation methods
+
+
+
+ Your validation methods are plugged into the engine and
+ executed against your data. Often, these methods use
+ resources specific to one application or framework so Commons
+ Validator doesn't directly provide pluggable validator actions.
+ However, it does have a set of common validation methods
+ (email addresses, dates, URLs, etc.) that help in creating
+ pluggable actions.
+
+
+
+
+ In order to use the Validator, the following basic steps are required:
+
+
+ Create a new instance of the
+ org.apache.commons.validator.Validator
class. Currently
+ Validator instances may be safely reused if the current
+ ValidatorResources are the same, as long as you have completed any
+ previous validation, and you do not try to utilize a particular
+ Validator instance from more than one thread at a time.
+
+
+ Add any resources needed to perform the validations, such as the
+ JavaBean to validate.
+
+
+ Call the validate method on
+ org.apache.commons.validator.Validator
.
+
+
+
+
+
+
+ The package Javadoc has useful information:
+
+
+
+ See the subversion repository for the latest source code.
+
+
+
+
+
+
+
+ The commons mailing lists act as the main support forum.
+ The user list is suitable for most library usage queries.
+ The dev list is intended for the development discussion.
+ Please remember that the lists are shared between all commons components,
+ so prefix your email by [validator].
+
+
+
+ Issues may be reported via ASF JIRA .
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/issue-tracking.xml b/Java-base/commons-validator/src/src/site/xdoc/issue-tracking.xml
new file mode 100644
index 000000000..fb3259200
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/issue-tracking.xml
@@ -0,0 +1,102 @@
+
+
+
+
+
+ Commons Validator Issue tracking
+ Commons Documentation Team
+
+
+
+
+
+ Commons Validator uses ASF JIRA for tracking issues.
+ See the Commons Validator JIRA project page .
+
+
+
+ To use JIRA you may need to create an account
+ (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically
+ created and you can use the Forgot Password
+ page to get a new password).
+
+
+
+ If you would like to report a bug, or raise an enhancement request with
+ Commons Validator please do the following:
+
+ Search existing open bugs .
+ If you find your issue listed then please add a comment with your details.
+ Search the mailing list archive(s) .
+ You may find your issue or idea has already been discussed.
+ Decide if your issue is a bug or an enhancement.
+ Submit either a bug report
+ or enhancement request .
+
+
+
+
+ Please also remember these points:
+
+ the more information you provide, the better we can help you
+ test cases are vital, particularly for any proposed enhancements
+ the developers of Commons Validator are all unpaid volunteers
+
+
+
+
+ For more information on subversion and creating patches see the
+ Apache Contributors Guide .
+
+
+
+ You may also find these links useful:
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/mail-lists.xml b/Java-base/commons-validator/src/src/site/xdoc/mail-lists.xml
new file mode 100644
index 000000000..e0b1075e6
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/mail-lists.xml
@@ -0,0 +1,202 @@
+
+
+
+
+
+ Commons Validator Mailing Lists
+ Commons Documentation Team
+
+
+
+
+
+ Commons Validator shares mailing lists with all the other
+ Commons Components .
+ To make it easier for people to only read messages related to components they are interested in,
+ the convention in Commons is to prefix the subject line of messages with the component's name,
+ for example:
+
+ [validator] Problem with the ...
+
+
+
+ Questions related to the usage of Commons Validator should be posted to the
+ User List .
+
+ The Developer List
+ is for questions and discussion related to the development of Commons Validator.
+
+ Please do not cross-post; developers are also subscribed to the user list.
+
+
+ Note: please don't send patches or attachments to any of the mailing lists.
+ Patches are best handled via the Issue Tracking system.
+ Otherwise, please upload the file to a public server and include the URL in the mail.
+
+
+
+
+
+ Please prefix the subject line of any messages for Commons Validator
+ with [validator] - thanks!
+
+
+
+
+
+
+
+
+
+ Other mailing lists which you may find useful include:
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/tasks.xml b/Java-base/commons-validator/src/src/site/xdoc/tasks.xml
new file mode 100644
index 000000000..c3737121c
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/tasks.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+ TODO
+
+
+
+
+
+ The following is a list of items that need to be completed in
+ Validator. Contributions are welcome!
+
+
+
+
+ Change the validation.xml file semantics to match a more general "bean" validation usage.
+ Currently, the <form-validation>, <formset>, <form>, and <field> elements
+ require a form-centric view of validations. Changing these to <bean-validation> or <validator-config>,
+ <beans>, <bean>, and <property> respectively would allow Validator to be used more easily in
+ non-form based environments. See the 2.0 DTD proposal for specifics.
+
+
+ The above changes to validation.xml could only apply to Validator's native configuration format. We
+ could add a ValidatorResources constructor that accepts a digester-rules file to allow parsing any
+ XML format into Validator configuration objects. This would allow higher level frameworks like Struts
+ to use configuration semantics specific to their domain.
+
+
+ ValidatorException is only thrown to indicate configuration and programmer errors
+ yet is a checked exception. ValidatorException should be converted to a RuntimeException to match its
+ real purpose. Furthermore, the exception handling for pluggable validations (ValidatorActions)
+ is not well defined or documented. RuntimeExceptions thrown from ValidatorActions should be propogated
+ out of the Validator framework as is because they indicate programmer error. Checked exceptions thrown
+ from a ValidatorAction should stop validation and be propogated out of the framework for handling as these
+ indicate an unrecoverable system failure. Validation method implementation becomes easier because they
+ can throw SQLException, IOException, etc. instead of wrapping the exception or defining it as a rule failure.
+ This allows clients to reliably distinguish between a normal validation failure (invalid data) and exceptional
+ conditions.
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/site/xdoc/validator_2_0_0_proposal.dtd b/Java-base/commons-validator/src/src/site/xdoc/validator_2_0_0_proposal.dtd
new file mode 100644
index 000000000..c5428fe10
--- /dev/null
+++ b/Java-base/commons-validator/src/src/site/xdoc/validator_2_0_0_proposal.dtd
@@ -0,0 +1,269 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractCommonTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractCommonTest.java
new file mode 100644
index 000000000..da2791c72
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractCommonTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Consolidates reading in XML config file into parent class.
+ *
+ * @version $Revision$
+ */
+abstract public class AbstractCommonTest extends TestCase {
+
+ /**
+ * Resources used for validation tests.
+ */
+ protected ValidatorResources resources = null;
+
+ public AbstractCommonTest(String string) {
+ super(string);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-numeric.xml.
+ */
+ protected void loadResources(String file) throws IOException, SAXException {
+ // Load resources
+ InputStream in = null;
+
+ try {
+ in = this.getClass().getResourceAsStream(file);
+ resources = new ValidatorResources(in);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractNumberTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractNumberTest.java
new file mode 100644
index 000000000..0b2f6b71a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/AbstractNumberTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Abstracts number unit tests methods.
+ *
+ * @version $Revision$
+ */
+abstract public class AbstractNumberTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected String FORM_KEY;
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected String ACTION;
+
+
+ public AbstractNumberTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-numeric.xml.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("TestNumber-config.xml");
+ }
+
+ @Override
+ protected void tearDown() {
+ }
+
+ /**
+ * Tests the number validation.
+ */
+ public void testNumber() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the float validation failure.
+ */
+ public void testNumberFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ valueTest(info, false);
+ }
+
+ /**
+ * 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.
+ */
+ protected void valueTest(Object 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(ACTION + " value ValidatorResult should contain the '" + ACTION + "' action.", result.containsAction(ACTION));
+ assertTrue(ACTION + " value ValidatorResult for the '" + ACTION + "' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
+ }
+
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ByteTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ByteTest.java
new file mode 100644
index 000000000..63ac3ed2a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ByteTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+
+
+/**
+ * Performs Validation Test for byte
validations.
+ *
+ * @version $Revision$
+ */
+public class ByteTest extends AbstractNumberTest {
+
+ public ByteTest(String name) {
+ super(name);
+ ACTION = "byte";
+ FORM_KEY = "byteForm";
+ }
+
+ /**
+ * Tests the byte validation.
+ */
+ public void testByte() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the byte validation.
+ */
+ public void testByteMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Byte.valueOf(Byte.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the byte validation.
+ */
+ public void testByteMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Byte.valueOf(Byte.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the byte validation failure.
+ */
+ public void testByteFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the byte validation failure.
+ */
+ public void testByteBeyondMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Byte.MIN_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the byte validation failure.
+ */
+ public void testByteBeyondMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Byte.MAX_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CreditCardValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CreditCardValidatorTest.java
new file mode 100644
index 000000000..fed4c505a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CreditCardValidatorTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the CreditCardValidator class.
+ *
+ * @version $Revision$
+ * @deprecated this test can be removed when the deprecated class is removed
+ */
+@Deprecated
+public class CreditCardValidatorTest extends TestCase {
+
+ private static final String VALID_VISA = "4417123456789113";
+ private static final String VALID_SHORT_VISA = "4222222222222";
+ private static final String VALID_AMEX = "378282246310005";
+ private static final String VALID_MASTERCARD = "5105105105105100";
+ private static final String VALID_DISCOVER = "6011000990139424";
+ private static final String VALID_DINERS = "30569309025904";
+
+ /**
+ * Constructor for CreditCardValidatorTest.
+ */
+ public CreditCardValidatorTest(String name) {
+ super(name);
+ }
+
+ public void testIsValid() {
+ CreditCardValidator ccv = new CreditCardValidator();
+
+ assertFalse(ccv.isValid(null));
+ assertFalse(ccv.isValid(""));
+ assertFalse(ccv.isValid("123456789012")); // too short
+ assertFalse(ccv.isValid("12345678901234567890")); // too long
+ assertFalse(ccv.isValid("4417123456789112"));
+ assertFalse(ccv.isValid("4417q23456w89113"));
+ assertTrue(ccv.isValid(VALID_VISA));
+ assertTrue(ccv.isValid(VALID_SHORT_VISA));
+ assertTrue(ccv.isValid(VALID_AMEX));
+ assertTrue(ccv.isValid(VALID_MASTERCARD));
+ assertTrue(ccv.isValid(VALID_DISCOVER));
+
+ // disallow Visa so it should fail even with good number
+ ccv = new CreditCardValidator(CreditCardValidator.AMEX);
+ assertFalse(ccv.isValid("4417123456789113"));
+ }
+
+ public void testAddAllowedCardType() {
+ CreditCardValidator ccv = new CreditCardValidator(CreditCardValidator.NONE);
+ // Turned off all cards so even valid numbers should fail
+ assertFalse(ccv.isValid(VALID_VISA));
+ assertFalse(ccv.isValid(VALID_AMEX));
+ assertFalse(ccv.isValid(VALID_MASTERCARD));
+ assertFalse(ccv.isValid(VALID_DISCOVER));
+
+ // test our custom type
+ ccv.addAllowedCardType(new DinersClub());
+ assertTrue(ccv.isValid(VALID_DINERS));
+ }
+
+ /**
+ * Test a custom implementation of CreditCardType.
+ */
+ private class DinersClub implements CreditCardValidator.CreditCardType {
+ private static final String PREFIX = "300,301,302,303,304,305,";
+ @Override
+ public boolean matches(String card) {
+ String prefix = card.substring(0, 3) + ",";
+ return ((PREFIX.contains(prefix)) && (card.length() == 14));
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CustomValidatorResourcesTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CustomValidatorResourcesTest.java
new file mode 100644
index 000000000..f1ee2ee7d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/CustomValidatorResourcesTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test custom ValidatorResources.
+ *
+ * @version $Revision$
+ */
+public class CustomValidatorResourcesTest extends TestCase {
+
+ /**
+ * Construct a test case with the specified name.
+ * @param name Name of the test
+ */
+ public CustomValidatorResourcesTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up.
+ */
+ @Override
+ protected void setUp() {
+ }
+
+ /**
+ * Tear Down
+ */
+ @Override
+ protected void tearDown() {
+ }
+
+ /**
+ * Test creating a custom validator resources.
+ */
+ public void testCustomResources() {
+ // Load resources
+ InputStream in = null;
+ try {
+ in = this.getClass().getResourceAsStream("TestNumber-config.xml");
+ } catch(Exception e) {
+ fail("Error loading resources: " + e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch(Exception e) {
+ }
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DateTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DateTest.java
new file mode 100644
index 000000000..79539d354
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DateTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Abstracts date unit tests methods.
+ *
+ * @version $Revision$
+ */
+public class DateTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected String FORM_KEY = "dateForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected String ACTION = "date";
+
+
+ public DateTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-numeric.xml.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("DateTest-config.xml");
+ }
+
+ /**
+ * Tests the date validation.
+ */
+ public void testValidDate() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("12/01/2005");
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the date validation.
+ */
+ public void testInvalidDate() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("12/01as/2005");
+ valueTest(info, false);
+ }
+
+
+ /**
+ * 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.
+ */
+ protected void valueTest(Object 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);
+ validator.setParameter(Validator.LOCALE_PARAM, Locale.US);
+
+ // 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(ACTION + " value ValidatorResult should contain the '" + ACTION + "' action.", result.containsAction(ACTION));
+ assertTrue(ACTION + " value ValidatorResult for the '" + ACTION + "' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
+ }
+
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DoubleTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DoubleTest.java
new file mode 100644
index 000000000..9e907ab36
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/DoubleTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+
+/**
+ * Performs Validation Test for double
validations.
+ *
+ * @version $Revision$
+ */
+public class DoubleTest extends AbstractNumberTest {
+
+ public DoubleTest(String name) {
+ super(name);
+ ACTION = "double";
+ FORM_KEY = "doubleForm";
+ }
+
+
+ /**
+ * Tests the double validation.
+ */
+ public void testDouble() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the double validation.
+ */
+ public void testDoubleMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Double.valueOf(Double.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the double validation.
+ */
+ public void testDoubleMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Double.valueOf(Double.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the double validation failure.
+ */
+ public void testDoubleFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ valueTest(info, false);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EmailTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EmailTest.java
new file mode 100644
index 000000000..1216bd83a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EmailTest.java
@@ -0,0 +1,449 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test for e-mail validations.
+ *
+ *
+ * @version $Revision$
+ * @deprecated to be removed when target class is removed
+ */
+@Deprecated
+public class EmailTest 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 EmailTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-regexp.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ loadResources("EmailTest-config.xml");
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Tests the e-mail validation with a dash in
+ * the address.
+ */
+ 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, false);
+ info.setValue("joeblow@apache.org ");
+ valueTest(info, false);
+ info.setValue("joe blow@apache.org ");
+ valueTest(info, false);
+ info.setValue("joeblow@apa che.org ");
+ valueTest(info, false);
+ info.setValue("\"joe blow\"@apache.org");
+ valueTest(info, true);
+
+ }
+
+ /**
+ * Tests the email validation with ascii control characters.
+ * (i.e. Ascii chars 0 - 31 and 127)
+ */
+ public void testEmailWithControlChars() {
+ 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"));
+ }
+
+ /**
+ * Tests the e-mail validation with a user at a TLD
+ */
+ public void testEmailAtTLD() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ info.setValue("m@de");
+ valueTest(info, false);
+
+ org.apache.commons.validator.routines.EmailValidator validator =
+ org.apache.commons.validator.routines.EmailValidator.getInstance(true, true);
+ boolean result = validator.isValid("m@de");
+ assertTrue("Result should have been true", result);
+
+ }
+
+ /**
+ * Test that @localhost and @localhost.localdomain
+ * addresses aren't declared valid by default
+ */
+ public void testEmailLocalhost() throws ValidatorException {
+ ValueBean info = new ValueBean();
+ info.setValue("joe@localhost");
+ valueTest(info, false);
+ info.setValue("joe@localhost.localdomain");
+ valueTest(info, false);
+ }
+
+ /**
+ * Write this test according to parts of RFC, as opposed to the type of character
+ * that is being tested.
+ *
+ * FIXME : 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 ", true),
+ new ResultPair("Abigail", true),
+ new ResultPair("Abigail<@a,@b,@c:abigail@example.com>", true),
+ new ResultPair("\"This is a phrase\"", true),
+ new ResultPair("\"Abigail \"", true),
+ new ResultPair("\"Joe & J. Harvey\" ", true),
+ new ResultPair("Abigail ", true),
+ new ResultPair("Abigail made this < abigail @ example . com >", true),
+ new ResultPair("Abigail(the bitch)@example.com", true),
+ new ResultPair("Abigail ", 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 ", true),
+ new ResultPair("Abigail ", true),
+ new ResultPair("(foo) abigail@example.com", true),
+ new ResultPair("abigail@example.com (foo)", true),
+ new ResultPair("\"Abi\\\"gail\" ", 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 ", true),
+ new ResultPair("Neuman@BBN-TENEXA", true),
+ new ResultPair("\"George, Ted\" ", 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 ", true),
+ new ResultPair("\"Joe &\\x0D\\x0A J. Harvey\" ", true),
+ new ResultPair("Gourmets: Pompous Person ,\\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 ", false),
+ new ResultPair("Abigail ", false),
+ new ResultPair("Abigail ", false),
+ new ResultPair("\"Abi\"gail\" ", 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)));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EntityImportTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EntityImportTest.java
new file mode 100644
index 000000000..200087176
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/EntityImportTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import java.net.URL;
+import java.util.Locale;
+
+
+/**
+ * Tests entity imports.
+ *
+ * @version $Revision$
+ */
+public class EntityImportTest extends AbstractCommonTest {
+
+ public EntityImportTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Tests the entity import loading the byteForm
form.
+ */
+ public void testEntityImport() throws Exception {
+ URL url = getClass().getResource("EntityImportTest-config.xml");
+ ValidatorResources resources = new ValidatorResources(url.toExternalForm());
+ assertNotNull("Form should be found", resources.getForm(Locale.getDefault(), "byteForm"));
+ }
+
+ /**
+ * Tests loading ValidatorResources from a URL
+ */
+ public void testParseURL() throws Exception {
+ URL url = getClass().getResource("EntityImportTest-config.xml");
+ ValidatorResources resources = new ValidatorResources(url);
+ assertNotNull("Form should be found", resources.getForm(Locale.getDefault(), "byteForm"));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExceptionTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExceptionTest.java
new file mode 100644
index 000000000..ff24b90bb
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExceptionTest.java
@@ -0,0 +1,150 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test for exception handling.
+ *
+ * @version $Revision$
+ */
+public class ExceptionTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "exceptionForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "raiseException";
+
+ public ExceptionTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-exception.xml.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ loadResources("ExceptionTest-config.xml");
+ }
+
+ /**
+ * Tests handling of checked exceptions - should become
+ * ValidatorExceptions.
+ */
+ public void testValidatorException() {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("VALIDATOR");
+
+ // 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 which can throw ValidatorException
+ try {
+ validator.validate();
+ fail("ValidatorException should occur here!");
+ } catch (ValidatorException expected) {
+ assertTrue("VALIDATOR-EXCEPTION".equals(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Tests handling of runtime exceptions.
+ *
+ * N.B. This test has been removed (renamed) as it currently
+ * serves no purpose. If/When exception handling
+ * is changed in Validator 2.0 it can be reconsidered
+ * then.
+ */
+ public void XtestRuntimeException() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("RUNTIME");
+
+ // 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 which can throw ValidatorException
+ try {
+ validator.validate();
+ //fail("RuntimeException should occur here!");
+ } catch (RuntimeException expected) {
+ fail("RuntimeExceptions should be treated as validation failures in Validator 1.x.");
+ // This will be true in Validator 2.0
+ //assertTrue("RUNTIME-EXCEPTION".equals(expected.getMessage()));
+ }
+ }
+
+ /**
+ * Tests handling of checked exceptions - should become
+ * ValidatorExceptions.
+ *
+ * N.B. This test has been removed (renamed) as it currently
+ * serves no purpose. If/When exception handling
+ * is changed in Validator 2.0 it can be reconsidered
+ * then.
+ */
+ public void XtestCheckedException() {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("CHECKED");
+
+ // 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 which can throw ValidatorException
+
+ // Tests Validator 1.x exception handling
+ try {
+ validator.validate();
+ } catch (ValidatorException expected) {
+ fail("Checked exceptions are not wrapped in ValidatorException in Validator 1.x.");
+ } catch (Exception e) {
+ assertTrue("CHECKED-EXCEPTION".equals(e.getMessage()));
+ }
+
+ // This will be true in Validator 2.0
+// try {
+// validator.validate();
+// fail("ValidatorException should occur here!");
+// } catch (ValidatorException expected) {
+// assertTrue("CHECKED-EXCEPTION".equals(expected.getMessage()));
+// }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExtensionTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExtensionTest.java
new file mode 100644
index 000000000..38301abba
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ExtensionTest.java
@@ -0,0 +1,365 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Performs tests for extension in form definitions. Performs the same tests
+ * RequiredNameTest does but with an equivalent validation definition with extension
+ * definitions (validator-extension.xml), plus an extra check on overriding rules and
+ * another one checking it mantains correct order when extending.
+ *
+ * @version $Revision$
+ */
+public class ExtensionTest extends TestCase {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "nameForm";
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY2 = "nameForm2";
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String CHECK_MSG_KEY = "nameForm.lastname.displayname";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "required";
+
+ /**
+ * Resources used for validation tests.
+ */
+ private ValidatorResources resources = null;
+
+ /**
+ * Constructor de ExtensionTest.
+ * @param arg0
+ */
+ public ExtensionTest(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-extension.xml.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ // Load resources
+ InputStream in = null;
+
+ try {
+ in = this.getClass().getResourceAsStream("ExtensionTest-config.xml");
+ resources = new ValidatorResources(in);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ @Override
+ protected void tearDown() {
+ }
+
+ /**
+ * Tests the required validation failure.
+ */
+ public void testRequired() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // 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 firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for first name if it is blank.
+ */
+ public void testRequiredFirstNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for first name.
+ */
+ public void testRequiredFirstName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name if it is blank.
+ */
+ public void testRequiredLastNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setLastName("");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name.
+ */
+ public void testRequiredLastName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setLastName("Smith");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+
+ }
+
+ /**
+ * Tests the required validation for first and last name.
+ */
+ public void testRequiredName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("Smith");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+ }
+
+
+ /**
+ * Tests if we can override a rule. We "can" override a rule if the message shown
+ * when the firstName required test fails and the lastName test is null.
+ */
+ public void testOverrideRule() throws ValidatorException {
+
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setLastName("Smith");
+
+ // Construct validator based on the loaded resources
+ // and the form key
+ Validator validator = new Validator(resources, FORM_KEY2);
+ // add the name bean to the validator as a resource
+ // for the validations to be performed on.
+ validator.setParameter(Validator.BEAN_PARAM, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have '" + CHECK_MSG_KEY + " as a key.", firstNameResult.field.getArg(0).getKey().equals(CHECK_MSG_KEY));
+
+ assertNull("Last Name ValidatorResult should be null.", lastNameResult);
+ }
+
+
+ /**
+ * Tests if the order is mantained when extending a form. Parent form fields should
+ * preceed self form fields, except if we override the rules.
+ */
+ public void testOrder() {
+
+ Form form = resources.getForm(ValidatorResources.defaultLocale, FORM_KEY);
+ Form form2 = resources.getForm(ValidatorResources.defaultLocale, FORM_KEY2);
+
+ assertNotNull(FORM_KEY + " is null.", form);
+ assertTrue("There should only be 2 fields in " + FORM_KEY, form.getFields().size() == 2);
+
+ assertNotNull(FORM_KEY2 + " is null.", form2);
+ assertTrue("There should only be 2 fields in " + FORM_KEY2, form2.getFields().size() == 2);
+
+ //get the first field
+ Field fieldFirstName = form.getFields().get(0);
+ //get the second field
+ Field fieldLastName = form.getFields().get(1);
+ assertTrue("firstName in " + FORM_KEY + " should be the first in the list", fieldFirstName.getKey().equals("firstName"));
+ assertTrue("lastName in " + FORM_KEY + " should be the first in the list", fieldLastName.getKey().equals("lastName"));
+
+// get the second field
+ fieldLastName = form2.getFields().get(0);
+ //get the first field
+ fieldFirstName = form2.getFields().get(1);
+ assertTrue("firstName in " + FORM_KEY2 + " should be the first in the list", fieldFirstName.getKey().equals("firstName"));
+ assertTrue("lastName in " + FORM_KEY2 + " should be the first in the list", fieldLastName.getKey().equals("lastName"));
+
+ }
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FieldTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FieldTest.java
new file mode 100644
index 000000000..06c728f20
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FieldTest.java
@@ -0,0 +1,286 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * Test Field
objects.
+ *
+ * @version $Revision$
+ */
+public class FieldTest extends TestCase {
+
+
+ protected Field field;
+
+ /**
+ * FieldTest constructor.
+ */
+ public FieldTest() {
+ super();
+ }
+
+ /**
+ * FieldTest constructor.
+ * @param name
+ */
+ public FieldTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test setup
+ */
+ @Override
+ public void setUp() {
+ field = new Field();
+ }
+
+ /**
+ * Test clean up
+ */
+ @Override
+ public void tearDown() {
+ field = null;
+ }
+
+ /**
+ * test Field with no arguments
+ */
+ public void testEmptyArgs() {
+
+ assertEquals("Empty Args(1) ", 0, field.getArgs("required").length);
+
+ }
+ /**
+ * test Field with only 'default' arguments, no positions specified.
+ */
+ public void testDefaultPositionImplied() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-1"));
+ field.addArg(createArg("default-position-2"));
+
+ assertEquals("testDefaultPositionImplied(1) ", 3, field.getArgs("required").length);
+ assertEquals("testDefaultPositionImplied(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testDefaultPositionImplied(3) ", "default-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testDefaultPositionImplied(4) ", "default-position-2", field.getArg("required", 2).getKey());
+
+ }
+
+ /**
+ * test Field with only 'default' arguments, positions specified.
+ */
+ public void testDefaultUsingPositions() {
+
+ field.addArg(createArg("default-position-1", 1));
+ field.addArg(createArg("default-position-0", 0));
+ field.addArg(createArg("default-position-2", 2));
+
+ assertEquals("testDefaultUsingPositions(1) ", 3, field.getArgs("required").length);
+ assertEquals("testDefaultUsingPositions(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testDefaultUsingPositions(3) ", "default-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testDefaultUsingPositions(4) ", "default-position-2", field.getArg("required", 2).getKey());
+
+ }
+
+ /**
+ * test Field with only 'default' arguments, position specified for one argument
+ */
+ public void testDefaultOnePosition() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-2", 2));
+ field.addArg(createArg("default-position-3"));
+
+ assertEquals("testDefaultOnePosition(1) ", 4, field.getArgs("required").length);
+ assertEquals("testDefaultOnePosition(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertNull("testDefaultOnePosition(3) ", field.getArg("required", 1));
+ assertEquals("testDefaultOnePosition(4) ", "default-position-2", field.getArg("required", 2).getKey());
+ assertEquals("testDefaultOnePosition(5) ", "default-position-3", field.getArg("required", 3).getKey());
+
+ }
+
+ /**
+ * test Field with only 'default' arguments, some position specified.
+ */
+ public void testDefaultSomePositions() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-2", 2));
+ field.addArg(createArg("default-position-3"));
+ field.addArg(createArg("default-position-1", 1));
+
+ assertEquals("testDefaultSomePositions(1) ", 4, field.getArgs("required").length);
+ assertEquals("testDefaultSomePositions(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testDefaultSomePositions(3) ", "default-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testDefaultSomePositions(4) ", "default-position-2", field.getArg("required", 2).getKey());
+ assertEquals("testDefaultSomePositions(5) ", "default-position-3", field.getArg("required", 3).getKey());
+
+ }
+
+ /**
+ * test Field with a 'default' argument overriden using 'position' property
+ */
+ public void testOverrideUsingPositionA() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-1"));
+ field.addArg(createArg("default-position-2"));
+ field.addArg(createArg("required-position-1", "required", 1));
+
+ // use 'required' as name
+ assertEquals("testOverrideUsingPositionA(1) ", 3, field.getArgs("required").length);
+ assertEquals("testOverrideUsingPositionA(2) ", "required-position-1", field.getArg("required", 1).getKey());
+
+ // use 'mask' as name
+ assertEquals("testOverrideUsingPositionA(3) ", 3, field.getArgs("mask").length);
+ assertEquals("testOverrideUsingPositionA(4) ", "default-position-1", field.getArg("mask", 1).getKey());
+
+ // Get Default
+ assertEquals("testOverrideUsingPositionA(5) ", "default-position-1", field.getArg(1).getKey());
+
+ }
+
+ /**
+ * test Field with a 'default' argument overriden using 'position' property
+ */
+ public void testOverrideUsingPositionB() {
+
+ field.addArg(createArg("required-position-3", "required", 3));
+ field.addArg(createArg("required-position-1", "required", 1));
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-1"));
+ field.addArg(createArg("default-position-2"));
+
+ // use 'required' as name
+ assertEquals("testOverrideUsingPositionB(1) ", 4, field.getArgs("required").length);
+ assertEquals("testOverrideUsingPositionB(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testOverrideUsingPositionB(3) ", "required-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testOverrideUsingPositionB(4) ", "default-position-2", field.getArg("required", 2).getKey());
+ assertEquals("testOverrideUsingPositionB(5) ", "required-position-3", field.getArg("required", 3).getKey());
+
+ // use 'mask' as name
+ assertEquals("testOverrideUsingPositionB(6) ", 4, field.getArgs("mask").length);
+ assertEquals("testOverrideUsingPositionB(6) ", "default-position-0", field.getArg("mask", 0).getKey());
+ assertEquals("testOverrideUsingPositionB(7) ", "default-position-1", field.getArg("mask", 1).getKey());
+ assertEquals("testOverrideUsingPositionB(8) ", "default-position-2", field.getArg("mask", 2).getKey());
+ assertNull("testOverrideUsingPositionB(9) ", field.getArg("mask", 3));
+
+ }
+
+ /**
+ * test Field with a 'default' argument overriden without positions specified.
+ */
+ public void testOverridePositionImplied() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("required-position-1", "required"));
+ field.addArg(createArg("required-position-2", "required"));
+ field.addArg(createArg("mask-position-1", "mask"));
+
+ // use 'required' as name
+ assertEquals("testOverridePositionImplied(1) ", 3, field.getArgs("required").length);
+ assertEquals("testOverridePositionImplied(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testOverridePositionImplied(3) ", "required-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testOverridePositionImplied(4) ", "required-position-2", field.getArg("required", 2).getKey());
+
+ // use 'mask' as name
+ assertEquals("testOverridePositionImplied(5) ", 3, field.getArgs("mask").length);
+ assertEquals("testOverridePositionImplied(6) ", "default-position-0", field.getArg("mask", 0).getKey());
+ assertEquals("testOverridePositionImplied(7) ", "mask-position-1", field.getArg("mask", 1).getKey());
+ assertNull("testOverridePositionImplied(8) ", field.getArg("mask", 2));
+
+ // Get Defaults
+ assertEquals("testOverridePositionImplied(9) ", "default-position-0", field.getArg(0).getKey());
+ assertNull("testOverridePositionImplied(10) ", field.getArg(1));
+ assertNull("testOverridePositionImplied(11) ", field.getArg(2));
+
+ }
+
+ /**
+ * test Field with a 'default' argument overriden with some positions specified
+ */
+ public void testOverrideSomePosition() {
+
+ field.addArg(createArg("default-position-0"));
+ field.addArg(createArg("default-position-1"));
+ field.addArg(createArg("default-position-2"));
+ field.addArg(createArg("required-position-1", "required", 1));
+ field.addArg(createArg("required-position-2", "required"));
+ field.addArg(createArg("mask-position-3", "mask"));
+
+ // use 'required' as name
+ assertEquals("testOverrideSomePosition(1) ", 4, field.getArgs("required").length);
+ assertEquals("testOverrideSomePosition(2) ", "default-position-0", field.getArg("required", 0).getKey());
+ assertEquals("testOverrideSomePosition(3) ", "required-position-1", field.getArg("required", 1).getKey());
+ assertEquals("testOverrideSomePosition(4) ", "required-position-2", field.getArg("required", 2).getKey());
+ assertNull("testOverrideSomePosition(5) ", field.getArg("required", 3));
+
+ // use 'mask' as name
+ assertEquals("testOverrideSomePosition(6) ", 4, field.getArgs("mask").length);
+ assertEquals("testOverrideSomePosition(7) ", "default-position-0", field.getArg("mask", 0).getKey());
+ assertEquals("testOverrideSomePosition(8) ", "default-position-1", field.getArg("mask", 1).getKey());
+ assertEquals("testOverrideSomePosition(9) ", "default-position-2", field.getArg("mask", 2).getKey());
+ assertEquals("testOverrideSomePosition(10) ", "mask-position-3", field.getArg("mask", 3).getKey());
+
+ // Get Defaults
+ assertEquals("testOverrideSomePosition(11) ", "default-position-0", field.getArg(0).getKey());
+ assertEquals("testOverrideSomePosition(12) ", "default-position-1", field.getArg(1).getKey());
+ assertEquals("testOverrideSomePosition(13) ", "default-position-2", field.getArg(2).getKey());
+ assertNull("testOverrideSomePosition(14) ", field.getArg(3));
+
+ }
+
+ /**
+ * Convenience Method - create argument (no name or position specified)
+ */
+ private Arg createArg(String key) {
+ Arg arg = new Arg();
+ arg.setKey(key);
+ return arg;
+ }
+
+ /**
+ * Convenience Method - create argument (no name, position specified)
+ */
+ private Arg createArg(String key, int position) {
+ Arg arg = createArg(key);
+ arg.setPosition(position);
+ return arg;
+ }
+
+ /**
+ * Convenience Method - create argument (name specified, no position)
+ */
+ private Arg createArg(String key, String name) {
+ Arg arg = createArg(key);
+ arg.setName(name);
+ return arg;
+ }
+
+ /**
+ * Convenience Method - create argument (name & position specified)
+ */
+ private Arg createArg(String key, String name, int position) {
+ Arg arg = createArg(key, name);
+ arg.setPosition(position);
+ return arg;
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FloatTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FloatTest.java
new file mode 100644
index 000000000..8b57a27f7
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/FloatTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+
+/**
+ * Performs Validation Test for float
validations.
+ *
+ * @version $Revision$
+ */
+public class FloatTest extends AbstractNumberTest {
+
+ public FloatTest(String name) {
+ super(name);
+ ACTION = "float";
+ FORM_KEY = "floatForm";
+ }
+
+ /**
+ * Tests the float validation.
+ */
+ public void testFloat() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the float validation.
+ */
+ public void testFloatMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Float.valueOf(Float.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the float validation.
+ */
+ public void testFloatMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Float.valueOf(Float.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the float validation failure.
+ */
+ public void testFloatFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ valueTest(info, false);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorImpl.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorImpl.java
new file mode 100644
index 000000000..fd5c272b1
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorImpl.java
@@ -0,0 +1,248 @@
+/*
+ * 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;
+
+import java.util.*;
+
+import org.apache.commons.validator.util.ValidatorUtils;
+
+/**
+ * Contains validation methods for different unit tests.
+ *
+ * @version $Revision$
+ */
+public class GenericTypeValidatorImpl {
+
+ /**
+ * Checks if the field can be successfully converted to a byte
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a byte
true
is returned.
+ * Otherwise false
.
+ */
+ public static Byte validateByte(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatByte(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a byte
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a byte
true
is returned.
+ * Otherwise false
.
+ */
+ public static Byte validateByte(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatByte(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a short
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a short
true
is returned.
+ * Otherwise false
.
+ */
+ public static Short validateShort(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatShort(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a short
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a short
true
is returned.
+ * Otherwise false
.
+ */
+ public static Short validateShort(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatShort(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a int
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a int
true
is returned.
+ * Otherwise false
.
+ */
+ public static Integer validateInt(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatInt(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a int
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a int
true
is returned.
+ * Otherwise false
.
+ */
+ public static Integer validateInt(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatInt(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a long
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a long
true
is returned.
+ * Otherwise false
.
+ */
+ public static Long validateLong(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatLong(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a long
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a long
true
is returned.
+ * Otherwise false
.
+ */
+ public static Long validateLong(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatLong(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a float
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a float
true
is returned.
+ * Otherwise false
.
+ */
+ public static Float validateFloat(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatFloat(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a float
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a float
true
is returned.
+ * Otherwise false
.
+ */
+ public static Float validateFloat(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatFloat(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a double
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a double
true
is returned.
+ * Otherwise false
.
+ */
+ public static Double validateDouble(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatDouble(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a double
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a double
true
is returned.
+ * Otherwise false
.
+ */
+ public static Double validateDouble(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatDouble(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a date
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a date
true
is returned.
+ * Otherwise false
.
+ */
+ public static Date validateDate(Object bean, Field field, Locale locale) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatDate(value, locale);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a date
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a date
true
is returned.
+ * Otherwise false
.
+ */
+ public static Date validateDate(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+ String datePattern = field.getVarValue("datePattern");
+ String datePatternStrict = field.getVarValue("datePatternStrict");
+
+ Date result = null;
+ if (datePattern != null && datePattern.length() > 0) {
+ result = GenericTypeValidator.formatDate(value, datePattern, false);
+ } else if (datePatternStrict != null && datePatternStrict.length() > 0) {
+ result = GenericTypeValidator.formatDate(value, datePatternStrict, true);
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
new file mode 100644
index 000000000..6014a5523
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericTypeValidatorTest.java
@@ -0,0 +1,195 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test for type validations.
+ *
+ * @version $Revision$
+ */
+public class GenericTypeValidatorTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "typeForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "byte";
+
+ public GenericTypeValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-type.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("GenericTypeValidatorTest-config.xml");
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * Tests the byte validation.
+ */
+ public void testType() throws ValidatorException {
+ // Create bean to run test on.
+ TypeBean info = new TypeBean();
+ info.setByte("12");
+ info.setShort("129");
+ info.setInteger("-144");
+ info.setLong("88000");
+ info.setFloat("12.1555f");
+ info.setDouble("129.1551511111d");
+
+ // 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);
+
+ Map hResultValues = results.getResultValueMap();
+
+ assertTrue("Expecting byte result to be an instance of Byte.", (hResultValues.get("byte") instanceof Byte));
+ assertTrue("Expecting short result to be an instance of Short.", (hResultValues.get("short") instanceof Short));
+ assertTrue("Expecting integer result to be an instance of Integer.", (hResultValues.get("integer") instanceof Integer));
+ assertTrue("Expecting long result to be an instance of Long.", (hResultValues.get("long") instanceof Long));
+ assertTrue("Expecting float result to be an instance of Float.", (hResultValues.get("float") instanceof Float));
+ assertTrue("Expecting double result to be an instance of Double.", (hResultValues.get("double") instanceof Double));
+
+ for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) {
+ String key = i.next();
+ Object value = hResultValues.get(key);
+
+ assertNotNull("value ValidatorResults.getResultValueMap() should not be null.", value);
+ }
+
+ //ValidatorResult result = results.getValidatorResult("value");
+
+ //assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
+ //assertTrue(ACTION + " value ValidatorResult should contain the '" + ACTION +"' action.", result.containsAction(ACTION));
+ //assertTrue(ACTION + " value ValidatorResult for the '" + ACTION +"' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
+
+ }
+
+ /**
+ * Tests the us locale
+ */
+ public void testUSLocale() throws ValidatorException {
+ // Create bean to run test on.
+ TypeBean info = new TypeBean();
+ info.setByte("12");
+ info.setShort("129");
+ info.setInteger("-144");
+ info.setLong("88000");
+ info.setFloat("12.1555");
+ info.setDouble("129.1551511111");
+ info.setDate("12/21/2010");
+ localeTest(info, Locale.US);
+ }
+
+ /**
+ * Tests the fr locale.
+ */
+ public void testFRLocale() throws ValidatorException {
+ // Create bean to run test on.
+ TypeBean info = new TypeBean();
+ info.setByte("12");
+ info.setShort("-129");
+ info.setInteger("1443");
+ info.setLong("88000");
+ info.setFloat("12,1555");
+ info.setDouble("129,1551511111");
+ info.setDate("21/12/2010");
+ Map map = localeTest(info, Locale.FRENCH);
+ assertTrue("float value not correct", ((Float)map.get("float")).intValue() == 12);
+ assertTrue("double value not correct", ((Double)map.get("double")).intValue() == 129);
+ }
+
+ /**
+ * Tests the locale.
+ */
+ private Map localeTest(TypeBean info, Locale locale) throws ValidatorException {
+
+ // Construct validator based on the loaded resources
+ // and the form key
+ Validator validator = new Validator(resources, "typeLocaleForm");
+ // add the name bean to the validator as a resource
+ // for the validations to be performed on.
+ validator.setParameter(Validator.BEAN_PARAM, info);
+ validator.setParameter("java.util.Locale", locale);
+
+ // 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);
+
+ Map hResultValues = results.getResultValueMap();
+
+ assertTrue("Expecting byte result to be an instance of Byte for locale: "+locale, (hResultValues.get("byte") instanceof Byte));
+ assertTrue("Expecting short result to be an instance of Short for locale: "+locale, (hResultValues.get("short") instanceof Short));
+ assertTrue("Expecting integer result to be an instance of Integer for locale: "+locale, (hResultValues.get("integer") instanceof Integer));
+ assertTrue("Expecting long result to be an instance of Long for locale: "+locale, (hResultValues.get("long") instanceof Long));
+ assertTrue("Expecting float result to be an instance of Float for locale: "+locale, (hResultValues.get("float") instanceof Float));
+ assertTrue("Expecting double result to be an instance of Double for locale: "+locale, (hResultValues.get("double") instanceof Double));
+ assertTrue("Expecting date result to be an instance of Date for locale: "+locale, (hResultValues.get("date") instanceof Date));
+
+ for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) {
+ String key = i.next();
+ Object value = hResultValues.get(key);
+
+ assertNotNull("value ValidatorResults.getResultValueMap() should not be null for locale: "+locale, value);
+ }
+ return hResultValues;
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
new file mode 100644
index 000000000..9eb7b8635
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorImpl.java
@@ -0,0 +1,275 @@
+/*
+ * 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;
+
+import org.apache.commons.validator.util.ValidatorUtils;
+
+/**
+ * Contains validation methods for different unit tests.
+ *
+ * @version $Revision$
+ */
+public class GenericValidatorImpl {
+
+ /**
+ * Throws a runtime exception if the value of the argument is "RUNTIME",
+ * an exception if the value of the argument is "CHECKED", and a
+ * ValidatorException otherwise.
+ *
+ * @throws RuntimeException with "RUNTIME-EXCEPTION as message"
+ * if value is "RUNTIME"
+ * @throws Exception with "CHECKED-EXCEPTION" as message
+ * if value is "CHECKED"
+ * @throws ValidatorException with "VALIDATOR-EXCEPTION" as message
+ * otherwise
+ */
+ public static boolean validateRaiseException(
+ final Object bean,
+ final Field field)
+ throws Exception {
+
+ final String value =
+ ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ if ("RUNTIME".equals(value)) {
+ throw new RuntimeException("RUNTIME-EXCEPTION");
+
+ } else if ("CHECKED".equals(value)) {
+ throw new Exception("CHECKED-EXCEPTION");
+
+ } else {
+ throw new ValidatorException("VALIDATOR-EXCEPTION");
+ }
+ }
+
+ /**
+ * Checks if the field is required.
+ *
+ * @return boolean If the field isn't null
and
+ * has a length greater than zero, true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateRequired(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return !GenericValidator.isBlankOrNull(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a byte
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a byte
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateByte(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isByte(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a short
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a short
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateShort(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isShort(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a int
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a int
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateInt(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isInt(value);
+ }
+
+ /**
+ * Checks if field is positive assuming it is an integer
+ *
+ * @param bean The value validation is being performed on.
+ * @param field Description of the field to be evaluated
+ * @return boolean If the integer field is greater than zero, returns
+ * true, otherwise returns false.
+ */
+ public static boolean validatePositive(Object bean , Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericTypeValidator.formatInt(value).intValue() > 0;
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a long
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a long
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateLong(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isLong(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a float
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a float
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateFloat(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isFloat(value);
+ }
+
+ /**
+ * Checks if the field can be successfully converted to a double
.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field can be successfully converted
+ * to a double
true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateDouble(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isDouble(value);
+ }
+
+ /**
+ * Checks if the field is an e-mail address.
+ *
+ * @param bean The value validation is being performed on.
+ * @param field the field to use
+ * @return boolean If the field is an e-mail address
+ * true
is returned.
+ * Otherwise false
.
+ */
+ public static boolean validateEmail(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ return GenericValidator.isEmail(value);
+ }
+
+ public final static String FIELD_TEST_NULL = "NULL";
+ public final static String FIELD_TEST_NOTNULL = "NOTNULL";
+ public final static String FIELD_TEST_EQUAL = "EQUAL";
+
+ public static boolean validateRequiredIf(
+ Object bean,
+ Field field,
+ Validator validator) {
+
+ Object form = validator.getParameterValue(Validator.BEAN_PARAM);
+ String value = null;
+ boolean required = false;
+ if (isStringOrNull(bean)) {
+ value = (String) bean;
+ } else {
+ value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+ }
+ int i = 0;
+ String fieldJoin = "AND";
+ if (!GenericValidator.isBlankOrNull(field.getVarValue("fieldJoin"))) {
+ fieldJoin = field.getVarValue("fieldJoin");
+ }
+ if (fieldJoin.equalsIgnoreCase("AND")) {
+ required = true;
+ }
+ while (!GenericValidator.isBlankOrNull(field.getVarValue("field[" + i + "]"))) {
+ String dependProp = field.getVarValue("field[" + i + "]");
+ String dependTest = field.getVarValue("fieldTest[" + i + "]");
+ String dependTestValue = field.getVarValue("fieldValue[" + i + "]");
+ String dependIndexed = field.getVarValue("fieldIndexed[" + i + "]");
+ if (dependIndexed == null) {
+ dependIndexed = "false";
+ }
+ String dependVal = null;
+ boolean this_required = false;
+ if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) {
+ String key = field.getKey();
+ if ((key.contains("[")) && (key.contains("]"))) {
+ String ind = key.substring(0, key.indexOf(".") + 1);
+ dependProp = ind + dependProp;
+ }
+ }
+ dependVal = ValidatorUtils.getValueAsString(form, dependProp);
+ if (dependTest.equals(FIELD_TEST_NULL)) {
+ if ((dependVal != null) && (dependVal.length() > 0)) {
+ this_required = false;
+ } else {
+ this_required = true;
+ }
+ }
+ if (dependTest.equals(FIELD_TEST_NOTNULL)) {
+ if ((dependVal != null) && (dependVal.length() > 0)) {
+ this_required = true;
+ } else {
+ this_required = false;
+ }
+ }
+ if (dependTest.equals(FIELD_TEST_EQUAL)) {
+ this_required = dependTestValue.equalsIgnoreCase(dependVal);
+ }
+ if (fieldJoin.equalsIgnoreCase("AND")) {
+ required = required && this_required;
+ } else {
+ required = required || this_required;
+ }
+ i++;
+ }
+ if (required) {
+ if ((value != null) && (value.length() > 0)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean isStringOrNull(Object o) {
+ if (o == null) {
+ return true; // TODO this condition is not exercised by any tests currently
+ }
+ return (o instanceof String);
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorTest.java
new file mode 100644
index 000000000..782b935ce
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/GenericValidatorTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the GenericValidator class.
+ *
+ * @version $Revision$
+ */
+public class GenericValidatorTest extends TestCase {
+
+ /**
+ * Constructor for GenericValidatorTest.
+ */
+ public GenericValidatorTest(String name) {
+ super(name);
+ }
+
+ public void testMinLength() {
+
+ // Use 0 for line end length
+ assertTrue("Min=5 End=0", GenericValidator.minLength("12345\n\r", 5, 0));
+ assertFalse("Min=6 End=0", GenericValidator.minLength("12345\n\r", 6, 0));
+ assertFalse("Min=7 End=0", GenericValidator.minLength("12345\n\r", 7, 0));
+ assertFalse("Min=8 End=0", GenericValidator.minLength("12345\n\r", 8, 0));
+
+ // Use 1 for line end length
+ assertTrue("Min=5 End=1", GenericValidator.minLength("12345\n\r", 5, 1));
+ assertTrue("Min=6 End=1", GenericValidator.minLength("12345\n\r", 6, 1));
+ assertFalse("Min=7 End=1", GenericValidator.minLength("12345\n\r", 7, 1));
+ assertFalse("Min=8 End=1", GenericValidator.minLength("12345\n\r", 8, 1));
+
+ // Use 2 for line end length
+ assertTrue("Min=5 End=2", GenericValidator.minLength("12345\n\r", 5, 2));
+ assertTrue("Min=6 End=2", GenericValidator.minLength("12345\n\r", 6, 2));
+ assertTrue("Min=7 End=2", GenericValidator.minLength("12345\n\r", 7, 2));
+ assertFalse("Min=8 End=2", GenericValidator.minLength("12345\n\r", 8, 2));
+ }
+
+ public void testMaxLength() {
+
+ // Use 0 for line end length
+ assertFalse("Max=4 End=0", GenericValidator.maxLength("12345\n\r", 4, 0));
+ assertTrue("Max=5 End=0", GenericValidator.maxLength("12345\n\r", 5, 0));
+ assertTrue("Max=6 End=0", GenericValidator.maxLength("12345\n\r", 6, 0));
+ assertTrue("Max=7 End=0", GenericValidator.maxLength("12345\n\r", 7, 0));
+
+ // Use 1 for line end length
+ assertFalse("Max=4 End=1", GenericValidator.maxLength("12345\n\r", 4, 1));
+ assertFalse("Max=5 End=1", GenericValidator.maxLength("12345\n\r", 5, 1));
+ assertTrue("Max=6 End=1", GenericValidator.maxLength("12345\n\r", 6, 1));
+ assertTrue("Max=7 End=1", GenericValidator.maxLength("12345\n\r", 7, 1));
+
+ // Use 2 for line end length
+ assertFalse("Max=4 End=2", GenericValidator.maxLength("12345\n\r", 4, 2));
+ assertFalse("Max=5 End=2", GenericValidator.maxLength("12345\n\r", 5, 2));
+ assertFalse("Max=6 End=2", GenericValidator.maxLength("12345\n\r", 6, 2));
+ assertTrue("Max=7 End=2", GenericValidator.maxLength("12345\n\r", 7, 2));
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java
new file mode 100644
index 000000000..514b57693
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * ISBNValidator Test Case.
+ *
+ * @version $Revision$
+ * @deprecated to be removed when the org.apache.commons.validator.ISBNValidator class is removed
+ */
+@Deprecated
+public class ISBNValidatorTest extends TestCase {
+
+ private static final String VALID_ISBN_RAW = "1930110995";
+ private static final String VALID_ISBN_DASHES = "1-930110-99-5";
+ private static final String VALID_ISBN_SPACES = "1 930110 99 5";
+ private static final String VALID_ISBN_X = "0-201-63385-X";
+ private static final String INVALID_ISBN = "068-556-98-45";
+
+ public ISBNValidatorTest(String name) {
+ super(name);
+ }
+
+ public void testIsValid() throws Exception {
+ ISBNValidator validator = new ISBNValidator();
+ assertFalse(validator.isValid(null));
+ assertFalse(validator.isValid(""));
+ assertFalse(validator.isValid("1"));
+ assertFalse(validator.isValid("12345678901234"));
+ assertFalse(validator.isValid("dsasdsadsads"));
+ assertFalse(validator.isValid("535365"));
+ assertFalse(validator.isValid("I love sparrows!"));
+ assertFalse(validator.isValid("--1 930110 99 5"));
+ assertFalse(validator.isValid("1 930110 99 5--"));
+ assertFalse(validator.isValid("1 930110-99 5-"));
+
+ assertTrue(validator.isValid(VALID_ISBN_RAW));
+ assertTrue(validator.isValid(VALID_ISBN_DASHES));
+ assertTrue(validator.isValid(VALID_ISBN_SPACES));
+ assertTrue(validator.isValid(VALID_ISBN_X));
+ assertFalse(validator.isValid(INVALID_ISBN));
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/IntegerTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/IntegerTest.java
new file mode 100644
index 000000000..14806a771
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/IntegerTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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;
+
+
+
+
+/**
+ * Performs Validation Test for int
validations.
+ *
+ * @version $Revision$
+ */
+public class IntegerTest extends AbstractNumberTest {
+
+
+ public IntegerTest(String name) {
+ super(name);
+ FORM_KEY = "intForm";
+ ACTION = "int";
+ }
+
+ /**
+ * Tests the int validation.
+ */
+ public void testInt() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the int validation.
+ */
+ public void testIntMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Integer.valueOf(Integer.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the int validation.
+ */
+ public void testIntegerMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Integer.valueOf(Integer.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the int validation failure.
+ */
+ public void testIntFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the int validation failure.
+ */
+ public void testIntBeyondMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Integer.MIN_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the int validation failure.
+ */
+ public void testIntBeyondMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Integer.MAX_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LocaleTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LocaleTest.java
new file mode 100644
index 000000000..95c933aec
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LocaleTest.java
@@ -0,0 +1,203 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test for locale validations.
+ *
+ * @version $Revision$
+ */
+public class LocaleTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation rules from the xml file.
+ */
+ protected static String FORM_KEY = "nameForm";
+
+ /** The key used to retrieve the validator action. */
+ protected static String ACTION = "required";
+
+ /**
+ * Constructor for the LocaleTest object
+ *
+ * @param name param
+ */
+ public LocaleTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from validator-locale.xml.
+ *
+ * @throws IOException If something goes wrong
+ * @throws SAXException If something goes wrong
+ */
+ @Override
+ protected void setUp()
+ throws IOException, SAXException {
+ // Load resources
+ loadResources("LocaleTest-config.xml");
+ }
+
+ /** The teardown method for JUnit */
+ @Override
+ protected void tearDown() {
+ }
+
+ /**
+ * See what happens when we try to validate with a Locale, Country and
+ * variant. Also check if the added locale validation field is getting used.
+ *
+ * @throws ValidatorException If something goes wrong
+ */
+ public void testLocale1()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("");
+
+ valueTest(name, new Locale("en", "US", "TEST1"), false, false, false);
+ }
+
+ /**
+ * See what happens when we try to validate with a Locale, Country and
+ * variant
+ *
+ * @throws ValidatorException If something goes wrong
+ */
+ public void testLocale2()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("");
+
+ valueTest(name, new Locale("en", "US", "TEST2"), true, false, true);
+ }
+
+ /**
+ * See what happens when we try to validate with a Locale, Country and
+ * variant
+ *
+ * @throws ValidatorException If something goes wrong
+ */
+ public void testLocale3()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("");
+
+ valueTest(name, new Locale("en", "UK"), false, true, true);
+ }
+
+ /**
+ * See if a locale of en_UK_TEST falls back to en_UK instead of default form
+ * set. Bug #16920 states that this isn't happening, even though it is
+ * passing this test. see #16920.
+ *
+ * @throws ValidatorException If something goes wrong
+ */
+ public void testLocale4()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("");
+
+ valueTest(name, new Locale("en", "UK", "TEST"), false, true, true);
+ }
+
+ /**
+ * See if a locale of language=en falls back to default form set.
+ *
+ * @throws ValidatorException If something goes wrong
+ */
+ public void testLocale5()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("");
+
+ valueTest(name, new Locale("en", ""), false, false, true);
+ }
+
+ /**
+ * Utlity class to run a test on a value.
+ *
+ * @param name param
+ * @param loc param
+ * @param firstGood param
+ * @param lastGood param
+ * @param middleGood param
+ * @throws ValidatorException If something goes wrong
+ */
+ private void valueTest(Object name, Locale loc, boolean firstGood, boolean lastGood, boolean middleGood)
+ 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, name);
+ validator.setParameter(Validator.LOCALE_PARAM, loc);
+ // 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 resultlast = results.getValidatorResult("lastName");
+ ValidatorResult resultfirst = results.getValidatorResult("firstName");
+ ValidatorResult resultmiddle = results.getValidatorResult("middleName");
+
+ if (firstGood) {
+ assertNull(resultfirst);
+ }
+ else {
+ assertNotNull(resultfirst);
+ }
+
+ if (middleGood) {
+ assertNull(resultmiddle);
+ }
+ else {
+ assertNotNull(resultmiddle);
+ }
+
+ if (lastGood) {
+ assertNull(resultlast);
+ }
+ else {
+ assertNotNull(resultlast);
+ }
+ }
+}
+
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LongTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LongTest.java
new file mode 100644
index 000000000..09660af54
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/LongTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+
+/**
+ * Performs Validation Test for long
validations.
+ *
+ * @version $Revision$
+ */
+public class LongTest extends AbstractNumberTest {
+
+ public LongTest(String name) {
+ super(name);
+ FORM_KEY = "longForm";
+ ACTION = "long";
+ }
+
+ /**
+ * Tests the long validation.
+ */
+ public void testLong() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue("0");
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the long validation.
+ */
+ public void testLongMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Long.valueOf(Long.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the long validation.
+ */
+ public void testLongMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Long.valueOf(Long.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the long validation failure.
+ */
+ public void testLongFailure() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the long validation failure.
+ */
+ public void testLongBeyondMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Long.MIN_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the long validation failure.
+ */
+ public void testLongBeyondMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Long.MAX_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java
new file mode 100644
index 000000000..67bef7fcc
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleConfigFilesTest.java
@@ -0,0 +1,268 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Tests that validator rules split between 2 different XML files get
+ * merged properly.
+ *
+ * @version $Revision$
+ */
+public class MultipleConfigFilesTest extends TestCase {
+
+ /**
+ * Resources used for validation tests.
+ */
+ private ValidatorResources resources = null;
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ private static final String FORM_KEY = "nameForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ private static final String ACTION = "required";
+
+ /**
+ * Constructor for MultipleConfigFilesTest.
+ * @param name
+ */
+ public MultipleConfigFilesTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from multiple xml files.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ InputStream[] streams =
+ new InputStream[] {
+ this.getClass().getResourceAsStream(
+ "MultipleConfigFilesTest-1-config.xml"),
+ this.getClass().getResourceAsStream(
+ "MultipleConfigFilesTest-2-config.xml")};
+
+ this.resources = new ValidatorResources(streams);
+
+ for (int i = 0; i < streams.length; i++) {
+ streams[i].close();
+ }
+ }
+
+ /**
+ * Check the forms and constants from different config files have
+ * been merged into the same FormSet.
+ */
+ public void testMergedConfig() {
+
+ // *********** Default Locale *******************
+
+ // Check the form from the first config file exists
+ Form form1 = resources.getForm("", "", "", "testForm1");
+ assertNotNull("Form 'testForm1' not found", form1);
+
+ // Check the form from the second config file exists
+ Form form2 = resources.getForm("", "", "", "testForm2");
+ assertNotNull("Form 'testForm2' not found", form2);
+
+ // Check the Constants for the form from the first config file
+ Field field1 = form1.getField("testProperty1");
+ assertEquals("testProperty1 - const 1", "testConstValue1", field1.getVarValue("var11"));
+ assertEquals("testProperty1 - const 2", "testConstValue2", field1.getVarValue("var12"));
+
+ // Check the Constants for the form from the second config file
+ Field field2 = form2.getField("testProperty2");
+ assertEquals("testProperty2 - const 1", "testConstValue1", field2.getVarValue("var21"));
+ assertEquals("testProperty2 - const 2", "testConstValue2", field2.getVarValue("var22"));
+
+ // *********** 'fr' locale *******************
+
+ // Check the form from the first config file exists
+ Form form1_fr = resources.getForm("fr", "", "", "testForm1_fr");
+ assertNotNull("Form 'testForm1_fr' not found", form1_fr);
+
+ // Check the form from the second config file exists
+ Form form2_fr = resources.getForm("fr", "", "", "testForm2_fr");
+ assertNotNull("Form 'testForm2_fr' not found", form2_fr);
+
+ // Check the Constants for the form from the first config file
+ Field field1_fr = form1_fr.getField("testProperty1_fr");
+ assertEquals("testProperty1_fr - const 1", "testConstValue1_fr", field1_fr.getVarValue("var11_fr"));
+ assertEquals("testProperty1_fr - const 2", "testConstValue2_fr", field1_fr.getVarValue("var12_fr"));
+
+ // Check the Constants for the form from the second config file
+ Field field2_fr = form2_fr.getField("testProperty2_fr");
+ assertEquals("testProperty2_fr - const 1", "testConstValue1_fr", field2_fr.getVarValue("var21_fr"));
+ assertEquals("testProperty2_fr - const 2", "testConstValue2_fr", field2_fr.getVarValue("var22_fr"));
+ }
+
+ /**
+ * With nothing provided, we should fail both because both are required.
+ */
+ public void testBothBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // 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 firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull(firstNameResult);
+ assertTrue(firstNameResult.containsAction(ACTION));
+ assertTrue(!firstNameResult.isValid(ACTION));
+
+ assertNotNull(lastNameResult);
+ assertTrue(lastNameResult.containsAction(ACTION));
+ assertTrue(!lastNameResult.isValid(ACTION));
+ assertTrue(!lastNameResult.containsAction("int"));
+ }
+
+ /**
+ * If the first name fails required, and the second test fails int, we should get two errors.
+ */
+ public void testRequiredFirstNameBlankLastNameShort()
+ throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull(firstNameResult);
+ assertTrue(firstNameResult.containsAction(ACTION));
+ assertTrue(!firstNameResult.isValid(ACTION));
+
+ assertNotNull(lastNameResult);
+ assertTrue(lastNameResult.containsAction("int"));
+ assertTrue(!lastNameResult.isValid("int"));
+ }
+
+ /**
+ * If the first name is there, and the last name fails int, we should get one error.
+ */
+ public void testRequiredLastNameShort() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Test");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull(firstNameResult);
+ assertTrue(firstNameResult.containsAction(ACTION));
+ assertTrue(firstNameResult.isValid(ACTION));
+
+ assertNotNull(lastNameResult);
+ assertTrue(lastNameResult.containsAction("int"));
+ assertTrue(!lastNameResult.isValid("int"));
+ }
+
+ /**
+ * If first name is ok and last name is ok and is an int, no errors.
+ */
+ public void testRequiredLastNameLong() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("12345678");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull(firstNameResult);
+ assertTrue(firstNameResult.containsAction(ACTION));
+ assertTrue(firstNameResult.isValid(ACTION));
+
+ assertNotNull(lastNameResult);
+ assertTrue(lastNameResult.containsAction("int"));
+ assertTrue(lastNameResult.isValid("int"));
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleTest.java
new file mode 100644
index 000000000..b6d6446e5
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/MultipleTest.java
@@ -0,0 +1,356 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test.
+ *
+ * @version $Revision$
+ */
+public class MultipleTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "nameForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "required";
+
+
+
+ public MultipleTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-multipletest.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("MultipleTests-config.xml");
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * With nothing provided, we should fail both because both are required.
+ */
+ public void testBothBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // 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 firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ assertTrue("Last Name ValidatorResults should not contain the 'int' action.", !lastNameResult.containsAction("int"));
+ }
+
+ /**
+ * If the first name fails required, and the second test fails int, we should get two errors.
+ */
+ public void testRequiredFirstNameBlankLastNameShort() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
+ assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
+ }
+
+ /**
+ * If the first name is there, and the last name fails int, we should get one error.
+ */
+ public void testRequiredLastNameShort() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Test");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
+ assertTrue("Last Name ValidatorResult for the 'int' action should have failed.", !lastNameResult.isValid("int"));
+ }
+
+ /**
+ * If first name is ok and last name is ok and is an int, no errors.
+ */
+ public void testRequiredLastNameLong() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("12345678");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the 'int' action.", lastNameResult.containsAction("int"));
+ assertTrue("Last Name ValidatorResult for the 'int' action should have passed.", lastNameResult.isValid("int"));
+ }
+
+ /**
+ * If middle name is not there, then the required dependent test should fail.
+ * No other tests should run
+ *
+ * @throws ValidatorException
+ */
+ public void testFailingFirstDependentValidator() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult middleNameResult = results.getValidatorResult("middleName");
+
+ assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
+
+ assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
+ assertTrue("Middle Name ValidatorResult for the 'required' action should have failed", !middleNameResult.isValid("required"));
+
+ assertTrue("Middle Name ValidatorResult should not contain the 'int' action.", !middleNameResult.containsAction("int"));
+
+ assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
+ }
+
+ /**
+ * If middle name is there but not int, then the required dependent test
+ * should pass, but the int dependent test should fail. No other tests should
+ * run.
+ *
+ * @throws ValidatorException
+ */
+ public void testFailingNextDependentValidator() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setMiddleName("TEST");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult middleNameResult = results.getValidatorResult("middleName");
+
+ assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
+
+ assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
+ assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
+
+ assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
+ assertTrue("Middle Name ValidatorResult for the 'int' action should have failed", !middleNameResult.isValid("int"));
+
+ assertTrue("Middle Name ValidatorResult should not contain the 'positive' action.", !middleNameResult.containsAction("positive"));
+ }
+
+ /**
+ * If middle name is there and a negative int, then the required and int
+ * dependent tests should pass, but the positive test should fail.
+ *
+ * @throws ValidatorException
+ */
+ public void testPassingDependentsFailingMain() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setMiddleName("-2534");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult middleNameResult = results.getValidatorResult("middleName");
+
+ assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
+
+ assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
+ assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
+
+ assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
+ assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
+
+ assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
+ assertTrue("Middle Name ValidatorResult for the 'positive' action should have failed", !middleNameResult.isValid("positive"));
+ }
+
+ /**
+ * If middle name is there and a positve int, then the required and int
+ * dependent tests should pass, and the positive test should pass.
+ *
+ * @throws ValidatorException
+ */
+ public void testPassingDependentsPassingMain() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setMiddleName("2534");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult middleNameResult = results.getValidatorResult("middleName");
+
+ assertNotNull("Middle Name ValidatorResult should not be null.", middleNameResult);
+
+ assertTrue("Middle Name ValidatorResult should contain the 'required' action.", middleNameResult.containsAction("required"));
+ assertTrue("Middle Name ValidatorResult for the 'required' action should have passed", middleNameResult.isValid("required"));
+
+ assertTrue("Middle Name ValidatorResult should contain the 'int' action.", middleNameResult.containsAction("int"));
+ assertTrue("Middle Name ValidatorResult for the 'int' action should have passed", middleNameResult.isValid("int"));
+
+ assertTrue("Middle Name ValidatorResult should contain the 'positive' action.", middleNameResult.containsAction("positive"));
+ assertTrue("Middle Name ValidatorResult for the 'positive' action should have passed", middleNameResult.isValid("positive"));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/NameBean.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/NameBean.java
new file mode 100644
index 000000000..544dcb190
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/NameBean.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+/**
+ * Value object that contains a first name and last name.
+ *
+ * @version $Revision$
+ */
+public class NameBean {
+
+ protected String firstName = null;
+
+ protected String middleName = null;
+
+ protected String lastName = null;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterTest.java
new file mode 100644
index 000000000..7a6cb606b
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.xml.sax.SAXException;
+
+/**
+ * This TestCase is a confirmation of the parameter of the validator's method.
+ *
+ * @version $Revision$
+ */
+public class ParameterTest extends AbstractCommonTest {
+
+ private static final String FORM_KEY = "nameForm";
+
+ private String firstName;
+
+ private String middleName;
+
+ private String lastName;
+
+ /**
+ * Constructor.
+ */
+ public ParameterTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * ValidatorResultsTest-config.xml.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("ParameterTest-config.xml");
+
+ // initialize values
+ firstName = "foo";
+ middleName = "123";
+ lastName = "456";
+
+ }
+
+ @Override
+ protected void tearDown() {
+ }
+
+ /**
+ * Test all validations ran and passed.
+ */
+ public void testAllValid() {
+
+ // Create bean to run test on.
+ NameBean bean = createNameBean();
+
+ 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, bean);
+ validator.setParameter(Validator.LOCALE_PARAM, Locale.getDefault());
+
+ // Get results of the validation.
+ try {
+ validator.validate();
+ } catch(Exception e) {
+ fail("Validator.validate() threw " + e);
+ }
+ assertParameterValue(validator, Validator.BEAN_PARAM, Object.class);
+ assertParameterValue(validator, Validator.FIELD_PARAM, Field.class);
+ assertParameterValue(validator, Validator.FORM_PARAM, Form.class);
+ assertParameterValue(validator, Validator.LOCALE_PARAM, Locale.class);
+ assertParameterValue(validator, Validator.VALIDATOR_ACTION_PARAM,
+ ValidatorAction.class);
+ assertParameterValue(validator, Validator.VALIDATOR_PARAM,
+ Validator.class);
+ assertParameterValue(validator, Validator.VALIDATOR_RESULTS_PARAM,
+ ValidatorResults.class);
+ }
+
+ private void assertParameterValue(Validator validator, String name,
+ Class> type) {
+ Object value = validator.getParameterValue(name);
+ assertNotNull("Expected '" + type.getName() + "' but was null", value);
+ assertTrue("Expected '" + type.getName() + "' but was '" + value.getClass().getName() + "'",
+ type.isInstance(value));
+ }
+
+ /**
+ * Create a NameBean.
+ */
+ private NameBean createNameBean() {
+ NameBean name = new NameBean();
+ name.setFirstName(firstName);
+ name.setMiddleName(middleName);
+ name.setLastName(lastName);
+ return name;
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterValidatorImpl.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterValidatorImpl.java
new file mode 100644
index 000000000..e8605d3f3
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ParameterValidatorImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Contains validation methods for different unit tests.
+ *
+ * @version $Revision$
+ */
+public class ParameterValidatorImpl {
+
+ /**
+ * ValidatorParameter is valid.
+ *
+ */
+ public static boolean validateParameter(
+ final java.lang.Object bean,
+ final org.apache.commons.validator.Form form,
+ final org.apache.commons.validator.Field field,
+ final org.apache.commons.validator.Validator validator,
+ final org.apache.commons.validator.ValidatorAction action,
+ final org.apache.commons.validator.ValidatorResults results,
+ final java.util.Locale locale)
+ throws Exception {
+
+ return true;
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredIfTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredIfTest.java
new file mode 100644
index 000000000..48162fb61
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredIfTest.java
@@ -0,0 +1,238 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Performs Validation Test.
+ *
+ * @version $Revision$
+ */
+public class RequiredIfTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "nameForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "requiredif";
+
+ public RequiredIfTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-requiredif.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("RequiredIfTest-config.xml");
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * With nothing provided, we should pass since the fields only fail on
+ * null if the other field is non-blank.
+ */
+ public void testRequired() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // 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 firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for first name if it is blank.
+ */
+ public void testRequiredFirstNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name.
+ */
+ public void testRequiredFirstName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Test");
+ name.setLastName("Test");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name if it is blank.
+ */
+ public void testRequiredLastNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name.
+ */
+ public void testRequiredLastName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("Smith");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("Last Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredNameTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredNameTest.java
new file mode 100644
index 000000000..94637b8d9
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RequiredNameTest.java
@@ -0,0 +1,269 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+
+/**
+ * Performs Validation Test.
+ *
+ * @version $Revision$
+ */
+public class RequiredNameTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "nameForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "required";
+
+ public RequiredNameTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-name-required.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("RequiredNameTest-config.xml");
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * Tests the required validation failure.
+ */
+ public void testRequired() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+
+ // 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, name);
+
+ // 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 firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for first name if it is blank.
+ */
+ public void testRequiredFirstNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for first name.
+ */
+ public void testRequiredFirstName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name if it is blank.
+ */
+ public void testRequiredLastNameBlank() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setLastName("");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have failed.", !lastNameResult.isValid(ACTION));
+ }
+
+ /**
+ * Tests the required validation for last name.
+ */
+ public void testRequiredLastName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setLastName("Smith");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have failed.", !firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+
+ }
+
+ /**
+ * Tests the required validation for first and last name.
+ */
+ public void testRequiredName() throws ValidatorException {
+ // Create bean to run test on.
+ NameBean name = new NameBean();
+ name.setFirstName("Joe");
+ name.setLastName("Smith");
+
+ // 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, name);
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+
+ results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult firstNameResult = results.getValidatorResult("firstName");
+ ValidatorResult lastNameResult = results.getValidatorResult("lastName");
+
+ assertNotNull("First Name ValidatorResult should not be null.", firstNameResult);
+ assertTrue("First Name ValidatorResult should contain the '" + ACTION +"' action.", firstNameResult.containsAction(ACTION));
+ assertTrue("First Name ValidatorResult for the '" + ACTION +"' action should have passed.", firstNameResult.isValid(ACTION));
+
+ assertNotNull("First Name ValidatorResult should not be null.", lastNameResult);
+ assertTrue("Last Name ValidatorResult should contain the '" + ACTION +"' action.", lastNameResult.containsAction(ACTION));
+ assertTrue("Last Name ValidatorResult for the '" + ACTION +"' action should have passed.", lastNameResult.isValid(ACTION));
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ResultPair.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ResultPair.java
new file mode 100644
index 000000000..37f63c5dc
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ResultPair.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * Groups tests and expected results.
+ *
+ * @version $Revision$
+ */
+ public class ResultPair {
+ public final String item;
+ public final boolean valid;
+
+ public ResultPair(String item, boolean valid) {
+ this.item = item;
+ this.valid = valid; //Whether the individual part of url is valid.
+ }
+ }
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RetrieveFormTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RetrieveFormTest.java
new file mode 100644
index 000000000..4b72857b9
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/RetrieveFormTest.java
@@ -0,0 +1,233 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+import junit.framework.TestCase;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests retrieving forms using different Locales.
+ *
+ * @version $Revision$
+ */
+public class RetrieveFormTest extends TestCase {
+
+ /**
+ * Resources used for validation tests.
+ */
+ private ValidatorResources resources = null;
+
+ /**
+ * Prefix for the forms.
+ */
+ private static final String FORM_PREFIX = "testForm_";
+
+ /**
+ * Prefix for the forms.
+ */
+ private static final Locale CANADA_FRENCH_XXX = new Locale("fr", "CA", "XXX");
+
+ /**
+ * Constructor for FormTest.
+ * @param name
+ */
+ public RetrieveFormTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from multiple xml files.
+ */
+ @Override
+ protected void setUp() throws IOException, SAXException {
+ InputStream[] streams =
+ new InputStream[] {
+ this.getClass().getResourceAsStream(
+ "RetrieveFormTest-config.xml")};
+
+ this.resources = new ValidatorResources(streams);
+
+ for (int i = 0; i < streams.length; i++) {
+ streams[i].close();
+ }
+ }
+
+ /**
+ * Test a form defined only in the "default" formset.
+ */
+ public void testDefaultForm() {
+
+ String formKey = FORM_PREFIX + "default";
+
+ // *** US locale ***
+ checkForm(Locale.US, formKey, "default");
+
+ // *** French locale ***
+ checkForm(Locale.FRENCH, formKey, "default");
+
+ // *** France locale ***
+ checkForm(Locale.FRANCE, formKey, "default");
+
+ // *** Candian (English) locale ***
+ checkForm(Locale.CANADA, formKey, "default");
+
+ // *** Candian French locale ***
+ checkForm(Locale.CANADA_FRENCH, formKey, "default");
+
+ // *** Candian French Variant locale ***
+ checkForm(CANADA_FRENCH_XXX, formKey, "default");
+
+ }
+
+ /**
+ * Test a form defined in the "default" formset and formsets
+ * where just the "language" is specified.
+ */
+ public void testLanguageForm() {
+
+ String formKey = FORM_PREFIX + "language";
+
+ // *** US locale ***
+ checkForm(Locale.US, formKey, "default");
+
+ // *** French locale ***
+ checkForm(Locale.FRENCH, formKey, "fr");
+
+ // *** France locale ***
+ checkForm(Locale.FRANCE, formKey, "fr");
+
+ // *** Candian (English) locale ***
+ checkForm(Locale.CANADA, formKey, "default");
+
+ // *** Candian French locale ***
+ checkForm(Locale.CANADA_FRENCH, formKey, "fr");
+
+ // *** Candian French Variant locale ***
+ checkForm(CANADA_FRENCH_XXX, formKey, "fr");
+
+ }
+
+ /**
+ * Test a form defined in the "default" formset, formsets
+ * where just the "language" is specified and formset where
+ * the language and country are specified.
+ */
+ public void testLanguageCountryForm() {
+
+ String formKey = FORM_PREFIX + "language_country";
+
+ // *** US locale ***
+ checkForm(Locale.US, formKey, "default");
+
+ // *** French locale ***
+ checkForm(Locale.FRENCH, formKey, "fr");
+
+ // *** France locale ***
+ checkForm(Locale.FRANCE, formKey, "fr_FR");
+
+ // *** Candian (English) locale ***
+ checkForm(Locale.CANADA, formKey, "default");
+
+ // *** Candian French locale ***
+ checkForm(Locale.CANADA_FRENCH, formKey, "fr_CA");
+
+ // *** Candian French Variant locale ***
+ checkForm(CANADA_FRENCH_XXX, formKey, "fr_CA");
+
+ }
+
+ /**
+ * Test a form defined in all the formsets
+ */
+ public void testLanguageCountryVariantForm() {
+
+ String formKey = FORM_PREFIX + "language_country_variant";
+
+ // *** US locale ***
+ checkForm(Locale.US, formKey, "default");
+
+ // *** French locale ***
+ checkForm(Locale.FRENCH, formKey, "fr");
+
+ // *** France locale ***
+ checkForm(Locale.FRANCE, formKey, "fr_FR");
+
+ // *** Candian (English) locale ***
+ checkForm(Locale.CANADA, formKey, "default");
+
+ // *** Candian French locale ***
+ checkForm(Locale.CANADA_FRENCH, formKey, "fr_CA");
+
+ // *** Candian French Variant locale ***
+ checkForm(CANADA_FRENCH_XXX, formKey, "fr_CA_XXX");
+
+ }
+
+ /**
+ * Test a form not defined
+ */
+ public void testFormNotFound() {
+
+ String formKey = "INVALID_NAME";
+
+ // *** US locale ***
+ checkFormNotFound(Locale.US, formKey);
+
+ // *** French locale ***
+ checkFormNotFound(Locale.FRENCH, formKey);
+
+ // *** France locale ***
+ checkFormNotFound(Locale.FRANCE, formKey);
+
+ // *** Candian (English) locale ***
+ checkFormNotFound(Locale.CANADA, formKey);
+
+ // *** Candian French locale ***
+ checkFormNotFound(Locale.CANADA_FRENCH, formKey);
+
+ // *** Candian French Variant locale ***
+ checkFormNotFound(CANADA_FRENCH_XXX, formKey);
+
+
+ }
+
+ private void checkForm(Locale locale, String formKey, String expectedVarValue) {
+
+ // Retrieve the Form
+ Form testForm = resources.getForm(locale, formKey);
+ assertNotNull("Form '" +formKey+"' null for locale " + locale, testForm);
+
+ // Validate the expected Form is retrieved by checking the "localeVar"
+ // value of the field.
+ Field testField = testForm.getField("testProperty");
+ assertEquals("Incorrect Form '" + formKey + "' for locale '" + locale + "'",
+ expectedVarValue,
+ testField.getVarValue("localeVar"));
+ }
+
+ private void checkFormNotFound(Locale locale, String formKey) {
+
+ // Retrieve the Form
+ Form testForm = resources.getForm(locale, formKey);
+ assertNull("Form '" +formKey+"' not null for locale " + locale, testForm);
+
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ShortTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ShortTest.java
new file mode 100644
index 000000000..d4d10152d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ShortTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+
+/**
+ * Performs Validation Test for short
validations.
+ *
+ * @version $Revision$
+ */
+public class ShortTest extends AbstractNumberTest {
+
+ public ShortTest(String name) {
+ super(name);
+ FORM_KEY = "shortForm";
+ ACTION = "short";
+ }
+
+ /**
+ * Tests the short validation.
+ */
+ public void testShortMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Short.valueOf(Short.MIN_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the short validation.
+ */
+ public void testShortMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Short.valueOf(Short.MAX_VALUE).toString());
+
+ valueTest(info, true);
+ }
+
+ /**
+ * Tests the short validation failure.
+ */
+ public void testShortBeyondMin() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Short.MIN_VALUE + "1");
+
+ valueTest(info, false);
+ }
+
+ /**
+ * Tests the short validation failure.
+ */
+ public void testShortBeyondMax() throws ValidatorException {
+ // Create bean to run test on.
+ ValueBean info = new ValueBean();
+ info.setValue(Short.MAX_VALUE + "1");
+
+ valueTest(info, false);
+ }
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/TypeBean.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/TypeBean.java
new file mode 100644
index 000000000..09f5c9aaf
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/TypeBean.java
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+/**
+ * Value object that contains different fields to test type conversion
+ * validation.
+ *
+ * @version $Revision$
+ */
+public class TypeBean {
+
+ private String sByte = null;
+ private String sShort = null;
+ private String sInteger = null;
+ private String sLong = null;
+ private String sFloat = null;
+ private String sDouble = null;
+ private String sDate = null;
+ private String sCreditCard = null;
+
+ public String getByte() {
+ return sByte;
+ }
+
+ public void setByte(String sByte) {
+ this.sByte = sByte;
+ }
+
+ public String getShort() {
+ return sShort;
+ }
+
+ public void setShort(String sShort) {
+ this.sShort = sShort;
+ }
+
+ public String getInteger() {
+ return sInteger;
+ }
+
+ public void setInteger(String sInteger) {
+ this.sInteger = sInteger;
+ }
+
+ public String getLong() {
+ return sLong;
+ }
+
+ public void setLong(String sLong) {
+ this.sLong = sLong;
+ }
+
+ public String getFloat() {
+ return sFloat;
+ }
+
+ public void setFloat(String sFloat) {
+ this.sFloat = sFloat;
+ }
+
+ public String getDouble() {
+ return sDouble;
+ }
+
+ public void setDouble(String sDouble) {
+ this.sDouble = sDouble;
+ }
+
+ public String getDate() {
+ return sDate;
+ }
+
+ public void setDate(String sDate) {
+ this.sDate = sDate;
+ }
+
+ public String getCreditCard() {
+ return sCreditCard;
+ }
+
+ public void setCreditCard(String sCreditCard) {
+ this.sCreditCard = sCreditCard;
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/UrlTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/UrlTest.java
new file mode 100644
index 000000000..af8c08359
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/UrlTest.java
@@ -0,0 +1,284 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * Performs Validation Test for url validations.
+ *
+ * @version $Revision$
+ * @deprecated to be removed when org.apache.commons.validator.UrlValidator is removed
+ */
+@Deprecated
+public class UrlTest extends TestCase {
+
+ private final boolean printStatus = false;
+ private final boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using.
+
+ public UrlTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+protected void setUp() {
+ for (int index = 0; index < testPartsIndex.length - 1; index++) {
+ testPartsIndex[index] = 0;
+ }
+ }
+
+ 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 {
+ StringBuilder testBuffer = new StringBuilder();
+ 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() {
+ StringBuilder carryMsg = new StringBuilder("{");
+ 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) {
+
+ UrlTest fct = new UrlTest("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
+ * ://? 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)};
+
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResourcesTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResourcesTest.java
new file mode 100644
index 000000000..3b95c1878
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResourcesTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test ValidatorResources.
+ *
+ * @version $Revision$
+ */
+public class ValidatorResourcesTest extends TestCase {
+
+ /**
+ * Constructor.
+ */
+ public ValidatorResourcesTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test null Input Stream for Validator Resources.
+ */
+ public void testNullInputStream() throws Exception {
+
+ try {
+ new ValidatorResources((InputStream)null);
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected result
+ // System.out.println("Exception: " + e);
+ }
+
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResultsTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResultsTest.java
new file mode 100644
index 000000000..eb452f13c
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorResultsTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Test ValidatorResults.
+ *
+ * @version $Revision$
+ */
+public class ValidatorResultsTest extends AbstractCommonTest {
+
+ private static final String FORM_KEY = "nameForm";
+ private static final String firstNameField = "firstName";
+ private static final String middleNameField = "middleName";
+ private static final String lastNameField = "lastName";
+
+ private String firstName;
+ private String middleName;
+ private String lastName;
+
+ /**
+ * Constructor.
+ */
+ public ValidatorResultsTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * ValidatorResultsTest-config.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("ValidatorResultsTest-config.xml");
+
+ // initialize values
+ firstName = "foo";
+ middleName = "123";
+ lastName = "456";
+
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * Test all validations ran and passed.
+ */
+ public void testAllValid() throws ValidatorException {
+
+ // Create bean to run test on.
+ NameBean bean = createNameBean();
+
+ // Validate.
+ ValidatorResults results = validate(bean);
+
+ // Check results
+ checkValidatorResult(results, firstNameField, "required", true);
+ checkValidatorResult(results, middleNameField, "required", true);
+ checkValidatorResult(results, middleNameField, "int", true);
+ checkValidatorResult(results, middleNameField, "positive", true);
+ checkValidatorResult(results, lastNameField, "required", true);
+ checkValidatorResult(results, lastNameField, "int", true);
+
+ }
+
+ /**
+ * Test some validations failed and some didn't run.
+ */
+ public void testErrors() throws ValidatorException {
+
+ middleName = "XXX";
+ lastName = null;
+
+ // Create bean to run test on.
+ NameBean bean = createNameBean();
+
+ // Validate.
+ ValidatorResults results = validate(bean);
+
+ // Check results
+ checkValidatorResult(results, firstNameField, "required", true);
+ checkValidatorResult(results, middleNameField, "required", true);
+ checkValidatorResult(results, middleNameField, "int", false);
+ checkNotRun(results, middleNameField, "positive");
+ checkValidatorResult(results, lastNameField, "required", false);
+ checkNotRun(results, lastNameField, "int");
+
+ }
+
+ /**
+ * Check a validator has not been run for a field and the result.
+ */
+ private void checkNotRun(ValidatorResults results, String field, String action) {
+ ValidatorResult result = results.getValidatorResult(field);
+ assertNotNull(field + " result", result);
+ assertFalse(field + "[" + action + "] run", result.containsAction(action));
+ // System.out.println(field + "[" + action + "] not run");
+ }
+
+ /**
+ * Check a validator has run for a field and the result.
+ */
+ private void checkValidatorResult(ValidatorResults results, String field, String action, boolean expected) {
+ ValidatorResult result = results.getValidatorResult(field);
+ // System.out.println(field + "[" + action + "]=" + result.isValid(action));
+ assertNotNull(field + " result", result);
+ assertTrue(field + "[" + action + "] not run", result.containsAction(action));
+ assertEquals(field + "[" + action + "] result", expected, result.isValid(action));
+ }
+
+ /**
+ * Create a NameBean.
+ */
+ private NameBean createNameBean() {
+ NameBean name = new NameBean();
+ name.setFirstName(firstName);
+ name.setMiddleName(middleName);
+ name.setLastName(lastName);
+ return name;
+ }
+
+ /**
+ * Validate results.
+ */
+ private ValidatorResults validate(Object bean) 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, bean);
+
+ // Get results of the validation.
+ ValidatorResults results = validator.validate();
+
+ return results;
+
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorTest.java
new file mode 100644
index 000000000..aa508c249
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValidatorTest.java
@@ -0,0 +1,286 @@
+/*
+ * 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;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.validator.util.ValidatorUtils;
+
+/**
+ * Performs Validation Test.
+ *
+ * @version $Revision$
+ */
+public class ValidatorTest extends TestCase {
+
+ public ValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Verify that one value generates an error and the other passes. The validation
+ * method being tested returns an object (null
will be considered an error).
+ */
+ public void testManualObject() {
+ // property name of the method we are validating
+ String property = "date";
+ // name of ValidatorAction
+ String action = "date";
+ ValidatorResources resources = setupDateResources(property, action);
+
+ TestBean bean = new TestBean();
+ bean.setDate("2/3/1999");
+
+ Validator validator = new Validator(resources, "testForm");
+ validator.setParameter(Validator.BEAN_PARAM, bean);
+
+ try {
+ ValidatorResults results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult result = results.getValidatorResult(property);
+
+ assertNotNull("Results are null.", results);
+
+ assertTrue("ValidatorResult does not contain '" + action + "' validator result.", result.containsAction(action));
+
+ assertTrue("Validation of the date formatting has failed.", result.isValid(action));
+ } catch (Exception e) {
+ fail("An exception was thrown while calling Validator.validate()");
+ }
+
+ bean.setDate("2/30/1999");
+
+ try {
+ ValidatorResults results = validator.validate();
+
+ assertNotNull("Results are null.", results);
+
+ ValidatorResult result = results.getValidatorResult(property);
+
+ assertNotNull("Results are null.", results);
+
+ assertTrue("ValidatorResult does not contain '" + action + "' validator result.", result.containsAction(action));
+
+ assertTrue("Validation of the date formatting has passed when it should have failed.", !result.isValid(action));
+ } catch (Exception e) {
+ fail("An exception was thrown while calling Validator.validate()");
+ }
+
+ }
+
+ public void testOnlyReturnErrors() throws ValidatorException {
+ // property name of the method we are validating
+ String property = "date";
+ // name of ValidatorAction
+ String action = "date";
+ ValidatorResources resources = setupDateResources(property, action);
+
+ TestBean bean = new TestBean();
+ bean.setDate("2/3/1999");
+
+ Validator validator = new Validator(resources, "testForm");
+ validator.setParameter(Validator.BEAN_PARAM, bean);
+
+ ValidatorResults results = validator.validate();
+
+ assertNotNull(results);
+
+ // Field passed and should be in results
+ assertTrue(results.getPropertyNames().contains(property));
+
+ // Field passed but should not be in results
+ validator.setOnlyReturnErrors(true);
+ results = validator.validate();
+ assertFalse(results.getPropertyNames().contains(property));
+ }
+
+ public void testOnlyValidateField() throws ValidatorException {
+ // property name of the method we are validating
+ String property = "date";
+ // name of ValidatorAction
+ String action = "date";
+ ValidatorResources resources = setupDateResources(property, action);
+
+ TestBean bean = new TestBean();
+ bean.setDate("2/3/1999");
+
+ Validator validator = new Validator(resources, "testForm", property);
+ validator.setParameter(Validator.BEAN_PARAM, bean);
+
+ ValidatorResults results = validator.validate();
+
+ assertNotNull(results);
+
+ // Field passed and should be in results
+ assertTrue(results.getPropertyNames().contains(property));
+ }
+
+
+ private ValidatorResources setupDateResources(String property, String action) {
+
+ ValidatorResources resources = new ValidatorResources();
+
+ ValidatorAction va = new ValidatorAction();
+ va.setName(action);
+ va.setClassname("org.apache.commons.validator.ValidatorTest");
+ va.setMethod("formatDate");
+ va.setMethodParams("java.lang.Object,org.apache.commons.validator.Field");
+
+ FormSet fs = new FormSet();
+ Form form = new Form();
+ form.setName("testForm");
+ Field field = new Field();
+ field.setProperty(property);
+ field.setDepends(action);
+ form.addField(field);
+ fs.addForm(form);
+
+ resources.addValidatorAction(va);
+ resources.addFormSet(fs);
+ resources.process();
+
+ return resources;
+ }
+
+ /**
+ * Verify that one value generates an error and the other passes. The validation
+ * method being tested returns a boolean
value.
+ */
+ public void testManualBoolean() {
+ ValidatorResources resources = new ValidatorResources();
+
+ ValidatorAction va = new ValidatorAction();
+ va.setName("capLetter");
+ va.setClassname("org.apache.commons.validator.ValidatorTest");
+ va.setMethod("isCapLetter");
+ va.setMethodParams("java.lang.Object,org.apache.commons.validator.Field,java.util.List");
+
+ FormSet fs = new FormSet();
+ Form form = new Form();
+ form.setName("testForm");
+ Field field = new Field();
+ field.setProperty("letter");
+ field.setDepends("capLetter");
+ form.addField(field);
+ fs.addForm(form);
+
+ resources.addValidatorAction(va);
+ resources.addFormSet(fs);
+ resources.process();
+
+ List> l = new ArrayList();
+
+ TestBean bean = new TestBean();
+ bean.setLetter("A");
+
+ Validator validator = new Validator(resources, "testForm");
+ validator.setParameter(Validator.BEAN_PARAM, bean);
+ validator.setParameter("java.util.List", l);
+
+ try {
+ validator.validate();
+ } catch (Exception e) {
+ fail("An exception was thrown while calling Validator.validate()");
+ }
+
+ assertEquals("Validation of the letter 'A'.", 0, l.size());
+
+ l.clear();
+ bean.setLetter("AA");
+
+ try {
+ validator.validate();
+ } catch (Exception e) {
+ fail("An exception was thrown while calling Validator.validate()");
+ }
+
+ assertEquals("Validation of the letter 'AA'.", 1, l.size());
+ }
+
+ /**
+ * Checks if the field is one upper case letter between 'A' and 'Z'.
+ */
+ public static boolean isCapLetter(Object bean, Field field, List l) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+
+ if (value != null && value.length() == 1) {
+ if (value.charAt(0) >= 'A' && value.charAt(0) <= 'Z') {
+ return true;
+ } else {
+ l.add("Error");
+ return false;
+ }
+ } else {
+ l.add("Error");
+ return false;
+ }
+ }
+
+ /**
+ * Formats a String
to a Date
.
+ * The Validator
will interpret a null
+ * as validation having failed.
+ */
+ public static Date formatDate(Object bean, Field field) {
+ String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+ Date date = null;
+
+ try {
+ DateFormat formatter = null;
+ formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
+
+ formatter.setLenient(false);
+
+ date = formatter.parse(value);
+ } catch (ParseException e) {
+ System.out.println("ValidatorTest.formatDate() - " + e.getMessage());
+ }
+
+ return date;
+ }
+
+ public class TestBean {
+ private String letter = null;
+ private String date = null;
+
+ public String getLetter() {
+ return letter;
+ }
+
+ public void setLetter(String letter) {
+ this.letter = letter;
+ }
+
+ public String getDate() {
+ return date;
+ }
+
+ public void setDate(String date) {
+ this.date = date;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValueBean.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValueBean.java
new file mode 100644
index 000000000..263f86bb8
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/ValueBean.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Value object for storing a value to run tests on.
+ *
+ * @version $Revision$
+ */
+public class ValueBean {
+
+ protected String value = null;
+
+ /**
+ * Gets the value.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value.
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/VarTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/VarTest.java
new file mode 100644
index 000000000..55079084a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/VarTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Test that the new Var attributes and the
+ * digester rule changes work.
+ *
+ * @version $Revision$
+ */
+public class VarTest extends AbstractCommonTest {
+
+ /**
+ * The key used to retrieve the set of validation
+ * rules from the xml file.
+ */
+ protected static String FORM_KEY = "testForm";
+
+ /**
+ * The key used to retrieve the validator action.
+ */
+ protected static String ACTION = "byte";
+
+
+
+ public VarTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Load ValidatorResources
from
+ * validator-multipletest.xml.
+ */
+ @Override
+protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("VarTest-config.xml");
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * With nothing provided, we should fail both because both are required.
+ */
+ public void testVars() {
+
+ Form form = resources.getForm(Locale.getDefault(), FORM_KEY);
+
+ // Get field 1
+ Field field1 = form.getField("field-1");
+ assertNotNull("field-1 is null.", field1);
+ assertEquals("field-1 property is wrong", "field-1", field1.getProperty());
+
+ // Get var-1-1
+ Var var11 = field1.getVar("var-1-1");
+ assertNotNull("var-1-1 is null.", var11);
+ assertEquals("var-1-1 name is wrong", "var-1-1", var11.getName());
+ assertEquals("var-1-1 value is wrong", "value-1-1", var11.getValue());
+ assertEquals("var-1-1 jstype is wrong", "jstype-1-1", var11.getJsType());
+ assertFalse("var-1-1 resource is true", var11.isResource());
+ assertNull("var-1-1 bundle is not null.", var11.getBundle());
+
+ // Get field 2
+ Field field2 = form.getField("field-2");
+ assertNotNull("field-2 is null.", field2);
+ assertEquals("field-2 property is wrong", "field-2", field2.getProperty());
+
+ // Get var-2-1
+ Var var21 = field2.getVar("var-2-1");
+ assertNotNull("var-2-1 is null.", var21);
+ assertEquals("var-2-1 name is wrong", "var-2-1", var21.getName());
+ assertEquals("var-2-1 value is wrong", "value-2-1", var21.getValue());
+ assertEquals("var-2-1 jstype is wrong", "jstype-2-1", var21.getJsType());
+ assertTrue("var-2-1 resource is false", var21.isResource());
+ assertEquals("var-2-1 bundle is wrong", "bundle-2-1", var21.getBundle());
+
+ // Get var-2-2
+ Var var22 = field2.getVar("var-2-2");
+ assertNotNull("var-2-2 is null.", var22);
+ assertEquals("var-2-2 name is wrong", "var-2-2", var22.getName());
+ assertEquals("var-2-2 value is wrong", "value-2-2", var22.getValue());
+ assertNull("var-2-2 jstype is not null", var22.getJsType());
+ assertFalse("var-2-2 resource is true", var22.isResource());
+ assertEquals("var-2-2 bundle is wrong", "bundle-2-2", var22.getBundle());
+
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/custom/CustomValidatorResources.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/custom/CustomValidatorResources.java
new file mode 100644
index 000000000..fdd673af5
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/custom/CustomValidatorResources.java
@@ -0,0 +1,44 @@
+/*
+ * 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.custom;
+
+import java.io.InputStream;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+import org.apache.commons.validator.ValidatorResources;
+
+/**
+ * Custom ValidatorResources implementation.
+ *
+ * @version $Revision$
+ */
+public class CustomValidatorResources extends ValidatorResources {
+
+ private static final long serialVersionUID = 1272843199141974642L;
+
+ /**
+ * Create a custom ValidatorResources object from an uri
+ *
+ * @param in InputStream for the validation.xml configuration file.
+ * @throws SAXException if the validation XML files are not valid or well formed.
+ * @throws IOException if an I/O error occurs processing the XML files
+ */
+ public CustomValidatorResources(InputStream in) throws IOException, SAXException {
+ super(in);
+ }
+
+}
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractCalendarValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractCalendarValidatorTest.java
new file mode 100644
index 000000000..067100216
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractCalendarValidatorTest.java
@@ -0,0 +1,261 @@
+/*
+ * 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.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Base Calendar Test Case.
+ *
+ * @version $Revision$
+ */
+public abstract class AbstractCalendarValidatorTest extends TestCase {
+
+ protected AbstractCalendarValidator validator;
+
+ protected static final TimeZone GMT = TimeZone.getTimeZone("GMT"); // 0 offset
+ protected static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours
+ protected static final TimeZone EET = TimeZone.getTimeZone("EET"); // + 2 hours
+ protected static final TimeZone UTC = TimeZone.getTimeZone("UTC"); // + 2 hours
+
+ protected String[] patternValid = new String[] {
+ "2005-01-01"
+ ,"2005-12-31"
+ ,"2004-02-29" // valid leap
+ ,"2005-04-30"
+ ,"05-12-31"
+ ,"2005-1-1"
+ ,"05-1-1"};
+ protected String[] localeValid = new String[] {
+ "01/01/2005"
+ ,"12/31/2005"
+ ,"02/29/2004" // valid leap
+ ,"04/30/2005"
+ ,"12/31/05"
+ ,"1/1/2005"
+ ,"1/1/05"};
+ protected Date[] patternExpect = new Date[] {
+ createDate(null, 20050101, 0)
+ ,createDate(null, 20051231, 0)
+ ,createDate(null, 20040229, 0)
+ ,createDate(null, 20050430, 0)
+ ,createDate(null, 20051231, 0)
+ ,createDate(null, 20050101, 0)
+ ,createDate(null, 20050101, 0)};
+ protected String[] patternInvalid = new String[] {
+ "2005-00-01" // zero month
+ ,"2005-01-00" // zero day
+ ,"2005-13-03" // month invalid
+ ,"2005-04-31" // invalid day
+ ,"2005-03-32" // invalid day
+ ,"2005-02-29" // invalid leap
+ ,"200X-01-01" // invalid char
+ ,"2005-0X-01" // invalid char
+ ,"2005-01-0X" // invalid char
+ ,"01/01/2005" // invalid pattern
+ ,"2005-01" // invalid pattern
+ ,"2005--01" // invalid pattern
+ ,"2005-01-"}; // invalid pattern
+ protected String[] localeInvalid = new String[] {
+ "01/00/2005" // zero month
+ ,"00/01/2005" // zero day
+ ,"13/01/2005" // month invalid
+ ,"04/31/2005" // invalid day
+ ,"03/32/2005" // invalid day
+ ,"02/29/2005" // invalid leap
+ ,"01/01/200X" // invalid char
+ ,"01/0X/2005" // invalid char
+ ,"0X/01/2005" // invalid char
+ ,"01-01-2005" // invalid pattern
+ ,"01/2005" // invalid pattern
+ // -------- ,"/01/2005" ---- passes on some JDK
+ ,"01//2005"}; // invalid pattern
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public AbstractCalendarValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set Up.
+ * @throws Exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Tear down
+ * @throws Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ validator = null;
+ }
+
+ /**
+ * Test Valid Dates with "pattern" validation
+ */
+ public void testPatternValid() {
+ for (int i = 0; i < patternValid.length; i++) {
+ String text = i + " value=[" +patternValid[i]+"] failed ";
+ Object date = validator.parse(patternValid[i], "yy-MM-dd", null, null);
+ assertNotNull("validateObj() " + text + date, date);
+ assertTrue("isValid() " + text, validator.isValid(patternValid[i], "yy-MM-dd"));
+ if (date instanceof Calendar) {
+ date = ((Calendar)date).getTime();
+ }
+ assertEquals("compare " + text, patternExpect[i], date);
+ }
+ }
+
+ /**
+ * Test Invalid Dates with "pattern" validation
+ */
+ public void testPatternInvalid() {
+ for (int i = 0; i < patternInvalid.length; i++) {
+ String text = i + " value=[" +patternInvalid[i]+"] passed ";
+ Object date = validator.parse(patternInvalid[i], "yy-MM-dd", null, null);
+ assertNull("validateObj() " + text + date, date);
+ assertFalse("isValid() " + text, validator.isValid(patternInvalid[i], "yy-MM-dd"));
+ }
+ }
+
+ /**
+ * Test Valid Dates with "locale" validation
+ */
+ public void testLocaleValid() {
+ for (int i = 0; i < localeValid.length; i++) {
+ String text = i + " value=[" +localeValid[i]+"] failed ";
+ Object date = validator.parse(localeValid[i], null, Locale.US, null);
+ assertNotNull("validateObj() " + text + date, date);
+ assertTrue("isValid() " + text, validator.isValid(localeValid[i], Locale.US));
+ if (date instanceof Calendar) {
+ date = ((Calendar)date).getTime();
+ }
+ assertEquals("compare " + text, patternExpect[i], date);
+ }
+ }
+
+ /**
+ * Test Invalid Dates with "locale" validation
+ */
+ public void testLocaleInvalid() {
+ for (int i = 0; i < localeInvalid.length; i++) {
+ String text = i + " value=[" +localeInvalid[i]+"] passed ";
+ Object date = validator.parse(localeInvalid[i], null, Locale.US, null);
+ assertNull("validateObj() " + text + date, date);
+ assertFalse("isValid() " + text, validator.isValid(localeInvalid[i], Locale.US));
+ }
+ }
+
+ /**
+ * Test Invalid Dates with "locale" validation
+ */
+ public void testFormat() {
+
+ // Create a Date or Calendar
+ Object test = validator.parse("2005-11-28", "yyyy-MM-dd", null, null);
+ assertNotNull("Test Date ", test);
+ assertEquals("Format pattern", "28.11.05", validator.format(test, "dd.MM.yy"));
+ assertEquals("Format locale", "11/28/05", validator.format(test, Locale.US));
+ }
+
+ /**
+ * Test validator serialization.
+ */
+ public void testSerialization() {
+ // Serialize the check digit routine
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(validator);
+ oos.flush();
+ oos.close();
+ } catch (Exception e) {
+ fail(validator.getClass().getName() + " error during serialization: " + e);
+ }
+
+ // Deserialize the test object
+ Object result = null;
+ try {
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ result = ois.readObject();
+ bais.close();
+ } catch (Exception e) {
+ fail(validator.getClass().getName() + " error during deserialization: " + e);
+ }
+ assertNotNull(result);
+ }
+
+ /**
+ * Create a calendar instance for a specified time zone, date and time.
+ *
+ * @param zone The time zone
+ * @param date The date in yyyyMMdd format
+ * @param time the time in HH:mm:ss format
+ * @return the new Calendar instance.
+ */
+ protected static Calendar createCalendar(TimeZone zone, int date, int time) {
+ Calendar calendar = zone == null ? Calendar.getInstance()
+ : Calendar.getInstance(zone);
+ int year = ((date / 10000) * 10000);
+ int mth = ((date / 100) * 100) - year;
+ int day = date - (year + mth);
+ int hour = ((time / 10000) * 10000);
+ int min = ((time / 100) * 100) - hour;
+ int sec = time - (hour + min);
+ calendar.set(Calendar.YEAR, (year / 10000));
+ calendar.set(Calendar.MONTH, ((mth / 100) - 1));
+ calendar.set(Calendar.DATE, day);
+ calendar.set(Calendar.HOUR_OF_DAY, (hour / 10000));
+ calendar.set(Calendar.MINUTE, (min / 100));
+ calendar.set(Calendar.SECOND, sec);
+ calendar.set(Calendar.MILLISECOND, 0);
+ return calendar;
+ }
+
+ /**
+ * Create a date instance for a specified time zone, date and time.
+ *
+ * @param zone The time zone
+ * @param date The date in yyyyMMdd format
+ * @param time the time in HH:mm:ss format
+ * @return the new Date instance.
+ */
+ protected static Date createDate(TimeZone zone, int date, int time) {
+ Calendar calendar = createCalendar(zone, date, time);
+ return calendar.getTime();
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java
new file mode 100644
index 000000000..1d88bcc67
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/AbstractNumberValidatorTest.java
@@ -0,0 +1,246 @@
+/*
+ * 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.TestCase;
+
+import java.util.Locale;
+import java.text.DecimalFormat;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.math.BigDecimal;
+/**
+ * Base Number Test Case.
+ *
+ * @version $Revision$
+ */
+public abstract class AbstractNumberValidatorTest extends TestCase {
+
+ protected AbstractNumberValidator validator;
+ protected AbstractNumberValidator strictValidator;
+
+ protected Number max;
+ protected Number maxPlusOne;
+ protected Number min;
+ protected Number minMinusOne;
+ protected String[] invalid;
+ protected String[] valid;
+ protected Number[] validCompare;
+
+ protected String[] invalidStrict;
+ protected String[] validStrict;
+ protected Number[] validStrictCompare;
+
+ protected String testPattern;
+ protected Number testNumber;
+ protected Number testZero;
+ protected String testStringUS;
+ protected String testStringDE;
+
+ protected String localeValue;
+ protected String localePattern;
+ protected Locale testLocale;
+ protected Number localeExpected;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public AbstractNumberValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Locale.setDefault(Locale.US);
+
+ }
+
+ /**
+ * Tear down
+ * @throws Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ validator = null;
+ strictValidator = null;
+ }
+
+ /**
+ * Test Format Type
+ */
+ public void testFormatType() {
+ assertEquals("Format Type A", 0, validator.getFormatType());
+ assertEquals("Format Type B", AbstractNumberValidator.STANDARD_FORMAT, validator.getFormatType());
+ }
+
+ /**
+ * Test Min/Max values allowed
+ */
+ public void testValidateMinMax() {
+ DecimalFormat fmt = new DecimalFormat("#");
+ if (max != null) {
+ assertEquals("Test Max", max, validator.parse(fmt.format(max), "#", null));
+ assertNull("Test Max + 1", validator.parse(fmt.format(maxPlusOne), "#", null));
+ assertEquals("Test Min", min, validator.parse(fmt.format(min), "#", null));
+ assertNull("Test min - 1", validator.parse(fmt.format(minMinusOne), "#", null));
+ }
+ }
+
+ /**
+ * Test Invalid, strict=true
+ */
+ public void testInvalidStrict() {
+ for (int i = 0; i < invalidStrict.length; i++) {
+ String text = "idx=["+i+"] value=[" + invalidStrict[i] + "]";
+ assertNull("(A) " + text, strictValidator.parse(invalidStrict[i], null, Locale.US));
+ assertFalse("(B) " + text, strictValidator.isValid(invalidStrict[i], null, Locale.US));
+ assertNull("(C) " + text, strictValidator.parse(invalidStrict[i], testPattern, null));
+ assertFalse("(D) " + text, strictValidator.isValid(invalidStrict[i], testPattern, null));
+ }
+ }
+
+ /**
+ * Test Invalid, strict=false
+ */
+ public void testInvalidNotStrict() {
+ for (int i = 0; i < invalid.length; i++) {
+ String text = "idx=["+i+"] value=[" + invalid[i] + "]";
+ assertNull("(A) " + text, validator.parse(invalid[i], null, Locale.US));
+ assertFalse("(B) " + text, validator.isValid(invalid[i], null, Locale.US));
+ assertNull("(C) " + text, validator.parse(invalid[i], testPattern, null));
+ assertFalse("(D) " + text, validator.isValid(invalid[i], testPattern, null));
+ }
+ }
+
+ /**
+ * Test Valid, strict=true
+ */
+ public void testValidStrict() {
+ for (int i = 0; i < validStrict.length; i++) {
+ String text = "idx=["+i+"] value=[" + validStrictCompare[i] + "]";
+ assertEquals("(A) " + text, validStrictCompare[i], strictValidator.parse(validStrict[i], null, Locale.US));
+ assertTrue("(B) " + text, strictValidator.isValid(validStrict[i], null, Locale.US));
+ assertEquals("(C) " + text, validStrictCompare[i], strictValidator.parse(validStrict[i], testPattern, null));
+ assertTrue("(D) " + text, strictValidator.isValid(validStrict[i], testPattern, null));
+ }
+ }
+
+ /**
+ * Test Valid, strict=false
+ */
+ public void testValidNotStrict() {
+ for (int i = 0; i < valid.length; i++) {
+ String text = "idx=["+i+"] value=[" + validCompare[i] + "]";
+ assertEquals("(A) " + text, validCompare[i], validator.parse(valid[i], null, Locale.US));
+ assertTrue("(B) " + text, validator.isValid(valid[i], null, Locale.US));
+ assertEquals("(C) " + text, validCompare[i], validator.parse(valid[i], testPattern, null));
+ assertTrue("(D) " + text, validator.isValid(valid[i], testPattern, null));
+ }
+ }
+
+ /**
+ * Test different Locale
+ */
+ public void testValidateLocale() {
+
+ assertEquals("US Locale, US Format", testNumber, strictValidator.parse(testStringUS, null, Locale.US));
+ assertNull("US Locale, DE Format", strictValidator.parse(testStringDE, null, Locale.US));
+
+ // Default German Locale
+ assertEquals("DE Locale, DE Format", testNumber, strictValidator.parse(testStringDE, null, Locale.GERMAN));
+ assertNull("DE Locale, US Format", strictValidator.parse(testStringUS, null, Locale.GERMAN));
+
+ // Default Locale has been set to Locale.US in setup()
+ assertEquals("Default Locale, US Format", testNumber, strictValidator.parse(testStringUS, null, null));
+ assertNull("Default Locale, DE Format", strictValidator.parse(testStringDE, null, null));
+ }
+
+ /**
+ * Test format() methods
+ */
+ public void testFormat() {
+ Number number = new BigDecimal("1234.5");
+ assertEquals("US Locale, US Format", "1,234.5", strictValidator.format(number, Locale.US));
+ assertEquals("DE Locale, DE Format", "1.234,5", strictValidator.format(number, Locale.GERMAN));
+ assertEquals("Pattern #,#0.00", "12,34.50", strictValidator.format(number, "#,#0.00"));
+ }
+
+ /**
+ * Test Range/Min/Max
+ */
+ public void testRangeMinMax() {
+ Number number9 = Integer.valueOf(9);
+ Number number10 = Integer.valueOf(10);
+ Number number11 = Integer.valueOf(11);
+ Number number19 = Integer.valueOf(19);
+ Number number20 = Integer.valueOf(20);
+ Number number21 = Integer.valueOf(21);
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", strictValidator.isInRange(number9 , number10, number20));
+ assertTrue("isInRange() = min", strictValidator.isInRange(number10 , number10, number20));
+ assertTrue("isInRange() in range", strictValidator.isInRange(number11 , number10, number20));
+ assertTrue("isInRange() = max", strictValidator.isInRange(number20 , number10, number20));
+ assertFalse("isInRange() > max", strictValidator.isInRange(number21 , number10, number20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", strictValidator.minValue(number9 , number10));
+ assertTrue("minValue() = min", strictValidator.minValue(number10 , number10));
+ assertTrue("minValue() > min", strictValidator.minValue(number11 , number10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", strictValidator.maxValue(number19 , number20));
+ assertTrue("maxValue() = max", strictValidator.maxValue(number20 , number20));
+ assertFalse("maxValue() > max", strictValidator.maxValue(number21 , number20));
+ }
+
+ /**
+ * Test validator serialization.
+ */
+ public void testSerialization() {
+ // Serialize the check digit routine
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(validator);
+ oos.flush();
+ oos.close();
+ } catch (Exception e) {
+ fail(validator.getClass().getName() + " error during serialization: " + e);
+ }
+
+ // Deserialize the test object
+ Object result = null;
+ try {
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ result = ois.readObject();
+ bais.close();
+ } catch (Exception e) {
+ fail(validator.getClass().getName() + " error during deserialization: " + e);
+ }
+ assertNotNull(result);
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigDecimalValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
new file mode 100644
index 000000000..5a0244662
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigDecimalValidatorTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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 java.math.BigDecimal;
+import java.util.Locale;
+
+/**
+ * Test Case for BigDecimalValidator.
+ *
+ * @version $Revision$
+ */
+public class BigDecimalValidatorTest extends AbstractNumberValidatorTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public BigDecimalValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new BigDecimalValidator(false);
+ strictValidator = new BigDecimalValidator();
+
+ testPattern = "#,###.###";
+
+ // testValidateMinMax()
+ max = null;
+ maxPlusOne = null;
+ min = null;
+ minMinusOne = null;
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.234X"};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12"};
+
+ // testValid()
+ testNumber = new BigDecimal("1234.5");
+ Number testNumber2 = new BigDecimal(".1");
+ Number testNumber3 = new BigDecimal("12345.67899");
+ testZero = new BigDecimal("0");
+ validStrict = new String[] {"0", "1234.5", "1,234.5", ".1", "12345.678990"};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber, testNumber2, testNumber3};
+ valid = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+ testStringUS = "1,234.5";
+ testStringDE = "1.234,5";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###,#";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test BigDecimalValidator validate Methods
+ */
+ public void testBigDecimalValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ BigDecimal expected = new BigDecimal(12345);
+ assertEquals("validate(A) default", expected, BigDecimalValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, BigDecimalValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, BigDecimalValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, BigDecimalValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", BigDecimalValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", BigDecimalValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", BigDecimalValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", BigDecimalValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", BigDecimalValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", BigDecimalValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", BigDecimalValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", BigDecimalValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", BigDecimalValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", BigDecimalValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", BigDecimalValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", BigDecimalValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test BigDecimal Range/Min/Max
+ */
+ public void testBigDecimalRangeMinMax() {
+ BigDecimalValidator validator = new BigDecimalValidator(true, AbstractNumberValidator.STANDARD_FORMAT, true);
+ BigDecimal number9 = new BigDecimal("9");
+ BigDecimal number10 = new BigDecimal("10");
+ BigDecimal number11 = new BigDecimal("11");
+ BigDecimal number19 = new BigDecimal("19");
+ BigDecimal number20 = new BigDecimal("20");
+ BigDecimal number21 = new BigDecimal("21");
+
+ float min = 10;
+ float max = 20;
+
+ // Test isInRange()
+ assertFalse("isInRange(A) < min", validator.isInRange(number9, min, max));
+ assertTrue("isInRange(A) = min", validator.isInRange(number10, min, max));
+ assertTrue("isInRange(A) in range", validator.isInRange(number11, min, max));
+ assertTrue("isInRange(A) = max", validator.isInRange(number20, min, max));
+ assertFalse("isInRange(A) > max", validator.isInRange(number21, min, max));
+
+ // Test minValue()
+ assertFalse("minValue(A) < min", validator.minValue(number9, min));
+ assertTrue("minValue(A) = min", validator.minValue(number10, min));
+ assertTrue("minValue(A) > min", validator.minValue(number11, min));
+
+ // Test minValue()
+ assertTrue("maxValue(A) < max", validator.maxValue(number19, max));
+ assertTrue("maxValue(A) = max", validator.maxValue(number20, max));
+ assertFalse("maxValue(A) > max", validator.maxValue(number21, max));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
new file mode 100644
index 000000000..2a74223b6
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/BigIntegerValidatorTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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 java.math.BigInteger;
+import java.util.Locale;
+
+/**
+ * Test Case for BigIntegerValidator.
+ *
+ * @version $Revision$
+ */
+public class BigIntegerValidatorTest extends AbstractNumberValidatorTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public BigIntegerValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new BigIntegerValidator(false, 0);
+ strictValidator = new BigIntegerValidator();
+
+ testPattern = "#,###";
+
+ // testValidateMinMax()
+ max = null;
+ maxPlusOne = null;
+ min = null;
+ minMinusOne = null;
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2"};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12"};
+
+ // testValid()
+ testNumber = new BigInteger("1234");
+ testZero = new BigInteger("0");
+ validStrict = new String[] {"0", "1234", "1,234"};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber};
+ valid = new String[] {"0", "1234", "1,234", "1,234.5", "1234X"};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+ testStringUS = "1,234";
+ testStringDE = "1.234";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test BigIntegerValidator validate Methods
+ */
+ public void testBigIntegerValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ BigInteger expected = new BigInteger("12345");
+ assertEquals("validate(A) default", expected, BigIntegerValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, BigIntegerValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, BigIntegerValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, BigIntegerValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", BigIntegerValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", BigIntegerValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", BigIntegerValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", BigIntegerValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", BigIntegerValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", BigIntegerValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", BigIntegerValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", BigIntegerValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", BigIntegerValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", BigIntegerValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", BigIntegerValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", BigIntegerValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test BigInteger Range/Min/Max
+ */
+ public void testBigIntegerRangeMinMax() {
+ BigIntegerValidator validator = (BigIntegerValidator)strictValidator;
+ BigInteger number9 = validator.validate("9", "#");
+ BigInteger number10 = validator.validate("10", "#");
+ BigInteger number11 = validator.validate("11", "#");
+ BigInteger number19 = validator.validate("19", "#");
+ BigInteger number20 = validator.validate("20", "#");
+ BigInteger number21 = validator.validate("21", "#");
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
+ assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
+ assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+ assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
+ assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, 10));
+ assertTrue("minValue() = min", validator.minValue(number10, 10));
+ assertTrue("minValue() > min", validator.minValue(number11, 10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, 20));
+ assertTrue("maxValue() = max", validator.maxValue(number20, 20));
+ assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java
new file mode 100644
index 000000000..98c2ed080
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * Test Case for ByteValidator.
+ *
+ * @version $Revision$
+ */
+public class ByteValidatorTest extends AbstractNumberValidatorTest {
+
+ private static final Byte BYTE_MIN_VAL = Byte.valueOf(Byte.MIN_VALUE);
+ private static final Byte BYTE_MAX_VAL = Byte.valueOf(Byte.MAX_VALUE);
+ private static final String BYTE_MAX = "127";
+ private static final String BYTE_MAX_0 = "127.99999999999999999999999"; // force double rounding
+ private static final String BYTE_MAX_1 = "128";
+ private static final String BYTE_MIN = "-128";
+ private static final String BYTE_MIN_0 = "-128.99999999999999999999999"; // force double rounding";
+ private static final String BYTE_MIN_1 = "-129";
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ByteValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new ByteValidator(false, 0);
+ strictValidator = new ByteValidator();
+
+ testPattern = "#,###";
+
+ // testValidateMinMax()
+ max = Byte.valueOf(Byte.MAX_VALUE);
+ maxPlusOne = Long.valueOf(max.longValue() + 1);
+ min = Byte.valueOf(Byte.MIN_VALUE);
+ minMinusOne = Long.valueOf(min.longValue() - 1);
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2", BYTE_MAX_1, BYTE_MIN_1, BYTE_MAX_0, BYTE_MIN_0};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12", BYTE_MAX_1, BYTE_MIN_1};
+
+ // testValid()
+ testNumber = Byte.valueOf((byte)123);
+ testZero = Byte.valueOf((byte)0);
+ validStrict = new String[] {"0", "123", ",123", BYTE_MAX, BYTE_MIN};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber, BYTE_MAX_VAL, BYTE_MIN_VAL};
+ valid = new String[] {"0", "123", ",123", ",123.5", "123X", BYTE_MAX, BYTE_MIN, BYTE_MAX_0, BYTE_MIN_0};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber, BYTE_MAX_VAL, BYTE_MIN_VAL, BYTE_MAX_VAL, BYTE_MIN_VAL};
+
+ testStringUS = ",123";
+ testStringDE = ".123";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test ByteValidator validate Methods
+ */
+ public void testByteValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00";
+ String patternVal = "1,23";
+ String germanPatternVal = "1.23";
+ String localeVal = ".123";
+ String defaultVal = ",123";
+ String XXXX = "XXXX";
+ Byte expected = Byte.valueOf((byte)123);
+ assertEquals("validate(A) default", expected, ByteValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, ByteValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, ByteValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, ByteValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", ByteValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", ByteValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", ByteValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", ByteValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", ByteValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", ByteValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", ByteValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", ByteValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", ByteValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", ByteValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", ByteValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", ByteValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Byte Range/Min/Max
+ */
+ public void testByteRangeMinMax() {
+ ByteValidator validator = (ByteValidator)strictValidator;
+ Byte number9 = validator.validate("9", "#");
+ Byte number10 = validator.validate("10", "#");
+ Byte number11 = validator.validate("11", "#");
+ Byte number19 = validator.validate("19", "#");
+ Byte number20 = validator.validate("20", "#");
+ Byte number21 = validator.validate("21", "#");
+ byte min = (byte)10;
+ byte max = (byte)20;
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, min, max));
+ assertTrue("isInRange() = min", validator.isInRange(number10, min, max));
+ assertTrue("isInRange() in range", validator.isInRange(number11, min, max));
+ assertTrue("isInRange() = max", validator.isInRange(number20, min, max));
+ assertFalse("isInRange() > max", validator.isInRange(number21, min, max));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, min));
+ assertTrue("minValue() = min", validator.minValue(number10, min));
+ assertTrue("minValue() > min", validator.minValue(number11, min));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, max));
+ assertTrue("maxValue() = max", validator.maxValue(number20, max));
+ assertFalse("maxValue() > max", validator.maxValue(number21, max));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CalendarValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CalendarValidatorTest.java
new file mode 100644
index 000000000..5e4b2be5d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CalendarValidatorTest.java
@@ -0,0 +1,279 @@
+/*
+ * 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 java.text.Format;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Test Case for CalendarValidator.
+ *
+ * @version $Revision$
+ */
+public class CalendarValidatorTest extends AbstractCalendarValidatorTest {
+
+ private static final int DATE_2005_11_23 = 20051123;
+ private static final int TIME_12_03_45 = 120345;
+
+ private CalendarValidator calValidator;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public CalendarValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ calValidator = new CalendarValidator();
+ validator = calValidator;
+ }
+
+ /**
+ * Test CalendarValidator validate Methods
+ */
+ public void testCalendarValidatorMethods() {
+ Locale.setDefault(Locale.US);
+ Locale locale = Locale.GERMAN;
+ String pattern = "yyyy-MM-dd";
+ String patternVal = "2005-12-31";
+ String germanVal = "31 Dez 2005";
+ String germanPattern = "dd MMM yyyy";
+ String localeVal = "31.12.2005";
+ String defaultVal = "12/31/05";
+ String XXXX = "XXXX";
+ Date expected = createCalendar(null, 20051231, 0).getTime();
+ assertEquals("validate(A) default", expected, CalendarValidator.getInstance().validate(defaultVal).getTime());
+ assertEquals("validate(A) locale ", expected, CalendarValidator.getInstance().validate(localeVal, locale).getTime());
+ assertEquals("validate(A) pattern", expected, CalendarValidator.getInstance().validate(patternVal, pattern).getTime());
+ assertEquals("validate(A) both", expected, CalendarValidator.getInstance().validate(germanVal, germanPattern, Locale.GERMAN).getTime());
+
+ assertTrue("isValid(A) default", CalendarValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", CalendarValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", CalendarValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", CalendarValidator.getInstance().isValid(germanVal, germanPattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", CalendarValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", CalendarValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", CalendarValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", CalendarValidator.getInstance().validate("31 Dec 2005", germanPattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", CalendarValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", CalendarValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", CalendarValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", CalendarValidator.getInstance().isValid("31 Dec 2005", germanPattern, Locale.GERMAN));
+
+ // Test Time Zone
+ TimeZone zone = (TimeZone.getDefault().getRawOffset() == EET.getRawOffset() ? EST : EET);
+ Date expectedZone = createCalendar(zone, 20051231, 0).getTime();
+ assertFalse("default/EET same ", expected.getTime() == expectedZone.getTime());
+
+ assertEquals("validate(C) default", expectedZone, CalendarValidator.getInstance().validate(defaultVal, zone).getTime());
+ assertEquals("validate(C) locale ", expectedZone, CalendarValidator.getInstance().validate(localeVal, locale, zone).getTime());
+ assertEquals("validate(C) pattern", expectedZone, CalendarValidator.getInstance().validate(patternVal, pattern, zone).getTime());
+ assertEquals("validate(C) both", expectedZone, CalendarValidator.getInstance().validate(germanVal, germanPattern, Locale.GERMAN, zone).getTime());
+ }
+
+ /**
+ * Test compare date methods
+ */
+ public void testCompare() {
+ int sameTime = 124522;
+ int testDate = 20050823;
+ Calendar diffHour = createCalendar(GMT, testDate, 115922); // same date, different time
+ Calendar diffMin = createCalendar(GMT, testDate, 124422); // same date, different time
+ Calendar diffSec = createCalendar(GMT, testDate, 124521); // same date, different time
+
+ Calendar value = createCalendar(GMT, testDate, sameTime); // test value
+ Calendar cal20050824 = createCalendar(GMT, 20050824, sameTime); // +1 day
+ Calendar cal20050822 = createCalendar(GMT, 20050822, sameTime); // -1 day
+
+ Calendar cal20050830 = createCalendar(GMT, 20050830, sameTime); // +1 week
+ Calendar cal20050816 = createCalendar(GMT, 20050816, sameTime); // -1 week
+
+ Calendar cal20050901 = createCalendar(GMT, 20050901, sameTime); // +1 month
+ Calendar cal20050801 = createCalendar(GMT, 20050801, sameTime); // same month
+ Calendar cal20050731 = createCalendar(GMT, 20050731, sameTime); // -1 month
+
+ Calendar cal20051101 = createCalendar(GMT, 20051101, sameTime); // +1 quarter (Feb Start)
+ Calendar cal20051001 = createCalendar(GMT, 20051001, sameTime); // +1 quarter
+ Calendar cal20050701 = createCalendar(GMT, 20050701, sameTime); // same quarter
+ Calendar cal20050630 = createCalendar(GMT, 20050630, sameTime); // -1 quarter
+
+ Calendar cal20060101 = createCalendar(GMT, 20060101, sameTime); // +1 year
+ Calendar cal20050101 = createCalendar(GMT, 20050101, sameTime); // same year
+ Calendar cal20041231 = createCalendar(GMT, 20041231, sameTime); // -1 year
+
+ assertEquals("hour GT", 1, calValidator.compare(value, diffHour, Calendar.HOUR_OF_DAY));
+ assertEquals("hour EQ", 0, calValidator.compare(value, diffMin, Calendar.HOUR_OF_DAY));
+ assertEquals("mins GT", 1, calValidator.compare(value, diffMin, Calendar.MINUTE));
+ assertEquals("mins EQ", 0, calValidator.compare(value, diffSec, Calendar.MINUTE));
+ assertEquals("secs GT", 1, calValidator.compare(value, diffSec, Calendar.SECOND));
+
+ assertEquals("date LT", -1, calValidator.compareDates(value, cal20050824)); // +1 day
+ assertEquals("date EQ", 0, calValidator.compareDates(value, diffHour)); // same day, diff hour
+ assertEquals("date(B)", 0, calValidator.compare(value, diffHour, Calendar.DAY_OF_YEAR)); // same day, diff hour
+ assertEquals("date GT", 1, calValidator.compareDates(value, cal20050822)); // -1 day
+
+ assertEquals("week LT", -1, calValidator.compareWeeks(value, cal20050830)); // +1 week
+ assertEquals("week =1", 0, calValidator.compareWeeks(value, cal20050824)); // +1 day
+ assertEquals("week =2", 0, calValidator.compareWeeks(value, cal20050822)); // same week
+ assertEquals("week =3", 0, calValidator.compare(value, cal20050822, Calendar.WEEK_OF_MONTH)); // same week
+ assertEquals("week =4", 0, calValidator.compareWeeks(value, cal20050822)); // -1 day
+ assertEquals("week GT", 1, calValidator.compareWeeks(value, cal20050816)); // -1 week
+
+ assertEquals("mnth LT", -1, calValidator.compareMonths(value, cal20050901)); // +1 month
+ assertEquals("mnth =1", 0, calValidator.compareMonths(value, cal20050830)); // +1 week
+ assertEquals("mnth =2", 0, calValidator.compareMonths(value, cal20050801)); // same month
+ assertEquals("mnth =3", 0, calValidator.compareMonths(value, cal20050816)); // -1 week
+ assertEquals("mnth GT", 1, calValidator.compareMonths(value, cal20050731)); // -1 month
+
+ assertEquals("qtrA <1", -1, calValidator.compareQuarters(value, cal20051101)); // +1 quarter (Feb)
+ assertEquals("qtrA <2", -1, calValidator.compareQuarters(value, cal20051001)); // +1 quarter
+ assertEquals("qtrA =1", 0, calValidator.compareQuarters(value, cal20050901)); // +1 month
+ assertEquals("qtrA =2", 0, calValidator.compareQuarters(value, cal20050701)); // same quarter
+ assertEquals("qtrA =3", 0, calValidator.compareQuarters(value, cal20050731)); // -1 month
+ assertEquals("qtrA GT", 1, calValidator.compareQuarters(value, cal20050630)); // -1 quarter
+
+ // Change quarter 1 to start in Feb
+ assertEquals("qtrB LT", -1, calValidator.compareQuarters(value, cal20051101, 2)); // +1 quarter (Feb)
+ assertEquals("qtrB =1", 0, calValidator.compareQuarters(value, cal20051001, 2)); // same quarter
+ assertEquals("qtrB =2", 0, calValidator.compareQuarters(value, cal20050901, 2)); // +1 month
+ assertEquals("qtrB =3", 1, calValidator.compareQuarters(value, cal20050701, 2)); // same quarter
+ assertEquals("qtrB =4", 1, calValidator.compareQuarters(value, cal20050731, 2)); // -1 month
+ assertEquals("qtrB GT", 1, calValidator.compareQuarters(value, cal20050630, 2)); // -1 quarter
+
+ assertEquals("year LT", -1, calValidator.compareYears(value, cal20060101)); // +1 year
+ assertEquals("year EQ", 0, calValidator.compareYears(value, cal20050101)); // same year
+ assertEquals("year GT", 1, calValidator.compareYears(value, cal20041231)); // -1 year
+
+ // invalid compare
+ try {
+ calValidator.compare(value, value, -1);
+ fail("Invalid Compare field - expected IllegalArgumentException to be thrown");
+ } catch (IllegalArgumentException e) {
+ assertEquals("check message", "Invalid field: -1", e.getMessage());
+ }
+ }
+
+ /**
+ * Test Date/Time style Validator (there isn't an implementation for this)
+ */
+ public void testDateTimeStyle() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ AbstractCalendarValidator dateTimeValidator =
+ new AbstractCalendarValidator(true, DateFormat.SHORT, DateFormat.SHORT) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected Object processParsedValue(Object value, Format formatter) {
+ return value;
+ }
+ };
+ assertTrue("validate(A) default", dateTimeValidator.isValid("31/12/05 14:23"));
+ assertTrue("validate(A) locale ", dateTimeValidator.isValid("12/31/05 2:23 PM", Locale.US));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+
+ /**
+ * Test format methods
+ */
+ @Override
+ public void testFormat() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ Calendar cal20050101 = createCalendar(GMT, 20051231, 11500);
+ assertNull("null", calValidator.format(null));
+ assertEquals("default", "31/12/05", calValidator.format(cal20050101));
+ assertEquals("locale", "12/31/05", calValidator.format(cal20050101, Locale.US));
+ assertEquals("patternA", "2005-12-31 01:15", calValidator.format(cal20050101, "yyyy-MM-dd HH:mm"));
+ assertEquals("patternB", "2005-12-31 GMT", calValidator.format(cal20050101, "yyyy-MM-dd z"));
+ assertEquals("both", "31 Dez 2005", calValidator.format(cal20050101, "dd MMM yyyy", Locale.GERMAN));
+
+ // EST Time Zone
+ assertEquals("EST default", "30/12/05", calValidator.format(cal20050101, EST));
+ assertEquals("EST locale", "12/30/05", calValidator.format(cal20050101, Locale.US, EST));
+ assertEquals("EST patternA", "2005-12-30 20:15", calValidator.format(cal20050101, "yyyy-MM-dd HH:mm", EST));
+ assertEquals("EST patternB", "2005-12-30 EST", calValidator.format(cal20050101, "yyyy-MM-dd z", EST));
+ assertEquals("EST both", "30 Dez 2005", calValidator.format(cal20050101, "dd MMM yyyy", Locale.GERMAN, EST));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+
+ /**
+ * Test adjustToTimeZone() method
+ */
+ public void testAdjustToTimeZone() {
+
+ Calendar calEST = createCalendar(EST, DATE_2005_11_23, TIME_12_03_45);
+ Date dateEST = calEST.getTime();
+
+ Calendar calGMT = createCalendar(GMT, DATE_2005_11_23, TIME_12_03_45);
+ Date dateGMT = calGMT.getTime();
+
+ Calendar calCET = createCalendar(EET, DATE_2005_11_23, TIME_12_03_45);
+ Date dateCET = calCET.getTime();
+
+ // Check the dates don't match
+ assertFalse("Check GMT != CET", dateGMT.getTime() == dateCET.getTime());
+ assertFalse("Check GMT != EST", dateGMT.getTime() == dateEST.getTime());
+ assertFalse("Check CET != EST", dateCET.getTime() == dateEST.getTime());
+
+ // EST to GMT and back
+ CalendarValidator.adjustToTimeZone(calEST, GMT);
+ assertEquals("EST to GMT", dateGMT, calEST.getTime());
+ assertFalse("Check EST = GMT", dateEST == calEST.getTime());
+ CalendarValidator.adjustToTimeZone(calEST, EST);
+ assertEquals("back to EST", dateEST, calEST.getTime());
+ assertFalse("Check EST != GMT", dateGMT == calEST.getTime());
+
+ // CET to GMT and back
+ CalendarValidator.adjustToTimeZone(calCET, GMT);
+ assertEquals("CET to GMT", dateGMT, calCET.getTime());
+ assertFalse("Check CET = GMT", dateCET == calCET.getTime());
+ CalendarValidator.adjustToTimeZone(calCET, EET);
+ assertEquals("back to CET", dateCET, calCET.getTime());
+ assertFalse("Check CET != GMT", dateGMT == calCET.getTime());
+
+ // Adjust to TimeZone with Same rules
+ Calendar calUTC = createCalendar(UTC, DATE_2005_11_23, TIME_12_03_45);
+ assertTrue("SAME: UTC = GMT", UTC.hasSameRules(GMT));
+ assertEquals("SAME: Check time (A)", calUTC.getTime(), calGMT.getTime());
+ assertFalse("SAME: Check GMT(A)", GMT.equals(calUTC.getTimeZone()));
+ assertTrue("SAME: Check UTC(A)", UTC.equals(calUTC.getTimeZone()));
+ CalendarValidator.adjustToTimeZone(calUTC, GMT);
+ assertEquals("SAME: Check time (B)", calUTC.getTime(), calGMT.getTime());
+ assertTrue("SAME: Check GMT(B)", GMT.equals(calUTC.getTimeZone()));
+ assertFalse("SAME: Check UTC(B)", UTC.equals(calUTC.getTimeZone()));
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java
new file mode 100644
index 000000000..29d79ddcf
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CodeValidatorTest.java
@@ -0,0 +1,262 @@
+/*
+ * 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 org.apache.commons.validator.routines.checkdigit.CheckDigit;
+import org.apache.commons.validator.routines.checkdigit.EAN13CheckDigit;
+
+import junit.framework.TestCase;
+
+/**
+ * CodeValidatorTest.java.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class CodeValidatorTest extends TestCase {
+
+ /**
+ * Construct a test with the specified name.
+ * @param name The name of the test
+ */
+ public CodeValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test Check Digit.
+ */
+ public void testCheckDigit() {
+ CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
+ String invalidEAN = "9781930110992";
+ String validEAN = "9781930110991";
+
+ // Test no CheckDigit (i.e. null)
+ assertNull("No CheckDigit", validator.getCheckDigit());
+ assertEquals("No CheckDigit invalid", invalidEAN, validator.validate(invalidEAN));
+ assertEquals("No CheckDigit valid", validEAN, validator.validate(validEAN));
+ assertEquals("No CheckDigit (is) invalid", true, validator.isValid(invalidEAN));
+ assertEquals("No CheckDigit (is) valid", true, validator.isValid(validEAN));
+
+ // Use the EAN-13 check digit routine
+ validator = new CodeValidator((String)null, -1, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+
+ assertNotNull("EAN CheckDigit", validator.getCheckDigit());
+ assertEquals("EAN CheckDigit invalid", null, validator.validate(invalidEAN));
+ assertEquals("EAN CheckDigit valid", validEAN, validator.validate(validEAN));
+ assertEquals("EAN CheckDigit (is) invalid", false, validator.isValid(invalidEAN));
+ assertEquals("EAN CheckDigit (is) valid", true, validator.isValid(validEAN));
+ assertEquals("EAN CheckDigit ex", null, validator.validate("978193011099X"));
+ }
+
+ /**
+ * Test the minimum/maximum length
+ */
+ public void testLength() {
+ CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
+ String length_10 = "1234567890";
+ String length_11 = "12345678901";
+ String length_12 = "123456789012";
+ String length_20 = "12345678901234567890";
+ String length_21 = "123456789012345678901";
+ String length_22 = "1234567890123456789012";
+
+ assertEquals("No min", -1, validator.getMinLength());
+ assertEquals("No max", -1, validator.getMaxLength());
+
+ assertEquals("No Length 10", length_10, validator.validate(length_10));
+ assertEquals("No Length 11", length_11, validator.validate(length_11));
+ assertEquals("No Length 12", length_12, validator.validate(length_12));
+ assertEquals("No Length 20", length_20, validator.validate(length_20));
+ assertEquals("No Length 21", length_21, validator.validate(length_21));
+ assertEquals("No Length 22", length_22, validator.validate(length_22));
+
+ validator = new CodeValidator((String)null, 11, -1, (CheckDigit)null);
+ assertEquals("Min 11 - min", 11, validator.getMinLength());
+ assertEquals("Min 11 - max", -1, validator.getMaxLength());
+ assertEquals("Min 11 - 10", null, validator.validate(length_10));
+ assertEquals("Min 11 - 11", length_11, validator.validate(length_11));
+ assertEquals("Min 11 - 12", length_12, validator.validate(length_12));
+ assertEquals("Min 11 - 20", length_20, validator.validate(length_20));
+ assertEquals("Min 11 - 21", length_21, validator.validate(length_21));
+ assertEquals("Min 11 - 22", length_22, validator.validate(length_22));
+
+ validator = new CodeValidator((String)null, -1, 21, (CheckDigit)null);
+ assertEquals("Max 21 - min", -1, validator.getMinLength());
+ assertEquals("Max 21 - max", 21, validator.getMaxLength());
+ assertEquals("Max 21 - 10", length_10, validator.validate(length_10));
+ assertEquals("Max 21 - 11", length_11, validator.validate(length_11));
+ assertEquals("Max 21 - 12", length_12, validator.validate(length_12));
+ assertEquals("Max 21 - 20", length_20, validator.validate(length_20));
+ assertEquals("Max 21 - 21", length_21, validator.validate(length_21));
+ assertEquals("Max 21 - 22", null, validator.validate(length_22));
+
+ validator = new CodeValidator((String)null, 11, 21, (CheckDigit)null);
+ assertEquals("Min 11 / Max 21 - min", 11, validator.getMinLength());
+ assertEquals("Min 11 / Max 21 - max", 21, validator.getMaxLength());
+ assertEquals("Min 11 / Max 21 - 10", null, validator.validate(length_10));
+ assertEquals("Min 11 / Max 21 - 11", length_11, validator.validate(length_11));
+ assertEquals("Min 11 / Max 21 - 12", length_12, validator.validate(length_12));
+ assertEquals("Min 11 / Max 21 - 20", length_20, validator.validate(length_20));
+ assertEquals("Min 11 / Max 21 - 21", length_21, validator.validate(length_21));
+ assertEquals("Min 11 / Max 21 - 22", null, validator.validate(length_22));
+
+ validator = new CodeValidator((String)null, 11, 11, (CheckDigit)null);
+ assertEquals("Exact 11 - min", 11, validator.getMinLength());
+ assertEquals("Exact 11 - max", 11, validator.getMaxLength());
+ assertEquals("Exact 11 - 10", null, validator.validate(length_10));
+ assertEquals("Exact 11 - 11", length_11, validator.validate(length_11));
+ assertEquals("Exact 11 - 12", null, validator.validate(length_12));
+ }
+
+ /**
+ * Test Regular Expression.
+ */
+ public void testRegex() {
+ CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
+
+ String value2 = "12";
+ String value3 = "123";
+ String value4 = "1234";
+ String value5 = "12345";
+ String invalid = "12a4";
+
+ // No Regular Expression
+ assertNull("No Regex", validator.getRegexValidator());
+ assertEquals("No Regex 2", value2, validator.validate(value2));
+ assertEquals("No Regex 3", value3, validator.validate(value3));
+ assertEquals("No Regex 4", value4, validator.validate(value4));
+ assertEquals("No Regex 5", value5, validator.validate(value5));
+ assertEquals("No Regex invalid", invalid, validator.validate(invalid));
+
+ // Regular Expression
+ String regex = "^([0-9]{3,4})$";
+ validator = new CodeValidator(regex, -1, -1, (CheckDigit)null);
+ assertNotNull("No Regex", validator.getRegexValidator());
+ assertEquals("Regex 2", null, validator.validate(value2));
+ assertEquals("Regex 3", value3, validator.validate(value3));
+ assertEquals("Regex 4", value4, validator.validate(value4));
+ assertEquals("Regex 5", null, validator.validate(value5));
+ assertEquals("Regex invalid", null, validator.validate(invalid));
+
+ // Reformatted
+ regex = "^([0-9]{3})(?:[-\\s])([0-9]{3})$";
+ validator = new CodeValidator(new RegexValidator(regex), 6, (CheckDigit)null);
+ assertEquals("Reformat 123-456", "123456", validator.validate("123-456"));
+ assertEquals("Reformat 123 456", "123456", validator.validate("123 456"));
+ assertEquals("Reformat 123456", null, validator.validate("123456"));
+ assertEquals("Reformat 123.456", null, validator.validate("123.456"));
+
+ regex = "^(?:([0-9]{3})(?:[-\\s])([0-9]{3}))|([0-9]{6})$";
+ validator = new CodeValidator(new RegexValidator(regex), 6, (CheckDigit)null);
+ assertEquals("Reformat 2 Regex", "RegexValidator{" + regex + "}", validator.getRegexValidator().toString());
+ assertEquals("Reformat 2 123-456", "123456", validator.validate("123-456"));
+ assertEquals("Reformat 2 123 456", "123456", validator.validate("123 456"));
+ assertEquals("Reformat 2 123456", "123456", validator.validate("123456"));
+
+ }
+
+ /**
+ * Test Regular Expression.
+ */
+ public void testNoInput() {
+ CodeValidator validator = new CodeValidator((String)null, -1, -1, (CheckDigit)null);
+ assertEquals("Null", null, validator.validate(null));
+ assertEquals("Zero Length", null, validator.validate(""));
+ assertEquals("Spaces", null, validator.validate(" "));
+ assertEquals("Trimmed", "A", validator.validate(" A "));
+ }
+
+ public void testValidator294_1() {
+ CodeValidator validator = new CodeValidator((String)null, 0, -1, (CheckDigit)null);
+ assertEquals("Null", null, validator.validate(null));
+ validator = new CodeValidator((String)null, -1, 0, (CheckDigit)null);
+ assertEquals("Null", null, validator.validate(null));
+ }
+
+ public void testValidator294_2() {
+ CodeValidator validator = new CodeValidator((String)null, -1, 0, (CheckDigit)null);
+ assertEquals("Null", null, validator.validate(null));
+ }
+
+ /**
+ * Test Regular Expression.
+ */
+ public void testConstructors() {
+ CodeValidator validator = null;
+ RegexValidator regex = new RegexValidator("^[0-9]*$");
+
+ // Constructor 1
+ validator = new CodeValidator(regex, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 1 - regex", regex, validator.getRegexValidator());
+ assertEquals("Constructor 1 - min length", -1, validator.getMinLength());
+ assertEquals("Constructor 1 - max length", -1, validator.getMaxLength());
+ assertEquals("Constructor 1 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+
+ // Constructor 2
+ validator = new CodeValidator(regex, 13, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 2 - regex", regex, validator.getRegexValidator());
+ assertEquals("Constructor 2 - min length", 13, validator.getMinLength());
+ assertEquals("Constructor 2 - max length", 13, validator.getMaxLength());
+ assertEquals("Constructor 2 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+
+ // Constructor 3
+ validator = new CodeValidator(regex, 10, 20, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 3 - regex", regex, validator.getRegexValidator());
+ assertEquals("Constructor 3 - min length", 10, validator.getMinLength());
+ assertEquals("Constructor 3 - max length", 20, validator.getMaxLength());
+ assertEquals("Constructor 3 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+
+ // Constructor 4
+ validator = new CodeValidator("^[0-9]*$", EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 4 - regex", "RegexValidator{^[0-9]*$}", validator.getRegexValidator().toString());
+ assertEquals("Constructor 4 - min length", -1, validator.getMinLength());
+ assertEquals("Constructor 4 - max length", -1, validator.getMaxLength());
+ assertEquals("Constructor 4 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+
+ // Constructor 5
+ validator = new CodeValidator("^[0-9]*$", 13, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 5 - regex", "RegexValidator{^[0-9]*$}", validator.getRegexValidator().toString());
+ assertEquals("Constructor 5 - min length", 13, validator.getMinLength());
+ assertEquals("Constructor 5 - max length", 13, validator.getMaxLength());
+ assertEquals("Constructor 5 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+
+ // Constructor 6
+ validator = new CodeValidator("^[0-9]*$", 10, 20, EAN13CheckDigit.EAN13_CHECK_DIGIT);
+ assertEquals("Constructor 6 - regex", "RegexValidator{^[0-9]*$}", validator.getRegexValidator().toString());
+ assertEquals("Constructor 6 - min length", 10, validator.getMinLength());
+ assertEquals("Constructor 6 - max length", 20, validator.getMaxLength());
+ assertEquals("Constructor 6 - check digit", EAN13CheckDigit.EAN13_CHECK_DIGIT, validator.getCheckDigit());
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
new file mode 100644
index 000000000..760538930
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CreditCardValidatorTest.java
@@ -0,0 +1,650 @@
+/*
+ * 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.TestCase;
+import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit;
+import org.apache.commons.validator.routines.CreditCardValidator.CreditCardRange;
+
+/**
+ * Test the CreditCardValidator class.
+ *
+ * @version $Revision$
+ */
+public class CreditCardValidatorTest extends TestCase {
+
+ private static final String VALID_VISA = "4417123456789113"; // 16
+ private static final String ERROR_VISA = "4417123456789112";
+ private static final String VALID_SHORT_VISA = "4222222222222"; // 13
+ private static final String ERROR_SHORT_VISA = "4222222222229";
+ private static final String VALID_AMEX = "378282246310005"; // 15
+ private static final String ERROR_AMEX = "378282246310001";
+ private static final String VALID_MASTERCARD = "5105105105105100";
+ private static final String ERROR_MASTERCARD = "5105105105105105";
+ private static final String VALID_DISCOVER = "6011000990139424";
+ private static final String ERROR_DISCOVER = "6011000990139421";
+ private static final String VALID_DISCOVER65 = "6534567890123458"; // FIXME need verified test data for Discover with "65" prefix
+ private static final String ERROR_DISCOVER65 = "6534567890123450"; // FIXME need verified test data for Discover with "65" prefix
+ private static final String VALID_DINERS = "30569309025904"; // 14
+ private static final String ERROR_DINERS = "30569309025901";
+ private static final String VALID_VPAY = "4370000000000061"; // 16
+ private static final String VALID_VPAY2 = "4370000000000012";
+ private static final String ERROR_VPAY = "4370000000000069";
+
+ private static final String [] VALID_CARDS = {
+ VALID_VISA,
+ VALID_SHORT_VISA,
+ VALID_AMEX,
+ VALID_MASTERCARD,
+ VALID_DISCOVER,
+ VALID_DISCOVER65,
+ VALID_DINERS,
+ VALID_VPAY,
+ VALID_VPAY2,
+ };
+
+ private static final String [] ERROR_CARDS = {
+ ERROR_VISA,
+ ERROR_SHORT_VISA,
+ ERROR_AMEX,
+ ERROR_MASTERCARD,
+ ERROR_DISCOVER,
+ ERROR_DISCOVER65,
+ ERROR_DINERS,
+ ERROR_VPAY,
+// ERROR_VPAY2,
+ "",
+ "12345678901", // too short (11)
+ "12345678901234567890", // too long (20)
+ "4417123456789112", // invalid check digit
+ };
+
+ /**
+ * Constructor for CreditCardValidatorTest.
+ */
+ public CreditCardValidatorTest(String name) {
+ super(name);
+ }
+
+ public void testIsValid() {
+ CreditCardValidator ccv = new CreditCardValidator();
+
+ assertNull(ccv.validate(null));
+
+ assertFalse(ccv.isValid(null));
+ assertFalse(ccv.isValid(""));
+ assertFalse(ccv.isValid("123456789012")); // too short
+ assertFalse(ccv.isValid("12345678901234567890")); // too long
+ assertFalse(ccv.isValid("4417123456789112"));
+ assertFalse(ccv.isValid("4417q23456w89113"));
+ assertTrue(ccv.isValid(VALID_VISA));
+ assertTrue(ccv.isValid(VALID_SHORT_VISA));
+ assertTrue(ccv.isValid(VALID_AMEX));
+ assertTrue(ccv.isValid(VALID_MASTERCARD));
+ assertTrue(ccv.isValid(VALID_DISCOVER));
+ assertTrue(ccv.isValid(VALID_DISCOVER65));
+
+ assertFalse(ccv.isValid(ERROR_VISA));
+ assertFalse(ccv.isValid(ERROR_SHORT_VISA));
+ assertFalse(ccv.isValid(ERROR_AMEX));
+ assertFalse(ccv.isValid(ERROR_MASTERCARD));
+ assertFalse(ccv.isValid(ERROR_DISCOVER));
+ assertFalse(ccv.isValid(ERROR_DISCOVER65));
+
+ // disallow Visa so it should fail even with good number
+ ccv = new CreditCardValidator(CreditCardValidator.AMEX);
+ assertFalse(ccv.isValid("4417123456789113"));
+ }
+
+ public void testAddAllowedCardType() {
+ CreditCardValidator ccv = new CreditCardValidator(CreditCardValidator.NONE);
+ // Turned off all cards so even valid numbers should fail
+ assertFalse(ccv.isValid(VALID_VISA));
+ assertFalse(ccv.isValid(VALID_AMEX));
+ assertFalse(ccv.isValid(VALID_MASTERCARD));
+ assertFalse(ccv.isValid(VALID_DISCOVER));
+ assertFalse(ccv.isValid(VALID_DINERS));
+ }
+
+ /**
+ * Test the CodeValidator array constructor
+ */
+ public void testArrayConstructor() {
+ CreditCardValidator ccv = new CreditCardValidator(new CodeValidator[]
+ {CreditCardValidator.VISA_VALIDATOR, CreditCardValidator.AMEX_VALIDATOR});
+
+ assertTrue(ccv.isValid(VALID_VISA));
+ assertTrue(ccv.isValid(VALID_SHORT_VISA));
+ assertTrue(ccv.isValid(VALID_AMEX));
+ assertFalse(ccv.isValid(VALID_MASTERCARD));
+ assertFalse(ccv.isValid(VALID_DISCOVER));
+
+ assertFalse(ccv.isValid(ERROR_VISA));
+ assertFalse(ccv.isValid(ERROR_SHORT_VISA));
+ assertFalse(ccv.isValid(ERROR_AMEX));
+ assertFalse(ccv.isValid(ERROR_MASTERCARD));
+ assertFalse(ccv.isValid(ERROR_DISCOVER));
+
+ try {
+ new CreditCardValidator((CodeValidator[]) null);
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException iae) {
+ // expected result
+ }
+ }
+
+ /**
+ * Test the Amex Card validator
+ */
+ public void testAmexValidator() {
+
+ CodeValidator validator = CreditCardValidator.AMEX_VALIDATOR;
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 15 and start with a "34" or "37"
+ assertFalse("Length 12", regex.isValid("343456789012"));
+ assertFalse("Length 13", regex.isValid("3434567890123"));
+ assertFalse("Length 14", regex.isValid("34345678901234"));
+ assertTrue("Length 15", regex.isValid("343456789012345"));
+ assertFalse("Length 16", regex.isValid("3434567890123456"));
+ assertFalse("Length 17", regex.isValid("34345678901234567"));
+ assertFalse("Length 18", regex.isValid("343456789012345678"));
+ assertFalse("Prefix 33", regex.isValid("333456789012345"));
+ assertTrue("Prefix 34", regex.isValid("343456789012345"));
+ assertFalse("Prefix 35", regex.isValid("353456789012345"));
+ assertFalse("Prefix 36", regex.isValid("363456789012345"));
+ assertTrue("Prefix 37", regex.isValid("373456789012345"));
+ assertFalse("Prefix 38", regex.isValid("383456789012345"));
+ assertFalse("Prefix 41", regex.isValid("413456789012345"));
+ assertFalse("Invalid Char", regex.isValid("3434567x9012345"));
+
+ // *********** Test Validator **********
+ assertTrue("Valid regex", regex.isValid(ERROR_AMEX));
+ assertFalse("Invalid", validator.isValid(ERROR_AMEX));
+ assertNull("validate()", validator.validate(ERROR_AMEX));
+ assertEquals(VALID_AMEX, validator.validate(VALID_AMEX));
+
+ assertTrue("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+
+ assertTrue("Valid-A", validator.isValid("371449635398431"));
+ assertTrue("Valid-B", validator.isValid("340000000000009"));
+ assertTrue("Valid-C", validator.isValid("370000000000002"));
+ assertTrue("Valid-D", validator.isValid("378734493671000"));
+ }
+
+ /**
+ * Test the Amex Card option
+ */
+ public void testAmexOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.AMEX);
+ assertFalse("Invalid", validator.isValid(ERROR_AMEX));
+ assertNull("validate()", validator.validate(ERROR_AMEX));
+ assertEquals(VALID_AMEX, validator.validate(VALID_AMEX));
+
+ assertTrue("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ /**
+ * Test the Diners Card validator
+ */
+ public void testDinersValidator() {
+
+ CodeValidator validator = CreditCardValidator.DINERS_VALIDATOR;
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 14 and start with a "300-305" or "3095" or "36" or "38" or "39"
+ assertFalse("Length 12-300", regex.isValid("300456789012"));
+ assertFalse("Length 12-36", regex.isValid("363456789012"));
+ assertFalse("Length 13-300", regex.isValid("3004567890123"));
+ assertFalse("Length 13-36", regex.isValid("3634567890123"));
+ assertTrue("Length 14-300", regex.isValid("30045678901234"));
+ assertTrue("Length 14-36", regex.isValid("36345678901234"));
+ assertFalse("Length 15-300", regex.isValid("300456789012345"));
+ assertFalse("Length 15-36", regex.isValid("363456789012345"));
+ assertFalse("Length 16-300", regex.isValid("3004567890123456"));
+ assertFalse("Length 16-36", regex.isValid("3634567890123456"));
+ assertFalse("Length 17-300", regex.isValid("30045678901234567"));
+ assertFalse("Length 17-36", regex.isValid("36345678901234567"));
+ assertFalse("Length 18-300", regex.isValid("300456789012345678"));
+ assertFalse("Length 18-36", regex.isValid("363456789012345678"));
+
+ assertTrue("Prefix 300", regex.isValid("30045678901234"));
+ assertTrue("Prefix 301", regex.isValid("30145678901234"));
+ assertTrue("Prefix 302", regex.isValid("30245678901234"));
+ assertTrue("Prefix 303", regex.isValid("30345678901234"));
+ assertTrue("Prefix 304", regex.isValid("30445678901234"));
+ assertTrue("Prefix 305", regex.isValid("30545678901234"));
+ assertFalse("Prefix 306", regex.isValid("30645678901234"));
+ assertFalse("Prefix 3094", regex.isValid("30945678901234"));
+ assertTrue( "Prefix 3095", regex.isValid("30955678901234"));
+ assertFalse("Prefix 3096", regex.isValid("30965678901234"));
+ assertFalse("Prefix 35", regex.isValid("35345678901234"));
+ assertTrue("Prefix 36", regex.isValid("36345678901234"));
+ assertFalse("Prefix 37", regex.isValid("37345678901234"));
+ assertTrue("Prefix 38", regex.isValid("38345678901234"));
+ assertTrue("Prefix 39", regex.isValid("39345678901234"));
+
+ assertFalse("Invalid Char-A", regex.isValid("3004567x901234"));
+ assertFalse("Invalid Char-B", regex.isValid("3634567x901234"));
+
+ // *********** Test Validator **********
+ assertTrue("Valid regex", regex.isValid(ERROR_DINERS));
+ assertFalse("Invalid", validator.isValid(ERROR_DINERS));
+ assertNull("validate()", validator.validate(ERROR_DINERS));
+ assertEquals(VALID_DINERS, validator.validate(VALID_DINERS));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertTrue("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+
+ assertTrue("Valid-A", validator.isValid("30000000000004"));
+ assertTrue("Valid-B", validator.isValid("30123456789019"));
+ assertTrue("Valid-C", validator.isValid("36432685260294"));
+
+ }
+
+ /**
+ * Test the Diners Card option
+ */
+ public void testDinersOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.DINERS);
+ assertFalse("Invalid", validator.isValid(ERROR_DINERS));
+ assertNull("validate()", validator.validate(ERROR_DINERS));
+ assertEquals(VALID_DINERS, validator.validate(VALID_DINERS));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertTrue("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ /**
+ * Test the Discover Card validator
+ */
+ public void testDiscoverValidator() {
+
+ CodeValidator validator = CreditCardValidator.DISCOVER_VALIDATOR;
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 16 and start with either "6011" or or "64[4-9]" or "65"
+ assertFalse("Length 12-6011", regex.isValid("601156789012"));
+ assertFalse("Length 12-65", regex.isValid("653456789012"));
+ assertFalse("Length 13-6011", regex.isValid("6011567890123"));
+ assertFalse("Length 13-65", regex.isValid("6534567890123"));
+ assertFalse("Length 14-6011", regex.isValid("60115678901234"));
+ assertFalse("Length 14-65", regex.isValid("65345678901234"));
+ assertFalse("Length 15-6011", regex.isValid("601156789012345"));
+ assertFalse("Length 15-65", regex.isValid("653456789012345"));
+ assertTrue("Length 16-6011", regex.isValid("6011567890123456"));
+ assertTrue("Length 16-644", regex.isValid("6444567890123456"));
+ assertTrue("Length 16-648", regex.isValid("6484567890123456"));
+ assertTrue("Length 16-65", regex.isValid("6534567890123456"));
+ assertFalse("Length 17-6011", regex.isValid("60115678901234567"));
+ assertFalse("Length 17-65", regex.isValid("65345678901234567"));
+ assertFalse("Length 18-6011", regex.isValid("601156789012345678"));
+ assertFalse("Length 18-65", regex.isValid("653456789012345678"));
+
+ assertFalse("Prefix 640", regex.isValid("6404567890123456"));
+ assertFalse("Prefix 641", regex.isValid("6414567890123456"));
+ assertFalse("Prefix 642", regex.isValid("6424567890123456"));
+ assertFalse("Prefix 643", regex.isValid("6434567890123456"));
+ assertFalse("Prefix 6010", regex.isValid("6010567890123456"));
+ assertFalse("Prefix 6012", regex.isValid("6012567890123456"));
+ assertFalse("Invalid Char", regex.isValid("6011567x90123456"));
+
+ // *********** Test Validator **********
+ assertTrue("Valid regex", regex.isValid(ERROR_DISCOVER));
+ assertTrue("Valid regex65", regex.isValid(ERROR_DISCOVER65));
+ assertFalse("Invalid", validator.isValid(ERROR_DISCOVER));
+ assertFalse("Invalid65", validator.isValid(ERROR_DISCOVER65));
+ assertNull("validate()", validator.validate(ERROR_DISCOVER));
+ assertEquals(VALID_DISCOVER, validator.validate(VALID_DISCOVER));
+ assertEquals(VALID_DISCOVER65, validator.validate(VALID_DISCOVER65));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertTrue("Discover", validator.isValid(VALID_DISCOVER));
+ assertTrue("Discover", validator.isValid(VALID_DISCOVER65));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+
+ assertTrue("Valid-A", validator.isValid("6011111111111117"));
+ assertTrue("Valid-B", validator.isValid("6011000000000004"));
+ assertTrue("Valid-C", validator.isValid("6011000000000012"));
+
+ }
+
+ /**
+ * Test the Discover Card option
+ */
+ public void testDiscoverOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.DISCOVER);
+ assertFalse("Invalid", validator.isValid(ERROR_DISCOVER));
+ assertFalse("Invalid65", validator.isValid(ERROR_DISCOVER65));
+ assertNull("validate()", validator.validate(ERROR_DISCOVER));
+ assertEquals(VALID_DISCOVER, validator.validate(VALID_DISCOVER));
+ assertEquals(VALID_DISCOVER65, validator.validate(VALID_DISCOVER65));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertTrue("Discover", validator.isValid(VALID_DISCOVER));
+ assertTrue("Discover", validator.isValid(VALID_DISCOVER65));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ /**
+ * Test the Mastercard Card validator
+ */
+ public void testMastercardValidator() {
+
+ CodeValidator validator = CreditCardValidator.MASTERCARD_VALIDATOR;
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 16 and start with a "51-55"
+ assertFalse("Length 12", regex.isValid("513456789012"));
+ assertFalse("Length 13", regex.isValid("5134567890123"));
+ assertFalse("Length 14", regex.isValid("51345678901234"));
+ assertFalse("Length 15", regex.isValid("513456789012345"));
+ assertTrue("Length 16", regex.isValid("5134567890123456"));
+ assertFalse("Length 17", regex.isValid("51345678901234567"));
+ assertFalse("Length 18", regex.isValid("513456789012345678"));
+ assertFalse("Prefix 41", regex.isValid("4134567890123456"));
+ assertFalse("Prefix 50", regex.isValid("5034567890123456"));
+ assertTrue("Prefix 51", regex.isValid("5134567890123456"));
+ assertTrue("Prefix 52", regex.isValid("5234567890123456"));
+ assertTrue("Prefix 53", regex.isValid("5334567890123456"));
+ assertTrue("Prefix 54", regex.isValid("5434567890123456"));
+ assertTrue("Prefix 55", regex.isValid("5534567890123456"));
+ assertFalse("Prefix 56", regex.isValid("5634567890123456"));
+ assertFalse("Prefix 61", regex.isValid("6134567890123456"));
+ assertFalse("Invalid Char", regex.isValid("5134567x90123456"));
+
+ // *********** Test Validator **********
+ assertTrue("Valid regex", regex.isValid(ERROR_MASTERCARD));
+ assertFalse("Invalid", validator.isValid(ERROR_MASTERCARD));
+ assertNull("validate()", validator.validate(ERROR_MASTERCARD));
+ assertEquals(VALID_MASTERCARD, validator.validate(VALID_MASTERCARD));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertTrue("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+
+ assertTrue("Valid-A", validator.isValid("5500000000000004"));
+ assertTrue("Valid-B", validator.isValid("5424000000000015"));
+ assertTrue("Valid-C", validator.isValid("5301250070000191"));
+ assertTrue("Valid-D", validator.isValid("5123456789012346"));
+ assertTrue("Valid-E", validator.isValid("5555555555554444"));
+
+ RegexValidator rev = validator.getRegexValidator();
+ final String PAD = "0000000000";
+ assertFalse("222099",rev.isValid("222099"+PAD));
+ for(int i=222100; i <= 272099; i++) {
+ String j = Integer.toString(i)+PAD;
+ assertTrue(j, rev.isValid(j));
+ }
+ assertFalse("272100",rev.isValid("272100"+PAD));
+ }
+
+ /**
+ * Test the Mastercard Card option
+ */
+ public void testMastercardOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.MASTERCARD);
+ assertFalse("Invalid", validator.isValid(ERROR_MASTERCARD));
+ assertNull("validate()", validator.validate(ERROR_MASTERCARD));
+ assertEquals(VALID_MASTERCARD, validator.validate(VALID_MASTERCARD));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertTrue("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertFalse("Visa", validator.isValid(VALID_VISA));
+ assertFalse("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ /**
+ * Test the Visa Card validator
+ */
+ public void testVisaValidator() {
+
+ CodeValidator validator = CreditCardValidator.VISA_VALIDATOR;
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 13 or 16, must start with a "4"
+ assertFalse("Length 12", regex.isValid("423456789012"));
+ assertTrue("Length 13", regex.isValid("4234567890123"));
+ assertFalse("Length 14", regex.isValid("42345678901234"));
+ assertFalse("Length 15", regex.isValid("423456789012345"));
+ assertTrue("Length 16", regex.isValid("4234567890123456"));
+ assertFalse("Length 17", regex.isValid("42345678901234567"));
+ assertFalse("Length 18", regex.isValid("423456789012345678"));
+ assertFalse("Invalid Pref-A", regex.isValid("3234567890123"));
+ assertFalse("Invalid Pref-B", regex.isValid("3234567890123456"));
+ assertFalse("Invalid Char-A", regex.isValid("4234567x90123"));
+ assertFalse("Invalid Char-B", regex.isValid("4234567x90123456"));
+
+ // *********** Test Validator **********
+ assertTrue("Valid regex", regex.isValid(ERROR_VISA));
+ assertTrue("Valid regex-S", regex.isValid(ERROR_SHORT_VISA));
+ assertFalse("Invalid", validator.isValid(ERROR_VISA));
+ assertFalse("Invalid-S", validator.isValid(ERROR_SHORT_VISA));
+ assertNull("validate()", validator.validate(ERROR_VISA));
+ assertEquals(VALID_VISA, validator.validate(VALID_VISA));
+ assertEquals(VALID_SHORT_VISA, validator.validate(VALID_SHORT_VISA));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertTrue("Visa", validator.isValid(VALID_VISA));
+ assertTrue("Visa Short", validator.isValid(VALID_SHORT_VISA));
+
+ assertTrue("Valid-A", validator.isValid("4111111111111111"));
+ assertTrue("Valid-C", validator.isValid("4543059999999982"));
+ assertTrue("Valid-B", validator.isValid("4462000000000003"));
+ assertTrue("Valid-D", validator.isValid("4508750000000009")); // Electron
+ assertTrue("Valid-E", validator.isValid("4012888888881881"));
+ }
+
+ /**
+ * Test the Visa Card option
+ */
+ public void testVisaOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.VISA);
+ assertFalse("Invalid", validator.isValid(ERROR_VISA));
+ assertFalse("Invalid-S", validator.isValid(ERROR_SHORT_VISA));
+ assertNull("validate()", validator.validate(ERROR_VISA));
+ assertEquals(VALID_VISA, validator.validate(VALID_VISA));
+ assertEquals(VALID_SHORT_VISA, validator.validate(VALID_SHORT_VISA));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertTrue("Visa", validator.isValid(VALID_VISA));
+ assertTrue("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ public void testVPayOption() {
+ CreditCardValidator validator = new CreditCardValidator(CreditCardValidator.VPAY);
+ assertTrue("Valid", validator.isValid(VALID_VPAY));
+ assertTrue("Valid", validator.isValid(VALID_VPAY2));
+ assertFalse("Invalid", validator.isValid(ERROR_VPAY));
+ assertEquals(VALID_VPAY, validator.validate(VALID_VPAY));
+ assertEquals(VALID_VPAY2, validator.validate(VALID_VPAY2));
+
+ assertFalse("Amex", validator.isValid(VALID_AMEX));
+ assertFalse("Diners", validator.isValid(VALID_DINERS));
+ assertFalse("Discover", validator.isValid(VALID_DISCOVER));
+ assertFalse("Mastercard", validator.isValid(VALID_MASTERCARD));
+ assertTrue("Visa", validator.isValid(VALID_VISA));
+ assertTrue("Visa Short", validator.isValid(VALID_SHORT_VISA));
+ }
+
+ /**
+ * Test using separators
+ */
+ public void testMastercardUsingSeparators() {
+
+ String MASTERCARD_REGEX_SEP = "^(5[1-5]\\d{2})(?:[- ])?(\\d{4})(?:[- ])?(\\d{4})(?:[- ])?(\\d{4})$";
+ CodeValidator validator = new CodeValidator(MASTERCARD_REGEX_SEP, LuhnCheckDigit.LUHN_CHECK_DIGIT);
+ RegexValidator regex = validator.getRegexValidator();
+
+ // ****** Test Regular Expression ******
+ // length 16 and start with a "51-55"
+ assertEquals("Number", "5134567890123456", regex.validate("5134567890123456"));
+ assertEquals("Hyphen", "5134567890123456", regex.validate("5134-5678-9012-3456"));
+ assertEquals("Space", "5134567890123456", regex.validate("5134 5678 9012 3456"));
+ assertEquals("MixedA", "5134567890123456", regex.validate("5134-5678 9012-3456"));
+ assertEquals("MixedB", "5134567890123456", regex.validate("5134 5678-9012 3456"));
+
+ assertFalse("Invalid Separator A", regex.isValid("5134.5678.9012.3456"));
+ assertFalse("Invalid Separator B", regex.isValid("5134_5678_9012_3456"));
+ assertFalse("Invalid Grouping A", regex.isValid("513-45678-9012-3456"));
+ assertFalse("Invalid Grouping B", regex.isValid("5134-567-89012-3456"));
+ assertFalse("Invalid Grouping C", regex.isValid("5134-5678-901-23456"));
+
+ // *********** Test Validator **********
+ assertEquals("Valid-A", "5500000000000004", validator.validate("5500-0000-0000-0004"));
+ assertEquals("Valid-B", "5424000000000015", validator.validate("5424 0000 0000 0015"));
+ assertEquals("Valid-C", "5301250070000191", validator.validate("5301-250070000191"));
+ assertEquals("Valid-D", "5123456789012346", validator.validate("5123456789012346"));
+ }
+
+ public void testGeneric() {
+ CreditCardValidator ccv = CreditCardValidator.genericCreditCardValidator();
+ for(String s : VALID_CARDS) {
+ assertTrue(s, ccv.isValid(s));
+ }
+ for(String s : ERROR_CARDS) {
+ assertFalse(s, ccv.isValid(s));
+ }
+ }
+
+ public void testRangeGeneratorNoLuhn() {
+ CodeValidator cv = CreditCardValidator.createRangeValidator(
+ new CreditCardRange[]{
+ new CreditCardRange("1",null,6,7),
+ new CreditCardRange("644","65", 8, 8)
+ },
+ null);
+ assertTrue(cv.isValid("1990000"));
+ assertTrue(cv.isValid("199000"));
+ assertFalse(cv.isValid("000000"));
+ assertFalse(cv.isValid("099999"));
+ assertFalse(cv.isValid("200000"));
+
+ assertFalse(cv.isValid("64399999"));
+ assertTrue(cv.isValid("64400000"));
+ assertTrue(cv.isValid("64900000"));
+ assertTrue(cv.isValid("65000000"));
+ assertTrue(cv.isValid("65999999"));
+ assertFalse(cv.isValid("66000000"));
+ }
+
+ public void testRangeGenerator() {
+ CreditCardValidator ccv = new CreditCardValidator(
+ new CodeValidator[] {
+ CreditCardValidator.AMEX_VALIDATOR,
+ CreditCardValidator.VISA_VALIDATOR,
+ CreditCardValidator.MASTERCARD_VALIDATOR,
+ CreditCardValidator.DISCOVER_VALIDATOR,
+ },
+ // Add missing validator
+ new CreditCardRange[]{
+ new CreditCardRange("300", "305", 14, 14), // Diners
+ new CreditCardRange("3095", null, 14, 14), // Diners
+ new CreditCardRange("36", null, 14, 14), // Diners
+ new CreditCardRange("38", "39", 14, 14), // Diners
+ }
+ // we don't have any VPAY examples yet that aren't handled by VISA
+ );
+ for(String s : VALID_CARDS) {
+ assertTrue(s, ccv.isValid(s));
+ }
+ for(String s : ERROR_CARDS) {
+ assertFalse(s, ccv.isValid(s));
+ }
+ }
+
+ public void testValidLength() {
+ assertTrue(CreditCardValidator.validLength(14, new CreditCardRange("", "", 14, 14)));
+ assertFalse(CreditCardValidator.validLength(15, new CreditCardRange("", "", 14, 14)));
+ assertFalse(CreditCardValidator.validLength(13, new CreditCardRange("", "", 14, 14)));
+
+ assertFalse(CreditCardValidator.validLength(14, new CreditCardRange("", "", 15, 17)));
+ assertTrue(CreditCardValidator.validLength(15, new CreditCardRange("", "", 15, 17)));
+ assertTrue(CreditCardValidator.validLength(16, new CreditCardRange("", "", 15, 17)));
+ assertTrue(CreditCardValidator.validLength(17, new CreditCardRange("", "", 15, 17)));
+ assertFalse(CreditCardValidator.validLength(18, new CreditCardRange("", "", 15, 17)));
+
+ assertFalse(CreditCardValidator.validLength(14, new CreditCardRange("", "", new int[]{15, 17})));
+ assertTrue(CreditCardValidator.validLength(15, new CreditCardRange("", "", new int[]{15, 17})));
+ assertFalse(CreditCardValidator.validLength(16, new CreditCardRange("", "", new int[]{15, 17})));
+ assertTrue(CreditCardValidator.validLength(17, new CreditCardRange("", "", new int[]{15, 17})));
+ assertFalse(CreditCardValidator.validLength(18, new CreditCardRange("", "", new int[]{15, 17})));
+ }
+
+ public void testDisjointRange() {
+ CreditCardValidator ccv = new CreditCardValidator(
+ new CreditCardRange[]{
+ new CreditCardRange("305", "4", new int[]{13, 16}),
+ }
+ );
+ assertEquals(13, VALID_SHORT_VISA.length());
+ assertEquals(16, VALID_VISA.length());
+ assertEquals(14, VALID_DINERS.length());
+ assertTrue(ccv.isValid(VALID_SHORT_VISA));
+ assertTrue(ccv.isValid(VALID_VISA));
+ assertFalse(ccv.isValid(ERROR_SHORT_VISA));
+ assertFalse(ccv.isValid(ERROR_VISA));
+ assertFalse(ccv.isValid(VALID_DINERS));
+ ccv = new CreditCardValidator(
+ new CreditCardRange[]{
+ // add 14 as a valid length
+ new CreditCardRange("305", "4", new int[]{13, 14, 16}),
+ }
+ );
+ assertTrue(ccv.isValid(VALID_DINERS));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java
new file mode 100644
index 000000000..12b9000cf
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.TestCase;
+
+import java.util.Locale;
+import java.math.BigDecimal;
+import java.text.DecimalFormatSymbols;
+
+/**
+ * Test Case for CurrencyValidator.
+ *
+ * @version $Revision$
+ */
+public class CurrencyValidatorTest extends TestCase {
+
+ private static final char CURRENCY_SYMBOL = '\u00A4';
+
+ private String US_DOLLAR;
+ private String UK_POUND;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public CurrencyValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ US_DOLLAR = (new DecimalFormatSymbols(Locale.US)).getCurrencySymbol();
+ UK_POUND = (new DecimalFormatSymbols(Locale.UK)).getCurrencySymbol();
+ }
+
+ /**
+ * Tear down
+ * @throws Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test Format Type
+ */
+ public void testFormatType() {
+ assertEquals("Format Type A", 1, CurrencyValidator.getInstance().getFormatType());
+ assertEquals("Format Type B", AbstractNumberValidator.CURRENCY_FORMAT, CurrencyValidator.getInstance().getFormatType());
+ }
+
+ /**
+ * Test Valid currency values
+ */
+ public void testValid() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ BigDecimalValidator validator = CurrencyValidator.getInstance();
+ BigDecimal expected = new BigDecimal("1234.56");
+ BigDecimal negative = new BigDecimal("-1234.56");
+ BigDecimal noDecimal = new BigDecimal("1234.00");
+ BigDecimal oneDecimal = new BigDecimal("1234.50");
+
+ assertEquals("Default locale", expected, validator.validate(UK_POUND + "1,234.56"));
+
+ assertEquals("UK locale", expected, validator.validate(UK_POUND + "1,234.56", Locale.UK));
+ assertEquals("UK negative", negative, validator.validate("-" + UK_POUND + "1,234.56", Locale.UK));
+ assertEquals("UK no decimal", noDecimal, validator.validate(UK_POUND + "1,234", Locale.UK));
+ assertEquals("UK 1 decimal", oneDecimal, validator.validate(UK_POUND + "1,234.5", Locale.UK));
+ assertEquals("UK 3 decimal", expected, validator.validate(UK_POUND + "1,234.567", Locale.UK));
+ assertEquals("UK no symbol", expected, validator.validate("1,234.56", Locale.UK));
+
+ assertEquals("US locale", expected, validator.validate(US_DOLLAR + "1,234.56", Locale.US));
+ assertEquals("US negative", negative, validator.validate("(" + US_DOLLAR + "1,234.56)", Locale.US));
+ assertEquals("US no decimal", noDecimal, validator.validate(US_DOLLAR + "1,234", Locale.US));
+ assertEquals("US 1 decimal", oneDecimal, validator.validate(US_DOLLAR + "1,234.5", Locale.US));
+ assertEquals("US 3 decimal", expected, validator.validate(US_DOLLAR + "1,234.567", Locale.US));
+ assertEquals("US no symbol", expected, validator.validate("1,234.56", Locale.US));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+
+ /**
+ * Test Invalid currency values
+ */
+ public void testInvalid() {
+ BigDecimalValidator validator = CurrencyValidator.getInstance();
+
+ // Invalid Missing
+ assertFalse("isValid() Null Value", validator.isValid(null));
+ assertFalse("isValid() Empty Value", validator.isValid(""));
+ assertNull("validate() Null Value", validator.validate(null));
+ assertNull("validate() Empty Value", validator.validate(""));
+
+ // Invalid UK
+ assertFalse("UK wrong symbol", validator.isValid(US_DOLLAR + "1,234.56", Locale.UK));
+ assertFalse("UK wrong negative", validator.isValid("(" + UK_POUND + "1,234.56)", Locale.UK));
+
+ // Invalid US
+ assertFalse("US wrong symbol", validator.isValid(UK_POUND + "1,234.56", Locale.US));
+ assertFalse("US wrong negative", validator.isValid("-" + US_DOLLAR + "1,234.56", Locale.US));
+ }
+
+ /**
+ * Test Valid integer (non-decimal) currency values
+ */
+ public void testIntegerValid() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ CurrencyValidator validator = new CurrencyValidator();
+ BigDecimal expected = new BigDecimal("1234.00");
+ BigDecimal negative = new BigDecimal("-1234.00");
+
+ assertEquals("Default locale", expected, validator.validate(UK_POUND +"1,234"));
+
+ assertEquals("UK locale", expected, validator.validate(UK_POUND + "1,234", Locale.UK));
+ assertEquals("UK negative", negative, validator.validate("-" + UK_POUND + "1,234", Locale.UK));
+
+ assertEquals("US locale", expected, validator.validate(US_DOLLAR + "1,234", Locale.US));
+ assertEquals("US negative", negative, validator.validate("(" + US_DOLLAR + "1,234)", Locale.US));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+
+ /**
+ * Test Invalid integer (non decimal) currency values
+ */
+ public void testIntegerInvalid() {
+ CurrencyValidator validator = new CurrencyValidator(true, false);
+
+ // Invalid UK - has decimals
+ assertFalse("UK positive", validator.isValid(UK_POUND + "1,234.56", Locale.UK));
+ assertFalse("UK negative", validator.isValid("-" + UK_POUND + "1,234.56", Locale.UK));
+
+ // Invalid US - has decimals
+ assertFalse("US positive", validator.isValid(US_DOLLAR + "1,234.56", Locale.US));
+ assertFalse("US negative", validator.isValid("(" + US_DOLLAR + "1,234.56)", Locale.US));
+ }
+
+
+ /**
+ * Test currency values with a pattern
+ */
+ public void testPattern() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ BigDecimalValidator validator = CurrencyValidator.getInstance();
+ String basicPattern = CURRENCY_SYMBOL + "#,##0.000";
+ String pattern = basicPattern + ";[" + basicPattern +"]";
+ BigDecimal expected = new BigDecimal("1234.567");
+ BigDecimal negative = new BigDecimal("-1234.567");
+
+ // Test Pattern
+ assertEquals("default", expected, validator.validate(UK_POUND + "1,234.567", pattern));
+ assertEquals("negative", negative, validator.validate("[" + UK_POUND + "1,234.567]", pattern));
+ assertEquals("no symbol +ve", expected, validator.validate("1,234.567", pattern));
+ assertEquals("no symbol -ve", negative, validator.validate("[1,234.567]", pattern));
+
+ // Test Pattern & Locale
+ assertEquals("default", expected, validator.validate(US_DOLLAR + "1,234.567", pattern, Locale.US));
+ assertEquals("negative", negative, validator.validate("[" + US_DOLLAR + "1,234.567]", pattern, Locale.US));
+ assertEquals("no symbol +ve", expected, validator.validate("1,234.567", pattern, Locale.US));
+ assertEquals("no symbol -ve", negative, validator.validate("[1,234.567]", pattern, Locale.US));
+
+ // invalid
+ assertFalse("invalid symbol", validator.isValid(US_DOLLAR + "1,234.567", pattern));
+ assertFalse("invalid symbol", validator.isValid(UK_POUND + "1,234.567", pattern, Locale.US));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java
new file mode 100644
index 000000000..a17f6b020
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java
@@ -0,0 +1,169 @@
+/*
+ * 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 java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Test Case for DateValidator.
+ *
+ * @version $Revision$
+ */
+public class DateValidatorTest extends AbstractCalendarValidatorTest {
+
+ private DateValidator dateValidator;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public DateValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set Up.
+ * @throws Exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ dateValidator = new DateValidator();
+ validator = dateValidator;
+ }
+
+ /**
+ * Test DateValidator validate Methods
+ */
+ public void testDateValidatorMethods() {
+ Locale.setDefault(Locale.US);
+ Locale locale = Locale.GERMAN;
+ String pattern = "yyyy-MM-dd";
+ String patternVal = "2005-12-31";
+ String germanVal = "31 Dez 2005";
+ String germanPattern = "dd MMM yyyy";
+ String localeVal = "31.12.2005";
+ String defaultVal = "12/31/05";
+ String XXXX = "XXXX";
+ Date expected = createCalendar(null, 20051231, 0).getTime();
+
+ assertEquals("validate(A) default", expected, DateValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, DateValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, DateValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, DateValidator.getInstance().validate(germanVal, germanPattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", DateValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", DateValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", DateValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", DateValidator.getInstance().isValid(germanVal, germanPattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", DateValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", DateValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", DateValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", DateValidator.getInstance().validate("31 Dec 2005", germanPattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", DateValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", DateValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", DateValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", DateValidator.getInstance().isValid("31 Dec 2005", germanPattern, Locale.GERMAN));
+
+ // Test Time Zone
+ TimeZone zone = (TimeZone.getDefault().getRawOffset() == EET.getRawOffset() ? EST : EET);
+ Date expectedZone = createCalendar(zone, 20051231, 0).getTime();
+ assertFalse("default/zone same "+zone, expected.getTime() == expectedZone.getTime());
+
+ assertEquals("validate(C) default", expectedZone, DateValidator.getInstance().validate(defaultVal, zone));
+ assertEquals("validate(C) locale ", expectedZone, DateValidator.getInstance().validate(localeVal, locale, zone));
+ assertEquals("validate(C) pattern", expectedZone, DateValidator.getInstance().validate(patternVal, pattern, zone));
+ assertEquals("validate(C) both", expectedZone, DateValidator.getInstance().validate(germanVal, germanPattern, Locale.GERMAN, zone));
+ }
+
+ /**
+ * Test compare date methods
+ */
+ public void testCompare() {
+ int sameTime = 124522;
+ int testDate = 20050823;
+ Date diffHour = createDate(GMT, testDate, 115922); // same date, different time
+
+ Date value = createDate(GMT, testDate, sameTime); // test value
+ Date date20050824 = createDate(GMT, 20050824, sameTime); // +1 day
+ Date date20050822 = createDate(GMT, 20050822, sameTime); // -1 day
+
+ Date date20050830 = createDate(GMT, 20050830, sameTime); // +1 week
+ Date date20050816 = createDate(GMT, 20050816, sameTime); // -1 week
+
+ Date date20050901 = createDate(GMT, 20050901, sameTime); // +1 month
+ Date date20050801 = createDate(GMT, 20050801, sameTime); // same month
+ Date date20050731 = createDate(GMT, 20050731, sameTime); // -1 month
+
+ Date date20051101 = createDate(GMT, 20051101, sameTime); // +1 quarter (Feb Start)
+ Date date20051001 = createDate(GMT, 20051001, sameTime); // +1 quarter
+ Date date20050701 = createDate(GMT, 20050701, sameTime); // same quarter
+ Date date20050630 = createDate(GMT, 20050630, sameTime); // -1 quarter
+ Date date20050110 = createDate(GMT, 20050110, sameTime); // Previous Year qtr (Fen start)
+
+ Date date20060101 = createDate(GMT, 20060101, sameTime); // +1 year
+ Date date20050101 = createDate(GMT, 20050101, sameTime); // same year
+ Date date20041231 = createDate(GMT, 20041231, sameTime); // -1 year
+
+ assertEquals("date LT", -1, dateValidator.compareDates(value, date20050824, GMT)); // +1 day
+ assertEquals("date EQ", 0, dateValidator.compareDates(value, diffHour, GMT)); // same day, diff hour
+ assertEquals("date GT", 1, dateValidator.compareDates(value, date20050822, GMT)); // -1 day
+
+ assertEquals("week LT", -1, dateValidator.compareWeeks(value, date20050830, GMT)); // +1 week
+ assertEquals("week =1", 0, dateValidator.compareWeeks(value, date20050824, GMT)); // +1 day
+ assertEquals("week =2", 0, dateValidator.compareWeeks(value, date20050822, GMT)); // same week
+ assertEquals("week =3", 0, dateValidator.compareWeeks(value, date20050822, GMT)); // -1 day
+ assertEquals("week GT", 1, dateValidator.compareWeeks(value, date20050816, GMT)); // -1 week
+
+ assertEquals("mnth LT", -1, dateValidator.compareMonths(value, date20050901, GMT)); // +1 month
+ assertEquals("mnth =1", 0, dateValidator.compareMonths(value, date20050830, GMT)); // +1 week
+ assertEquals("mnth =2", 0, dateValidator.compareMonths(value, date20050801, GMT)); // same month
+ assertEquals("mnth =3", 0, dateValidator.compareMonths(value, date20050816, GMT)); // -1 week
+ assertEquals("mnth GT", 1, dateValidator.compareMonths(value, date20050731, GMT)); // -1 month
+
+ assertEquals("qtrA <1", -1, dateValidator.compareQuarters(value, date20051101, GMT)); // +1 quarter (Feb)
+ assertEquals("qtrA <2", -1, dateValidator.compareQuarters(value, date20051001, GMT)); // +1 quarter
+ assertEquals("qtrA =1", 0, dateValidator.compareQuarters(value, date20050901, GMT)); // +1 month
+ assertEquals("qtrA =2", 0, dateValidator.compareQuarters(value, date20050701, GMT)); // same quarter
+ assertEquals("qtrA =3", 0, dateValidator.compareQuarters(value, date20050731, GMT)); // -1 month
+ assertEquals("qtrA GT", 1, dateValidator.compareQuarters(value, date20050630, GMT)); // -1 quarter
+
+ // Change quarter 1 to start in Feb
+ assertEquals("qtrB LT", -1, dateValidator.compareQuarters(value, date20051101, GMT, 2)); // +1 quarter (Feb)
+ assertEquals("qtrB =1", 0, dateValidator.compareQuarters(value, date20051001, GMT, 2)); // same quarter
+ assertEquals("qtrB =2", 0, dateValidator.compareQuarters(value, date20050901, GMT, 2)); // +1 month
+ assertEquals("qtrB =3", 1, dateValidator.compareQuarters(value, date20050701, GMT, 2)); // same quarter
+ assertEquals("qtrB =4", 1, dateValidator.compareQuarters(value, date20050731, GMT, 2)); // -1 month
+ assertEquals("qtrB GT", 1, dateValidator.compareQuarters(value, date20050630, GMT, 2)); // -1 quarter
+ assertEquals("qtrB prev", 1, dateValidator.compareQuarters(value, date20050110, GMT, 2)); // Jan Prev year qtr
+
+ assertEquals("year LT", -1, dateValidator.compareYears(value, date20060101, GMT)); // +1 year
+ assertEquals("year EQ", 0, dateValidator.compareYears(value, date20050101, GMT)); // same year
+ assertEquals("year GT", 1, dateValidator.compareYears(value, date20041231, GMT)); // -1 year
+
+ // Compare using alternative TimeZone
+ Date sameDayTwoAm = createDate(GMT, testDate, 20000);
+ assertEquals("date LT", -1, dateValidator.compareDates(value, date20050824, EST)); // +1 day
+ assertEquals("date EQ", 0, dateValidator.compareDates(value, diffHour, EST)); // same day, diff hour
+ assertEquals("date EQ", 1, dateValidator.compareDates(value, sameDayTwoAm, EST)); // same day, diff hour
+ assertEquals("date GT", 1, dateValidator.compareDates(value, date20050822, EST)); // -1 day
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
new file mode 100644
index 000000000..417de6f30
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
@@ -0,0 +1,721 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.net.HttpURLConnection;
+import java.net.IDN;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.validator.routines.DomainValidator.ArrayType;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the DomainValidator.
+ *
+ * @version $Revision$
+ */
+public class DomainValidatorTest extends TestCase {
+
+ private DomainValidator validator;
+
+ @Override
+ public void setUp() {
+ validator = DomainValidator.getInstance();
+ DomainValidator.clearTLDOverrides(); // N.B. this clears the inUse flag, allowing overrides
+ }
+
+ public void testValidDomains() {
+ assertTrue("apache.org should validate", validator.isValid("apache.org"));
+ assertTrue("www.google.com should validate", validator.isValid("www.google.com"));
+
+ assertTrue("test-domain.com should validate", validator.isValid("test-domain.com"));
+ assertTrue("test---domain.com should validate", validator.isValid("test---domain.com"));
+ assertTrue("test-d-o-m-ain.com should validate", validator.isValid("test-d-o-m-ain.com"));
+ assertTrue("two-letter domain label should validate", validator.isValid("as.uk"));
+
+ assertTrue("case-insensitive ApAchE.Org should validate", validator.isValid("ApAchE.Org"));
+
+ assertTrue("single-character domain label should validate", validator.isValid("z.com"));
+
+ assertTrue("i.have.an-example.domain.name should validate", validator.isValid("i.have.an-example.domain.name"));
+ }
+
+ public void testInvalidDomains() {
+ assertFalse("bare TLD .org shouldn't validate", validator.isValid(".org"));
+ assertFalse("domain name with spaces shouldn't validate", validator.isValid(" apache.org "));
+ assertFalse("domain name containing spaces shouldn't validate", validator.isValid("apa che.org"));
+ assertFalse("domain name starting with dash shouldn't validate", validator.isValid("-testdomain.name"));
+ assertFalse("domain name ending with dash shouldn't validate", validator.isValid("testdomain-.name"));
+ assertFalse("domain name starting with multiple dashes shouldn't validate", validator.isValid("---c.com"));
+ assertFalse("domain name ending with multiple dashes shouldn't validate", validator.isValid("c--.com"));
+ assertFalse("domain name with invalid TLD shouldn't validate", validator.isValid("apache.rog"));
+
+ assertFalse("URL shouldn't validate", validator.isValid("http://www.apache.org"));
+ assertFalse("Empty string shouldn't validate as domain name", validator.isValid(" "));
+ assertFalse("Null shouldn't validate as domain name", validator.isValid(null));
+ }
+
+ public void testTopLevelDomains() {
+ // infrastructure TLDs
+ assertTrue(".arpa should validate as iTLD", validator.isValidInfrastructureTld(".arpa"));
+ assertFalse(".com shouldn't validate as iTLD", validator.isValidInfrastructureTld(".com"));
+
+ // generic TLDs
+ assertTrue(".name should validate as gTLD", validator.isValidGenericTld(".name"));
+ assertFalse(".us shouldn't validate as gTLD", validator.isValidGenericTld(".us"));
+
+ // country code TLDs
+ assertTrue(".uk should validate as ccTLD", validator.isValidCountryCodeTld(".uk"));
+ assertFalse(".org shouldn't validate as ccTLD", validator.isValidCountryCodeTld(".org"));
+
+ // case-insensitive
+ assertTrue(".COM should validate as TLD", validator.isValidTld(".COM"));
+ assertTrue(".BiZ should validate as TLD", validator.isValidTld(".BiZ"));
+
+ // corner cases
+ assertFalse("invalid TLD shouldn't validate", validator.isValid(".nope")); // TODO this is not guaranteed invalid forever
+ assertFalse("empty string shouldn't validate as TLD", validator.isValid(""));
+ assertFalse("null shouldn't validate as TLD", validator.isValid(null));
+ }
+
+ public void testAllowLocal() {
+ DomainValidator noLocal = DomainValidator.getInstance(false);
+ DomainValidator allowLocal = DomainValidator.getInstance(true);
+
+ // Default is false, and should use singletons
+ assertEquals(noLocal, validator);
+
+ // Default won't allow local
+ assertFalse("localhost.localdomain should validate", noLocal.isValid("localhost.localdomain"));
+ assertFalse("localhost should validate", noLocal.isValid("localhost"));
+
+ // But it may be requested
+ assertTrue("localhost.localdomain should validate", allowLocal.isValid("localhost.localdomain"));
+ assertTrue("localhost should validate", allowLocal.isValid("localhost"));
+ assertTrue("hostname should validate", allowLocal.isValid("hostname"));
+ assertTrue("machinename should validate", allowLocal.isValid("machinename"));
+
+ // Check the localhost one with a few others
+ assertTrue("apache.org should validate", allowLocal.isValid("apache.org"));
+ assertFalse("domain name with spaces shouldn't validate", allowLocal.isValid(" apache.org "));
+ }
+
+ public void testIDN() {
+ assertTrue("b\u00fccher.ch in IDN should validate", validator.isValid("www.xn--bcher-kva.ch"));
+ }
+
+ public void testIDNJava6OrLater() {
+ String version = System.getProperty("java.version");
+ if (version.compareTo("1.6") < 0) {
+ System.out.println("Cannot run Unicode IDN tests");
+ return; // Cannot run the test
+ } // xn--d1abbgf6aiiy.xn--p1ai http://президент.рф
+ assertTrue("b\u00fccher.ch should validate", validator.isValid("www.b\u00fccher.ch"));
+ assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("xn--d1abbgf6aiiy.xn--p1ai"));
+ assertTrue("президент.рф should validate", validator.isValid("президент.рф"));
+ assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("www.\uFFFD.ch"));
+ }
+
+ // RFC2396: domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
+ public void testRFC2396domainlabel() { // use fixed valid TLD
+ assertTrue("a.ch should validate", validator.isValid("a.ch"));
+ assertTrue("9.ch should validate", validator.isValid("9.ch"));
+ assertTrue("az.ch should validate", validator.isValid("az.ch"));
+ assertTrue("09.ch should validate", validator.isValid("09.ch"));
+ assertTrue("9-1.ch should validate", validator.isValid("9-1.ch"));
+ assertFalse("91-.ch should not validate", validator.isValid("91-.ch"));
+ assertFalse("-.ch should not validate", validator.isValid("-.ch"));
+ }
+
+ // RFC2396 toplabel = alpha | alpha *( alphanum | "-" ) alphanum
+ public void testRFC2396toplabel() {
+ // These tests use non-existent TLDs so currently need to use a package protected method
+ assertTrue("a.c (alpha) should validate", validator.isValidDomainSyntax("a.c"));
+ assertTrue("a.cc (alpha alpha) should validate", validator.isValidDomainSyntax("a.cc"));
+ assertTrue("a.c9 (alpha alphanum) should validate", validator.isValidDomainSyntax("a.c9"));
+ assertTrue("a.c-9 (alpha - alphanum) should validate", validator.isValidDomainSyntax("a.c-9"));
+ assertTrue("a.c-z (alpha - alpha) should validate", validator.isValidDomainSyntax("a.c-z"));
+
+ assertFalse("a.9c (alphanum alpha) should fail", validator.isValidDomainSyntax("a.9c"));
+ assertFalse("a.c- (alpha -) should fail", validator.isValidDomainSyntax("a.c-"));
+ assertFalse("a.- (-) should fail", validator.isValidDomainSyntax("a.-"));
+ assertFalse("a.-9 (- alphanum) should fail", validator.isValidDomainSyntax("a.-9"));
+ }
+
+ public void testDomainNoDots() {// rfc1123
+ assertTrue("a (alpha) should validate", validator.isValidDomainSyntax("a"));
+ assertTrue("9 (alphanum) should validate", validator.isValidDomainSyntax("9"));
+ assertTrue("c-z (alpha - alpha) should validate", validator.isValidDomainSyntax("c-z"));
+
+ assertFalse("c- (alpha -) should fail", validator.isValidDomainSyntax("c-"));
+ assertFalse("-c (- alpha) should fail", validator.isValidDomainSyntax("-c"));
+ assertFalse("- (-) should fail", validator.isValidDomainSyntax("-"));
+ }
+
+ public void testValidator297() {
+ assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("xn--d1abbgf6aiiy.xn--p1ai")); // This uses a valid TLD
+ }
+
+ // labels are a max of 63 chars and domains 253
+ public void testValidator306() {
+ final String longString = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789A";
+ assertEquals(63, longString.length()); // 26 * 2 + 11
+
+ assertTrue("63 chars label should validate", validator.isValidDomainSyntax(longString+".com"));
+ assertFalse("64 chars label should fail", validator.isValidDomainSyntax(longString+"x.com"));
+
+ assertTrue("63 chars TLD should validate", validator.isValidDomainSyntax("test."+longString));
+ assertFalse("64 chars TLD should fail", validator.isValidDomainSyntax("test.x"+longString));
+
+ final String longDomain =
+ longString
+ + "." + longString
+ + "." + longString
+ + "." + longString.substring(0,61)
+ ;
+ assertEquals(253, longDomain.length());
+ assertTrue("253 chars domain should validate", validator.isValidDomainSyntax(longDomain));
+ assertFalse("254 chars domain should fail", validator.isValidDomainSyntax(longDomain+"x"));
+ }
+
+ // Check that IDN.toASCII behaves as it should (when wrapped by DomainValidator.unicodeToASCII)
+ // Tests show that method incorrectly trims a trailing "." character
+ public void testUnicodeToASCII() {
+ String[] asciidots = {
+ "",
+ ",",
+ ".", // fails IDN.toASCII, but should pass wrapped version
+ "a.", // ditto
+ "a.b",
+ "a..b",
+ "a...b",
+ ".a",
+ "..a",
+ };
+ for(String s : asciidots) {
+ assertEquals(s,DomainValidator.unicodeToASCII(s));
+ }
+ // RFC3490 3.1. 1)
+// Whenever dots are used as label separators, the following
+// characters MUST be recognized as dots: U+002E (full stop), U+3002
+// (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61
+// (halfwidth ideographic full stop).
+ final String otherDots[][] = {
+ {"b\u3002", "b.",},
+ {"b\uFF0E", "b.",},
+ {"b\uFF61", "b.",},
+ {"\u3002", ".",},
+ {"\uFF0E", ".",},
+ {"\uFF61", ".",},
+ };
+ for(String s[] : otherDots) {
+ assertEquals(s[1],DomainValidator.unicodeToASCII(s[0]));
+ }
+ }
+
+ // Check if IDN.toASCII is broken or not
+ public void testIsIDNtoASCIIBroken() {
+ System.out.println(">>DomainValidatorTest.testIsIDNtoASCIIBroken()");
+ final String input = ".";
+ final boolean ok = input.equals(IDN.toASCII(input));
+ System.out.println("IDN.toASCII is " + (ok? "OK" : "BROKEN"));
+ String props[] = {
+ "java.version", // Java Runtime Environment version
+ "java.vendor", // Java Runtime Environment vendor
+ "java.vm.specification.version", // Java Virtual Machine specification version
+ "java.vm.specification.vendor", // Java Virtual Machine specification vendor
+ "java.vm.specification.name", // Java Virtual Machine specification name
+ "java.vm.version", // Java Virtual Machine implementation version
+ "java.vm.vendor", // Java Virtual Machine implementation vendor
+ "java.vm.name", // Java Virtual Machine implementation name
+ "java.specification.version", // Java Runtime Environment specification version
+ "java.specification.vendor", // Java Runtime Environment specification vendor
+ "java.specification.name", // Java Runtime Environment specification name
+ "java.class.version", // Java class format version number
+ };
+ for(String t : props) {
+ System.out.println(t + "=" + System.getProperty(t));
+ }
+ System.out.println("< ianaTlds = new HashSet(); // keep for comparison with array contents
+ DomainValidator dv = DomainValidator.getInstance();
+ File txtFile = new File("target/tlds-alpha-by-domain.txt");
+ long timestamp = download(txtFile, "https://data.iana.org/TLD/tlds-alpha-by-domain.txt", 0L);
+ final File htmlFile = new File("target/tlds-alpha-by-domain.html");
+ // N.B. sometimes the html file may be updated a day or so after the txt file
+ // if the txt file contains entries not found in the html file, try again in a day or two
+ download(htmlFile,"https://www.iana.org/domains/root/db", timestamp);
+
+ BufferedReader br = new BufferedReader(new FileReader(txtFile));
+ String line;
+ final String header;
+ line = br.readLine(); // header
+ if (line.startsWith("# Version ")) {
+ header = line.substring(2);
+ } else {
+ br.close();
+ throw new IOException("File does not have expected Version header");
+ }
+ final boolean generateUnicodeTlds = false; // Change this to generate Unicode TLDs as well
+
+ // Parse html page to get entries
+ Map htmlInfo = getHtmlInfo(htmlFile);
+ Map missingTLD = new TreeMap(); // stores entry and comments as String[]
+ Map missingCC = new TreeMap();
+ while((line = br.readLine()) != null) {
+ if (!line.startsWith("#")) {
+ final String unicodeTld; // only different from asciiTld if that was punycode
+ final String asciiTld = line.toLowerCase(Locale.ENGLISH);
+ if (line.startsWith("XN--")) {
+ unicodeTld = IDN.toUnicode(line);
+ } else {
+ unicodeTld = asciiTld;
+ }
+ if (!dv.isValidTld(asciiTld)) {
+ String [] info = htmlInfo.get(asciiTld);
+ if (info != null) {
+ String type = info[0];
+ String comment = info[1];
+ if ("country-code".equals(type)) { // Which list to use?
+ missingCC.put(asciiTld, unicodeTld + " " + comment);
+ if (generateUnicodeTlds) {
+ missingCC.put(unicodeTld, asciiTld + " " + comment);
+ }
+ } else {
+ missingTLD.put(asciiTld, unicodeTld + " " + comment);
+ if (generateUnicodeTlds) {
+ missingTLD.put(unicodeTld, asciiTld + " " + comment);
+ }
+ }
+ } else {
+ System.err.println("Expected to find HTML info for "+ asciiTld);
+ }
+ }
+ ianaTlds.add(asciiTld);
+ // Don't merge these conditions; generateUnicodeTlds is final so needs to be separate to avoid a warning
+ if (generateUnicodeTlds) {
+ if (!unicodeTld.equals(asciiTld)) {
+ ianaTlds.add(unicodeTld);
+ }
+ }
+ }
+ }
+ br.close();
+ // List html entries not in TLD text list
+ for(String key : (new TreeMap(htmlInfo)).keySet()) {
+ if (!ianaTlds.contains(key)) {
+ if (isNotInRootZone(key)) {
+ System.out.println("INFO: HTML entry not yet in root zone: "+key);
+ } else {
+ System.err.println("WARN: Expected to find text entry for html: "+key);
+ }
+ }
+ }
+ if (!missingTLD.isEmpty()) {
+ printMap(header, missingTLD, "TLD");
+ }
+ if (!missingCC.isEmpty()) {
+ printMap(header, missingCC, "CC");
+ }
+ // Check if internal tables contain any additional entries
+ isInIanaList("INFRASTRUCTURE_TLDS", ianaTlds);
+ isInIanaList("COUNTRY_CODE_TLDS", ianaTlds);
+ isInIanaList("GENERIC_TLDS", ianaTlds);
+ // Don't check local TLDS isInIanaList("LOCAL_TLDS", ianaTlds);
+ System.out.println("Finished checks");
+ }
+
+ private static void printMap(final String header, Map map, String string) {
+ System.out.println("Entries missing from "+ string +" List\n");
+ if (header != null) {
+ System.out.println(" // Taken from " + header);
+ }
+ Iterator> it = map.entrySet().iterator();
+ while(it.hasNext()){
+ Map.Entry me = it.next();
+ System.out.println(" \"" + me.getKey() + "\", // " + me.getValue());
+ }
+ System.out.println("\nDone");
+ }
+
+ private static Map getHtmlInfo(final File f) throws IOException {
+ final Map info = new HashMap();
+
+// .ax
+ final Pattern domain = Pattern.compile(".*country-code
+ final Pattern type = Pattern.compile("\\s+ ([^<]+) ");
+//
+// Ålands landskapsregering
+ final Pattern comment = Pattern.compile("\\s+([^<]+) ");
+
+ final BufferedReader br = new BufferedReader(new FileReader(f));
+ String line;
+ while((line=br.readLine())!=null){
+ Matcher m = domain.matcher(line);
+ if (m.lookingAt()) {
+ String dom = m.group(1);
+ String typ = "??";
+ String com = "??";
+ line = br.readLine();
+ while (line.matches("^\\s*$")) { // extra blank lines introduced
+ line = br.readLine();
+ }
+ Matcher t = type.matcher(line);
+ if (t.lookingAt()) {
+ typ = t.group(1);
+ line = br.readLine();
+ if (line.matches("\\s+.*")){
+ line = br.readLine();
+ }
+ line = br.readLine();
+ }
+ // Should have comment; is it wrapped?
+ while(!line.matches(".*.*")){
+ line += " " +br.readLine();
+ }
+ Matcher n = comment.matcher(line);
+ if (n.lookingAt()) {
+ com = n.group(1);
+ }
+ // Don't save unused entries
+ if (com.contains("Not assigned") || com.contains("Retired") || typ.equals("test")) {
+// System.out.println("Ignored: " + typ + " " + dom + " " +com);
+ } else {
+ info.put(dom.toLowerCase(Locale.ENGLISH), new String[]{typ, com});
+// System.out.println("Storing: " + typ + " " + dom + " " +com);
+ }
+ } else {
+ System.err.println("Unexpected type: " + line);
+ }
+ }
+ }
+ br.close();
+ return info;
+ }
+
+ /*
+ * Download a file if it is more recent than our cached copy.
+ * Unfortunately the server does not seem to honour If-Modified-Since for the
+ * Html page, so we check if it is newer than the txt file and skip download if so
+ */
+ private static long download(File f, String tldurl, long timestamp) throws IOException {
+ final int HOUR = 60*60*1000; // an hour in ms
+ final long modTime;
+ // For testing purposes, don't download files more than once an hour
+ if (f.canRead()) {
+ modTime = f.lastModified();
+ if (modTime > System.currentTimeMillis()-HOUR) {
+ System.out.println("Skipping download - found recent " + f);
+ return modTime;
+ }
+ } else {
+ modTime = 0;
+ }
+ HttpURLConnection hc = (HttpURLConnection) new URL(tldurl).openConnection();
+ if (modTime > 0) {
+ SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");//Sun, 06 Nov 1994 08:49:37 GMT
+ String since = sdf.format(new Date(modTime));
+ hc.addRequestProperty("If-Modified-Since", since);
+ System.out.println("Found " + f + " with date " + since);
+ }
+ if (hc.getResponseCode() == 304) {
+ System.out.println("Already have most recent " + tldurl);
+ } else {
+ System.out.println("Downloading " + tldurl);
+ byte buff[] = new byte[1024];
+ InputStream is = hc.getInputStream();
+
+ FileOutputStream fos = new FileOutputStream(f);
+ int len;
+ while((len=is.read(buff)) != -1) {
+ fos.write(buff, 0, len);
+ }
+ fos.close();
+ is.close();
+ System.out.println("Done");
+ }
+ return f.lastModified();
+ }
+
+ /**
+ * Check whether the domain is in the root zone currently.
+ * Reads the URL http://www.iana.org/domains/root/db/*domain*.html
+ * (using a local disk cache)
+ * and checks for the string "This domain is not present in the root zone at this time."
+ * @param domain the domain to check
+ * @return true if the string is found
+ */
+ private static boolean isNotInRootZone(String domain) {
+ String tldurl = "http://www.iana.org/domains/root/db/" + domain + ".html";
+ File rootCheck = new File("target","tld_" + domain + ".html");
+ BufferedReader in = null;
+ try {
+ download(rootCheck, tldurl, 0L);
+ in = new BufferedReader(new FileReader(rootCheck));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ if (inputLine.contains("This domain is not present in the root zone at this time.")) {
+ return true;
+ }
+ }
+ in.close();
+ } catch (IOException e) {
+ } finally {
+ closeQuietly(in);
+ }
+ return false;
+ }
+
+ private static void closeQuietly(Closeable in) {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ // isInIanaList and isSorted are split into two methods.
+ // If/when access to the arrays is possible without reflection, the intermediate
+ // methods can be dropped
+ private static boolean isInIanaList(String arrayName, Set ianaTlds) throws Exception {
+ Field f = DomainValidator.class.getDeclaredField(arrayName);
+ final boolean isPrivate = Modifier.isPrivate(f.getModifiers());
+ if (isPrivate) {
+ f.setAccessible(true);
+ }
+ String[] array = (String[]) f.get(null);
+ try {
+ return isInIanaList(arrayName, array, ianaTlds);
+ } finally {
+ if (isPrivate) {
+ f.setAccessible(false);
+ }
+ }
+ }
+
+ private static boolean isInIanaList(String name, String [] array, Set ianaTlds) {
+ for(int i = 0; i < array.length; i++) {
+ if (!ianaTlds.contains(array[i])) {
+ System.out.println(name + " contains unexpected value: " + array[i]);
+ }
+ }
+ return true;
+ }
+
+ private static boolean isSortedLowerCase(String arrayName) throws Exception {
+ Field f = DomainValidator.class.getDeclaredField(arrayName);
+ final boolean isPrivate = Modifier.isPrivate(f.getModifiers());
+ if (isPrivate) {
+ f.setAccessible(true);
+ }
+ String[] array = (String[]) f.get(null);
+ try {
+ return isSortedLowerCase(arrayName, array);
+ } finally {
+ if (isPrivate) {
+ f.setAccessible(false);
+ }
+ }
+ }
+
+ private static boolean isLowerCase(String string) {
+ return string.equals(string.toLowerCase(Locale.ENGLISH));
+ }
+
+ // Check if an array is strictly sorted - and lowerCase
+ private static boolean isSortedLowerCase(String name, String [] array) {
+ boolean sorted = true;
+ boolean strictlySorted = true;
+ final int length = array.length;
+ boolean lowerCase = isLowerCase(array[length-1]); // Check the last entry
+ for(int i = 0; i < length-1; i++) { // compare all but last entry with next
+ final String entry = array[i];
+ final String nextEntry = array[i+1];
+ final int cmp = entry.compareTo(nextEntry);
+ if (cmp > 0) { // out of order
+ System.out.println("Out of order entry: " + entry + " < " + nextEntry + " in " + name);
+ sorted = false;
+ } else if (cmp == 0) {
+ strictlySorted = false;
+ System.out.println("Duplicated entry: " + entry + " in " + name);
+ }
+ if (!isLowerCase(entry)) {
+ System.out.println("Non lowerCase entry: " + entry + " in " + name);
+ lowerCase = false;
+ }
+ }
+ return sorted && strictlySorted && lowerCase;
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DoubleValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DoubleValidatorTest.java
new file mode 100644
index 000000000..f002bc922
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/DoubleValidatorTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * Test Case for DoubleValidator.
+ *
+ * @version $Revision$
+ */
+public class DoubleValidatorTest extends AbstractNumberValidatorTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public DoubleValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new DoubleValidator(false, 0);
+ strictValidator = new DoubleValidator();
+
+ testPattern = "#,###.#";
+
+ // testValidateMinMax()
+ max = null;
+ maxPlusOne = null;
+ min = null;
+ minMinusOne = null;
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2"};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12"};
+
+ // testValid()
+ testNumber = Double.valueOf(1234.5);
+ testZero = Double.valueOf(0);
+ validStrict = new String[] {"0", "1234.5", "1,234.5"};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber};
+ valid = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+ testStringUS = "1,234.5";
+ testStringDE = "1.234,5";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###,#";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test DoubleValidator validate Methods
+ */
+ public void testDoubleValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ Double expected = Double.valueOf(12345);
+ assertEquals("validate(A) default", expected, DoubleValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, DoubleValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, DoubleValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, DoubleValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", DoubleValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", DoubleValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", DoubleValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", DoubleValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", DoubleValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", DoubleValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", DoubleValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", DoubleValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", DoubleValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", DoubleValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", DoubleValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", DoubleValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Double Range/Min/Max
+ */
+ public void testDoubleRangeMinMax() {
+ DoubleValidator validator = (DoubleValidator)strictValidator;
+ Double number9 = validator.validate("9", "#");
+ Double number10 = validator.validate("10", "#");
+ Double number11 = validator.validate("11", "#");
+ Double number19 = validator.validate("19", "#");
+ Double number20 = validator.validate("20", "#");
+ Double number21 = validator.validate("21", "#");
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
+ assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
+ assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+ assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
+ assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, 10));
+ assertTrue("minValue() = min", validator.minValue(number10, 10));
+ assertTrue("minValue() > min", validator.minValue(number11, 10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, 20));
+ assertTrue("maxValue() = max", validator.maxValue(number20, 20));
+ assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
new file mode 100644
index 000000000..0df920253
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
@@ -0,0 +1,545 @@
+/*
+ * 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.TestCase;
+
+import org.apache.commons.validator.ResultPair;
+
+/**
+ * Performs Validation Test for e-mail validations.
+ *
+ *
+ * @version $Revision$
+ */
+public class EmailValidatorTest extends TestCase {
+
+ /**
+ * 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";
+
+ private EmailValidator validator;
+
+ public EmailValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+protected void setUp() {
+ validator = EmailValidator.getInstance();
+ }
+
+ @Override
+protected void tearDown() {
+ }
+
+ /**
+ * Tests the e-mail validation.
+ */
+ public void testEmail() {
+ assertTrue(validator.isValid("jsmith@apache.org"));
+ }
+
+ /**
+ * Tests the email validation with numeric domains.
+ */
+ public void testEmailWithNumericAddress() {
+ assertTrue(validator.isValid("someone@[216.109.118.76]"));
+ assertTrue(validator.isValid("someone@yahoo.com"));
+ }
+
+ /**
+ * Tests the e-mail validation.
+ */
+ public void testEmailExtension() {
+ assertTrue(validator.isValid("jsmith@apache.org"));
+
+ assertTrue(validator.isValid("jsmith@apache.com"));
+
+ assertTrue(validator.isValid("jsmith@apache.net"));
+
+ assertTrue(validator.isValid("jsmith@apache.info"));
+
+ assertFalse(validator.isValid("jsmith@apache."));
+
+ assertFalse(validator.isValid("jsmith@apache.c"));
+
+ assertTrue(validator.isValid("someone@yahoo.museum"));
+
+ assertFalse(validator.isValid("someone@yahoo.mu-seum"));
+ }
+
+ /**
+ * Tests the e-mail validation with a dash in
+ * the address.
+ */
+ public void testEmailWithDash() {
+ assertTrue(validator.isValid("andy.noble@data-workshop.com"));
+
+ assertFalse(validator.isValid("andy-noble@data-workshop.-com"));
+
+ assertFalse(validator.isValid("andy-noble@data-workshop.c-om"));
+
+ assertFalse(validator.isValid("andy-noble@data-workshop.co-m"));
+ }
+
+ /**
+ * Tests the e-mail validation with a dot at the end of
+ * the address.
+ */
+ public void testEmailWithDotEnd() {
+ assertFalse(validator.isValid("andy.noble@data-workshop.com."));
+ }
+
+ /**
+ * Tests the e-mail validation with an RCS-noncompliant character in
+ * the address.
+ */
+ public void testEmailWithBogusCharacter() {
+
+ assertFalse(validator.isValid("andy.noble@\u008fdata-workshop.com"));
+
+ // The ' character is valid in an email username.
+ assertTrue(validator.isValid("andy.o'reilly@data-workshop.com"));
+
+ // But not in the domain name.
+ assertFalse(validator.isValid("andy@o'reilly.data-workshop.com"));
+
+ // The + character is valid in an email username.
+ assertTrue(validator.isValid("foo+bar@i.am.not.in.us.example.com"));
+
+ // But not in the domain name
+ assertFalse(validator.isValid("foo+bar@example+3.com"));
+
+ // Domains with only special characters aren't allowed (VALIDATOR-286)
+ assertFalse(validator.isValid("test@%*.com"));
+ assertFalse(validator.isValid("test@^.com"));
+
+ }
+
+ public void testVALIDATOR_315() {
+ assertFalse(validator.isValid("me@at&t.net"));
+ assertTrue(validator.isValid("me@att.net")); // Make sure TLD is not the cause of the failure
+ }
+
+ public void testVALIDATOR_278() {
+ assertFalse(validator.isValid("someone@-test.com"));// hostname starts with dash/hyphen
+ assertFalse(validator.isValid("someone@test-.com"));// hostname ends with dash/hyphen
+ }
+
+ public void testValidator235() {
+ String version = System.getProperty("java.version");
+ if (version.compareTo("1.6") < 0) {
+ System.out.println("Cannot run Unicode IDN tests");
+ return; // Cannot run the test
+ }
+ assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("someone@xn--d1abbgf6aiiy.xn--p1ai"));
+ assertTrue("президент.рф should validate", validator.isValid("someone@президент.рф"));
+ assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
+ assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
+ assertTrue("www.b\u00fccher.ch should validate", validator.isValid("someone@www.b\u00fccher.ch"));
+ assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("someone@www.\uFFFD.ch"));
+ }
+
+ /**
+ * Tests the email validation with commas.
+ */
+ public void testEmailWithCommas() {
+ assertFalse(validator.isValid("joeblow@apa,che.org"));
+
+ assertFalse(validator.isValid("joeblow@apache.o,rg"));
+
+ assertFalse(validator.isValid("joeblow@apache,org"));
+
+ }
+
+ /**
+ * Tests the email validation with spaces.
+ */
+ public void testEmailWithSpaces() {
+ assertFalse(validator.isValid("joeblow @apache.org"));
+
+ assertFalse(validator.isValid("joeblow@ apache.org"));
+
+ assertFalse(validator.isValid(" joeblow@apache.org"));
+
+ assertFalse(validator.isValid("joeblow@apache.org "));
+
+ assertFalse(validator.isValid("joe blow@apache.org "));
+
+ assertFalse(validator.isValid("joeblow@apa che.org "));
+
+ assertTrue(validator.isValid("\"joeblow \"@apache.org"));
+
+ assertTrue(validator.isValid("\" joeblow\"@apache.org"));
+
+ assertTrue(validator.isValid("\" joe blow \"@apache.org"));
+
+ }
+
+ /**
+ * Tests the email validation with ascii control characters.
+ * (i.e. Ascii chars 0 - 31 and 127)
+ */
+ public void testEmailWithControlChars() {
+ 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"));
+ }
+
+ /**
+ * Test that @localhost and @localhost.localdomain
+ * addresses are declared as valid when requested.
+ */
+ public void testEmailLocalhost() {
+ // Check the default is not to allow
+ EmailValidator noLocal = EmailValidator.getInstance(false);
+ EmailValidator allowLocal = EmailValidator.getInstance(true);
+ assertEquals(validator, noLocal);
+
+ // Depends on the validator
+ assertTrue(
+ "@localhost.localdomain should be accepted but wasn't",
+ allowLocal.isValid("joe@localhost.localdomain")
+ );
+ assertTrue(
+ "@localhost should be accepted but wasn't",
+ allowLocal.isValid("joe@localhost")
+ );
+
+ assertFalse(
+ "@localhost.localdomain should be accepted but wasn't",
+ noLocal.isValid("joe@localhost.localdomain")
+ );
+ assertFalse(
+ "@localhost should be accepted but wasn't",
+ noLocal.isValid("joe@localhost")
+ );
+ }
+
+ /**
+ * VALIDATOR-296 - A / or a ! is valid in the user part,
+ * but not in the domain part
+ */
+ public void testEmailWithSlashes() {
+ assertTrue(
+ "/ and ! valid in username",
+ validator.isValid("joe!/blow@apache.org")
+ );
+ assertFalse(
+ "/ not valid in domain",
+ validator.isValid("joe@ap/ache.org")
+ );
+ assertFalse(
+ "! not valid in domain",
+ validator.isValid("joe@apac!he.org")
+ );
+ }
+
+ /**
+ * Write this test according to parts of RFC, as opposed to the type of character
+ * that is being tested.
+ */
+ public void testEmailUserName() {
+
+ assertTrue(validator.isValid("joe1blow@apache.org"));
+
+ assertTrue(validator.isValid("joe$blow@apache.org"));
+
+ assertTrue(validator.isValid("joe-@apache.org"));
+
+ assertTrue(validator.isValid("joe_@apache.org"));
+
+ assertTrue(validator.isValid("joe+@apache.org")); // + is valid unquoted
+
+ assertTrue(validator.isValid("joe!@apache.org")); // ! is valid unquoted
+
+ assertTrue(validator.isValid("joe*@apache.org")); // * is valid unquoted
+
+ assertTrue(validator.isValid("joe'@apache.org")); // ' is valid unquoted
+
+ assertTrue(validator.isValid("joe%45@apache.org")); // % is valid unquoted
+
+ assertTrue(validator.isValid("joe?@apache.org")); // ? is valid unquoted
+
+ assertTrue(validator.isValid("joe&@apache.org")); // & ditto
+
+ assertTrue(validator.isValid("joe=@apache.org")); // = ditto
+
+ assertTrue(validator.isValid("+joe@apache.org")); // + is valid unquoted
+
+ assertTrue(validator.isValid("!joe@apache.org")); // ! is valid unquoted
+
+ assertTrue(validator.isValid("*joe@apache.org")); // * is valid unquoted
+
+ assertTrue(validator.isValid("'joe@apache.org")); // ' is valid unquoted
+
+ assertTrue(validator.isValid("%joe45@apache.org")); // % is valid unquoted
+
+ assertTrue(validator.isValid("?joe@apache.org")); // ? is valid unquoted
+
+ assertTrue(validator.isValid("&joe@apache.org")); // & ditto
+
+ assertTrue(validator.isValid("=joe@apache.org")); // = ditto
+
+ assertTrue(validator.isValid("+@apache.org")); // + is valid unquoted
+
+ assertTrue(validator.isValid("!@apache.org")); // ! is valid unquoted
+
+ assertTrue(validator.isValid("*@apache.org")); // * is valid unquoted
+
+ assertTrue(validator.isValid("'@apache.org")); // ' is valid unquoted
+
+ assertTrue(validator.isValid("%@apache.org")); // % is valid unquoted
+
+ assertTrue(validator.isValid("?@apache.org")); // ? is valid unquoted
+
+ assertTrue(validator.isValid("&@apache.org")); // & ditto
+
+ assertTrue(validator.isValid("=@apache.org")); // = ditto
+
+
+ //UnQuoted Special characters are invalid
+
+ assertFalse(validator.isValid("joe.@apache.org")); // . not allowed at end of local part
+
+ assertFalse(validator.isValid(".joe@apache.org")); // . not allowed at start of local part
+
+ assertFalse(validator.isValid(".@apache.org")); // . not allowed alone
+
+ assertTrue(validator.isValid("joe.ok@apache.org")); // . allowed embedded
+
+ assertFalse(validator.isValid("joe..ok@apache.org")); // .. not allowed embedded
+
+ assertFalse(validator.isValid("..@apache.org")); // .. not allowed alone
+
+ assertFalse(validator.isValid("joe(@apache.org"));
+
+ assertFalse(validator.isValid("joe)@apache.org"));
+
+ assertFalse(validator.isValid("joe,@apache.org"));
+
+ assertFalse(validator.isValid("joe;@apache.org"));
+
+
+ //Quoted Special characters are valid
+ assertTrue(validator.isValid("\"joe.\"@apache.org"));
+
+ assertTrue(validator.isValid("\".joe\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe+\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe@\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe!\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe*\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe'\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe(\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe)\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe,\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe%45\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe;\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe?\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe&\"@apache.org"));
+
+ assertTrue(validator.isValid("\"joe=\"@apache.org"));
+
+ assertTrue(validator.isValid("\"..\"@apache.org"));
+
+ // escaped quote character valid in quoted string
+ assertTrue(validator.isValid("\"john\\\"doe\"@apache.org"));
+
+ assertTrue(validator.isValid("john56789.john56789.john56789.john56789.john56789.john56789.john@example.com"));
+
+ assertFalse(validator.isValid("john56789.john56789.john56789.john56789.john56789.john56789.john5@example.com"));
+
+ assertTrue(validator.isValid("\\>escape\\\\special\\^characters\\<@example.com"));
+
+ assertTrue(validator.isValid("Abc\\@def@example.com"));
+
+ assertFalse(validator.isValid("Abc@def@example.com"));
+
+ assertTrue(validator.isValid("space\\ monkey@example.com"));
+ }
+
+ /**
+ * 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.
+ */
+ private static final 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 ", true),
+ new ResultPair("Abigail", true),
+ new ResultPair("Abigail<@a,@b,@c:abigail@example.com>", true),
+ new ResultPair("\"This is a phrase\"", true),
+ new ResultPair("\"Abigail \"", true),
+ new ResultPair("\"Joe & J. Harvey\" ", true),
+ new ResultPair("Abigail ", true),
+ new ResultPair("Abigail made this < abigail @ example . com >", true),
+ new ResultPair("Abigail(the bitch)@example.com", true),
+ new ResultPair("Abigail ", 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 ", true),
+ new ResultPair("Abigail ", true),
+ new ResultPair("(foo) abigail@example.com", true),
+ new ResultPair("abigail@example.com (foo)", true),
+ new ResultPair("\"Abi\\\"gail\" ", 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 ", true),
+ new ResultPair("Neuman@BBN-TENEXA", true),
+ new ResultPair("\"George, Ted\" ", 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 ", true),
+ new ResultPair("\"Joe &\\x0D\\x0A J. Harvey\" ", true),
+ new ResultPair("Gourmets: Pompous Person ,\\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 ", false),
+ new ResultPair("Abigail ", false),
+ new ResultPair("Abigail ", false),
+ new ResultPair("\"Abi\"gail\" ", 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
+ *
+ * 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() {
+ for (int index = 0; index < testEmailFromPerl.length; index++) {
+ String item = testEmailFromPerl[index].item;
+ if (testEmailFromPerl[index].valid) {
+ assertTrue("Should be OK: "+item, validator.isValid(item));
+ } else {
+ assertFalse("Should fail: "+item, validator.isValid(item));
+ }
+ }
+ }
+
+ public void testValidator293(){
+ assertTrue(validator.isValid("abc-@abc.com"));
+ assertTrue(validator.isValid("abc_@abc.com"));
+ assertTrue(validator.isValid("abc-def@abc.com"));
+ assertTrue(validator.isValid("abc_def@abc.com"));
+ assertFalse(validator.isValid("abc@abc_def.com"));
+ }
+
+ public void testValidator365() {
+ assertFalse(validator.isValid(
+ "Loremipsumdolorsitametconsecteturadipiscingelit.Nullavitaeligulamattisrhoncusnuncegestasmattisleo."+
+ "Donecnonsapieninmagnatristiquedictumaacturpis.Fusceorciduifacilisisutsapieneuconsequatpharetralectus."+
+ "Quisqueenimestpulvinarutquamvitaeportamattisex.Nullamquismaurisplaceratconvallisjustoquisportamauris."+
+ "Innullalacusconvalliseufringillautvenenatissitametdiam.Maecenasluctusligulascelerisquepulvinarfeugiat."+
+ "Sedmolestienullaaliquetorciluctusidpharetranislfinibus.Suspendissemalesuadatinciduntduisitametportaarcusollicitudinnec."+
+ "Donecetmassamagna.Curabitururnadiampretiumveldignissimporttitorfringillaeuneque."+
+ "Duisantetelluspharetraidtinciduntinterdummolestiesitametfelis.Utquisquamsitametantesagittisdapibusacnonodio."+
+ "Namrutrummolestiediamidmattis.Cumsociisnatoquepenatibusetmagnisdisparturientmontesnasceturridiculusmus."+
+ "Morbiposueresedmetusacconsectetur.Etiamquisipsumvitaejustotempusmaximus.Sedultriciesplaceratvolutpat."+
+ "Integerlacuslectusmaximusacornarequissagittissitametjusto."+
+ "Cumsociisnatoquepenatibusetmagnisdisparturientmontesnasceturridiculusmus.Maecenasindictumpurussedrutrumex.Nullafacilisi."+
+ "Integerfinibusfinibusmietpharetranislfaucibusvel.Maecenasegetdolorlacinialobortisjustovelullamcorpersem."+
+ "Vivamusaliquetpurusidvariusornaresapienrisusrutrumnisitinciduntmollissemnequeidmetus."+
+ "Etiamquiseleifendpurus.Nuncfelisnuncscelerisqueiddignissimnecfinibusalibero."+
+ "Nuncsemperenimnequesitamethendreritpurusfacilisisac.Maurisdapibussemperfelisdignissimgravida."+
+ "Aeneanultricesblanditnequealiquamfinibusodioscelerisqueac.Aliquamnecmassaeumaurisfaucibusfringilla."+
+ "Etiamconsequatligulanisisitametaliquamnibhtemporquis.Nuncinterdumdignissimnullaatsodalesarcusagittiseu."+
+ "Proinpharetrametusneclacuspulvinarsedvolutpatliberoornare.Sedligulanislpulvinarnonlectuseublanditfacilisisante."+
+ "Sedmollisnislalacusauctorsuscipit.Inhachabitasseplateadictumst.Phasellussitametvelittemporvenenatisfeliseuegestasrisus."+
+ "Aliquameteratsitametnibhcommodofinibus.Morbiefficiturodiovelpulvinariaculis."+
+ "Aeneantemporipsummassaaconsecteturturpisfaucibusultrices.Praesentsodalesmaurisquisportafermentum."+
+ "Etiamnisinislvenenatisvelauctorutullamcorperinjusto.Proinvelligulaerat.Phasellusvestibulumgravidamassanonfeugiat."+
+ "Maecenaspharetraeuismodmetusegetefficitur.Suspendisseamet@gmail.com"));
+ }
+
+ /**
+ * Tests the e-mail validation with a user at a TLD
+ *
+ * http://tools.ietf.org/html/rfc5321#section-2.3.5
+ * (In the case of a top-level domain used by itself in an
+ * email address, a single string is used without any dots)
+ */
+ public void testEmailAtTLD() {
+ EmailValidator val = EmailValidator.getInstance(false, true);
+ assertTrue(val.isValid("test@com"));
+ }
+
+ public void testValidator359() {
+ EmailValidator val = EmailValidator.getInstance(false, true);
+ assertFalse(val.isValid("test@.com"));
+ }
+
+ public void testValidator374() {
+ assertTrue(validator.isValid("abc@school.school"));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java
new file mode 100644
index 000000000..ccf2703ea
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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 java.text.DecimalFormat;
+import java.util.Locale;
+
+/**
+ * Test Case for FloatValidator.
+ *
+ * @version $Revision$
+ */
+public class FloatValidatorTest extends AbstractNumberValidatorTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public FloatValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new FloatValidator(false, 0);
+ strictValidator = new FloatValidator();
+
+ testPattern = "#,###.#";
+
+ // testValidateMinMax()
+ max = Float.valueOf(Float.MAX_VALUE);
+ maxPlusOne = Double.valueOf(max.doubleValue() * 10);
+ min = Float.valueOf(Float.MAX_VALUE * -1);
+ minMinusOne = Double.valueOf(min.doubleValue() * 10);
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2"};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12"};
+
+ // testValid()
+ testNumber = Float.valueOf(1234.5f);
+ testZero = Float.valueOf(0);
+ validStrict = new String[] {"0", "1234.5", "1,234.5"};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber};
+ valid = new String[] {"0", "1234.5", "1,234.5", "1,234.5", "1234.5X"};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+ testStringUS = "1,234.5";
+ testStringDE = "1.234,5";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###,#";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test FloatValidator validate Methods
+ */
+ public void testFloatValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String localeVal = "12.345";
+ String germanPatternVal = "1.23.45";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ Float expected = Float.valueOf(12345);
+ assertEquals("validate(A) default", expected, FloatValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, FloatValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, FloatValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, FloatValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", FloatValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", FloatValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", FloatValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", FloatValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", FloatValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", FloatValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", FloatValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", FloatValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", FloatValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", FloatValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", FloatValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", FloatValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Float validation for values too small to handle.
+ * (slightly different from max/min which are the largest +ve/-ve
+ */
+ public void testFloatSmallestValues() {
+ String pattern = "#.#################################################################";
+ DecimalFormat fmt = new DecimalFormat(pattern);
+
+ // Validate Smallest +ve value
+ Float smallestPositive = Float.valueOf(Float.MIN_VALUE);
+ String strSmallestPositive = fmt.format(smallestPositive);
+ assertEquals("Smallest +ve", smallestPositive, FloatValidator.getInstance().validate(strSmallestPositive, pattern));
+
+ // Validate Smallest -ve value
+ Float smallestNegative = Float.valueOf(Float.MIN_VALUE * -1);
+ String strSmallestNegative = fmt.format(smallestNegative);
+ assertEquals("Smallest -ve", smallestNegative, FloatValidator.getInstance().validate(strSmallestNegative, pattern));
+
+ // Validate Too Small +ve
+ Double tooSmallPositive = Double.valueOf(((double)Float.MIN_VALUE / (double)10));
+ String strTooSmallPositive = fmt.format(tooSmallPositive);
+ assertFalse("Too small +ve", FloatValidator.getInstance().isValid(strTooSmallPositive, pattern));
+
+ // Validate Too Small -ve
+ Double tooSmallNegative = Double.valueOf(tooSmallPositive.doubleValue() * -1);
+ String strTooSmallNegative = fmt.format(tooSmallNegative);
+ assertFalse("Too small -ve", FloatValidator.getInstance().isValid(strTooSmallNegative, pattern));
+ }
+
+ /**
+ * Test Float Range/Min/Max
+ */
+ public void testFloatRangeMinMax() {
+ FloatValidator validator = (FloatValidator)strictValidator;
+ Float number9 = validator.validate("9", "#");
+ Float number10 = validator.validate("10", "#");
+ Float number11 = validator.validate("11", "#");
+ Float number19 = validator.validate("19", "#");
+ Float number20 = validator.validate("20", "#");
+ Float number21 = validator.validate("21", "#");
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
+ assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
+ assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+ assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
+ assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, 10));
+ assertTrue("minValue() = min", validator.minValue(number10, 10));
+ assertTrue("minValue() > min", validator.minValue(number11, 10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, 20));
+ assertTrue("maxValue() = max", validator.maxValue(number20, 20));
+ assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
new file mode 100644
index 000000000..beb74502c
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
@@ -0,0 +1,362 @@
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.apache.commons.validator.routines.IBANValidator.Validator;
+import org.apache.commons.validator.routines.checkdigit.IBANCheckDigit;
+import org.junit.Test;
+
+/**
+ * IBANValidator Test Case.
+ * @since 1.5.0
+ */
+public class IBANValidatorTest {
+
+ // It's not clear whether IBANs can contain lower case characters
+ // so we test for both where possible
+ // Note that the BIC near the start of the code is always upper case or digits
+ private final String[] validIBANFormat = new String[] {
+ "AD1200012030200359100100",
+ "AE070331234567890123456",
+ "AL47212110090000000235698741",
+ "AT611904300234573201",
+ "AZ21NABZ00000000137010001944",
+ "BA391290079401028494",
+ "BE68539007547034",
+ "BG80BNBG96611020345678",
+ "BH67BMAG00001299123456",
+ "BR1800000000141455123924100C2",
+ "BR1800360305000010009795493C1",
+ "BR9700360305000010009795493P1",
+ "BY13NBRB3600900000002Z00AB00",
+ "CH9300762011623852957",
+ "CR05015202001026284066",
+ "CY17002001280000001200527600",
+ "CZ6508000000192000145399",
+ "CZ9455000000001011038930",
+ "DE89370400440532013000",
+ "DK5000400440116243",
+ "DO28BAGR00000001212453611324",
+ "EE382200221020145685",
+ "EG380019000500000000263180002",
+ "ES9121000418450200051332",
+ "FI2112345600000785",
+ "FI5542345670000081",
+ "FO6264600001631634",
+ "FR1420041010050500013M02606",
+ "GB29NWBK60161331926819",
+ "GE29NB0000000101904917",
+ "GI75NWBK000000007099453",
+ "GL8964710001000206",
+ "GR1601101250000000012300695",
+ "GT82TRAJ01020000001210029690",
+ "HR1210010051863000160",
+ "HU42117730161111101800000000",
+ "IE29AIBK93115212345678",
+ "IL620108000000099999999",
+ "IQ98NBIQ850123456789012",
+ "IS140159260076545510730339",
+ "IT60X0542811101000000123456",
+ "JO94CBJO0010000000000131000302",
+ "KW81CBKU0000000000001234560101",
+ "KZ86125KZT5004100100",
+ "LB62099900000001001901229114",
+ "LC55HEMM000100010012001200023015",
+ "LI21088100002324013AA",
+ "LT121000011101001000",
+ "LU280019400644750000",
+ "LV80BANK0000435195001",
+ "MC5811222000010123456789030",
+ "MD24AG000225100013104168",
+ "ME25505000012345678951",
+ "MK07250120000058984",
+ "MR1300020001010000123456753",
+ "MT84MALT011000012345MTLCAST001S",
+ "MU17BOMM0101101030300200000MUR",
+ "NL91ABNA0417164300",
+ "NO9386011117947",
+ "PK36SCBL0000001123456702",
+ "PL61109010140000071219812874",
+ "PS92PALS000000000400123456702",
+ "PT50000201231234567890154",
+ "QA58DOHB00001234567890ABCDEFG",
+ "RO49AAAA1B31007593840000",
+ "RS35260005601001611379",
+ "SA0380000000608010167519",
+ "SC18SSCB11010000000000001497USD",
+ "SE4550000000058398257466",
+ "SI56191000000123438",
+ "SI56263300012039086",
+ "SK3112000000198742637541",
+ "SM86U0322509800000000270100",
+ "ST68000100010051845310112",
+ "SV62CENR00000000000000700025",
+ "SV43ACAT00000000000000123123",
+ "TL380080012345678910157",
+ "TN5910006035183598478831",
+ "TR330006100519786457841326",
+ "UA213223130000026007233566001",
+ "UA213996220000026007233566001",
+ "VA59001123000012345678",
+ "VG96VPVG0000012345678901",
+ "XK051212012345678906",
+ };
+
+ private final String[] invalidIBANFormat = new String[] {
+ "", // empty
+ " ", // empty
+ "A", // too short
+ "AB", // too short
+ "FR1420041010050500013m02606", // lowercase version
+ "MT84MALT011000012345mtlcast001s", // lowercase version
+ "LI21088100002324013aa", // lowercase version
+ "QA58DOHB00001234567890abcdefg", // lowercase version
+ "RO49AAAA1b31007593840000", // lowercase version
+ "LC62HEMM000100010012001200023015", // wrong in SWIFT
+ "BY00NBRB3600000000000Z00AB00", // Wrong in SWIFT v73
+ "ST68000200010192194210112", // ditto
+ "SV62CENR0000000000000700025", // ditto
+ };
+
+ private static final IBANValidator VALIDATOR = IBANValidator.getInstance();
+
+ @Test
+ public void testValid() {
+ for(String f : validIBANFormat) {
+ assertTrue("Checksum fail: "+f, IBANCheckDigit.IBAN_CHECK_DIGIT.isValid(f));
+ assertTrue("Missing validator: "+f, VALIDATOR.hasValidator(f));
+ assertTrue(f, VALIDATOR.isValid(f));
+ }
+ }
+
+ @Test
+ public void testInValid() {
+ for(String f : invalidIBANFormat) {
+ assertFalse(f, VALIDATOR.isValid(f));
+ }
+ }
+
+ @Test
+ public void testNull() {
+ assertFalse("isValid(null)", VALIDATOR.isValid(null));
+ }
+
+ @Test
+ public void testHasValidator() {
+ assertTrue("GB", VALIDATOR.hasValidator("GB"));
+ assertFalse("gb", VALIDATOR.hasValidator("gb"));
+ }
+
+ @Test
+ public void testGetValidator() {
+ assertNotNull("GB", VALIDATOR.getValidator("GB"));
+ assertNull("gb", VALIDATOR.getValidator("gb"));
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testSetDefaultValidator1() {
+ assertNotNull(VALIDATOR.setValidator("GB", 15, "GB"));
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testSetDefaultValidator2() {
+ assertNotNull(VALIDATOR.setValidator("GB", -1, "GB"));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testSetValidatorLC() {
+ IBANValidator validator = new IBANValidator();
+ assertNotNull(validator.setValidator("gb", 15, "GB"));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testSetValidatorLen7() {
+ IBANValidator validator = new IBANValidator();
+ assertNotNull(validator.setValidator("GB", 7, "GB"));
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testSetValidatorLen35() {
+ IBANValidator validator = new IBANValidator();
+ assertNotNull(validator.setValidator("GB", 35, "GB")); // valid params, but immutable validator
+ }
+
+ @Test
+ public void testSetValidatorLen_1() {
+ IBANValidator validator = new IBANValidator();
+ assertNotNull("should be present",validator.setValidator("GB", -1, ""));
+ assertNull("no longer present",validator.setValidator("GB", -1, ""));
+ }
+
+ @Test
+ public void testSorted() {
+ IBANValidator validator = new IBANValidator();
+ Validator[] vals = validator.getDefaultValidators();
+ assertNotNull(vals);
+ for(int i=1; i < vals.length; i++) {
+ if (vals[i].countryCode.compareTo(vals[i-1].countryCode) <= 0) {
+ fail("Not sorted: "+vals[i].countryCode+ " <= " + vals[i-1].countryCode);
+ }
+ }
+ }
+
+ private static void checkIBAN(File file, IBANValidator val) throws Exception {
+ // The IBAN Registry (TXT) file is a TAB-separated file
+ // Rows are the entry types, columns are the countries
+ CSVFormat format = CSVFormat.DEFAULT.withDelimiter('\t');
+ Reader rdr = new InputStreamReader(new FileInputStream(file), "ISO_8859_1");
+ CSVParser p = new CSVParser(rdr, format);
+ CSVRecord country = null;
+ CSVRecord cc = null;
+ CSVRecord structure = null;
+ CSVRecord length = null;
+ for (CSVRecord o : p) {
+ String item = o.get(0);
+ if ("Name of country".equals(item)) {
+ country = o;
+ } else if ("IBAN prefix country code (ISO 3166)".equals(item)) {
+ cc = o;
+ } else if ("IBAN structure".equals(item)) {
+ structure = o;
+ } else if ("IBAN length".equals(item)) {
+ length = o;
+ }
+ }
+ for (int i=1; i < country.size(); i++) {
+ String newLength = length.get(i).split("!")[0]; // El Salvador currently has "28!n"
+ String newRE = fmtRE(structure.get(i), Integer.parseInt(newLength));
+ final Validator valre = val.getValidator(cc.get(i));
+ if (valre == null) {
+ System.out.println("// Missing entry:");
+ printEntry(
+ cc.get(i),
+ newLength,
+ newRE,
+ country.get(i));
+ } else {
+ String currentLength = Integer.toString(valre.lengthOfIBAN);
+ String currentRE = valre.validator.toString()
+ .replaceAll("^.+?\\{(.+)}","$1") // Extract RE from RegexValidator{re} string
+ .replaceAll("\\\\d","\\\\\\\\d"); // convert \d to \\d
+ // The above assumes that the RegexValidator contains a single Regex
+ if (currentRE.equals(newRE) && currentLength.equals(newLength)) {
+
+ } else {
+ System.out.println("// Expected: " + newRE + ", " + newLength + " Actual: " + currentRE + ", " + currentLength);
+ printEntry(
+ cc.get(i),
+ newLength,
+ newRE,
+ country.get(i));
+ }
+
+ }
+ }
+ p.close();
+ }
+
+ private static void printEntry(String ccode, String length, String ib, String country) {
+ String fmt = String.format("\"%s\"", ib);
+ System.out.printf(" new Validator(\"%s\", %s, %-40s), // %s\n",
+ ccode,
+ length,
+ fmt,
+ country);
+ }
+
+ // Unfortunately Java only returns the last match of repeated patterns
+ // Use a manual repeat instead
+ private static final String IBAN_PART = "(?:(\\d+)!([acn]))"; // Assume all parts are fixed length
+ private static final Pattern IBAN_PAT = Pattern.compile(
+ "([A-Z]{2})"+IBAN_PART+IBAN_PART+IBAN_PART+IBAN_PART+"?"+IBAN_PART+"?"+IBAN_PART+"?"+IBAN_PART+"?");
+
+ // convert IBAN type string and length to regex
+ private static String formatToRE(String type, int len) {
+ char ctype = type.charAt(0); // assume type.length() == 1
+ switch(ctype) {
+ case 'n':
+ return String.format("\\\\d{%d}",len);
+ case 'a':
+ return String.format("[A-Z]{%d}",len);
+ case 'c':
+ return String.format("[A-Z0-9]{%d}",len);
+ default:
+ throw new IllegalArgumentException("Unexpected type " + type);
+ }
+ }
+
+ private static String fmtRE(String iban_pat, int iban_len) {
+ Matcher m = IBAN_PAT.matcher(iban_pat);
+ if (m.matches()) {
+ StringBuilder sb = new StringBuilder();
+ String cc = m.group(1); // country code
+ int totalLen = cc.length();
+ sb.append(cc);
+ int len = Integer.parseInt(m.group(2)); // length of part
+ String curType = m.group(3); // part type
+ for (int i = 4; i <= m.groupCount(); i += 2) {
+ if (m.group(i) == null) { // reached an optional group
+ break;
+ }
+ int count = Integer.parseInt(m.group(i));
+ String type = m.group(i+1);
+ if (type.equals(curType)) { // more of the same type
+ len += count;
+ } else {
+ sb.append(formatToRE(curType,len));
+ totalLen += len;
+ curType = type;
+ len = count;
+ }
+ }
+ sb.append(formatToRE(curType,len));
+ totalLen += len;
+ if (iban_len != totalLen) {
+ throw new IllegalArgumentException("IBAN pattern " + iban_pat + " does not match length " + iban_len);
+ }
+ return sb.toString();
+ } else {
+ throw new IllegalArgumentException("Unexpected IBAN pattern " + iban_pat);
+ }
+ }
+
+ public static void main(String [] a) throws Exception {
+ IBANValidator validator = new IBANValidator();
+ File iban_tsv = new File("target","iban-registry.tsv");
+ if (iban_tsv.canRead()) {
+ checkIBAN(iban_tsv, validator);
+ } else {
+ System.out.println("Please load the file " + iban_tsv.getCanonicalPath() + " from https://www.swift.com/standards/data-standards/iban");
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISBNValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISBNValidatorTest.java
new file mode 100644
index 000000000..95637093f
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISBNValidatorTest.java
@@ -0,0 +1,326 @@
+/*
+ * 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 java.util.regex.Pattern;
+import junit.framework.TestCase;
+
+/**
+ * ISBNValidator Test Case.
+ *
+ * @version $Revision$
+ */
+public class ISBNValidatorTest extends TestCase {
+
+ private final String[] validISBN10Format = new String[] {
+ "1234567890",
+ "123456789X",
+ "12345-1234567-123456-X",
+ "12345 1234567 123456 X",
+ "1-2-3-4",
+ "1 2 3 4",
+ };
+
+ private final String[] invalidISBN10Format = new String[] {
+ "", // empty
+ " ", // empty
+ "1", // too short
+ "123456789", // too short
+ "12345678901", // too long
+ "12345678X0", // X not at end
+ "123456-1234567-123456-X", // Group too long
+ "12345-12345678-123456-X", // Publisher too long
+ "12345-1234567-1234567-X", // Title too long
+ "12345-1234567-123456-X2", // Check Digit too long
+ "--1 930110 99 5", // format
+ "1 930110 99 5--", // format
+ "1 930110-99 5-", // format
+ "1.2.3.4", // Invalid Separator
+ "1=2=3=4", // Invalid Separator
+ "1_2_3_4", // Invalid Separator
+ "123456789Y", // Other character at the end
+ "dsasdsadsa", // invalid characters
+ "I love sparrows!", // invalid characters
+ "068-556-98-45" // format
+ };
+
+ private final String[] validISBN13Format = new String[] {
+ "9781234567890",
+ "9791234567890",
+ "978-12345-1234567-123456-1",
+ "979-12345-1234567-123456-1",
+ "978 12345 1234567 123456 1",
+ "979 12345 1234567 123456 1",
+ "978-1-2-3-4",
+ "979-1-2-3-4",
+ "978 1 2 3 4",
+ "979 1 2 3 4",
+ };
+
+ private final String[] invalidISBN13Format = new String[] {
+ "", // empty
+ " ", // empty
+ "1", // too short
+ "978123456789", // too short
+ "97812345678901", // too long
+ "978-123456-1234567-123456-1", // Group too long
+ "978-12345-12345678-123456-1", // Publisher too long
+ "978-12345-1234567-1234567-1", // Title too long
+ "978-12345-1234567-123456-12", // Check Digit too long
+ "--978 1 930110 99 1", // format
+ "978 1 930110 99 1--", // format
+ "978 1 930110-99 1-", // format
+ "123-4-567890-12-8", // format
+ "978.1.2.3.4", // Invalid Separator
+ "978=1=2=3=4", // Invalid Separator
+ "978_1_2_3_4", // Invalid Separator
+ "978123456789X", // invalid character
+ "978-0-201-63385-X", // invalid character
+ "dsasdsadsadsa", // invalid characters
+ "I love sparrows!", // invalid characters
+ "979-1-234-567-89-6" // format
+ };
+
+ /**
+ * Create a test case with the specified name.
+ * @param name The name of the test
+ */
+ public ISBNValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test Valid ISBN-10 formats.
+ */
+ public void testValidISBN10Format() {
+ Pattern pattern = Pattern.compile(ISBNValidator.ISBN10_REGEX);
+ for (int i = 0; i < validISBN10Format.length; i++) {
+ assertTrue("Pattern[" + i + "]=" + validISBN10Format[i], pattern.matcher(validISBN10Format[i]).matches());
+ }
+ }
+
+ /**
+ * Test Invalid ISBN-10 formats.
+ */
+ public void testInvalidISBN10Format() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ Pattern pattern = Pattern.compile(ISBNValidator.ISBN10_REGEX);
+ for (int i = 0; i < invalidISBN10Format.length; i++) {
+ assertFalse("Pattern[" + i + "]=" + invalidISBN10Format[i], pattern.matcher(invalidISBN10Format[i]).matches());
+ assertFalse("isValidISBN10[" + i + "]=" + invalidISBN10Format[i], validator.isValidISBN10(invalidISBN10Format[i]));
+ assertNull("validateISBN10[" + i + "]=" + invalidISBN10Format[i], validator.validateISBN10(invalidISBN10Format[i]));
+ }
+ }
+
+ /**
+ * Test Valid ISBN-13 formats.
+ */
+ public void testValidISBN13Format() {
+ Pattern pattern = Pattern.compile(ISBNValidator.ISBN13_REGEX);
+ for (int i = 0; i < validISBN13Format.length; i++) {
+ assertTrue("Pattern[" + i + "]=" + validISBN13Format[i], pattern.matcher(validISBN13Format[i]).matches());
+ }
+ }
+
+ /**
+ * Test Invalid ISBN-13 formats.
+ */
+ public void testInvalidISBN13Format() {
+ Pattern pattern = Pattern.compile(ISBNValidator.ISBN13_REGEX);
+ ISBNValidator validator = ISBNValidator.getInstance();
+ for (int i = 0; i < invalidISBN13Format.length; i++) {
+ assertFalse("Pattern[" + i + "]=" + invalidISBN13Format[i], pattern.matcher(invalidISBN13Format[i]).matches());
+ assertFalse("isValidISBN13[" + i + "]=" + invalidISBN13Format[i], validator.isValidISBN13(invalidISBN13Format[i]));
+ assertNull("validateISBN13[" + i + "]=" + invalidISBN13Format[i], validator.validateISBN13(invalidISBN13Format[i]));
+ }
+ }
+
+ /**
+ * Test isValid() ISBN-10 codes
+ */
+ public void testIsValidISBN10() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ assertTrue("isValidISBN10-1", validator.isValidISBN10("1930110995"));
+ assertTrue("isValidISBN10-2", validator.isValidISBN10("1-930110-99-5"));
+ assertTrue("isValidISBN10-3", validator.isValidISBN10("1 930110 99 5"));
+ assertTrue("isValidISBN10-4", validator.isValidISBN10("020163385X"));
+ assertTrue("isValidISBN10-5", validator.isValidISBN10("0-201-63385-X"));
+ assertTrue("isValidISBN10-6", validator.isValidISBN10("0 201 63385 X"));
+
+ assertTrue("isValid-1", validator.isValid("1930110995"));
+ assertTrue("isValid-2", validator.isValid("1-930110-99-5"));
+ assertTrue("isValid-3", validator.isValid("1 930110 99 5"));
+ assertTrue("isValid-4", validator.isValid("020163385X"));
+ assertTrue("isValid-5", validator.isValid("0-201-63385-X"));
+ assertTrue("isValid-6", validator.isValid("0 201 63385 X"));
+ }
+
+ /**
+ * Test isValid() ISBN-13 codes
+ */
+ public void testIsValidISBN13() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ assertTrue("isValidISBN13-1", validator.isValidISBN13("9781930110991"));
+ assertTrue("isValidISBN13-2", validator.isValidISBN13("978-1-930110-99-1"));
+ assertTrue("isValidISBN13-3", validator.isValidISBN13("978 1 930110 99 1"));
+ assertTrue("isValidISBN13-4", validator.isValidISBN13("9780201633856"));
+ assertTrue("isValidISBN13-5", validator.isValidISBN13("978-0-201-63385-6"));
+ assertTrue("isValidISBN13-6", validator.isValidISBN13("978 0 201 63385 6"));
+
+ assertTrue("isValid-1", validator.isValid("9781930110991"));
+ assertTrue("isValid-2", validator.isValid("978-1-930110-99-1"));
+ assertTrue("isValid-3", validator.isValid("978 1 930110 99 1"));
+ assertTrue("isValid-4", validator.isValid("9780201633856"));
+ assertTrue("isValid-5", validator.isValid("978-0-201-63385-6"));
+ assertTrue("isValid-6", validator.isValid("978 0 201 63385 6"));
+ }
+
+ /**
+ * Test validate() ISBN-10 codes (don't convert)
+ */
+ public void testValidateISBN10() {
+ ISBNValidator validator = ISBNValidator.getInstance(false);
+ assertEquals("validateISBN10-1", "1930110995", validator.validateISBN10("1930110995"));
+ assertEquals("validateISBN10-2", "1930110995", validator.validateISBN10("1-930110-99-5"));
+ assertEquals("validateISBN10-3", "1930110995", validator.validateISBN10("1 930110 99 5"));
+ assertEquals("validateISBN10-4", "020163385X", validator.validateISBN10("020163385X"));
+ assertEquals("validateISBN10-5", "020163385X", validator.validateISBN10("0-201-63385-X"));
+ assertEquals("validateISBN10-6", "020163385X", validator.validateISBN10("0 201 63385 X"));
+
+ assertEquals("validate-1", "1930110995", validator.validate("1930110995"));
+ assertEquals("validate-2", "1930110995", validator.validate("1-930110-99-5"));
+ assertEquals("validate-3", "1930110995", validator.validate("1 930110 99 5"));
+ assertEquals("validate-4", "020163385X", validator.validate("020163385X"));
+ assertEquals("validate-5", "020163385X", validator.validate("0-201-63385-X"));
+ assertEquals("validate-6", "020163385X", validator.validate("0 201 63385 X"));
+ }
+
+ /**
+ * Test validate() ISBN-10 codes (convert)
+ */
+ public void testValidateISBN10Convert() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ assertEquals("validate-1", "9781930110991", validator.validate("1930110995"));
+ assertEquals("validate-2", "9781930110991", validator.validate("1-930110-99-5"));
+ assertEquals("validate-3", "9781930110991", validator.validate("1 930110 99 5"));
+ assertEquals("validate-4", "9780201633856", validator.validate("020163385X"));
+ assertEquals("validate-5", "9780201633856", validator.validate("0-201-63385-X"));
+ assertEquals("validate-6", "9780201633856", validator.validate("0 201 63385 X"));
+ }
+
+ /**
+ * Test validate() ISBN-13 codes
+ */
+ public void testValidateISBN13() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ assertEquals("validateISBN13-1", "9781930110991", validator.validateISBN13("9781930110991"));
+ assertEquals("validateISBN13-2", "9781930110991", validator.validateISBN13("978-1-930110-99-1"));
+ assertEquals("validateISBN13-3", "9781930110991", validator.validateISBN13("978 1 930110 99 1"));
+ assertEquals("validateISBN13-4", "9780201633856", validator.validateISBN13("9780201633856"));
+ assertEquals("validateISBN13-5", "9780201633856", validator.validateISBN13("978-0-201-63385-6"));
+ assertEquals("validateISBN13-6", "9780201633856", validator.validateISBN13("978 0 201 63385 6"));
+
+ assertEquals("validate-1", "9781930110991", validator.validate("9781930110991"));
+ assertEquals("validate-2", "9781930110991", validator.validate("978-1-930110-99-1"));
+ assertEquals("validate-3", "9781930110991", validator.validate("978 1 930110 99 1"));
+ assertEquals("validate-4", "9780201633856", validator.validate("9780201633856"));
+ assertEquals("validate-5", "9780201633856", validator.validate("978-0-201-63385-6"));
+ assertEquals("validate-6", "9780201633856", validator.validate("978 0 201 63385 6"));
+ }
+
+ /**
+ * Test null values
+ */
+ public void testNull() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ assertFalse("isValid", validator.isValid(null));
+ assertFalse("isValidISBN10", validator.isValidISBN10(null));
+ assertFalse("isValidISBN13", validator.isValidISBN13(null));
+ assertNull("validate", validator.validate(null));
+ assertNull("validateISBN10", validator.validateISBN10(null));
+ assertNull("validateISBN13", validator.validateISBN13(null));
+ assertNull("convertToISBN13", validator.convertToISBN13(null));
+ }
+
+ /**
+ * Test Invalid ISBN-10 codes
+ */
+ public void testInvalid() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ String baseCode = "193011099";
+ assertFalse("ISBN10-0", validator.isValid(baseCode + "0"));
+ assertFalse("ISBN10-1", validator.isValid(baseCode + "1"));
+ assertFalse("ISBN10-2", validator.isValid(baseCode + "2"));
+ assertFalse("ISBN10-3", validator.isValid(baseCode + "3"));
+ assertFalse("ISBN10-4", validator.isValid(baseCode + "4"));
+ assertTrue("ISBN10-5", validator.isValid(baseCode + "5")); // valid check digit
+ assertFalse("ISBN10-6", validator.isValid(baseCode + "6"));
+ assertFalse("ISBN10-7", validator.isValid(baseCode + "7"));
+ assertFalse("ISBN10-8", validator.isValid(baseCode + "8"));
+ assertFalse("ISBN10-9", validator.isValid(baseCode + "9"));
+ assertFalse("ISBN10-X", validator.isValid(baseCode + "X"));
+
+ baseCode = "978193011099";
+ assertFalse("ISBN13-0", validator.isValid(baseCode + "0"));
+ assertTrue("ISBN13-1", validator.isValid(baseCode + "1")); // valid check digit
+ assertFalse("ISBN13-2", validator.isValid(baseCode + "2"));
+ assertFalse("ISBN13-3", validator.isValid(baseCode + "3"));
+ assertFalse("ISBN13-4", validator.isValid(baseCode + "4"));
+ assertFalse("ISBN13-5", validator.isValid(baseCode + "5"));
+ assertFalse("ISBN13-6", validator.isValid(baseCode + "6"));
+ assertFalse("ISBN13-7", validator.isValid(baseCode + "7"));
+ assertFalse("ISBN13-8", validator.isValid(baseCode + "8"));
+ assertFalse("ISBN13-9", validator.isValid(baseCode + "9"));
+ }
+
+ /**
+ * Test method for {@link org.apache.commons.validator.routines.ISBNValidator#convertToISBN13(java.lang.String)}.
+ */
+ public void testConversionErrors() {
+ ISBNValidator validator = ISBNValidator.getInstance();
+ String input = null;
+ try {
+ input = "123456789 ";
+ validator.convertToISBN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ try {
+ input = "12345678901";
+ validator.convertToISBN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ try {
+ input = "";
+ validator.convertToISBN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ try {
+ input = "X234567890";
+ validator.convertToISBN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISINValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISINValidatorTest.java
new file mode 100644
index 000000000..afcecad37
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISINValidatorTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.TestCase;
+
+/**
+ * ISINValidator Test Case.
+ *
+ * @since 1.7
+ */
+public class ISINValidatorTest extends TestCase {
+
+ private static final ISINValidator VALIDATOR_TRUE = ISINValidator.getInstance(true);
+
+ private static final ISINValidator VALIDATOR_FALSE = ISINValidator.getInstance(false);
+
+ private final String[] validFormat = new String[] {
+ "US0378331005",
+ "BMG8571G1096",
+ "AU0000XVGZA3",
+ "GB0002634946",
+ "FR0004026250",
+ "DK0009763344",
+ "GB00B03MLX29",
+ "US7562071065",
+ "US56845T3059",
+ "LU0327357389",
+ "US032511BN64",
+ "INE112A01023",
+ "EZ0000000003", // Invented; for use in ISINValidator
+ "XS0000000009",
+ };
+
+ private final String[] invalidFormat = new String[] {
+ null,
+ "", // empty
+ " ", // empty
+ "US037833100O", // proper check digit is '5', see above
+ "BMG8571G109D", // proper check digit is '6', see above
+ "AU0000XVGZAD", // proper check digit is '3', see above
+ "GB000263494I", // proper check digit is '6', see above
+ "FR000402625C", // proper check digit is '0', see above
+ "DK000976334H", // proper check digit is '4', see above
+ "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
+ "AU0000xvgzA3", // disallow lower case NSIN
+ "gb0002634946", // disallow lower case ISO code
+ };
+
+ // Invalid codes if country checking is enabled
+ private final String[] invalidFormatTrue = new String[] {
+ "AA0000000006", // Invalid country code
+ };
+
+ public ISINValidatorTest(String name) {
+ super(name);
+ }
+
+ public void testIsValidTrue() {
+ for(String f : validFormat) {
+ assertTrue(f, VALIDATOR_TRUE.isValid(f));
+ }
+ }
+
+ public void testInvalidTrue() {
+ for(String f : invalidFormat) {
+ assertFalse(f, VALIDATOR_TRUE.isValid(f));
+ }
+ for(String f : invalidFormatTrue) {
+ assertFalse(f, VALIDATOR_TRUE.isValid(f));
+ }
+ }
+
+ public void testIsValidFalse() {
+ for(String f : validFormat) {
+ assertTrue(f, VALIDATOR_FALSE.isValid(f));
+ }
+ }
+
+ public void testInvalidFalse() {
+ for(String f : invalidFormat) {
+ assertFalse(f, VALIDATOR_FALSE.isValid(f));
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISSNValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISSNValidatorTest.java
new file mode 100644
index 000000000..2f7c10735
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ISSNValidatorTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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 java.util.Random;
+
+import org.apache.commons.validator.routines.checkdigit.CheckDigit;
+import org.apache.commons.validator.routines.checkdigit.EAN13CheckDigit;
+
+import junit.framework.TestCase;
+
+/**
+ * ISSNValidator Test Case.
+ *
+ * @since 1.5.0
+ */
+public class ISSNValidatorTest extends TestCase {
+
+ private static final ISSNValidator VALIDATOR = ISSNValidator.getInstance();
+
+ private final String[] validFormat = new String[] {
+ "ISSN 0317-8471",
+ "1050-124X",
+ "ISSN 1562-6865",
+ "1063-7710",
+ "1748-7188",
+ "ISSN 0264-2875",
+ "1750-0095",
+ "1188-1534",
+ "1911-1479",
+ "ISSN 1911-1460",
+ "0001-6772",
+ "1365-201X",
+ "0264-3596",
+ "1144-875X",
+ };
+
+ private final String[] invalidFormat = new String[] {
+ "", // empty
+ " ", // empty
+ "ISBN 0317-8471", // wrong prefix
+ "'1050-124X", // leading garbage
+ "ISSN1562-6865", // missing separator
+ "10637710", // missing separator
+ "1748-7188'", // trailing garbage
+ "ISSN 0264-2875", // extra space
+ "1750 0095", // invalid separator
+ "1188_1534", // invalid separator
+ "1911-1478", // invalid checkdigit
+ };
+
+ /**
+ * Create a test case with the specified name.
+ * @param name The name of the test
+ */
+ public ISSNValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test isValid() ISSN codes
+ */
+ public void testIsValidISSN() {
+ for(String f : validFormat) {
+ assertTrue(f, VALIDATOR.isValid(f));
+ }
+ }
+
+ /**
+ * Test null values
+ */
+ public void testNull() {
+ assertFalse("isValid", VALIDATOR.isValid(null));
+ }
+
+ /**
+ * Test Invalid ISSN codes
+ */
+ public void testInvalid() {
+ for(String f : invalidFormat) {
+ assertFalse(f, VALIDATOR.isValid(f));
+ }
+ }
+
+ public void testIsValidISSNConvertNull() {
+ assertNull(VALIDATOR.convertToEAN13(null, "00"));
+ }
+
+ public void testIsValidISSNConvertSuffix() {
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, null));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, ""));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, "0"));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, "A"));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, "AA"));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ try {
+ assertNull(VALIDATOR.convertToEAN13(null, "999"));
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ }
+
+ /**
+ * Test isValid() ISSN codes and convert them
+ */
+ public void testIsValidISSNConvert() {
+ CheckDigit ean13cd = EAN13CheckDigit.EAN13_CHECK_DIGIT;
+ Random r = new Random();
+ for(String f : validFormat) {
+ String suffix = String.format("%02d", r.nextInt(100));
+ String ean13 = VALIDATOR.convertToEAN13(f, suffix);
+ assertTrue(ean13, ean13cd.isValid(ean13));
+ }
+ // internet samples
+ assertEquals("9771144875007", VALIDATOR.convertToEAN13("1144-875X", "00"));
+ assertEquals("9770264359008", VALIDATOR.convertToEAN13("0264-3596", "00"));
+ assertEquals("9771234567003", VALIDATOR.convertToEAN13("1234-5679", "00"));
+ }
+
+ /**
+ * Test Invalid EAN-13 ISSN prefix codes
+ * Test Input length
+ */
+ public void testConversionErrors() {
+ String input = null;
+ try {
+ input = "9780072129519";
+ VALIDATOR.extractFromEAN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ try {
+ input = "9791090636071";
+ VALIDATOR.extractFromEAN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ try {
+ input = "03178471";
+ VALIDATOR.extractFromEAN13(input);
+ fail("Expected IllegalArgumentException for '" + input + "'");
+ } catch (IllegalArgumentException e) {
+ // expected result
+ }
+ }
+
+ /**
+ * Test Invalid EAN-13 ISSN codes
+ */
+ public void testValidCheckDigitEan13() {
+ assertNull(VALIDATOR.extractFromEAN13("9771234567001"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567002"));
+ assertNotNull(VALIDATOR.extractFromEAN13("9771234567003")); // valid check digit
+ assertNull(VALIDATOR.extractFromEAN13("9771234567004"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567005"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567006"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567007"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567008"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567009"));
+ assertNull(VALIDATOR.extractFromEAN13("9771234567000"));
+ }
+ /**
+ * Test valid EAN-13 ISSN codes and extract the ISSN
+ */
+ public void testIsValidExtract() {
+ assertEquals("12345679", VALIDATOR.extractFromEAN13("9771234567003"));
+ assertEquals("00014664", VALIDATOR.extractFromEAN13("9770001466006"));
+ assertEquals("03178471", VALIDATOR.extractFromEAN13("9770317847001"));
+ assertEquals("1144875X", VALIDATOR.extractFromEAN13("9771144875007"));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java
new file mode 100644
index 000000000..34dae8fdd
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/InetAddressValidatorTest.java
@@ -0,0 +1,621 @@
+/*
+ * 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.TestCase;
+
+/**
+ * Test cases for InetAddressValidator.
+ *
+ * @version $Revision$
+ */
+public class InetAddressValidatorTest extends TestCase {
+
+ private InetAddressValidator validator;
+
+ /**
+ * Constructor.
+ * @param name
+ */
+ public InetAddressValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() {
+ validator = new InetAddressValidator();
+ }
+
+ /**
+ * Test IPs that point to real, well-known hosts (without actually looking them up).
+ */
+ public void testInetAddressesFromTheWild() {
+ assertTrue("www.apache.org IP should be valid", validator.isValid("140.211.11.130"));
+ assertTrue("www.l.google.com IP should be valid", validator.isValid("72.14.253.103"));
+ assertTrue("fsf.org IP should be valid", validator.isValid("199.232.41.5"));
+ assertTrue("appscs.ign.com IP should be valid", validator.isValid("216.35.123.87"));
+ }
+
+ public void testVALIDATOR_335() {
+ assertTrue("2001:0438:FFFE:0000:0000:0000:0000:0A35 should be valid", validator.isValid("2001:0438:FFFE:0000:0000:0000:0000:0A35"));
+ }
+
+ public void testVALIDATOR_419() {
+ String addr;
+ addr = "0:0:0:0:0:0:13.1.68.3";
+ assertTrue(addr, validator.isValid(addr));
+ addr = "0:0:0:0:0:FFFF:129.144.52.38";
+ assertTrue(addr, validator.isValid(addr));
+ addr = "::13.1.68.3";
+ assertTrue(addr, validator.isValid(addr));
+ addr = "::FFFF:129.144.52.38";
+ assertTrue(addr, validator.isValid(addr));
+
+ addr = "::ffff:192.168.1.1:192.168.1.1";
+ assertFalse(addr, validator.isValid(addr));
+ addr = "::192.168.1.1:192.168.1.1";
+ assertFalse(addr, validator.isValid(addr));
+ }
+
+ /**
+ * Test valid and invalid IPs from each address class.
+ */
+ public void testInetAddressesByClass() {
+ assertTrue("class A IP should be valid", validator.isValid("24.25.231.12"));
+ assertFalse("illegal class A IP should be invalid", validator.isValid("2.41.32.324"));
+
+ assertTrue("class B IP should be valid", validator.isValid("135.14.44.12"));
+ assertFalse("illegal class B IP should be invalid", validator.isValid("154.123.441.123"));
+
+ assertTrue("class C IP should be valid", validator.isValid("213.25.224.32"));
+ assertFalse("illegal class C IP should be invalid", validator.isValid("201.543.23.11"));
+
+ assertTrue("class D IP should be valid", validator.isValid("229.35.159.6"));
+ assertFalse("illegal class D IP should be invalid", validator.isValid("231.54.11.987"));
+
+ assertTrue("class E IP should be valid", validator.isValid("248.85.24.92"));
+ assertFalse("illegal class E IP should be invalid", validator.isValid("250.21.323.48"));
+ }
+
+ /**
+ * Test reserved IPs.
+ */
+ public void testReservedInetAddresses() {
+ assertTrue("localhost IP should be valid", validator.isValid("127.0.0.1"));
+ assertTrue("broadcast IP should be valid", validator.isValid("255.255.255.255"));
+ }
+
+ /**
+ * Test obviously broken IPs.
+ */
+ public void testBrokenInetAddresses() {
+ assertFalse("IP with characters should be invalid", validator.isValid("124.14.32.abc"));
+// assertFalse("IP with leading zeroes should be invalid", validator.isValid("124.14.32.01"));
+ assertFalse("IP with three groups should be invalid", validator.isValid("23.64.12"));
+ assertFalse("IP with five groups should be invalid", validator.isValid("26.34.23.77.234"));
+ }
+
+ /**
+ * Test IPv6 addresses.
+ * These tests were ported from a
+ * Perl script .
+ *
+ */
+ public void testIPv6() {
+ // The original Perl script contained a lot of duplicate tests.
+ // I removed the duplicates I noticed, but there may be more.
+// assertFalse("IPV6 empty string should be invalid", validator.isValidInet6Address(""));// empty string
+ assertTrue("IPV6 ::1 should be valid", validator.isValidInet6Address("::1"));// loopback, compressed, non-routable
+ assertTrue("IPV6 :: should be valid", validator.isValidInet6Address("::"));// unspecified, compressed, non-routable
+ assertTrue("IPV6 0:0:0:0:0:0:0:1 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0:1"));// loopback, full
+ assertTrue("IPV6 0:0:0:0:0:0:0:0 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0:0"));// unspecified, full
+ assertTrue("IPV6 2001:DB8:0:0:8:800:200C:417A should be valid", validator.isValidInet6Address("2001:DB8:0:0:8:800:200C:417A"));// unicast, full
+ assertTrue("IPV6 FF01:0:0:0:0:0:0:101 should be valid", validator.isValidInet6Address("FF01:0:0:0:0:0:0:101"));// multicast, full
+ assertTrue("IPV6 2001:DB8::8:800:200C:417A should be valid", validator.isValidInet6Address("2001:DB8::8:800:200C:417A"));// unicast, compressed
+ assertTrue("IPV6 FF01::101 should be valid", validator.isValidInet6Address("FF01::101"));// multicast, compressed
+ assertFalse("IPV6 2001:DB8:0:0:8:800:200C:417A:221 should be invalid", validator.isValidInet6Address("2001:DB8:0:0:8:800:200C:417A:221"));// unicast, full
+ assertFalse("IPV6 FF01::101::2 should be invalid", validator.isValidInet6Address("FF01::101::2"));// multicast, compressed
+ assertTrue("IPV6 fe80::217:f2ff:fe07:ed62 should be valid", validator.isValidInet6Address("fe80::217:f2ff:fe07:ed62"));
+ assertTrue("IPV6 2001:0000:1234:0000:0000:C1C0:ABCD:0876 should be valid", validator.isValidInet6Address("2001:0000:1234:0000:0000:C1C0:ABCD:0876"));
+ assertTrue("IPV6 3ffe:0b00:0000:0000:0001:0000:0000:000a should be valid", validator.isValidInet6Address("3ffe:0b00:0000:0000:0001:0000:0000:000a"));
+ assertTrue("IPV6 FF02:0000:0000:0000:0000:0000:0000:0001 should be valid", validator.isValidInet6Address("FF02:0000:0000:0000:0000:0000:0000:0001"));
+ assertTrue("IPV6 0000:0000:0000:0000:0000:0000:0000:0001 should be valid", validator.isValidInet6Address("0000:0000:0000:0000:0000:0000:0000:0001"));
+ assertTrue("IPV6 0000:0000:0000:0000:0000:0000:0000:0000 should be valid", validator.isValidInet6Address("0000:0000:0000:0000:0000:0000:0000:0000"));
+ assertFalse("IPV6 02001:0000:1234:0000:0000:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("02001:0000:1234:0000:0000:C1C0:ABCD:0876")); // extra 0 not allowed!
+ assertFalse("IPV6 2001:0000:1234:0000:00001:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("2001:0000:1234:0000:00001:C1C0:ABCD:0876")); // extra 0 not allowed!
+ assertFalse("IPV6 2001:0000:1234:0000:0000:C1C0:ABCD:0876 0 should be invalid", validator.isValidInet6Address("2001:0000:1234:0000:0000:C1C0:ABCD:0876 0")); // junk after valid address
+ assertFalse("IPV6 2001:0000:1234: 0000:0000:C1C0:ABCD:0876 should be invalid", validator.isValidInet6Address("2001:0000:1234: 0000:0000:C1C0:ABCD:0876")); // internal space
+ assertFalse("IPV6 3ffe:0b00:0000:0001:0000:0000:000a should be invalid", validator.isValidInet6Address("3ffe:0b00:0000:0001:0000:0000:000a")); // seven segments
+ assertFalse("IPV6 FF02:0000:0000:0000:0000:0000:0000:0000:0001 should be invalid", validator.isValidInet6Address("FF02:0000:0000:0000:0000:0000:0000:0000:0001")); // nine segments
+ assertFalse("IPV6 3ffe:b00::1::a should be invalid", validator.isValidInet6Address("3ffe:b00::1::a")); // double "::"
+ assertFalse("IPV6 ::1111:2222:3333:4444:5555:6666:: should be invalid", validator.isValidInet6Address("::1111:2222:3333:4444:5555:6666::")); // double "::"
+ assertTrue("IPV6 2::10 should be valid", validator.isValidInet6Address("2::10"));
+ assertTrue("IPV6 ff02::1 should be valid", validator.isValidInet6Address("ff02::1"));
+ assertTrue("IPV6 fe80:: should be valid", validator.isValidInet6Address("fe80::"));
+ assertTrue("IPV6 2002:: should be valid", validator.isValidInet6Address("2002::"));
+ assertTrue("IPV6 2001:db8:: should be valid", validator.isValidInet6Address("2001:db8::"));
+ assertTrue("IPV6 2001:0db8:1234:: should be valid", validator.isValidInet6Address("2001:0db8:1234::"));
+ assertTrue("IPV6 ::ffff:0:0 should be valid", validator.isValidInet6Address("::ffff:0:0"));
+ assertTrue("IPV6 1:2:3:4:5:6:7:8 should be valid", validator.isValidInet6Address("1:2:3:4:5:6:7:8"));
+ assertTrue("IPV6 1:2:3:4:5:6::8 should be valid", validator.isValidInet6Address("1:2:3:4:5:6::8"));
+ assertTrue("IPV6 1:2:3:4:5::8 should be valid", validator.isValidInet6Address("1:2:3:4:5::8"));
+ assertTrue("IPV6 1:2:3:4::8 should be valid", validator.isValidInet6Address("1:2:3:4::8"));
+ assertTrue("IPV6 1:2:3::8 should be valid", validator.isValidInet6Address("1:2:3::8"));
+ assertTrue("IPV6 1:2::8 should be valid", validator.isValidInet6Address("1:2::8"));
+ assertTrue("IPV6 1::8 should be valid", validator.isValidInet6Address("1::8"));
+ assertTrue("IPV6 1::2:3:4:5:6:7 should be valid", validator.isValidInet6Address("1::2:3:4:5:6:7"));
+ assertTrue("IPV6 1::2:3:4:5:6 should be valid", validator.isValidInet6Address("1::2:3:4:5:6"));
+ assertTrue("IPV6 1::2:3:4:5 should be valid", validator.isValidInet6Address("1::2:3:4:5"));
+ assertTrue("IPV6 1::2:3:4 should be valid", validator.isValidInet6Address("1::2:3:4"));
+ assertTrue("IPV6 1::2:3 should be valid", validator.isValidInet6Address("1::2:3"));
+ assertTrue("IPV6 ::2:3:4:5:6:7:8 should be valid", validator.isValidInet6Address("::2:3:4:5:6:7:8"));
+ assertTrue("IPV6 ::2:3:4:5:6:7 should be valid", validator.isValidInet6Address("::2:3:4:5:6:7"));
+ assertTrue("IPV6 ::2:3:4:5:6 should be valid", validator.isValidInet6Address("::2:3:4:5:6"));
+ assertTrue("IPV6 ::2:3:4:5 should be valid", validator.isValidInet6Address("::2:3:4:5"));
+ assertTrue("IPV6 ::2:3:4 should be valid", validator.isValidInet6Address("::2:3:4"));
+ assertTrue("IPV6 ::2:3 should be valid", validator.isValidInet6Address("::2:3"));
+ assertTrue("IPV6 ::8 should be valid", validator.isValidInet6Address("::8"));
+ assertTrue("IPV6 1:2:3:4:5:6:: should be valid", validator.isValidInet6Address("1:2:3:4:5:6::"));
+ assertTrue("IPV6 1:2:3:4:5:: should be valid", validator.isValidInet6Address("1:2:3:4:5::"));
+ assertTrue("IPV6 1:2:3:4:: should be valid", validator.isValidInet6Address("1:2:3:4::"));
+ assertTrue("IPV6 1:2:3:: should be valid", validator.isValidInet6Address("1:2:3::"));
+ assertTrue("IPV6 1:2:: should be valid", validator.isValidInet6Address("1:2::"));
+ assertTrue("IPV6 1:: should be valid", validator.isValidInet6Address("1::"));
+ assertTrue("IPV6 1:2:3:4:5::7:8 should be valid", validator.isValidInet6Address("1:2:3:4:5::7:8"));
+ assertFalse("IPV6 1:2:3::4:5::7:8 should be invalid", validator.isValidInet6Address("1:2:3::4:5::7:8")); // Double "::"
+ assertFalse("IPV6 12345::6:7:8 should be invalid", validator.isValidInet6Address("12345::6:7:8"));
+ assertTrue("IPV6 1:2:3:4::7:8 should be valid", validator.isValidInet6Address("1:2:3:4::7:8"));
+ assertTrue("IPV6 1:2:3::7:8 should be valid", validator.isValidInet6Address("1:2:3::7:8"));
+ assertTrue("IPV6 1:2::7:8 should be valid", validator.isValidInet6Address("1:2::7:8"));
+ assertTrue("IPV6 1::7:8 should be valid", validator.isValidInet6Address("1::7:8"));
+ // IPv4 addresses as dotted-quads
+ assertTrue("IPV6 1:2:3:4:5:6:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4:5:6:1.2.3.4"));
+ assertTrue("IPV6 1:2:3:4:5::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4:5::1.2.3.4"));
+ assertTrue("IPV6 1:2:3:4::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4::1.2.3.4"));
+ assertTrue("IPV6 1:2:3::1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3::1.2.3.4"));
+ assertTrue("IPV6 1:2::1.2.3.4 should be valid", validator.isValidInet6Address("1:2::1.2.3.4"));
+ assertTrue("IPV6 1::1.2.3.4 should be valid", validator.isValidInet6Address("1::1.2.3.4"));
+ assertTrue("IPV6 1:2:3:4::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3:4::5:1.2.3.4"));
+ assertTrue("IPV6 1:2:3::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2:3::5:1.2.3.4"));
+ assertTrue("IPV6 1:2::5:1.2.3.4 should be valid", validator.isValidInet6Address("1:2::5:1.2.3.4"));
+ assertTrue("IPV6 1::5:1.2.3.4 should be valid", validator.isValidInet6Address("1::5:1.2.3.4"));
+ assertTrue("IPV6 1::5:11.22.33.44 should be valid", validator.isValidInet6Address("1::5:11.22.33.44"));
+ assertFalse("IPV6 1::5:400.2.3.4 should be invalid", validator.isValidInet6Address("1::5:400.2.3.4"));
+ assertFalse("IPV6 1::5:260.2.3.4 should be invalid", validator.isValidInet6Address("1::5:260.2.3.4"));
+ assertFalse("IPV6 1::5:256.2.3.4 should be invalid", validator.isValidInet6Address("1::5:256.2.3.4"));
+ assertFalse("IPV6 1::5:1.256.3.4 should be invalid", validator.isValidInet6Address("1::5:1.256.3.4"));
+ assertFalse("IPV6 1::5:1.2.256.4 should be invalid", validator.isValidInet6Address("1::5:1.2.256.4"));
+ assertFalse("IPV6 1::5:1.2.3.256 should be invalid", validator.isValidInet6Address("1::5:1.2.3.256"));
+ assertFalse("IPV6 1::5:300.2.3.4 should be invalid", validator.isValidInet6Address("1::5:300.2.3.4"));
+ assertFalse("IPV6 1::5:1.300.3.4 should be invalid", validator.isValidInet6Address("1::5:1.300.3.4"));
+ assertFalse("IPV6 1::5:1.2.300.4 should be invalid", validator.isValidInet6Address("1::5:1.2.300.4"));
+ assertFalse("IPV6 1::5:1.2.3.300 should be invalid", validator.isValidInet6Address("1::5:1.2.3.300"));
+ assertFalse("IPV6 1::5:900.2.3.4 should be invalid", validator.isValidInet6Address("1::5:900.2.3.4"));
+ assertFalse("IPV6 1::5:1.900.3.4 should be invalid", validator.isValidInet6Address("1::5:1.900.3.4"));
+ assertFalse("IPV6 1::5:1.2.900.4 should be invalid", validator.isValidInet6Address("1::5:1.2.900.4"));
+ assertFalse("IPV6 1::5:1.2.3.900 should be invalid", validator.isValidInet6Address("1::5:1.2.3.900"));
+ assertFalse("IPV6 1::5:300.300.300.300 should be invalid", validator.isValidInet6Address("1::5:300.300.300.300"));
+ assertFalse("IPV6 1::5:3000.30.30.30 should be invalid", validator.isValidInet6Address("1::5:3000.30.30.30"));
+ assertFalse("IPV6 1::400.2.3.4 should be invalid", validator.isValidInet6Address("1::400.2.3.4"));
+ assertFalse("IPV6 1::260.2.3.4 should be invalid", validator.isValidInet6Address("1::260.2.3.4"));
+ assertFalse("IPV6 1::256.2.3.4 should be invalid", validator.isValidInet6Address("1::256.2.3.4"));
+ assertFalse("IPV6 1::1.256.3.4 should be invalid", validator.isValidInet6Address("1::1.256.3.4"));
+ assertFalse("IPV6 1::1.2.256.4 should be invalid", validator.isValidInet6Address("1::1.2.256.4"));
+ assertFalse("IPV6 1::1.2.3.256 should be invalid", validator.isValidInet6Address("1::1.2.3.256"));
+ assertFalse("IPV6 1::300.2.3.4 should be invalid", validator.isValidInet6Address("1::300.2.3.4"));
+ assertFalse("IPV6 1::1.300.3.4 should be invalid", validator.isValidInet6Address("1::1.300.3.4"));
+ assertFalse("IPV6 1::1.2.300.4 should be invalid", validator.isValidInet6Address("1::1.2.300.4"));
+ assertFalse("IPV6 1::1.2.3.300 should be invalid", validator.isValidInet6Address("1::1.2.3.300"));
+ assertFalse("IPV6 1::900.2.3.4 should be invalid", validator.isValidInet6Address("1::900.2.3.4"));
+ assertFalse("IPV6 1::1.900.3.4 should be invalid", validator.isValidInet6Address("1::1.900.3.4"));
+ assertFalse("IPV6 1::1.2.900.4 should be invalid", validator.isValidInet6Address("1::1.2.900.4"));
+ assertFalse("IPV6 1::1.2.3.900 should be invalid", validator.isValidInet6Address("1::1.2.3.900"));
+ assertFalse("IPV6 1::300.300.300.300 should be invalid", validator.isValidInet6Address("1::300.300.300.300"));
+ assertFalse("IPV6 1::3000.30.30.30 should be invalid", validator.isValidInet6Address("1::3000.30.30.30"));
+ assertFalse("IPV6 ::400.2.3.4 should be invalid", validator.isValidInet6Address("::400.2.3.4"));
+ assertFalse("IPV6 ::260.2.3.4 should be invalid", validator.isValidInet6Address("::260.2.3.4"));
+ assertFalse("IPV6 ::256.2.3.4 should be invalid", validator.isValidInet6Address("::256.2.3.4"));
+ assertFalse("IPV6 ::1.256.3.4 should be invalid", validator.isValidInet6Address("::1.256.3.4"));
+ assertFalse("IPV6 ::1.2.256.4 should be invalid", validator.isValidInet6Address("::1.2.256.4"));
+ assertFalse("IPV6 ::1.2.3.256 should be invalid", validator.isValidInet6Address("::1.2.3.256"));
+ assertFalse("IPV6 ::300.2.3.4 should be invalid", validator.isValidInet6Address("::300.2.3.4"));
+ assertFalse("IPV6 ::1.300.3.4 should be invalid", validator.isValidInet6Address("::1.300.3.4"));
+ assertFalse("IPV6 ::1.2.300.4 should be invalid", validator.isValidInet6Address("::1.2.300.4"));
+ assertFalse("IPV6 ::1.2.3.300 should be invalid", validator.isValidInet6Address("::1.2.3.300"));
+ assertFalse("IPV6 ::900.2.3.4 should be invalid", validator.isValidInet6Address("::900.2.3.4"));
+ assertFalse("IPV6 ::1.900.3.4 should be invalid", validator.isValidInet6Address("::1.900.3.4"));
+ assertFalse("IPV6 ::1.2.900.4 should be invalid", validator.isValidInet6Address("::1.2.900.4"));
+ assertFalse("IPV6 ::1.2.3.900 should be invalid", validator.isValidInet6Address("::1.2.3.900"));
+ assertFalse("IPV6 ::300.300.300.300 should be invalid", validator.isValidInet6Address("::300.300.300.300"));
+ assertFalse("IPV6 ::3000.30.30.30 should be invalid", validator.isValidInet6Address("::3000.30.30.30"));
+ assertTrue("IPV6 fe80::217:f2ff:254.7.237.98 should be valid", validator.isValidInet6Address("fe80::217:f2ff:254.7.237.98"));
+ assertTrue("IPV6 ::ffff:192.168.1.26 should be valid", validator.isValidInet6Address("::ffff:192.168.1.26"));
+ assertFalse("IPV6 2001:1:1:1:1:1:255Z255X255Y255 should be invalid", validator.isValidInet6Address("2001:1:1:1:1:1:255Z255X255Y255")); // garbage instead of "." in IPv4
+ assertFalse("IPV6 ::ffff:192x168.1.26 should be invalid", validator.isValidInet6Address("::ffff:192x168.1.26")); // ditto
+ assertTrue("IPV6 ::ffff:192.168.1.1 should be valid", validator.isValidInet6Address("::ffff:192.168.1.1"));
+ assertTrue("IPV6 0:0:0:0:0:0:13.1.68.3 should be valid", validator.isValidInet6Address("0:0:0:0:0:0:13.1.68.3"));// IPv4-compatible IPv6 address, full, deprecated
+ assertTrue("IPV6 0:0:0:0:0:FFFF:129.144.52.38 should be valid", validator.isValidInet6Address("0:0:0:0:0:FFFF:129.144.52.38"));// IPv4-mapped IPv6 address, full
+ assertTrue("IPV6 ::13.1.68.3 should be valid", validator.isValidInet6Address("::13.1.68.3"));// IPv4-compatible IPv6 address, compressed, deprecated
+ assertTrue("IPV6 ::FFFF:129.144.52.38 should be valid", validator.isValidInet6Address("::FFFF:129.144.52.38"));// IPv4-mapped IPv6 address, compressed
+ assertTrue("IPV6 fe80:0:0:0:204:61ff:254.157.241.86 should be valid", validator.isValidInet6Address("fe80:0:0:0:204:61ff:254.157.241.86"));
+ assertTrue("IPV6 fe80::204:61ff:254.157.241.86 should be valid", validator.isValidInet6Address("fe80::204:61ff:254.157.241.86"));
+ assertTrue("IPV6 ::ffff:12.34.56.78 should be valid", validator.isValidInet6Address("::ffff:12.34.56.78"));
+ assertFalse("IPV6 ::ffff:2.3.4 should be invalid", validator.isValidInet6Address("::ffff:2.3.4"));
+ assertFalse("IPV6 ::ffff:257.1.2.3 should be invalid", validator.isValidInet6Address("::ffff:257.1.2.3"));
+ assertFalse("IPV6 1.2.3.4 should be invalid", validator.isValidInet6Address("1.2.3.4"));
+ assertFalse("IPV6 1.2.3.4:1111:2222:3333:4444::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222:3333:4444::5555"));
+ assertFalse("IPV6 1.2.3.4:1111:2222:3333::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222:3333::5555"));
+ assertFalse("IPV6 1.2.3.4:1111:2222::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111:2222::5555"));
+ assertFalse("IPV6 1.2.3.4:1111::5555 should be invalid", validator.isValidInet6Address("1.2.3.4:1111::5555"));
+ assertFalse("IPV6 1.2.3.4::5555 should be invalid", validator.isValidInet6Address("1.2.3.4::5555"));
+ assertFalse("IPV6 1.2.3.4:: should be invalid", validator.isValidInet6Address("1.2.3.4::"));
+ // Testing IPv4 addresses represented as dotted-quads
+ // Leading zeroes in IPv4 addresses not allowed: some systems treat the leading "0" in ".086" as the start of an octal number
+ // Update: The BNF in RFC-3986 explicitly defines the dec-octet (for IPv4 addresses) not to have a leading zero
+ assertFalse("IPV6 fe80:0000:0000:0000:0204:61ff:254.157.241.086 should be invalid", validator.isValidInet6Address("fe80:0000:0000:0000:0204:61ff:254.157.241.086"));
+ assertTrue("IPV6 ::ffff:192.0.2.128 should be valid", validator.isValidInet6Address("::ffff:192.0.2.128")); // but this is OK, since there's a single digit
+ assertFalse("IPV6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4 should be invalid", validator.isValidInet6Address("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:00.00.00.00 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:00.00.00.00"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:000.000.000.000 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:000.000.000.000"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:256.256.256.256 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:256.256.256.256"));
+ assertTrue("IPV6 fe80:0000:0000:0000:0204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80:0000:0000:0000:0204:61ff:fe9d:f156"));
+ assertTrue("IPV6 fe80:0:0:0:204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80:0:0:0:204:61ff:fe9d:f156"));
+ assertTrue("IPV6 fe80::204:61ff:fe9d:f156 should be valid", validator.isValidInet6Address("fe80::204:61ff:fe9d:f156"));
+ assertFalse("IPV6 : should be invalid", validator.isValidInet6Address(":"));
+ assertTrue("IPV6 ::ffff:c000:280 should be valid", validator.isValidInet6Address("::ffff:c000:280"));
+ assertFalse("IPV6 1111:2222:3333:4444::5555: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::5555:"));
+ assertFalse("IPV6 1111:2222:3333::5555: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:"));
+ assertFalse("IPV6 1111:2222::5555: should be invalid", validator.isValidInet6Address("1111:2222::5555:"));
+ assertFalse("IPV6 1111::5555: should be invalid", validator.isValidInet6Address("1111::5555:"));
+ assertFalse("IPV6 ::5555: should be invalid", validator.isValidInet6Address("::5555:"));
+ assertFalse("IPV6 ::: should be invalid", validator.isValidInet6Address(":::"));
+ assertFalse("IPV6 1111: should be invalid", validator.isValidInet6Address("1111:"));
+ assertFalse("IPV6 :1111:2222:3333:4444::5555 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::5555"));
+ assertFalse("IPV6 :1111:2222:3333::5555 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555"));
+ assertFalse("IPV6 :1111:2222::5555 should be invalid", validator.isValidInet6Address(":1111:2222::5555"));
+ assertFalse("IPV6 :1111::5555 should be invalid", validator.isValidInet6Address(":1111::5555"));
+ assertFalse("IPV6 :::5555 should be invalid", validator.isValidInet6Address(":::5555"));
+ assertTrue("IPV6 2001:0db8:85a3:0000:0000:8a2e:0370:7334 should be valid", validator.isValidInet6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
+ assertTrue("IPV6 2001:db8:85a3:0:0:8a2e:370:7334 should be valid", validator.isValidInet6Address("2001:db8:85a3:0:0:8a2e:370:7334"));
+ assertTrue("IPV6 2001:db8:85a3::8a2e:370:7334 should be valid", validator.isValidInet6Address("2001:db8:85a3::8a2e:370:7334"));
+ assertTrue("IPV6 2001:0db8:0000:0000:0000:0000:1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0000:0000:0000:0000:1428:57ab"));
+ assertTrue("IPV6 2001:0db8:0000:0000:0000::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0000:0000:0000::1428:57ab"));
+ assertTrue("IPV6 2001:0db8:0:0:0:0:1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0:0:0:0:1428:57ab"));
+ assertTrue("IPV6 2001:0db8:0:0::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8:0:0::1428:57ab"));
+ assertTrue("IPV6 2001:0db8::1428:57ab should be valid", validator.isValidInet6Address("2001:0db8::1428:57ab"));
+ assertTrue("IPV6 2001:db8::1428:57ab should be valid", validator.isValidInet6Address("2001:db8::1428:57ab"));
+ assertTrue("IPV6 ::ffff:0c22:384e should be valid", validator.isValidInet6Address("::ffff:0c22:384e"));
+ assertTrue("IPV6 2001:0db8:1234:0000:0000:0000:0000:0000 should be valid", validator.isValidInet6Address("2001:0db8:1234:0000:0000:0000:0000:0000"));
+ assertTrue("IPV6 2001:0db8:1234:ffff:ffff:ffff:ffff:ffff should be valid", validator.isValidInet6Address("2001:0db8:1234:ffff:ffff:ffff:ffff:ffff"));
+ assertTrue("IPV6 2001:db8:a::123 should be valid", validator.isValidInet6Address("2001:db8:a::123"));
+ assertFalse("IPV6 123 should be invalid", validator.isValidInet6Address("123"));
+ assertFalse("IPV6 ldkfj should be invalid", validator.isValidInet6Address("ldkfj"));
+ assertFalse("IPV6 2001::FFD3::57ab should be invalid", validator.isValidInet6Address("2001::FFD3::57ab"));
+ assertFalse("IPV6 2001:db8:85a3::8a2e:37023:7334 should be invalid", validator.isValidInet6Address("2001:db8:85a3::8a2e:37023:7334"));
+ assertFalse("IPV6 2001:db8:85a3::8a2e:370k:7334 should be invalid", validator.isValidInet6Address("2001:db8:85a3::8a2e:370k:7334"));
+ assertFalse("IPV6 1:2:3:4:5:6:7:8:9 should be invalid", validator.isValidInet6Address("1:2:3:4:5:6:7:8:9"));
+ assertFalse("IPV6 1::2::3 should be invalid", validator.isValidInet6Address("1::2::3"));
+ assertFalse("IPV6 1:::3:4:5 should be invalid", validator.isValidInet6Address("1:::3:4:5"));
+ assertFalse("IPV6 1:2:3::4:5:6:7:8:9 should be invalid", validator.isValidInet6Address("1:2:3::4:5:6:7:8:9"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:6666:7777:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777::"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:6666:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::"));
+ assertTrue("IPV6 1111:2222:3333:4444:: should be valid", validator.isValidInet6Address("1111:2222:3333:4444::"));
+ assertTrue("IPV6 1111:2222:3333:: should be valid", validator.isValidInet6Address("1111:2222:3333::"));
+ assertTrue("IPV6 1111:2222:: should be valid", validator.isValidInet6Address("1111:2222::"));
+ assertTrue("IPV6 1111:: should be valid", validator.isValidInet6Address("1111::"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:6666::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::8888"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::8888"));
+ assertTrue("IPV6 1111:2222:3333:4444::8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::8888"));
+ assertTrue("IPV6 1111:2222:3333::8888 should be valid", validator.isValidInet6Address("1111:2222:3333::8888"));
+ assertTrue("IPV6 1111:2222::8888 should be valid", validator.isValidInet6Address("1111:2222::8888"));
+ assertTrue("IPV6 1111::8888 should be valid", validator.isValidInet6Address("1111::8888"));
+ assertTrue("IPV6 ::8888 should be valid", validator.isValidInet6Address("::8888"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777:8888"));
+ assertTrue("IPV6 1111:2222:3333:4444::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::7777:8888"));
+ assertTrue("IPV6 1111:2222:3333::7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::7777:8888"));
+ assertTrue("IPV6 1111:2222::7777:8888 should be valid", validator.isValidInet6Address("1111:2222::7777:8888"));
+ assertTrue("IPV6 1111::7777:8888 should be valid", validator.isValidInet6Address("1111::7777:8888"));
+ assertTrue("IPV6 ::7777:8888 should be valid", validator.isValidInet6Address("::7777:8888"));
+ assertTrue("IPV6 1111:2222:3333:4444::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777:8888"));
+ assertTrue("IPV6 1111:2222:3333::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::6666:7777:8888"));
+ assertTrue("IPV6 1111:2222::6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::6666:7777:8888"));
+ assertTrue("IPV6 1111::6666:7777:8888 should be valid", validator.isValidInet6Address("1111::6666:7777:8888"));
+ assertTrue("IPV6 ::6666:7777:8888 should be valid", validator.isValidInet6Address("::6666:7777:8888"));
+ assertTrue("IPV6 1111:2222:3333::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777:8888"));
+ assertTrue("IPV6 1111:2222::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::5555:6666:7777:8888"));
+ assertTrue("IPV6 1111::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::5555:6666:7777:8888"));
+ assertTrue("IPV6 ::5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::5555:6666:7777:8888"));
+ assertTrue("IPV6 1111:2222::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 1111::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 ::4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 1111::3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 ::3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::3333:4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 ::2222:3333:4444:5555:6666:7777:8888 should be valid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333:4444:5555::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444:5555::123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333:4444::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::123.123.123.123"));
+ assertTrue("IPV6 1111:2222::123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::123.123.123.123"));
+ assertTrue("IPV6 1111::123.123.123.123 should be valid", validator.isValidInet6Address("1111::123.123.123.123"));
+ assertTrue("IPV6 ::123.123.123.123 should be valid", validator.isValidInet6Address("::123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333:4444::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333:4444::6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::6666:123.123.123.123"));
+ assertTrue("IPV6 1111::6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::6666:123.123.123.123"));
+ assertTrue("IPV6 ::6666:123.123.123.123 should be valid", validator.isValidInet6Address("::6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222:3333::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222:3333::5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::5555:6666:123.123.123.123"));
+ assertTrue("IPV6 ::5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111:2222::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111:2222::4444:5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::4444:5555:6666:123.123.123.123"));
+ assertTrue("IPV6 ::4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::4444:5555:6666:123.123.123.123"));
+ assertTrue("IPV6 1111::3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("1111::3333:4444:5555:6666:123.123.123.123"));
+ assertTrue("IPV6 ::2222:3333:4444:5555:6666:123.123.123.123 should be valid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:123.123.123.123"));
+ // Trying combinations of "0" and "::"
+ // These are all syntactically correct, but are bad form
+ // because "0" adjacent to "::" should be combined into "::"
+ assertTrue("IPV6 ::0:0:0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0:0:0"));
+ assertTrue("IPV6 ::0:0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0:0"));
+ assertTrue("IPV6 ::0:0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0:0"));
+ assertTrue("IPV6 ::0:0:0:0 should be valid", validator.isValidInet6Address("::0:0:0:0"));
+ assertTrue("IPV6 ::0:0:0 should be valid", validator.isValidInet6Address("::0:0:0"));
+ assertTrue("IPV6 ::0:0 should be valid", validator.isValidInet6Address("::0:0"));
+ assertTrue("IPV6 ::0 should be valid", validator.isValidInet6Address("::0"));
+ assertTrue("IPV6 0:0:0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0:0:0::"));
+ assertTrue("IPV6 0:0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0:0::"));
+ assertTrue("IPV6 0:0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0:0::"));
+ assertTrue("IPV6 0:0:0:0:: should be valid", validator.isValidInet6Address("0:0:0:0::"));
+ assertTrue("IPV6 0:0:0:: should be valid", validator.isValidInet6Address("0:0:0::"));
+ assertTrue("IPV6 0:0:: should be valid", validator.isValidInet6Address("0:0::"));
+ assertTrue("IPV6 0:: should be valid", validator.isValidInet6Address("0::"));
+ // Invalid data
+ assertFalse("IPV6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX should be invalid", validator.isValidInet6Address("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX"));
+ // Too many components
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:9999 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:9999"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888::"));
+ assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:8888:9999 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888:9999"));
+ // Too few components
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555"));
+ assertFalse("IPV6 1111:2222:3333:4444 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444"));
+ assertFalse("IPV6 1111:2222:3333 should be invalid", validator.isValidInet6Address("1111:2222:3333"));
+ assertFalse("IPV6 1111:2222 should be invalid", validator.isValidInet6Address("1111:2222"));
+ assertFalse("IPV6 1111 should be invalid", validator.isValidInet6Address("1111"));
+ // Missing :
+ assertFalse("IPV6 11112222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("11112222:3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:22223333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:22223333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:33334444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:33334444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:44445555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:44445555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:55556666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:55556666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:66667777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:66667777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:77778888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:77778888"));
+ // Missing : intended for ::
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:"));
+ assertFalse("IPV6 1111:2222:3333:4444: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:"));
+ assertFalse("IPV6 1111:2222:3333: should be invalid", validator.isValidInet6Address("1111:2222:3333:"));
+ assertFalse("IPV6 1111:2222: should be invalid", validator.isValidInet6Address("1111:2222:"));
+ assertFalse("IPV6 :8888 should be invalid", validator.isValidInet6Address(":8888"));
+ assertFalse("IPV6 :7777:8888 should be invalid", validator.isValidInet6Address(":7777:8888"));
+ assertFalse("IPV6 :6666:7777:8888 should be invalid", validator.isValidInet6Address(":6666:7777:8888"));
+ assertFalse("IPV6 :5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":5555:6666:7777:8888"));
+ assertFalse("IPV6 :4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":2222:3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:7777:8888"));
+ // :::
+ assertFalse("IPV6 :::2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:::3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:::4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:::5555:6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::6666:7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::7777:8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:::8888"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:::"));
+ // Double ::
+ assertFalse("IPV6 ::2222::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222::4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 ::2222:3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333::5555:6666:7777:8888"));
+ assertFalse("IPV6 ::2222:3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444::6666:7777:8888"));
+ assertFalse("IPV6 ::2222:3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555::7777:8888"));
+ assertFalse("IPV6 ::2222:3333:4444:5555:7777::8888 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:7777::8888"));
+ assertFalse("IPV6 ::2222:3333:4444:5555:7777:8888:: should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:7777:8888::"));
+ assertFalse("IPV6 1111::3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address("1111::3333::5555:6666:7777:8888"));
+ assertFalse("IPV6 1111::3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111::3333:4444::6666:7777:8888"));
+ assertFalse("IPV6 1111::3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555::7777:8888"));
+ assertFalse("IPV6 1111::3333:4444:5555:6666::8888 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666::8888"));
+ assertFalse("IPV6 1111::3333:4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777::"));
+ assertFalse("IPV6 1111:2222::4444::6666:7777:8888 should be invalid", validator.isValidInet6Address("1111:2222::4444::6666:7777:8888"));
+ assertFalse("IPV6 1111:2222::4444:5555::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555::7777:8888"));
+ assertFalse("IPV6 1111:2222::4444:5555:6666::8888 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666::8888"));
+ assertFalse("IPV6 1111:2222::4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777::"));
+ assertFalse("IPV6 1111:2222:3333::5555::7777:8888 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555::7777:8888"));
+ assertFalse("IPV6 1111:2222:3333::5555:6666::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666::8888"));
+ assertFalse("IPV6 1111:2222:3333::5555:6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777::"));
+ assertFalse("IPV6 1111:2222:3333:4444::6666::8888 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666::8888"));
+ assertFalse("IPV6 1111:2222:3333:4444::6666:7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777::"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555::7777:: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777::"));
+ // Too many components"
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::1.2.3.4"));
+ assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:1.2.3.4.5 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:1.2.3.4.5"));
+ // Too few components
+ assertFalse("IPV6 1111:2222:3333:4444:5555:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:1.2.3.4"));
+ assertFalse("IPV6 1111:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:1.2.3.4"));
+ assertFalse("IPV6 1.2.3.4 should be invalid", validator.isValidInet6Address("1.2.3.4"));
+ // Missing :
+ assertFalse("IPV6 11112222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("11112222:3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:22223333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:22223333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:33334444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:33334444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:44445555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:44445555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:55556666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:55556666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:66661.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:66661.2.3.4"));
+ // Missing .
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255255.255.255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255255.255.255"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255.255255.255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255.255255.255"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:255.255.255255 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:255.255.255255"));
+ // Missing : intended for ::
+ assertFalse("IPV6 :1.2.3.4 should be invalid", validator.isValidInet6Address(":1.2.3.4"));
+ assertFalse("IPV6 :6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":6666:1.2.3.4"));
+ assertFalse("IPV6 :5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":2222:3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:1.2.3.4"));
+ // :::
+ assertFalse("IPV6 :::2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:::3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:::3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:::4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::1.2.3.4"));
+ // Double ::
+ assertFalse("IPV6 ::2222::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222::4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 ::2222:3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 ::2222:3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444::6666:1.2.3.4"));
+ assertFalse("IPV6 ::2222:3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555::1.2.3.4"));
+ assertFalse("IPV6 1111::3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 1111::3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333:4444::6666:1.2.3.4"));
+ assertFalse("IPV6 1111::3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111::3333:4444:5555::1.2.3.4"));
+ assertFalse("IPV6 1111:2222::4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222::4444::6666:1.2.3.4"));
+ assertFalse("IPV6 1111:2222::4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222::4444:5555::1.2.3.4"));
+ assertFalse("IPV6 1111:2222:3333::5555::1.2.3.4 should be invalid", validator.isValidInet6Address("1111:2222:3333::5555::1.2.3.4"));
+ // Missing parts
+ assertFalse("IPV6 ::. should be invalid", validator.isValidInet6Address("::."));
+ assertFalse("IPV6 ::.. should be invalid", validator.isValidInet6Address("::.."));
+ assertFalse("IPV6 ::... should be invalid", validator.isValidInet6Address("::..."));
+ assertFalse("IPV6 ::1... should be invalid", validator.isValidInet6Address("::1..."));
+ assertFalse("IPV6 ::1.2.. should be invalid", validator.isValidInet6Address("::1.2.."));
+ assertFalse("IPV6 ::1.2.3. should be invalid", validator.isValidInet6Address("::1.2.3."));
+ assertFalse("IPV6 ::.2.. should be invalid", validator.isValidInet6Address("::.2.."));
+ assertFalse("IPV6 ::.2.3. should be invalid", validator.isValidInet6Address("::.2.3."));
+ assertFalse("IPV6 ::.2.3.4 should be invalid", validator.isValidInet6Address("::.2.3.4"));
+ assertFalse("IPV6 ::..3. should be invalid", validator.isValidInet6Address("::..3."));
+ assertFalse("IPV6 ::..3.4 should be invalid", validator.isValidInet6Address("::..3.4"));
+ assertFalse("IPV6 ::...4 should be invalid", validator.isValidInet6Address("::...4"));
+ // Extra : in front
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:7777:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:7777::"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666::"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::"));
+ assertFalse("IPV6 :1111:2222:3333:4444:: should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::"));
+ assertFalse("IPV6 :1111:2222:3333:: should be invalid", validator.isValidInet6Address(":1111:2222:3333::"));
+ assertFalse("IPV6 :1111:2222:: should be invalid", validator.isValidInet6Address(":1111:2222::"));
+ assertFalse("IPV6 :1111:: should be invalid", validator.isValidInet6Address(":1111::"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666::8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::8888"));
+ assertFalse("IPV6 :1111:2222:3333::8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::8888"));
+ assertFalse("IPV6 :1111:2222::8888 should be invalid", validator.isValidInet6Address(":1111:2222::8888"));
+ assertFalse("IPV6 :1111::8888 should be invalid", validator.isValidInet6Address(":1111::8888"));
+ assertFalse("IPV6 :::8888 should be invalid", validator.isValidInet6Address(":::8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::7777:8888"));
+ assertFalse("IPV6 :1111:2222::7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::7777:8888"));
+ assertFalse("IPV6 :1111::7777:8888 should be invalid", validator.isValidInet6Address(":1111::7777:8888"));
+ assertFalse("IPV6 :::7777:8888 should be invalid", validator.isValidInet6Address(":::7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::6666:7777:8888"));
+ assertFalse("IPV6 :1111::6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::6666:7777:8888"));
+ assertFalse("IPV6 :::6666:7777:8888 should be invalid", validator.isValidInet6Address(":::6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::5555:6666:7777:8888"));
+ assertFalse("IPV6 :::5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111:2222::4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :::4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":1111::3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :::3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :::2222:3333:4444:5555:6666:7777:8888 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:7777:8888"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333:4444:5555::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444:5555::1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333:4444::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::1.2.3.4"));
+ assertFalse("IPV6 :1111:2222::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::1.2.3.4"));
+ assertFalse("IPV6 :1111::1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::1.2.3.4"));
+ assertFalse("IPV6 :::1.2.3.4 should be invalid", validator.isValidInet6Address(":::1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333:4444::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333:4444::6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::6666:1.2.3.4"));
+ assertFalse("IPV6 :1111::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::6666:1.2.3.4"));
+ assertFalse("IPV6 :::6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222:3333::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222:3333::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :::5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111:2222::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111:2222::4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :::4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :1111::3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":1111::3333:4444:5555:6666:1.2.3.4"));
+ assertFalse("IPV6 :::2222:3333:4444:5555:6666:1.2.3.4 should be invalid", validator.isValidInet6Address(":::2222:3333:4444:5555:6666:1.2.3.4"));
+ // Extra : at end
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666:7777::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:7777:::"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666:::"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:::"));
+ assertFalse("IPV6 1111:2222:3333:4444::: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:::"));
+ assertFalse("IPV6 1111:2222:3333::: should be invalid", validator.isValidInet6Address("1111:2222:3333:::"));
+ assertFalse("IPV6 1111:2222::: should be invalid", validator.isValidInet6Address("1111:2222:::"));
+ assertFalse("IPV6 1111::: should be invalid", validator.isValidInet6Address("1111:::"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555:6666::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555:6666::8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::8888:"));
+ assertFalse("IPV6 1111:2222:3333::8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::8888:"));
+ assertFalse("IPV6 1111:2222::8888: should be invalid", validator.isValidInet6Address("1111:2222::8888:"));
+ assertFalse("IPV6 1111::8888: should be invalid", validator.isValidInet6Address("1111::8888:"));
+ assertFalse("IPV6 ::8888: should be invalid", validator.isValidInet6Address("::8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444:5555::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444:5555::7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::7777:8888:"));
+ assertFalse("IPV6 1111:2222::7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::7777:8888:"));
+ assertFalse("IPV6 1111::7777:8888: should be invalid", validator.isValidInet6Address("1111::7777:8888:"));
+ assertFalse("IPV6 ::7777:8888: should be invalid", validator.isValidInet6Address("::7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333:4444::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333:4444::6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::6666:7777:8888:"));
+ assertFalse("IPV6 1111::6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::6666:7777:8888:"));
+ assertFalse("IPV6 ::6666:7777:8888: should be invalid", validator.isValidInet6Address("::6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222:3333::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222:3333::5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::5555:6666:7777:8888:"));
+ assertFalse("IPV6 ::5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111:2222::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111:2222::4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 ::4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 1111::3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("1111::3333:4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 ::3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::3333:4444:5555:6666:7777:8888:"));
+ assertFalse("IPV6 ::2222:3333:4444:5555:6666:7777:8888: should be invalid", validator.isValidInet6Address("::2222:3333:4444:5555:6666:7777:8888:"));
+ assertTrue("IPV6 0:a:b:c:d:e:f:: should be valid", validator.isValidInet6Address("0:a:b:c:d:e:f::"));
+ assertTrue("IPV6 ::0:a:b:c:d:e:f should be valid", validator.isValidInet6Address("::0:a:b:c:d:e:f")); // syntactically correct, but bad form (::0:... could be combined)
+ assertTrue("IPV6 a:b:c:d:e:f:0:: should be valid", validator.isValidInet6Address("a:b:c:d:e:f:0::"));
+ assertFalse("IPV6 ':10.0.0.1 should be invalid", validator.isValidInet6Address("':10.0.0.1"));
+ }
+}
+
+
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IntegerValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IntegerValidatorTest.java
new file mode 100644
index 000000000..110ac47af
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/IntegerValidatorTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * Test Case for IntegerValidator.
+ *
+ * @version $Revision$
+ */
+public class IntegerValidatorTest extends AbstractNumberValidatorTest {
+
+ private static final Integer INT_MIN_VAL = Integer.valueOf(Integer.MIN_VALUE);
+ private static final Integer INT_MAX_VAL = Integer.valueOf(Integer.MAX_VALUE);
+ private static final String INT_MAX = "2147483647";
+ private static final String INT_MAX_0 = "2147483647.99999999999999999999999"; // force double rounding
+ private static final String INT_MAX_1 = "2147483648";
+ private static final String INT_MIN = "-2147483648";
+ private static final String INT_MIN_0 = "-2147483648.99999999999999999999999"; // force double rounding";
+ private static final String INT_MIN_1 = "-2147483649";
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public IntegerValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new IntegerValidator(false, 0);
+ strictValidator = new IntegerValidator();
+
+ testPattern = "#,###";
+
+ // testValidateMinMax()
+ max = Integer.valueOf(Integer.MAX_VALUE);
+ maxPlusOne = Long.valueOf(max.longValue() + 1);
+ min = Integer.valueOf(Integer.MIN_VALUE);
+ minMinusOne = Long.valueOf(min.longValue() - 1);
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2", INT_MAX_1, INT_MIN_1};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12", INT_MAX_1, INT_MIN_1};
+
+ // testValid()
+ testNumber = Integer.valueOf(1234);
+ testZero = Integer.valueOf(0);
+ validStrict = new String[] {"0", "1234", "1,234", INT_MAX, INT_MIN};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber, INT_MAX_VAL, INT_MIN_VAL};
+ valid = new String[] {"0", "1234", "1,234", "1,234.5", "1234X", INT_MAX, INT_MIN, INT_MAX_0, INT_MIN_0};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber, INT_MAX_VAL, INT_MIN_VAL, INT_MAX_VAL, INT_MIN_VAL};
+
+ testStringUS = "1,234";
+ testStringDE = "1.234";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+ }
+
+ /**
+ * Test IntegerValidator validate Methods
+ */
+ public void testIntegerValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ Integer expected = Integer.valueOf(12345);
+ assertEquals("validate(A) default", expected, IntegerValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, IntegerValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, IntegerValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, IntegerValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", IntegerValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", IntegerValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", IntegerValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", IntegerValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", IntegerValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", IntegerValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", IntegerValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", IntegerValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", IntegerValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", IntegerValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", IntegerValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", IntegerValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Integer Range/Min/Max
+ */
+ public void testIntegerRangeMinMax() {
+ IntegerValidator validator = (IntegerValidator)strictValidator;
+ Integer number9 = validator.validate("9", "#");
+ Integer number10 = validator.validate("10", "#");
+ Integer number11 = validator.validate("11", "#");
+ Integer number19 = validator.validate("19", "#");
+ Integer number20 = validator.validate("20", "#");
+ Integer number21 = validator.validate("21", "#");
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
+ assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
+ assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+ assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
+ assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, 10));
+ assertTrue("minValue() = min", validator.minValue(number10, 10));
+ assertTrue("minValue() > min", validator.minValue(number11, 10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, 20));
+ assertTrue("maxValue() = max", validator.maxValue(number20, 20));
+ assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ }
+ public void testMinMaxValues() {
+ assertTrue("2147483647 is max integer", validator.isValid("2147483647"));
+ assertFalse("2147483648 > max integer", validator.isValid("2147483648"));
+ assertTrue("-2147483648 is min integer", validator.isValid("-2147483648"));
+ assertFalse("-2147483649 < min integer", validator.isValid("-2147483649"));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java
new file mode 100644
index 000000000..3b8fe0892
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * Test Case for LongValidator.
+ *
+ * @version $Revision$
+ */
+public class LongValidatorTest extends AbstractNumberValidatorTest {
+
+ private static final Long LONG_MIN_VAL = Long.valueOf(Long.MIN_VALUE);
+ private static final Long LONG_MAX_VAL = Long.valueOf(Long.MAX_VALUE);
+ private static final String LONG_MAX = "9223372036854775807";
+ private static final String LONG_MAX_0 = "9223372036854775807.99999999999999999999999"; // force double rounding
+ private static final String LONG_MAX_1 = "9223372036854775808";
+ private static final String LONG_MIN = "-9223372036854775808";
+ private static final String LONG_MIN_0 = "-9223372036854775808.99999999999999999999999"; // force double rounding
+ private static final String LONG_MIN_1 = "-9223372036854775809";
+
+ private static final String NINES = "9999999999999999999999999999999999999";
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public LongValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new LongValidator(false, 0);
+ strictValidator = new LongValidator();
+
+ testPattern = "#,###";
+
+ // testValidateMinMax()
+ max = null;
+ maxPlusOne = null;
+ min = null;
+ minMinusOne = null;
+
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2", LONG_MAX_1, LONG_MIN_1, NINES};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12", "", LONG_MAX_1, LONG_MIN_1, NINES};
+
+ // testValid()
+ testNumber = Long.valueOf(1234);
+ testZero = Long.valueOf(0);
+ validStrict = new String[] {"0", "1234", "1,234", LONG_MAX, LONG_MIN};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber, LONG_MAX_VAL, LONG_MIN_VAL};
+ valid = new String[] {"0", "1234", "1,234", "1,234.5", "1234X", LONG_MAX, LONG_MIN, LONG_MAX_0, LONG_MIN_0};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber, LONG_MAX_VAL, LONG_MIN_VAL, LONG_MAX_VAL, LONG_MIN_VAL};
+
+ testStringUS = "1,234";
+ testStringDE = "1.234";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test LongValidator validate Methods
+ */
+ public void testLongValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ Long expected = Long.valueOf(12345);
+ assertEquals("validate(A) default", expected, LongValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, LongValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, LongValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, LongValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", LongValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", LongValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", LongValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", LongValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", LongValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", LongValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", LongValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", LongValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", LongValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", LongValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", LongValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", LongValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Long Range/Min/Max
+ */
+ public void testLongRangeMinMax() {
+ LongValidator validator = (LongValidator)strictValidator;
+ Long number9 = validator.validate("9", "#");
+ Long number10 = validator.validate("10", "#");
+ Long number11 = validator.validate("11", "#");
+ Long number19 = validator.validate("19", "#");
+ Long number20 = validator.validate("20", "#");
+ Long number21 = validator.validate("21", "#");
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, 10, 20));
+ assertTrue("isInRange() = min", validator.isInRange(number10, 10, 20));
+ assertTrue("isInRange() in range", validator.isInRange(number11, 10, 20));
+ assertTrue("isInRange() = max", validator.isInRange(number20, 10, 20));
+ assertFalse("isInRange() > max", validator.isInRange(number21, 10, 20));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, 10));
+ assertTrue("minValue() = min", validator.minValue(number10, 10));
+ assertTrue("minValue() > min", validator.minValue(number11, 10));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, 20));
+ assertTrue("maxValue() = max", validator.maxValue(number20, 20));
+ assertFalse("maxValue() > max", validator.maxValue(number21, 20));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java
new file mode 100644
index 000000000..79f819772
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.TestCase;
+
+import java.util.Locale;
+import java.math.BigDecimal;
+/**
+ * Test Case for PercentValidator.
+ *
+ * @version $Revision$
+ */
+public class PercentValidatorTest extends TestCase {
+
+ protected PercentValidator validator;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public PercentValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ validator = new PercentValidator();
+ }
+
+ /**
+ * Tear down
+ * @throws Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ validator = null;
+ }
+
+ /**
+ * Test Format Type
+ */
+ public void testFormatType() {
+ assertEquals("Format Type A", 2, PercentValidator.getInstance().getFormatType());
+ assertEquals("Format Type B", AbstractNumberValidator.PERCENT_FORMAT, PercentValidator.getInstance().getFormatType());
+ }
+
+ /**
+ * Test Valid percentage values
+ */
+ public void testValid() {
+ // Set the default Locale
+ Locale origDefault = Locale.getDefault();
+ Locale.setDefault(Locale.UK);
+
+ BigDecimalValidator validator = PercentValidator.getInstance();
+ BigDecimal expected = new BigDecimal("0.12");
+ BigDecimal negative = new BigDecimal("-0.12");
+ BigDecimal hundred = new BigDecimal("1.00");
+
+ assertEquals("Default locale", expected, validator.validate("12%"));
+ assertEquals("Default negtve", negative, validator.validate("-12%"));
+
+ // Invalid UK
+ assertEquals("UK locale", expected, validator.validate("12%", Locale.UK));
+ assertEquals("UK negative", negative, validator.validate("-12%", Locale.UK));
+ assertEquals("UK No symbol", expected, validator.validate("12", Locale.UK));
+
+ // Invalid US - can't find a Locale with different symbols!
+ assertEquals("US locale", expected, validator.validate("12%", Locale.US));
+ assertEquals("US negative", negative, validator.validate("-12%", Locale.US));
+ assertEquals("US No symbol", expected, validator.validate("12", Locale.US));
+
+ assertEquals("100%", hundred, validator.validate("100%"));
+
+ // Restore the original default
+ Locale.setDefault(origDefault);
+ }
+
+ /**
+ * Test Invalid percentage values
+ */
+ public void testInvalid() {
+ BigDecimalValidator validator = PercentValidator.getInstance();
+
+ // Invalid Missing
+ assertFalse("isValid() Null Value", validator.isValid(null));
+ assertFalse("isValid() Empty Value", validator.isValid(""));
+ assertNull("validate() Null Value", validator.validate(null));
+ assertNull("validate() Empty Value", validator.validate(""));
+
+ // Invalid UK
+ assertFalse("UK wrong symbol", validator.isValid("12@", Locale.UK)); // ???
+ assertFalse("UK wrong negative", validator.isValid("(12%)", Locale.UK));
+
+ // Invalid US - can't find a Locale with different symbols!
+ assertFalse("US wrong symbol", validator.isValid("12@", Locale.US)); // ???
+ assertFalse("US wrong negative", validator.isValid("(12%)", Locale.US));
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/RegexValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/RegexValidatorTest.java
new file mode 100644
index 000000000..2be23928e
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/RegexValidatorTest.java
@@ -0,0 +1,296 @@
+/*
+ * 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 java.util.regex.PatternSyntaxException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test Case for RegexValidatorTest.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class RegexValidatorTest extends TestCase {
+
+ private static final String REGEX = "^([abc]*)(?:\\-)([DEF]*)(?:\\-)([123]*)$";
+
+ private static final String COMPONENT_1 = "([abc]{3})";
+ private static final String COMPONENT_2 = "([DEF]{3})";
+ private static final String COMPONENT_3 = "([123]{3})";
+ private static final String SEPARATOR_1 = "(?:\\-)";
+ private static final String SEPARATOR_2 = "(?:\\s)";
+ private static final String REGEX_1 = "^" + COMPONENT_1 + SEPARATOR_1 + COMPONENT_2 + SEPARATOR_1 + COMPONENT_3 + "$";
+ private static final String REGEX_2 = "^" + COMPONENT_1 + SEPARATOR_2 + COMPONENT_2 + SEPARATOR_2 + COMPONENT_3 + "$";
+ private static final String REGEX_3 = "^" + COMPONENT_1 + COMPONENT_2 + COMPONENT_3 + "$";
+ private static final String[] MULTIPLE_REGEX = new String[] {REGEX_1, REGEX_2, REGEX_3};
+
+ /**
+ * Constrct a new test case.
+ * @param name The name of the test
+ */
+ public RegexValidatorTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set Up.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Tear Down.
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test instance methods with single regular expression.
+ */
+ public void testSingle() {
+ RegexValidator sensitive = new RegexValidator(REGEX);
+ RegexValidator insensitive = new RegexValidator(REGEX, false);
+
+ // isValid()
+ assertEquals("Sensitive isValid() valid", true, sensitive.isValid("ac-DE-1"));
+ assertEquals("Sensitive isValid() invalid", false, sensitive.isValid("AB-de-1"));
+ assertEquals("Insensitive isValid() valid", true, insensitive.isValid("AB-de-1"));
+ assertEquals("Insensitive isValid() invalid", false, insensitive.isValid("ABd-de-1"));
+
+ // validate()
+ assertEquals("Sensitive validate() valid", "acDE1", sensitive.validate("ac-DE-1"));
+ assertEquals("Sensitive validate() invalid", null, sensitive.validate("AB-de-1"));
+ assertEquals("Insensitive validate() valid", "ABde1", insensitive.validate("AB-de-1"));
+ assertEquals("Insensitive validate() invalid", null, insensitive.validate("ABd-de-1"));
+
+ // match()
+ checkArray("Sensitive match() valid", new String[] {"ac", "DE", "1"}, sensitive.match("ac-DE-1"));
+ checkArray("Sensitive match() invalid", null, sensitive.match("AB-de-1"));
+ checkArray("Insensitive match() valid", new String[] {"AB", "de", "1"}, insensitive.match("AB-de-1"));
+ checkArray("Insensitive match() invalid", null, insensitive.match("ABd-de-1"));
+ assertEquals("validate one", "ABC", (new RegexValidator("^([A-Z]*)$")).validate("ABC"));
+ checkArray("match one", new String[] {"ABC"}, (new RegexValidator("^([A-Z]*)$")).match("ABC"));
+ }
+
+ /**
+ * Test with multiple regular expressions (case sensitive).
+ */
+ public void testMultipleSensitive() {
+
+ // ------------ Set up Sensitive Validators
+ RegexValidator multiple = new RegexValidator(MULTIPLE_REGEX);
+ RegexValidator single1 = new RegexValidator(REGEX_1);
+ RegexValidator single2 = new RegexValidator(REGEX_2);
+ RegexValidator single3 = new RegexValidator(REGEX_3);
+
+ // ------------ Set up test values
+ String value = "aac FDE 321";
+ String expect = "aacFDE321";
+ String[] array = new String[] {"aac", "FDE", "321"};
+
+ // isValid()
+ assertEquals("Sensitive isValid() Multiple", true, multiple.isValid(value));
+ assertEquals("Sensitive isValid() 1st", false, single1.isValid(value));
+ assertEquals("Sensitive isValid() 2nd", true, single2.isValid(value));
+ assertEquals("Sensitive isValid() 3rd", false, single3.isValid(value));
+
+ // validate()
+ assertEquals("Sensitive validate() Multiple", expect, multiple.validate(value));
+ assertEquals("Sensitive validate() 1st", null, single1.validate(value));
+ assertEquals("Sensitive validate() 2nd", expect, single2.validate(value));
+ assertEquals("Sensitive validate() 3rd", null, single3.validate(value));
+
+ // match()
+ checkArray("Sensitive match() Multiple", array, multiple.match(value));
+ checkArray("Sensitive match() 1st", null, single1.match(value));
+ checkArray("Sensitive match() 2nd", array, single2.match(value));
+ checkArray("Sensitive match() 3rd", null, single3.match(value));
+
+ // All invalid
+ value = "AAC*FDE*321";
+ assertEquals("isValid() Invalid", false, multiple.isValid(value));
+ assertEquals("validate() Invalid", null, multiple.validate(value));
+ assertEquals("match() Multiple", null, multiple.match(value));
+ }
+
+ /**
+ * Test with multiple regular expressions (case in-sensitive).
+ */
+ public void testMultipleInsensitive() {
+
+ // ------------ Set up In-sensitive Validators
+ RegexValidator multiple = new RegexValidator(MULTIPLE_REGEX, false);
+ RegexValidator single1 = new RegexValidator(REGEX_1, false);
+ RegexValidator single2 = new RegexValidator(REGEX_2, false);
+ RegexValidator single3 = new RegexValidator(REGEX_3, false);
+
+ // ------------ Set up test values
+ String value = "AAC FDE 321";
+ String expect = "AACFDE321";
+ String[] array = new String[] {"AAC", "FDE", "321"};
+
+ // isValid()
+ assertEquals("isValid() Multiple", true, multiple.isValid(value));
+ assertEquals("isValid() 1st", false, single1.isValid(value));
+ assertEquals("isValid() 2nd", true, single2.isValid(value));
+ assertEquals("isValid() 3rd", false, single3.isValid(value));
+
+ // validate()
+ assertEquals("validate() Multiple", expect, multiple.validate(value));
+ assertEquals("validate() 1st", null, single1.validate(value));
+ assertEquals("validate() 2nd", expect, single2.validate(value));
+ assertEquals("validate() 3rd", null, single3.validate(value));
+
+ // match()
+ checkArray("match() Multiple", array, multiple.match(value));
+ checkArray("match() 1st", null, single1.match(value));
+ checkArray("match() 2nd", array, single2.match(value));
+ checkArray("match() 3rd", null, single3.match(value));
+
+ // All invalid
+ value = "AAC*FDE*321";
+ assertEquals("isValid() Invalid", false, multiple.isValid(value));
+ assertEquals("validate() Invalid", null, multiple.validate(value));
+ assertEquals("match() Multiple", null, multiple.match(value));
+ }
+
+ /**
+ * Test Null value
+ */
+ public void testNullValue() {
+
+ RegexValidator validator = new RegexValidator(REGEX);
+ assertEquals("Instance isValid()", false, validator.isValid(null));
+ assertEquals("Instance validate()", null, validator.validate(null));
+ assertEquals("Instance match()", null, validator.match(null));
+ }
+
+ /**
+ * Test exceptions
+ */
+ public void testMissingRegex() {
+
+ // Single Regular Expression - null
+ try {
+ new RegexValidator((String)null);
+ fail("Single Null - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Single Null", "Regular expression[0] is missing", e.getMessage());
+ }
+
+ // Single Regular Expression - Zero Length
+ try {
+ new RegexValidator("");
+ fail("Single Zero Length - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Single Zero Length", "Regular expression[0] is missing", e.getMessage());
+ }
+
+ // Multiple Regular Expression - Null array
+ try {
+ new RegexValidator((String[])null);
+ fail("Null Array - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Null Array", "Regular expressions are missing", e.getMessage());
+ }
+
+ // Multiple Regular Expression - Zero Length array
+ try {
+ new RegexValidator(new String[0]);
+ fail("Zero Length Array - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Zero Length Array", "Regular expressions are missing", e.getMessage());
+ }
+
+ // Multiple Regular Expression - Array has Null
+ String[] expressions = new String[] {"ABC", null};
+ try {
+ new RegexValidator(expressions);
+ fail("Array has Null - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Array has Null", "Regular expression[1] is missing", e.getMessage());
+ }
+
+ // Multiple Regular Expression - Array has Zero Length
+ expressions = new String[] {"", "ABC"};
+ try {
+ new RegexValidator(expressions);
+ fail("Array has Zero Length - expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Array has Zero Length", "Regular expression[0] is missing", e.getMessage());
+ }
+ }
+
+ /**
+ * Test exceptions
+ */
+ public void testExceptions() {
+ String invalidRegex = "^([abCD12]*$";
+ try {
+ new RegexValidator(invalidRegex);
+ } catch (PatternSyntaxException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Test toString() method
+ */
+ public void testToString() {
+ RegexValidator single = new RegexValidator(REGEX);
+ assertEquals("Single", "RegexValidator{" + REGEX + "}", single.toString());
+
+ RegexValidator multiple = new RegexValidator(new String[] {REGEX, REGEX});
+ assertEquals("Multiple", "RegexValidator{" + REGEX + "," + REGEX + "}", multiple.toString());
+ }
+
+ /**
+ * Compare two arrays
+ * @param label Label for the test
+ * @param expect Expected array
+ * @param result Actual array
+ */
+ private void checkArray(String label, String[] expect, String[] result) {
+
+ // Handle nulls
+ if (expect == null || result == null) {
+ if (expect == null && result == null) {
+ return; // valid, both null
+ } else {
+ fail(label + " Null expect=" + expect + " result=" + result);
+ }
+ return; // not strictly necessary, but prevents possible NPE below
+ }
+
+ // Check Length
+ if (expect.length != result.length) {
+ fail(label + " Length expect=" + expect.length + " result=" + result.length);
+ }
+
+ // Check Values
+ for (int i = 0; i < expect.length; i++) {
+ assertEquals(label +" value[" + i + "]", expect[i], result[i]);
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java
new file mode 100644
index 000000000..937230001
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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 java.util.Locale;
+
+/**
+ * Test Case for ShortValidator.
+ *
+ * @version $Revision$
+ */
+public class ShortValidatorTest extends AbstractNumberValidatorTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ShortValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ validator = new ShortValidator(false, 0);
+ strictValidator = new ShortValidator();
+
+ testPattern = "#,###";
+
+ // testValidateMinMax()
+ max = Short.valueOf(Short.MAX_VALUE);
+ maxPlusOne = Long.valueOf(max.longValue() + 1);
+ min = Short.valueOf(Short.MIN_VALUE);
+ minMinusOne = Long.valueOf(min.longValue() - 1);
+
+ // testInvalidStrict()
+ invalidStrict = new String[] {null, "", "X", "X12", "12X", "1X2", "1.2"};
+
+ // testInvalidNotStrict()
+ invalid = new String[] {null, "", "X", "X12"};
+
+ // testValid()
+ testNumber = Short.valueOf((short)1234);
+ testZero = Short.valueOf((short)0);
+ validStrict = new String[] {"0", "1234", "1,234"};
+ validStrictCompare = new Number[] {testZero, testNumber, testNumber};
+ valid = new String[] {"0", "1234", "1,234", "1,234.5", "1234X"};
+ validCompare = new Number[] {testZero, testNumber, testNumber, testNumber, testNumber};
+
+ testStringUS = "1,234";
+ testStringDE = "1.234";
+
+ // Localized Pattern test
+ localeValue = testStringDE;
+ localePattern = "#.###";
+ testLocale = Locale.GERMANY;
+ localeExpected = testNumber;
+
+ }
+
+ /**
+ * Test ShortValidator validate Methods
+ */
+ public void testShortValidatorMethods() {
+ Locale locale = Locale.GERMAN;
+ String pattern = "0,00,00";
+ String patternVal = "1,23,45";
+ String germanPatternVal = "1.23.45";
+ String localeVal = "12.345";
+ String defaultVal = "12,345";
+ String XXXX = "XXXX";
+ Short expected = Short.valueOf((short)12345);
+ assertEquals("validate(A) default", expected, ShortValidator.getInstance().validate(defaultVal));
+ assertEquals("validate(A) locale ", expected, ShortValidator.getInstance().validate(localeVal, locale));
+ assertEquals("validate(A) pattern", expected, ShortValidator.getInstance().validate(patternVal, pattern));
+ assertEquals("validate(A) both", expected, ShortValidator.getInstance().validate(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertTrue("isValid(A) default", ShortValidator.getInstance().isValid(defaultVal));
+ assertTrue("isValid(A) locale ", ShortValidator.getInstance().isValid(localeVal, locale));
+ assertTrue("isValid(A) pattern", ShortValidator.getInstance().isValid(patternVal, pattern));
+ assertTrue("isValid(A) both", ShortValidator.getInstance().isValid(germanPatternVal, pattern, Locale.GERMAN));
+
+ assertNull("validate(B) default", ShortValidator.getInstance().validate(XXXX));
+ assertNull("validate(B) locale ", ShortValidator.getInstance().validate(XXXX, locale));
+ assertNull("validate(B) pattern", ShortValidator.getInstance().validate(XXXX, pattern));
+ assertNull("validate(B) both", ShortValidator.getInstance().validate(patternVal, pattern, Locale.GERMAN));
+
+ assertFalse("isValid(B) default", ShortValidator.getInstance().isValid(XXXX));
+ assertFalse("isValid(B) locale ", ShortValidator.getInstance().isValid(XXXX, locale));
+ assertFalse("isValid(B) pattern", ShortValidator.getInstance().isValid(XXXX, pattern));
+ assertFalse("isValid(B) both", ShortValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN));
+ }
+
+ /**
+ * Test Short Range/Min/Max
+ */
+ public void testShortRangeMinMax() {
+ ShortValidator validator = (ShortValidator)strictValidator;
+ Short number9 = validator.validate("9", "#");
+ Short number10 = validator.validate("10", "#");
+ Short number11 = validator.validate("11", "#");
+ Short number19 = validator.validate("19", "#");
+ Short number20 = validator.validate("20", "#");
+ Short number21 = validator.validate("21", "#");
+ short min = (short)10;
+ short max = (short)20;
+
+ // Test isInRange()
+ assertFalse("isInRange() < min", validator.isInRange(number9, min, max));
+ assertTrue("isInRange() = min", validator.isInRange(number10, min, max));
+ assertTrue("isInRange() in range", validator.isInRange(number11, min, max));
+ assertTrue("isInRange() = max", validator.isInRange(number20, min, max));
+ assertFalse("isInRange() > max", validator.isInRange(number21, min, max));
+
+ // Test minValue()
+ assertFalse("minValue() < min", validator.minValue(number9, min));
+ assertTrue("minValue() = min", validator.minValue(number10, min));
+ assertTrue("minValue() > min", validator.minValue(number11, min));
+
+ // Test minValue()
+ assertTrue("maxValue() < max", validator.maxValue(number19, max));
+ assertTrue("maxValue() = max", validator.maxValue(number20, max));
+ assertFalse("maxValue() > max", validator.maxValue(number21, max));
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
new file mode 100644
index 000000000..aabc942f2
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
@@ -0,0 +1,342 @@
+/*
+ * 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.TestCase;
+
+import java.util.Date;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Test Case for TimeValidator.
+ *
+ * @version $Revision$
+ */
+public class TimeValidatorTest extends TestCase {
+
+ protected static final TimeZone GMT = TimeZone.getTimeZone("GMT"); // 0 offset
+ protected static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours
+
+ protected TimeValidator validator;
+
+ protected String[] patternValid = new String[] {
+ "23-59-59"
+ ,"00-00-00"
+ ,"00-00-01"
+ ,"0-0-0"
+ ,"1-12-1"
+ ,"10-49-18"
+ ,"16-23-46"};
+ protected Date[] patternExpect = new Date[] {
+ createDate(null, 235959, 0)
+ ,createDate(null, 0, 0)
+ ,createDate(null, 1, 0)
+ ,createDate(null, 0, 0)
+ ,createDate(null, 11201, 0)
+ ,createDate(null, 104918, 0)
+ ,createDate(null, 162346, 0)};
+ protected String[] localeValid = new String[] {
+ "23:59"
+ ,"00:00"
+ ,"00:01"
+ ,"0:0"
+ ,"1:12"
+ ,"10:49"
+ ,"16:23"};
+ protected Date[] localeExpect = new Date[] {
+ createDate(null, 235900, 0)
+ ,createDate(null, 0, 0)
+ ,createDate(null, 100, 0)
+ ,createDate(null, 0, 0)
+ ,createDate(null, 11200, 0)
+ ,createDate(null, 104900, 0)
+ ,createDate(null, 162300, 0)};
+ protected String[] patternInvalid = new String[] {
+ "24-00-00" // midnight
+ ,"24-00-01" // past midnight
+ ,"25-02-03" // invalid hour
+ ,"10-61-31" // invalid minute
+ ,"10-01-61" // invalid second
+ ,"05:02-29" // invalid sep
+ ,"0X-01:01" // invalid sep
+ ,"05-0X-01" // invalid char
+ ,"10-01-0X" // invalid char
+ ,"01:01:05" // invalid pattern
+ ,"10-10" // invalid pattern
+ ,"10--10" // invalid pattern
+ ,"10-10-"}; // invalid pattern
+ protected String[] localeInvalid = new String[] {
+ "24:00" // midnight
+ ,"24:00" // past midnight
+ ,"25:02" // invalid hour
+ ,"10:61" // invalid minute
+ ,"05-02" // invalid sep
+ ,"0X:01" // invalid sep
+ ,"05:0X" // invalid char
+ ,"01-01" // invalid pattern
+ ,"10:" // invalid pattern
+ ,"10::1" // invalid pattern
+ ,"10:1:"}; // invalid pattern
+
+ private Locale origDefault;
+ private TimeZone defaultZone;
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public TimeValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ validator = new TimeValidator();
+ defaultZone = TimeZone.getDefault();
+ origDefault = Locale.getDefault();
+ }
+
+ /**
+ * Tear down
+ * @throws Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ validator = null;
+ Locale.setDefault(origDefault);
+ TimeZone.setDefault(defaultZone);
+ }
+
+ /**
+ * Test Valid Dates with "pattern" validation
+ */
+ public void testPatternValid() {
+ for (int i = 0; i < patternValid.length; i++) {
+ String text = i + " value=[" +patternValid[i]+"] failed ";
+ Calendar calendar = validator.validate(patternValid[i], "HH-mm-ss");
+ assertNotNull("validateObj() " + text, calendar);
+ Date date = calendar.getTime();
+ assertTrue("isValid() " + text, validator.isValid(patternValid[i], "HH-mm-ss"));
+ assertEquals("compare " + text, patternExpect[i], date);
+ }
+ }
+
+ /**
+ * Test Invalid Dates with "pattern" validation
+ */
+ public void testPatternInvalid() {
+ for (int i = 0; i < patternInvalid.length; i++) {
+ String text = i + " value=[" +patternInvalid[i]+"] passed ";
+ Object date = validator.validate(patternInvalid[i], "HH-mm-ss");
+ assertNull("validate() " + text + date, date);
+ assertFalse("isValid() " + text, validator.isValid(patternInvalid[i], "HH-mm-ss"));
+ }
+ }
+
+ /**
+ * Test Valid Dates with "locale" validation
+ */
+ public void testLocaleValid() {
+ for (int i = 0; i < localeValid.length; i++) {
+ String text = i + " value=[" +localeValid[i]+"] failed ";
+ Calendar calendar = validator.validate(localeValid[i], Locale.UK);
+ assertNotNull("validate() " + text, calendar);
+ Date date = calendar.getTime();
+ assertTrue("isValid() " + text, validator.isValid(localeValid[i], Locale.UK));
+ assertEquals("compare " + text, localeExpect[i], date);
+ }
+ }
+
+ /**
+ * Test Invalid Dates with "locale" validation
+ */
+ public void testLocaleInvalid() {
+ for (int i = 0; i < localeInvalid.length; i++) {
+ String text = i + " value=[" +localeInvalid[i]+"] passed ";
+ Object date = validator.validate(localeInvalid[i], Locale.US);
+ assertNull("validate() " + text + date, date);
+ assertFalse("isValid() " + text, validator.isValid(localeInvalid[i], Locale.UK));
+ }
+ }
+
+ /**
+ * Test time zone methods.
+ */
+ public void testTimeZone() {
+ // Set the default Locale & TimeZone
+ Locale.setDefault(Locale.UK);
+ TimeZone.setDefault(GMT);
+
+ Calendar result = null;
+
+ // Default Locale, Default TimeZone
+ result = validator.validate("18:01");
+ assertNotNull("default result", result);
+ assertEquals("default zone", GMT, result.getTimeZone());
+ assertEquals("default hour", 18, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("default minute", 01, result.get(Calendar.MINUTE));
+ result = null;
+
+ // Default Locale, diff TimeZone
+ result = validator.validate("16:49", EST);
+ assertNotNull("zone result", result);
+ assertEquals("zone zone", EST, result.getTimeZone());
+ assertEquals("zone hour", 16, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("zone minute", 49, result.get(Calendar.MINUTE));
+ result = null;
+
+ // Pattern, diff TimeZone
+ result = validator.validate("14-34", "HH-mm", EST);
+ assertNotNull("pattern result", result);
+ assertEquals("pattern zone", EST, result.getTimeZone());
+ assertEquals("pattern hour", 14, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("pattern minute", 34, result.get(Calendar.MINUTE));
+ result = null;
+
+ // Locale, diff TimeZone
+ result = validator.validate("7:18 PM", Locale.US, EST);
+ assertNotNull("locale result", result);
+ assertEquals("locale zone", EST, result.getTimeZone());
+ assertEquals("locale hour", 19, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("locale minute", 18, result.get(Calendar.MINUTE));
+ result = null;
+
+ // Locale & Pattern, diff TimeZone
+ result = validator.validate("31/Dez/05 21-05", "dd/MMM/yy HH-mm", Locale.GERMAN, EST);
+ assertNotNull("pattern result", result);
+ assertEquals("pattern zone", EST, result.getTimeZone());
+ assertEquals("pattern day", 2005, result.get(Calendar.YEAR));
+ assertEquals("pattern day", 11, result.get(Calendar.MONTH)); // months are 0-11
+ assertEquals("pattern day", 31, result.get(Calendar.DATE));
+ assertEquals("pattern hour", 21, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("pattern minute", 05, result.get(Calendar.MINUTE));
+ result = null;
+
+ // Locale & Pattern, default TimeZone
+ result = validator.validate("31/Dez/05 21-05", "dd/MMM/yy HH-mm", Locale.GERMAN);
+ assertNotNull("pattern result", result);
+ assertEquals("pattern zone", GMT, result.getTimeZone());
+ assertEquals("pattern day", 2005, result.get(Calendar.YEAR));
+ assertEquals("pattern day", 11, result.get(Calendar.MONTH)); // months are 0-11
+ assertEquals("pattern day", 31, result.get(Calendar.DATE));
+ assertEquals("pattern hour", 21, result.get(Calendar.HOUR_OF_DAY));
+ assertEquals("pattern minute", 05, result.get(Calendar.MINUTE));
+ result = null;
+
+ }
+
+ /**
+ * Test Invalid Dates with "locale" validation
+ */
+ public void testFormat() {
+ // Set the default Locale
+ Locale.setDefault(Locale.UK);
+
+ Object test = TimeValidator.getInstance().validate("16:49:23", "HH:mm:ss");
+ assertNotNull("Test Date ", test);
+ assertEquals("Format pattern", "16-49-23", validator.format(test, "HH-mm-ss"));
+ assertEquals("Format locale", "4:49 PM", validator.format(test, Locale.US));
+ assertEquals("Format default", "16:49", validator.format(test));
+
+ }
+
+ /**
+ * Test compare date methods
+ */
+ public void testCompare() {
+ int testTime = 154523;
+ int min = 100;
+ int hour = 10000;
+
+ Calendar milliGreater = createTime(GMT, testTime, 500); // > milli sec
+ Calendar value = createTime(GMT, testTime, 400); // test value
+ Calendar milliLess = createTime(GMT, testTime, 300); // < milli sec
+
+ Calendar secGreater = createTime(GMT, testTime + 1, 100); // +1 sec
+ Calendar secLess = createTime(GMT, testTime - 1, 100); // -1 sec
+
+ Calendar minGreater = createTime(GMT, testTime + min, 100); // +1 min
+ Calendar minLess = createTime(GMT, testTime - min, 100); // -1 min
+
+ Calendar hourGreater = createTime(GMT, testTime + hour, 100); // +1 hour
+ Calendar hourLess = createTime(GMT, testTime - hour, 100); // -1 hour
+
+ assertEquals("mili LT", -1, validator.compareTime(value, milliGreater)); // > milli
+ assertEquals("mili EQ", 0, validator.compareTime(value, value)); // same time
+ assertEquals("mili GT", 1, validator.compareTime(value, milliLess)); // < milli
+
+ assertEquals("secs LT", -1, validator.compareSeconds(value, secGreater)); // +1 sec
+ assertEquals("secs =1", 0, validator.compareSeconds(value, milliGreater)); // > milli
+ assertEquals("secs =2", 0, validator.compareSeconds(value, value)); // same time
+ assertEquals("secs =3", 0, validator.compareSeconds(value, milliLess)); // < milli
+ assertEquals("secs GT", 1, validator.compareSeconds(value, secLess)); // -1 sec
+
+ assertEquals("mins LT", -1, validator.compareMinutes(value, minGreater)); // +1 min
+ assertEquals("mins =1", 0, validator.compareMinutes(value, secGreater)); // +1 sec
+ assertEquals("mins =2", 0, validator.compareMinutes(value, value)); // same time
+ assertEquals("mins =3", 0, validator.compareMinutes(value, secLess)); // -1 sec
+ assertEquals("mins GT", 1, validator.compareMinutes(value, minLess)); // -1 min
+
+ assertEquals("hour LT", -1, validator.compareHours(value, hourGreater)); // +1 hour
+ assertEquals("hour =1", 0, validator.compareHours(value, minGreater)); // +1 min
+ assertEquals("hour =2", 0, validator.compareHours(value, value)); // same time
+ assertEquals("hour =3", 0, validator.compareHours(value, minLess)); // -1 min
+ assertEquals("hour GT", 1, validator.compareHours(value, hourLess)); // -1 hour
+
+ }
+
+ /**
+ * Create a calendar instance for a specified time zone, date and time.
+ *
+ * @param zone The time zone
+ * @param time the time in HH:mm:ss format
+ * @param millisecond the milliseconds
+ * @return the new Calendar instance.
+ */
+ protected static Calendar createTime(TimeZone zone, int time, int millisecond) {
+ Calendar calendar = zone == null ? Calendar.getInstance()
+ : Calendar.getInstance(zone);
+ int hour = ((time / 10000) * 10000);
+ int min = ((time / 100) * 100) - hour;
+ int sec = time - (hour + min);
+ calendar.set(Calendar.YEAR, 1970);
+ calendar.set(Calendar.MONTH, 0);
+ calendar.set(Calendar.DATE, 1);
+ calendar.set(Calendar.HOUR_OF_DAY, (hour / 10000));
+ calendar.set(Calendar.MINUTE, (min / 100));
+ calendar.set(Calendar.SECOND, sec);
+ calendar.set(Calendar.MILLISECOND, millisecond);
+ return calendar;
+ }
+
+ /**
+ * Create a date instance for a specified time zone, date and time.
+ *
+ * @param zone The time zone
+ * @param time the time in HH:mm:ss format
+ * @param millisecond the milliseconds
+ * @return the new Date instance.
+ */
+ protected static Date createDate(TimeZone zone, int time, int millisecond) {
+ Calendar calendar = createTime(zone, time, millisecond);
+ return calendar.getTime();
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
new file mode 100644
index 000000000..b34a030be
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
@@ -0,0 +1,618 @@
+/*
+ * 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 org.apache.commons.validator.ResultPair;
+
+import junit.framework.TestCase;
+
+/**
+ * Performs Validation Test for url validations.
+ *
+ * @version $Revision$
+ */
+public class UrlValidatorTest extends TestCase {
+
+ private final boolean printStatus = false;
+ private final boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using.
+
+ public UrlValidatorTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() {
+ for (int index = 0; index < testPartsIndex.length - 1; index++) {
+ testPartsIndex[index] = 0;
+ }
+ }
+
+ public void testIsValid() {
+ testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
+ setUp();
+ long 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() ");
+ }
+ //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, long options) {
+ UrlValidator urlVal = new UrlValidator(null, 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 {
+ StringBuilder testBuffer = new StringBuilder();
+ 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);
+ assertTrue(urlValidator.isValid("http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org"));
+ }
+
+ public void testValidator204() {
+ String[] schemes = {"http","https"};
+ UrlValidator urlValidator = new UrlValidator(schemes);
+ assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
+ }
+
+ public void testValidator218() {
+ UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
+ assertTrue("parentheses should be valid in URLs",
+ validator.isValid("http://somewhere.com/pathxyz/file(1).html"));
+ }
+
+ public void testValidator235() {
+ String version = System.getProperty("java.version");
+ if (version.compareTo("1.6") < 0) {
+ System.out.println("Cannot run Unicode IDN tests");
+ return; // Cannot run the test
+ }
+ UrlValidator validator = new UrlValidator();
+ assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai"));
+ assertTrue("президент.рф should validate", validator.isValid("http://президент.рф"));
+ assertTrue("www.b\u00fccher.ch should validate", validator.isValid("http://www.b\u00fccher.ch"));
+ assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("http://www.\uFFFD.ch"));
+ assertTrue("www.b\u00fccher.ch should validate", validator.isValid("ftp://www.b\u00fccher.ch"));
+ assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("ftp://www.\uFFFD.ch"));
+ }
+
+ public void testValidator248() {
+ RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"});
+ UrlValidator validator = new UrlValidator(regex, 0);
+
+ assertTrue("localhost URL should validate",
+ validator.isValid("http://localhost/test/index.html"));
+ assertTrue("first.my-testing should validate",
+ validator.isValid("http://first.my-testing/test/index.html"));
+ assertTrue("sup3r.my-testing should validate",
+ validator.isValid("http://sup3r.my-testing/test/index.html"));
+
+ assertFalse("broke.my-test should not validate",
+ validator.isValid("http://broke.my-test/test/index.html"));
+
+ assertTrue("www.apache.org should still validate",
+ validator.isValid("http://www.apache.org/test/index.html"));
+
+ // Now check using options
+ validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
+
+ assertTrue("localhost URL should validate",
+ validator.isValid("http://localhost/test/index.html"));
+
+ assertTrue("machinename URL should validate",
+ validator.isValid("http://machinename/test/index.html"));
+
+ assertTrue("www.apache.org should still validate",
+ validator.isValid("http://www.apache.org/test/index.html"));
+ }
+
+ public void testValidator288() {
+ UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
+
+ assertTrue("hostname should validate",
+ validator.isValid("http://hostname"));
+
+ assertTrue("hostname with path should validate",
+ validator.isValid("http://hostname/test/index.html"));
+
+ assertTrue("localhost URL should validate",
+ validator.isValid("http://localhost/test/index.html"));
+
+ assertFalse("first.my-testing should not validate",
+ validator.isValid("http://first.my-testing/test/index.html"));
+
+ assertFalse("broke.hostname should not validate",
+ validator.isValid("http://broke.hostname/test/index.html"));
+
+ assertTrue("www.apache.org should still validate",
+ validator.isValid("http://www.apache.org/test/index.html"));
+
+ // Turn it off, and check
+ validator = new UrlValidator(0);
+
+ assertFalse("hostname should no longer validate",
+ validator.isValid("http://hostname"));
+
+ assertFalse("localhost URL should no longer validate",
+ validator.isValid("http://localhost/test/index.html"));
+
+ assertTrue("www.apache.org should still validate",
+ validator.isValid("http://www.apache.org/test/index.html"));
+ }
+
+ public void testValidator276() {
+ // file:// isn't allowed by default
+ UrlValidator validator = new UrlValidator();
+
+ assertTrue("http://apache.org/ should be allowed by default",
+ validator.isValid("http://www.apache.org/test/index.html"));
+
+ assertFalse("file:///c:/ shouldn't be allowed by default",
+ validator.isValid("file:///C:/some.file"));
+
+ assertFalse("file:///c:\\ shouldn't be allowed by default",
+ validator.isValid("file:///C:\\some.file"));
+
+ assertFalse("file:///etc/ shouldn't be allowed by default",
+ validator.isValid("file:///etc/hosts"));
+
+ assertFalse("file://localhost/etc/ shouldn't be allowed by default",
+ validator.isValid("file://localhost/etc/hosts"));
+
+ assertFalse("file://localhost/c:/ shouldn't be allowed by default",
+ validator.isValid("file://localhost/c:/some.file"));
+
+ // Turn it on, and check
+ // Note - we need to enable local urls when working with file:
+ validator = new UrlValidator(new String[] {"http","file"}, UrlValidator.ALLOW_LOCAL_URLS);
+
+ assertTrue("http://apache.org/ should be allowed by default",
+ validator.isValid("http://www.apache.org/test/index.html"));
+
+ assertTrue("file:///c:/ should now be allowed",
+ validator.isValid("file:///C:/some.file"));
+
+ assertTrue("file:///c:\\ should be allowed",
+ validator.isValid("file:///C:\\some.file"));
+
+ assertTrue("file:///etc/ should now be allowed",
+ validator.isValid("file:///etc/hosts"));
+
+ assertTrue("file://localhost/etc/ should now be allowed",
+ validator.isValid("file://localhost/etc/hosts"));
+
+ assertTrue("file://localhost/c:/ should now be allowed",
+ validator.isValid("file://localhost/c:/some.file"));
+
+ // These are never valid
+ assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/",
+ validator.isValid("file://C:/some.file"));
+
+ assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/",
+ validator.isValid("file://C:\\some.file"));
+ }
+
+ public void testValidator391OK() {
+ String[] schemes = {"file"};
+ UrlValidator urlValidator = new UrlValidator(schemes);
+ assertTrue(urlValidator.isValid("file:///C:/path/to/dir/"));
+ }
+
+ public void testValidator391FAILS() {
+ String[] schemes = {"file"};
+ UrlValidator urlValidator = new UrlValidator(schemes);
+ assertTrue(urlValidator.isValid("file:/C:/path/to/dir/"));
+ }
+
+ public void testValidator309() {
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
+ assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
+ assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
+ urlValidator = new UrlValidator(new String[] {"HTTP","HTTPS"});
+ assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
+ assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
+ assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
+ }
+
+ public void testValidator339(){
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://www.cnn.com/WORLD/?hpt=sitenav")); // without
+ assertTrue(urlValidator.isValid("http://www.cnn.com./WORLD/?hpt=sitenav")); // with
+ assertFalse(urlValidator.isValid("http://www.cnn.com../")); // doubly dotty
+ assertFalse(urlValidator.isValid("http://www.cnn.invalid/"));
+ assertFalse(urlValidator.isValid("http://www.cnn.invalid./")); // check . does not affect invalid domains
+ }
+
+ public void testValidator339IDN(){
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://президент.рф/WORLD/?hpt=sitenav")); // without
+ assertTrue(urlValidator.isValid("http://президент.рф./WORLD/?hpt=sitenav")); // with
+ assertFalse(urlValidator.isValid("http://президент.рф..../")); // very dotty
+ assertFalse(urlValidator.isValid("http://президент.рф.../")); // triply dotty
+ assertFalse(urlValidator.isValid("http://президент.рф../")); // doubly dotty
+ }
+
+ public void testValidator342(){
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://example.rocks/"));
+ assertTrue(urlValidator.isValid("http://example.rocks"));
+ }
+
+ public void testValidator411(){
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://example.rocks:/"));
+ assertTrue(urlValidator.isValid("http://example.rocks:0/"));
+ assertTrue(urlValidator.isValid("http://example.rocks:65535/"));
+ assertFalse(urlValidator.isValid("http://example.rocks:65536/"));
+ assertFalse(urlValidator.isValid("http://example.rocks:100000/"));
+ }
+
+ public void testValidator464() {
+ String[] schemes = {"file"};
+ UrlValidator urlValidator = new UrlValidator(schemes);
+ String fileOK = "file:///bad ^ domain.com/label/test";
+ String fileNAK = "file://bad ^ domain.com/label/test";
+ assertTrue(fileOK, urlValidator.isValid(fileOK));
+ assertFalse(fileNAK, urlValidator.isValid(fileNAK));
+ }
+
+ 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];
+ maxIndex &= (index == (part.length - 1));
+ if (carry) {
+ if (index < part.length - 1) {
+ index++;
+ testPartsIndex[testPartsIndexIndex] = index;
+ carry = false;
+ } else {
+ testPartsIndex[testPartsIndexIndex] = 0;
+ carry = true;
+ }
+ }
+ }
+
+
+ return (!maxIndex);
+ }
+
+ private String testPartsIndextoString() {
+ StringBuilder carryMsg = new StringBuilder("{");
+ 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);
+ }
+
+ public void testValidator290() {
+ UrlValidator validator = new UrlValidator();
+ assertTrue(validator.isValid("http://xn--h1acbxfam.idn.icann.org/"));
+// assertTrue(validator.isValid("http://xn--e1afmkfd.xn--80akhbyknj4f"));
+ // Internationalized country code top-level domains
+ assertTrue(validator.isValid("http://test.xn--lgbbat1ad8j")); //Algeria
+ assertTrue(validator.isValid("http://test.xn--fiqs8s")); // China
+ assertTrue(validator.isValid("http://test.xn--fiqz9s")); // China
+ assertTrue(validator.isValid("http://test.xn--wgbh1c")); // Egypt
+ assertTrue(validator.isValid("http://test.xn--j6w193g")); // Hong Kong
+ assertTrue(validator.isValid("http://test.xn--h2brj9c")); // India
+ assertTrue(validator.isValid("http://test.xn--mgbbh1a71e")); // India
+ assertTrue(validator.isValid("http://test.xn--fpcrj9c3d")); // India
+ assertTrue(validator.isValid("http://test.xn--gecrj9c")); // India
+ assertTrue(validator.isValid("http://test.xn--s9brj9c")); // India
+ assertTrue(validator.isValid("http://test.xn--xkc2dl3a5ee0h")); // India
+ assertTrue(validator.isValid("http://test.xn--45brj9c")); // India
+ assertTrue(validator.isValid("http://test.xn--mgba3a4f16a")); // Iran
+ assertTrue(validator.isValid("http://test.xn--mgbayh7gpa")); // Jordan
+ assertTrue(validator.isValid("http://test.xn--mgbc0a9azcg")); // Morocco
+ assertTrue(validator.isValid("http://test.xn--ygbi2ammx")); // Palestinian Territory
+ assertTrue(validator.isValid("http://test.xn--wgbl6a")); // Qatar
+ assertTrue(validator.isValid("http://test.xn--p1ai")); // Russia
+ assertTrue(validator.isValid("http://test.xn--mgberp4a5d4ar")); // Saudi Arabia
+ assertTrue(validator.isValid("http://test.xn--90a3ac")); // Serbia
+ assertTrue(validator.isValid("http://test.xn--yfro4i67o")); // Singapore
+ assertTrue(validator.isValid("http://test.xn--clchc0ea0b2g2a9gcd")); // Singapore
+ assertTrue(validator.isValid("http://test.xn--3e0b707e")); // South Korea
+ assertTrue(validator.isValid("http://test.xn--fzc2c9e2c")); // Sri Lanka
+ assertTrue(validator.isValid("http://test.xn--xkc2al3hye2a")); // Sri Lanka
+ assertTrue(validator.isValid("http://test.xn--ogbpf8fl")); // Syria
+ assertTrue(validator.isValid("http://test.xn--kprw13d")); // Taiwan
+ assertTrue(validator.isValid("http://test.xn--kpry57d")); // Taiwan
+ assertTrue(validator.isValid("http://test.xn--o3cw4h")); // Thailand
+ assertTrue(validator.isValid("http://test.xn--pgbs0dh")); // Tunisia
+ assertTrue(validator.isValid("http://test.xn--mgbaam7a8h")); // United Arab Emirates
+ // Proposed internationalized ccTLDs
+// assertTrue(validator.isValid("http://test.xn--54b7fta0cc")); // Bangladesh
+// assertTrue(validator.isValid("http://test.xn--90ae")); // Bulgaria
+// assertTrue(validator.isValid("http://test.xn--node")); // Georgia
+// assertTrue(validator.isValid("http://test.xn--4dbrk0ce")); // Israel
+// assertTrue(validator.isValid("http://test.xn--mgb9awbf")); // Oman
+// assertTrue(validator.isValid("http://test.xn--j1amh")); // Ukraine
+// assertTrue(validator.isValid("http://test.xn--mgb2ddes")); // Yemen
+ // Test TLDs
+// assertTrue(validator.isValid("http://test.xn--kgbechtv")); // Arabic
+// assertTrue(validator.isValid("http://test.xn--hgbk6aj7f53bba")); // Persian
+// assertTrue(validator.isValid("http://test.xn--0zwm56d")); // Chinese
+// assertTrue(validator.isValid("http://test.xn--g6w251d")); // Chinese
+// assertTrue(validator.isValid("http://test.xn--80akhbyknj4f")); // Russian
+// assertTrue(validator.isValid("http://test.xn--11b5bs3a9aj6g")); // Hindi
+// assertTrue(validator.isValid("http://test.xn--jxalpdlp")); // Greek
+// assertTrue(validator.isValid("http://test.xn--9t4b11yi5a")); // Korean
+// assertTrue(validator.isValid("http://test.xn--deba0ad")); // Yiddish
+// assertTrue(validator.isValid("http://test.xn--zckzah")); // Japanese
+// assertTrue(validator.isValid("http://test.xn--hlcj6aya9esc7a")); // Tamil
+ }
+
+ public void testValidator361() {
+ UrlValidator validator = new UrlValidator();
+ assertTrue(validator.isValid("http://hello.tokyo/"));
+ }
+
+ public void testValidator363(){
+ UrlValidator urlValidator = new UrlValidator();
+ assertTrue(urlValidator.isValid("http://www.example.org/a/b/hello..world"));
+ assertTrue(urlValidator.isValid("http://www.example.org/a/hello..world"));
+ assertTrue(urlValidator.isValid("http://www.example.org/hello.world/"));
+ assertTrue(urlValidator.isValid("http://www.example.org/hello..world/"));
+ assertTrue(urlValidator.isValid("http://www.example.org/hello.world"));
+ assertTrue(urlValidator.isValid("http://www.example.org/hello..world"));
+ assertTrue(urlValidator.isValid("http://www.example.org/..world"));
+ assertTrue(urlValidator.isValid("http://www.example.org/.../world"));
+ assertFalse(urlValidator.isValid("http://www.example.org/../world"));
+ assertFalse(urlValidator.isValid("http://www.example.org/.."));
+ assertFalse(urlValidator.isValid("http://www.example.org/../"));
+ assertFalse(urlValidator.isValid("http://www.example.org/./.."));
+ assertFalse(urlValidator.isValid("http://www.example.org/././.."));
+ assertTrue(urlValidator.isValid("http://www.example.org/..."));
+ assertTrue(urlValidator.isValid("http://www.example.org/.../"));
+ assertTrue(urlValidator.isValid("http://www.example.org/.../.."));
+ }
+
+ public void testValidator375() {
+ UrlValidator validator = new UrlValidator();
+ String url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";
+ assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
+ url = "http://[::1]:80/index.html";
+ assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
+ url = "http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:80/index.html";
+ assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url));
+ }
+
+
+ public void testValidator353() { // userinfo
+ UrlValidator validator = new UrlValidator();
+ assertTrue(validator.isValid("http://www.apache.org:80/path"));
+ assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path"));
+ assertTrue(validator.isValid("http://user:@www.apache.org:80/path"));
+ assertTrue(validator.isValid("http://user@www.apache.org:80/path"));
+ assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path"));
+ assertFalse(validator.isValid("http://:pass@www.apache.org:80/path"));
+ assertFalse(validator.isValid("http://:@www.apache.org:80/path"));
+ assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path"));
+ assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path"));
+ }
+
+ public void testValidator382() {
+ UrlValidator validator = new UrlValidator();
+ assertTrue(validator.isValid("ftp://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose"));
+ }
+
+ public void testValidator380() {
+ UrlValidator validator = new UrlValidator();
+ assertTrue(validator.isValid("http://www.apache.org:80/path"));
+ assertTrue(validator.isValid("http://www.apache.org:8/path"));
+ assertTrue(validator.isValid("http://www.apache.org:/path"));
+ }
+
+ public void testValidator420() {
+ UrlValidator validator = new UrlValidator();
+ assertFalse(validator.isValid("http://example.com/serach?address=Main Avenue"));
+ assertTrue(validator.isValid("http://example.com/serach?address=Main%20Avenue"));
+ assertTrue(validator.isValid("http://example.com/serach?address=Main+Avenue"));
+ }
+
+ public void testValidator467() {
+ UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
+ assertTrue(validator.isValid("https://example.com/some_path/path/"));
+ assertTrue(validator.isValid("https://example.com//somepath/path/"));
+ assertTrue(validator.isValid("https://example.com//some_path/path/"));
+ }
+
+ //-------------------- Test data for creating a composite URL
+ /**
+ * The data given below approximates the 4 parts of a URL
+ * ://? 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)};
+
+ ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true),
+ 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", false),
+ new ResultPair("go.cc", 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), // max possible
+ new ResultPair(":65536", false), // max possible +1
+ new ResultPair(":0", true),
+ new ResultPair("", true),
+ new ResultPair(":-1", false),
+ new ResultPair(":65636", false),
+ new ResultPair(":999999999999999999", false),
+ 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 ----------------
+ private final String[] schemes = {"http", "gopher", "g0-To+.",
+ "not_valid" // TODO this will need to be dropped if the ctor validates schemes
+ };
+
+ ResultPair[] testScheme = {new ResultPair("http", true),
+ new ResultPair("ftp", false),
+ new ResultPair("httpd", false),
+ new ResultPair("gopher", true),
+ new ResultPair("g0-to+.", true),
+ new ResultPair("not_valid", false), // underscore not allowed
+ new ResultPair("HtTp", true),
+ new ResultPair("telnet", false)};
+
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ABANumberCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ABANumberCheckDigitTest.java
new file mode 100644
index 000000000..18793dd2b
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ABANumberCheckDigitTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ABA Number Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class ABANumberCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ABANumberCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = ABANumberCheckDigit.ABAN_CHECK_DIGIT;
+ valid = new String[] {
+ "123456780",
+ "123123123",
+ "011000015",
+ "111000038",
+ "231381116",
+ "121181976"
+ };
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/AbstractCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/AbstractCheckDigitTest.java
new file mode 100644
index 000000000..c903d371e
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/AbstractCheckDigitTest.java
@@ -0,0 +1,334 @@
+/*
+ * 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.checkdigit;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Luhn Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public abstract class AbstractCheckDigitTest extends TestCase {
+
+ /** logging instance */
+ protected Log log = LogFactory.getLog(getClass());
+
+ /** Check digit routine being tested */
+ protected int checkDigitLth = 1;
+
+ /** Check digit routine being tested */
+ protected CheckDigit routine;
+
+ /**
+ * Array of valid code values
+ * These must contain valid strings *including* the check digit.
+ *
+ * They are passed to:
+ * CheckDigit.isValid(expects string including checkdigit)
+ * which is expected to return true
+ * and
+ * AbstractCheckDigitTest.createInvalidCodes() which
+ * mangles the last character to check that the result is now invalid.
+ * and
+ * the truncated string is passed to
+ * CheckDigit.calculate(expects string without checkdigit)
+ * the result is compared with the last character
+ */
+ protected String[] valid;
+
+ /**
+ * Array of invalid code values
+ *
+ * These are currently passed to both
+ * CheckDigit.calculate(expects a string without checkdigit)
+ * which is expected to throw an exception
+ * However that only applies if the string is syntactically incorrect;
+ * and
+ * CheckDigit.isValid(expects a string including checkdigit)
+ * which is expected to return false
+ *
+ * See https://issues.apache.org/jira/browse/VALIDATOR-344 for some dicussion on this
+ */
+ protected String[] invalid = new String[] {"12345678A"};
+
+ /** code value which sums to zero */
+ protected String zeroSum = "0000000000";
+
+ /** Prefix for error messages */
+ protected String missingMessage = "Code is missing";
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public AbstractCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Tear Down - clears routine and valid codes.
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ valid = null;
+ routine = null;
+ }
+
+ /**
+ * Test isValid() for valid values.
+ */
+ public void testIsValidTrue() {
+ if (log.isDebugEnabled()) {
+ log.debug("testIsValidTrue() for " + routine.getClass().getName());
+ }
+
+ // test valid values
+ for (int i = 0; i < valid.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug(" " + i + " Testing Valid Code=[" + valid[i] + "]");
+ }
+ assertTrue("valid[" + i +"]: " + valid[i], routine.isValid(valid[i]));
+ }
+ }
+
+ /**
+ * Test isValid() for invalid values.
+ */
+ public void testIsValidFalse() {
+ if (log.isDebugEnabled()) {
+ log.debug("testIsValidFalse() for " + routine.getClass().getName());
+ }
+
+ // test invalid code values
+ for (int i = 0; i < invalid.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug(" " + i + " Testing Invalid Code=[" + invalid[i] + "]");
+ }
+ assertFalse("invalid[" + i +"]: " + invalid[i], routine.isValid(invalid[i]));
+ }
+
+ // test invalid check digit values
+ String[] invalidCheckDigits = createInvalidCodes(valid);
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug(" " + i + " Testing Invalid Check Digit, Code=[" + invalidCheckDigits[i] + "]");
+ }
+ assertFalse("invalid check digit[" + i +"]: " + invalidCheckDigits[i], routine.isValid(invalidCheckDigits[i]));
+ }
+ }
+
+ /**
+ * Test calculate() for valid values.
+ */
+ public void testCalculateValid() {
+ if (log.isDebugEnabled()) {
+ log.debug("testCalculateValid() for " + routine.getClass().getName());
+ }
+
+ // test valid values
+ for (int i = 0; i < valid.length; i++) {
+ String code = removeCheckDigit(valid[i]);
+ String expected = checkDigit(valid[i]);
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(" " + i + " Testing Valid Check Digit, Code=[" + code + "] expected=[" + expected + "]");
+ }
+ assertEquals("valid[" + i +"]: " + valid[i], expected, routine.calculate(code));
+ } catch (Exception e) {
+ fail("valid[" + i +"]=" + valid[i] + " threw " + e);
+ }
+ }
+
+ }
+
+ /**
+ * Test calculate() for invalid values.
+ */
+ public void testCalculateInvalid() {
+
+ if (log.isDebugEnabled()) {
+ log.debug("testCalculateInvalid() for " + routine.getClass().getName());
+ }
+
+ // test invalid code values
+ for (int i = 0; i < invalid.length; i++) {
+ try {
+ final String code = invalid[i];
+ if (log.isDebugEnabled()) {
+ log.debug(" " + i + " Testing Invalid Check Digit, Code=[" + code + "]");
+ }
+ String expected = checkDigit(code);
+ String actual = routine.calculate(removeCheckDigit(code));
+ // If exception not thrown, check that the digit is incorrect instead
+ if (expected.equals(actual)) {
+ fail("Expected mismatch for " + code + " expected " + expected + " actual " + actual);
+ }
+ } catch (CheckDigitException e) {
+ // possible failure messages:
+ // Invalid ISBN Length ...
+ // Invalid Character[ ...
+ // Are there any others?
+ assertTrue("Invalid Character[" +i +"]=" + e.getMessage(), e.getMessage().startsWith("Invalid "));
+// WAS assertTrue("Invalid Character[" +i +"]=" + e.getMessage(), e.getMessage().startsWith("Invalid Character["));
+ }
+ }
+ }
+
+ /**
+ * Test missing code
+ */
+ public void testMissingCode() {
+
+ // isValid() null
+ assertFalse("isValid() Null", routine.isValid(null));
+
+ // isValid() zero length
+ assertFalse("isValid() Zero Length", routine.isValid(""));
+
+ // isValid() length 1
+ // Don't use 0, because that passes for Verhoef (not sure why yet)
+ assertFalse("isValid() Length 1", routine.isValid("9"));
+
+ // calculate() null
+ try {
+ routine.calculate(null);
+ fail("calculate() Null - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Null", missingMessage, e.getMessage());
+ }
+
+ // calculate() zero length
+ try {
+ routine.calculate("");
+ fail("calculate() Zero Length - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Zero Length", missingMessage, e.getMessage());
+ }
+ }
+
+ /**
+ * Test zero sum
+ */
+ public void testZeroSum() {
+
+ assertFalse("isValid() Zero Sum", routine.isValid(zeroSum));
+
+ try {
+ routine.calculate(zeroSum);
+ fail("Zero Sum - expected exception");
+ } catch (Exception e) {
+ assertEquals("isValid() Zero Sum", "Invalid code, sum is zero", e.getMessage());
+ }
+
+ }
+
+ /**
+ * Test check digit serialization.
+ */
+ public void testSerialization() {
+ // Serialize the check digit routine
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(routine);
+ oos.flush();
+ oos.close();
+ } catch (Exception e) {
+ fail(routine.getClass().getName() + " error during serialization: " + e);
+ }
+
+ // Deserialize the test object
+ Object result = null;
+ try {
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ result = ois.readObject();
+ bais.close();
+ } catch (Exception e) {
+ fail(routine.getClass().getName() + " error during deserialization: " + e);
+ }
+ assertNotNull(result);
+ }
+
+ private static final String POSSIBLE_CHECK_DIGITS = "0123456789 ABCDEFHIJKLMNOPQRSTUVWXYZ\tabcdefghijklmnopqrstuvwxyz!@£$%^&*()_+";
+// private static final String POSSIBLE_CHECK_DIGITS = "0123456789";
+ /**
+ * Returns an array of codes with invalid check digits.
+ *
+ * @param codes Codes with valid check digits
+ * @return Codes with invalid check digits
+ */
+ protected String[] createInvalidCodes(String[] codes) {
+ List list = new ArrayList();
+
+ // create invalid check digit values
+ for (String fullCode : codes) {
+ String code = removeCheckDigit(fullCode);
+ String check = checkDigit(fullCode);
+ for (int j = 0; j < POSSIBLE_CHECK_DIGITS.length(); j++) {
+ String curr = POSSIBLE_CHECK_DIGITS.substring(j, j + 1);//"" + Character.forDigit(j, 10);
+ if (!curr.equals(check)) {
+ list.add(code + curr);
+ }
+ }
+ }
+
+ return list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Returns a code with the Check Digit (i.e. last character) removed.
+ *
+ * @param code The code
+ * @return The code without the check digit
+ */
+ protected String removeCheckDigit(String code) {
+ if (code == null || code.length() <= checkDigitLth) {
+ return null;
+ }
+ return code.substring(0, code.length() - checkDigitLth);
+ }
+
+ /**
+ * Returns the check digit (i.e. last character) for a code.
+ *
+ * @param code The code
+ * @return The check digit
+ */
+ protected String checkDigit(String code) {
+ if (code == null || code.length() <= checkDigitLth) {
+ return "";
+ }
+ int start = code.length() - checkDigitLth;
+ return code.substring(start);
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/CUSIPCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/CUSIPCheckDigitTest.java
new file mode 100644
index 000000000..b45d19e8d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/CUSIPCheckDigitTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * CUSIP Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class CUSIPCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Construct a new test.
+ * @param name test name
+ */
+ public CUSIPCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = CUSIPCheckDigit.CUSIP_CHECK_DIGIT;
+ valid = new String[] {"037833100",
+ "931142103",
+ "837649128",
+ "392690QT3",
+ "594918104",
+ "86770G101",
+ "Y8295N109",
+ "G8572F100"
+ };
+ invalid = new String[] {"0378#3100"};
+ }
+
+ private static String invalidCheckDigits[] = {"DUS0421CW",
+ "DUS0421CN",
+ "DUS0421CE"
+ };
+
+ public void testVALIDATOR_336_InvalidCheckDigits() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit, routine.isValid(invalidCheckDigit));
+ }
+ }
+
+ private static String validCheckDigits[] = {"DUS0421C5"};
+
+ public void testVALIDATOR_336_ValidCheckDigits() {
+ for (int i = 0; i < validCheckDigits.length; i++) {
+ String validCheckDigit = validCheckDigits[i];
+ assertTrue("Should fail: " + validCheckDigit, routine.isValid(validCheckDigit));
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/EAN13CheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/EAN13CheckDigitTest.java
new file mode 100644
index 000000000..203483eff
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/EAN13CheckDigitTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * EAN-13 Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class EAN13CheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public EAN13CheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = EAN13CheckDigit.EAN13_CHECK_DIGIT;
+ valid = new String[] {
+ "9780072129519",
+ "9780764558313",
+ "4025515373438",
+ "0095673400332"};
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java
new file mode 100644
index 000000000..a2253b037
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/IBANCheckDigitTest.java
@@ -0,0 +1,255 @@
+/*
+ * 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.checkdigit;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+
+
+/**
+ * EAN-13 Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class IBANCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public IBANCheckDigitTest(String name) {
+ super(name);
+ checkDigitLth = 2;
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = IBANCheckDigit.IBAN_CHECK_DIGIT;
+ valid = new String[] {
+ "AD1200012030200359100100", // Andorra
+ "AE070331234567890123456", // United Arab Emirates
+ "AL47212110090000000235698741", // Albania
+ "AT611904300234573201", // Austria
+ "AZ21NABZ00000000137010001944", // Azerbaijan
+ "BA391290079401028494", // Bosnia and Herzegovina
+ "BE62510007547061", // Belgium
+ "BE68539007547034", // Belgium
+ "BG80BNBG96611020345678", // Bulgaria
+ "BH67BMAG00001299123456", // Bahrain
+ "BR1800000000141455123924100C2", // Brazil
+ "BY13NBRB3600900000002Z00AB00", // Belarus
+ "CH3900700115201849173", // Switzerland
+ "CH9300762011623852957", // Switzerland
+ "CR05015202001026284066", // Costa Rica
+ "CY17002001280000001200527600", // Cyprus
+ "CZ6508000000192000145399", // Czechoslovakia
+ "DE89370400440532013000", // Germany
+ "DK5000400440116243", // Denmark
+ "DO28BAGR00000001212453611324", // Dominican Republic
+ "EE382200221020145685", // Estonia
+ "ES8023100001180000012345", // Spain
+ "FI2112345600000785", // Finland
+ "FO6264600001631634", // Denmark (Faroes)
+ "FR1420041010050500013M02606", // France
+ "GB29NWBK60161331926819", // UK
+ "GI75NWBK000000007099453", // Gibraltar
+ "GL8964710001000206", // Denmark (Greenland)
+ "GR1601101250000000012300695", // Greece
+ "GT82TRAJ01020000001210029690", // Guatemala
+ "HR1210010051863000160", // Croatia
+ "HU42117730161111101800000000", // Hungary
+ "IE29AIBK93115212345678", // Ireland
+ "IL620108000000099999999", // Israel
+ "IQ98NBIQ850123456789012", // Iraq
+ "IS140159260076545510730339", // Iceland
+ "IT60X0542811101000000123456", // Italy
+ "JO94CBJO0010000000000131000302",// Jordan
+ "KW81CBKU0000000000001234560101",// Kuwait
+ "KZ86125KZT5004100100", // Kazakhstan
+ "LB62099900000001001901229114", // Lebanon
+ "LC55HEMM000100010012001200023015",//Saint Lucia
+ "LI21088100002324013AA", // Liechtenstein (Principality of)
+ "LT121000011101001000", // Lithuania
+ "LU280019400644750000", // Luxembourg
+ "LV80BANK0000435195001", // Latvia
+ "MC5811222000010123456789030", // Monaco
+ "MD24AG000225100013104168", // Moldova
+ "ME25505000012345678951", // Montenegro
+ "MK07250120000058984", // Macedonia, Former Yugoslav Republic of
+ "MR1300020001010000123456753", // Mauritania
+ "MT84MALT011000012345MTLCAST001S",// Malta
+ "MU17BOMM0101101030300200000MUR",// Mauritius
+ "NL39RABO0300065264", // Netherlands
+ "NL91ABNA0417164300", // Netherlands
+ "NO9386011117947", // Norway
+ "PK36SCBL0000001123456702", // Pakistan
+ "PL27114020040000300201355387", // Poland
+ "PL60102010260000042270201111", // Poland
+ "PS92PALS000000000400123456702", // Palestine, State of
+ "PT50000201231234567890154", // Portugal
+ "QA58DOHB00001234567890ABCDEFG", // Qatar
+ "RO49AAAA1B31007593840000", // Romania
+ "RS35260005601001611379", // Serbia
+ "SA0380000000608010167519", // Saudi Arabia
+ "SC18SSCB11010000000000001497USD",// Seychelles
+ "SE3550000000054910000003", // Sweden
+ "SI56191000000123438", // Slovenia
+ "SK3112000000198742637541", // Slovak Republic
+ "SM86U0322509800000000270100", // San Marino
+ "ST68000100010051845310112", // Sao Tome and Principe
+ "SV62CENR00000000000000700025", // El Salvador
+ "TL380080012345678910157", // Timor-Leste
+ "TN5910006035183598478831", // Tunisia
+ "TR330006100519786457841326", // Turkey
+ "UA213223130000026007233566001", // Ukraine
+ "VA59001123000012345678", // Vatican City State
+ "VG96VPVG0000012345678901", // Virgin Islands, British
+ "XK051212012345678906", // Republic of Kosovo
+
+ // Codes AA and ZZ will never be used as ISO countries nor in IBANs
+ // add some dummy calculated codes to test the limits
+ // Current minimum length is Norway = 15
+ // Current maximum length is Malta = 31
+ // N.B. These codes will fail online checkers which validate the IBAN format
+ //234567890123456789012345678901
+ "AA0200000000053",
+ "AA9700000000089",
+ "AA9800000000071",
+ "ZZ02ZZZZZZZZZZZZZZZZZZZZZZZZZ04",
+ "ZZ97ZZZZZZZZZZZZZZZZZZZZZZZZZ40",
+ "ZZ98ZZZZZZZZZZZZZZZZZZZZZZZZZ22",
+ };
+ /*
+ * sources
+ * https://intranet.birmingham.ac.uk/finance/documents/public/IBAN.pdf
+ * http://www.paymentscouncil.org.uk/resources_and_publications/ibans_in_europe/
+ */
+ invalid = new String[] {
+ "510007+47061BE63",
+ "IE01AIBK93118702569045",
+ "AA0000000000089",
+ "AA9900000000053",
+ };
+ zeroSum = null;
+ missingMessage = "Invalid Code length=0";
+
+ }
+
+ /**
+ * Test zero sum
+ */
+ @Override
+ public void testZeroSum() {
+ // ignore, don't run this test
+
+ // example code used to create dummy IBANs
+// try {
+// for(int i=0; i<97;i++) {
+// String check = String.format("ZZ00ZZZZZZZZZZZZZZZZZZZZZZZZZ%02d", new Object[]{Integer.valueOf(i)});
+// String chk = routine.calculate(check);
+// if (chk.equals("97")||chk.equals("98")||chk.equals("02")) {
+// System.out.println(check+ " "+chk);
+// }
+// }
+// } catch (CheckDigitException e) {
+// e.printStackTrace();
+// }
+ }
+
+ /**
+ * Returns an array of codes with invalid check digits.
+ *
+ * @param codes Codes with valid check digits
+ * @return Codes with invalid check digits
+ */
+ @Override
+ protected String[] createInvalidCodes(String[] codes) {
+ List list = new ArrayList();
+
+ // create invalid check digit values
+ for (int i = 0; i < codes.length; i++) {
+ String code = removeCheckDigit(codes[i]);
+ String check = checkDigit(codes[i]);
+ for (int j = 2; j <= 98; j++) { // check digits can be from 02-98 (00 and 01 are not possible)
+ String curr = j > 9 ? "" + j : "0" + j;
+ if (!curr.equals(check)) {
+ list.add(code.substring(0, 2) + curr + code.substring(4));
+ }
+ }
+ }
+
+ return list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Returns a code with the Check Digits (i.e. characters 3&4) set to "00".
+ *
+ * @param code The code
+ * @return The code with the zeroed check digits
+ */
+ @Override
+ protected String removeCheckDigit(String code) {
+ return code.substring(0, 2) + "00" + code.substring(4);
+ }
+
+ /**
+ * Returns the check digit (i.e. last character) for a code.
+ *
+ * @param code The code
+ * @return The check digit
+ */
+ @Override
+ protected String checkDigit(String code) {
+ if (code == null || code.length() <= checkDigitLth) {
+ return "";
+ }
+ return code.substring(2, 4);
+ }
+
+ public void testOther() throws Exception {
+ BufferedReader rdr = null;
+ try {
+ rdr = new BufferedReader(
+ new InputStreamReader(
+ this.getClass().getResourceAsStream("IBANtests.txt"),"ASCII"));
+ String line;
+ while((line=rdr.readLine()) != null) {
+ if (!line.startsWith("#") && line.length() > 0) {
+ if (line.startsWith("-")) {
+ line = line.substring(1);
+ Assert.assertFalse(line, routine.isValid(line.replaceAll(" ", "")));
+ } else {
+ Assert.assertTrue(line, routine.isValid(line.replaceAll(" ", "")));
+ }
+ }
+ }
+ } finally {
+ if (rdr != null) {
+ rdr.close();
+ }
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBN10CheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBN10CheckDigitTest.java
new file mode 100644
index 000000000..9f7a8b47e
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBN10CheckDigitTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ISBN-10 Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class ISBN10CheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ISBN10CheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = ISBN10CheckDigit.ISBN10_CHECK_DIGIT;
+ valid = new String[] {
+ "1930110995",
+ "020163385X",
+ "1932394354",
+ "1590596277"
+ };
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBNCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBNCheckDigitTest.java
new file mode 100644
index 000000000..98d752da6
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBNCheckDigitTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ISBN-10/ISBN-13 Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class ISBNCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ISBNCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = ISBNCheckDigit.ISBN_CHECK_DIGIT;
+ valid = new String[] {
+ "9780072129519",
+ "9780764558313",
+ "1930110995",
+ "020163385X",
+ "1590596277", // ISBN-10 Ubuntu Book
+ "9781590596272" // ISBN-13 Ubuntu Book
+ };
+ missingMessage = "ISBN Code is missing";
+ zeroSum = "000000000000";
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ public void testInvalidLength() {
+ assertFalse("isValid() Lth 9 ", routine.isValid("123456789"));
+ assertFalse("isValid() Lth 11", routine.isValid("12345678901"));
+ assertFalse("isValid() Lth 12", routine.isValid("123456789012"));
+ assertFalse("isValid() Lth 14", routine.isValid("12345678901234"));
+
+ try {
+ routine.calculate("12345678");
+ fail("calculate() Lth 8 - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Lth 8", "Invalid ISBN Length = 8", e.getMessage());
+ }
+
+ try {
+ routine.calculate("1234567890");
+ fail("calculate() Lth 10 - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Lth 10", "Invalid ISBN Length = 10", e.getMessage());
+ }
+
+ try {
+ routine.calculate("12345678901");
+ fail("calculate() Lth 11 - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Lth 11", "Invalid ISBN Length = 11", e.getMessage());
+ }
+
+ try {
+ routine.calculate("1234567890123");
+ fail("calculate() Lth 13 - expected exception");
+ } catch (Exception e) {
+ assertEquals("calculate() Lth 13", "Invalid ISBN Length = 13", e.getMessage());
+ }
+ }
+
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
new file mode 100644
index 000000000..a3e218dfb
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ISIN Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class ISINCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ISINCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = ISINCheckDigit.ISIN_CHECK_DIGIT;
+ valid = new String[] {"US0378331005",
+ "BMG8571G1096",
+ "AU0000XVGZA3",
+ "GB0002634946",
+ "FR0004026250",
+ "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
+ "DK0009763344",
+ "dk0009763344", // TODO lowercase is currently accepted, but is this valid?
+ "AU0000xvgza3", // lowercase NSIN
+ "EZ0000000003", // Invented; for use in ISINValidatorTest
+ "XS0000000009", // ditto
+ "AA0000000006", // ditto
+ };
+ invalid = new String[] {"0378#3100"};
+ }
+
+ private static String invalidCheckDigits[] =
+ {"US037833100O", // proper check digit is '5', see above
+ "BMG8571G109D", // proper check digit is '6', see above
+ "AU0000XVGZAD", // proper check digit is '3', see above
+ "GB000263494I", // proper check digit is '6', see above
+ "FR000402625C", // proper check digit is '0', see above
+ "DK000976334H", // proper check digit is '4', see above
+ };
+
+ public void testVALIDATOR_345() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit, routine.isValid(invalidCheckDigit));
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISSNCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISSNCheckDigitTest.java
new file mode 100644
index 000000000..ba5120850
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ISSNCheckDigitTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ISSN Check Digit Test.
+ *
+ * @since 1.5.0
+ */
+public class ISSNCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ISSNCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = ISSNCheckDigit.ISSN_CHECK_DIGIT;
+ valid = new String[] {
+ "03178471",
+ "1050124X",
+ "15626865",
+ "10637710",
+ "17487188",
+ "02642875",
+ "17500095",
+ "11881534",
+ "19111479",
+ "19111460",
+ "00016772",
+ "1365201X",
+ };
+ invalid = new String[] {
+ "03178472", // wrong check
+ "1050-124X", // format char
+ " 1365201X",
+ "1365201X ",
+ " 1365201X ",
+ };
+ missingMessage = "Code is missing";
+ zeroSum = "00000000";
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/LuhnCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/LuhnCheckDigitTest.java
new file mode 100644
index 000000000..f70bb2f6c
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/LuhnCheckDigitTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * Luhn Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class LuhnCheckDigitTest extends AbstractCheckDigitTest {
+
+ private static final String VALID_VISA = "4417123456789113";
+ private static final String VALID_SHORT_VISA = "4222222222222";
+ private static final String VALID_AMEX = "378282246310005";
+ private static final String VALID_MASTERCARD = "5105105105105100";
+ private static final String VALID_DISCOVER = "6011000990139424";
+ private static final String VALID_DINERS = "30569309025904";
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public LuhnCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ routine = LuhnCheckDigit.LUHN_CHECK_DIGIT;
+
+ valid = new String[] {
+ VALID_VISA,
+ VALID_SHORT_VISA,
+ VALID_AMEX,
+ VALID_MASTERCARD,
+ VALID_DISCOVER,
+ VALID_DINERS};
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenABACheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenABACheckDigitTest.java
new file mode 100644
index 000000000..5c73d8a33
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenABACheckDigitTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ModulusTenCheckDigit ABA Number Check Digit Test.
+ *
+ * @version $Revision$
+ */
+public class ModulusTenABACheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ModulusTenABACheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = new ModulusTenCheckDigit(new int[] { 1, 7, 3 }, true);
+ valid = new String[] {
+ "123456780",
+ "123123123",
+ "011000015",
+ "111000038",
+ "231381116",
+ "121181976"
+ };
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenCUSIPCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenCUSIPCheckDigitTest.java
new file mode 100644
index 000000000..35fa8bedd
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenCUSIPCheckDigitTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ModulusTenCheckDigit CUSIP Test.
+ *
+ * @version $Revision$
+ */
+public class ModulusTenCUSIPCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Construct a new test.
+ * @param name test name
+ */
+ public ModulusTenCUSIPCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = new ModulusTenCheckDigit(new int[] { 1, 2}, true, true);
+ valid = new String[] {"037833100",
+ "931142103",
+ "837649128",
+ "392690QT3",
+ "594918104",
+ "86770G101",
+ "Y8295N109",
+ "G8572F100"
+ };
+ invalid = new String[] {"0378#3100"};
+ }
+
+ private static String invalidCheckDigits[] = {"DUS0421CW",
+ "DUS0421CN",
+ "DUS0421CE"
+ };
+
+ public void testVALIDATOR_336_InvalidCheckDigits() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit, routine.isValid(invalidCheckDigit));
+ }
+ }
+
+ private static String validCheckDigits[] = {"DUS0421C5"};
+
+ public void testVALIDATOR_336_ValidCheckDigits() {
+ for (int i = 0; i < validCheckDigits.length; i++) {
+ String validCheckDigit = validCheckDigits[i];
+ assertTrue("Should fail: " + validCheckDigit, routine.isValid(validCheckDigit));
+ }
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenEAN13CheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenEAN13CheckDigitTest.java
new file mode 100644
index 000000000..ca5df7a38
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenEAN13CheckDigitTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ModulusTenCheckDigit EAN-13 Test.
+ *
+ * @version $Revision$
+ */
+public class ModulusTenEAN13CheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ModulusTenEAN13CheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = new ModulusTenCheckDigit(new int[] { 1, 3 }, true);
+ valid = new String[] {
+ "9780072129519",
+ "9780764558313",
+ "4025515373438",
+ "0095673400332"};
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenLuhnCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenLuhnCheckDigitTest.java
new file mode 100644
index 000000000..27bb26a6d
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenLuhnCheckDigitTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ModulusTenCheckDigit Luhn Test.
+ *
+ * @version $Revision$
+ */
+public class ModulusTenLuhnCheckDigitTest extends AbstractCheckDigitTest {
+
+ private static final String VALID_VISA = "4417123456789113";
+ private static final String VALID_SHORT_VISA = "4222222222222";
+ private static final String VALID_AMEX = "378282246310005";
+ private static final String VALID_MASTERCARD = "5105105105105100";
+ private static final String VALID_DISCOVER = "6011000990139424";
+ private static final String VALID_DINERS = "30569309025904";
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ModulusTenLuhnCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ routine = new ModulusTenCheckDigit(new int[] {1, 2}, true, true);
+
+ valid = new String[] {
+ VALID_VISA,
+ VALID_SHORT_VISA,
+ VALID_AMEX,
+ VALID_MASTERCARD,
+ VALID_DISCOVER,
+ VALID_DINERS};
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenSedolCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenSedolCheckDigitTest.java
new file mode 100644
index 000000000..c38540649
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenSedolCheckDigitTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ModulusTenCheckDigit SEDOL Test.
+ *
+ * @version $Revision$
+ */
+public class ModulusTenSedolCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public ModulusTenSedolCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = new ModulusTenCheckDigit(new int[] { 1, 3, 1, 7, 3, 9, 1 });
+ valid = new String[] {
+ "0263494",
+ "0870612",
+ "B06LQ97",
+ "3437575",
+ "B07LF55",
+ };
+ invalid = new String[] {"123#567"};
+ zeroSum = "0000000";
+ }
+
+ private static String invalidCheckDigits[] = {
+ "026349E", // proper check digit is '4', see above
+ "087061C", // proper check digit is '2', see above
+ "B06LQ9H", // proper check digit is '7', see above
+ "343757F", // proper check digit is '5', see above
+ "B07LF5F", // proper check digit is '5', see above
+ };
+
+ public void testVALIDATOR_346() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit, routine.isValid(invalidCheckDigit));
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigitTest.java
new file mode 100644
index 000000000..269473e44
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigitTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.checkdigit;
+
+
+/**
+ * ISIN Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class SedolCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Constructor
+ * @param name test name
+ */
+ public SedolCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = SedolCheckDigit.SEDOL_CHECK_DIGIT;
+ valid = new String[] {
+ "0263494",
+ "0870612",
+ "B06LQ97",
+ "3437575",
+ "B07LF55",
+ };
+ invalid = new String[] {"123#567"};
+ zeroSum = "0000000";
+ }
+
+ private static String invalidCheckDigits[] = {
+ "026349E", // proper check digit is '4', see above
+ "087061C", // proper check digit is '2', see above
+ "B06LQ9H", // proper check digit is '7', see above
+ "343757F", // proper check digit is '5', see above
+ "B07LF5F", // proper check digit is '5', see above
+ };
+
+ public void testVALIDATOR_346() {
+ for (int i = 0; i < invalidCheckDigits.length; i++) {
+ String invalidCheckDigit = invalidCheckDigits[i];
+ assertFalse("Should fail: " + invalidCheckDigit, routine.isValid(invalidCheckDigit));
+ }
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/VerhoeffCheckDigitTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/VerhoeffCheckDigitTest.java
new file mode 100644
index 000000000..c4270e5f1
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/routines/checkdigit/VerhoeffCheckDigitTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.checkdigit;
+
+/**
+ * Verhoeff Check Digit Test.
+ *
+ * @version $Revision$
+ * @since Validator 1.4
+ */
+public class VerhoeffCheckDigitTest extends AbstractCheckDigitTest {
+
+ /**
+ * Construct a new test.
+ * @param name test name
+ */
+ public VerhoeffCheckDigitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up routine & valid codes.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ routine = VerhoeffCheckDigit.VERHOEFF_CHECK_DIGIT;
+ valid = new String[] {
+ "15",
+ "1428570",
+ "12345678902"
+ };
+ }
+
+ /**
+ * Test zero sum
+ */
+ @Override
+ public void testZeroSum() {
+ // ignore, don't run this test
+ }
+}
diff --git a/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/util/FlagsTest.java b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/util/FlagsTest.java
new file mode 100644
index 000000000..9ae88c088
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/java/org/apache/commons/validator/util/FlagsTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the Flags class.
+ *
+ * @version $Revision$
+ */
+public class FlagsTest extends TestCase {
+
+ /**
+ * Declare some flags for testing.
+ */
+ private static final long LONG_FLAG = 1;
+ private static final long LONG_FLAG_2 = 2;
+ private static final int INT_FLAG = 4;
+
+ /**
+ * Constructor for FlagsTest.
+ */
+ public FlagsTest(String name) {
+ super(name);
+ }
+
+ public void testHashCode() {
+ Flags f = new Flags(45);
+ assertEquals(f.hashCode(), 45);
+ }
+
+ public void testGetFlags() {
+ Flags f = new Flags(45);
+ assertEquals(f.getFlags(), 45);
+ }
+
+ public void testIsOnOff() {
+ Flags f = new Flags();
+ f.turnOn(LONG_FLAG);
+ f.turnOn(INT_FLAG);
+ assertTrue(f.isOn(LONG_FLAG));
+ assertTrue(!f.isOff(LONG_FLAG));
+
+ assertTrue(f.isOn(INT_FLAG));
+ assertTrue(!f.isOff(INT_FLAG));
+
+ assertTrue(f.isOff(LONG_FLAG_2));
+ }
+
+ public void testTurnOnOff() {
+ }
+
+ public void testTurnOff() {
+ }
+
+ public void testTurnOffAll() {
+ Flags f = new Flags(98432);
+ f.turnOffAll();
+ assertEquals(0, f.getFlags());
+ }
+
+ public void testClear() {
+ Flags f = new Flags(98432);
+ f.clear();
+ assertEquals(0, f.getFlags());
+ }
+
+ public void testTurnOnAll() {
+ Flags f = new Flags();
+ f.turnOnAll();
+ assertEquals(~0, f.getFlags());
+ }
+
+ public void testIsOn_isFalseWhenNotAllFlagsInArgumentAreOn() {
+ Flags first = new Flags(1);
+ long firstAndSecond = 3;
+
+ assertFalse(first.isOn(firstAndSecond));
+ }
+
+ public void testIsOn_isTrueWhenHighOrderBitIsSetAndQueried() {
+ Flags allOn = new Flags(~0);
+ long highOrderBit = 0x8000000000000000L;
+
+ assertTrue(allOn.isOn(highOrderBit));
+ }
+
+ /**
+ * Test for Object clone()
+ */
+ public void testClone() {
+ }
+
+ /**
+ * Test for boolean equals(Object)
+ */
+ public void testEqualsObject() {
+ }
+
+ /**
+ * Test for String toString()
+ */
+ public void testToString() {
+ Flags f = new Flags();
+ String s = f.toString();
+ assertEquals(64, s.length());
+
+ f.turnOn(INT_FLAG);
+ s = f.toString();
+ assertEquals(64, s.length());
+
+ assertEquals(
+ "0000000000000000000000000000000000000000000000000000000000000100",
+ s);
+ }
+
+}
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/DateTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/DateTest-config.xml
new file mode 100644
index 000000000..10fed9763
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/DateTest-config.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EmailTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EmailTest-config.xml
new file mode 100644
index 000000000..114a2d866
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EmailTest-config.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-byteform.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-byteform.xml
new file mode 100644
index 000000000..a243b26b4
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-byteform.xml
@@ -0,0 +1,19 @@
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-config.xml
new file mode 100644
index 000000000..58d334f60
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/EntityImportTest-config.xml
@@ -0,0 +1,33 @@
+
+]>
+
+
+
+
+
+
+ &byteform;
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExceptionTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExceptionTest-config.xml
new file mode 100644
index 000000000..c6189fe98
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExceptionTest-config.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExtensionTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExtensionTest-config.xml
new file mode 100644
index 000000000..e57c355d6
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ExtensionTest-config.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/GenericTypeValidatorTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/GenericTypeValidatorTest-config.xml
new file mode 100644
index 000000000..c621f6878
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/GenericTypeValidatorTest-config.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/LocaleTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/LocaleTest-config.xml
new file mode 100644
index 000000000..aa4875849
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/LocaleTest-config.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-1-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-1-config.xml
new file mode 100644
index 000000000..36aab8188
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-1-config.xml
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ testConstName1
+ testConstValue1
+
+
+
+
+
+
+
+
+
+ testConstName1_fr
+ testConstValue1_fr
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-2-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-2-config.xml
new file mode 100644
index 000000000..0af4948c7
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-2-config.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+
+ testConstName2
+ testConstValue2
+
+
+
+
+
+
+
+
+
+
+
+ testConstName2_fr
+ testConstValue2_fr
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleTests-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleTests-config.xml
new file mode 100644
index 000000000..7ae62e590
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/MultipleTests-config.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ParameterTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ParameterTest-config.xml
new file mode 100644
index 000000000..3ef0f9309
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ParameterTest-config.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredIfTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredIfTest-config.xml
new file mode 100644
index 000000000..6a89ba7f5
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredIfTest-config.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredNameTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredNameTest-config.xml
new file mode 100644
index 000000000..cd3fd7f89
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RequiredNameTest-config.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RetrieveFormTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RetrieveFormTest-config.xml
new file mode 100644
index 000000000..ff931e523
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/RetrieveFormTest-config.xml
@@ -0,0 +1,157 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/TestNumber-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/TestNumber-config.xml
new file mode 100644
index 000000000..796286dc7
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/TestNumber-config.xml
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ValidatorResultsTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ValidatorResultsTest-config.xml
new file mode 100644
index 000000000..0d2f2fa3a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/ValidatorResultsTest-config.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/VarTest-config.xml b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/VarTest-config.xml
new file mode 100644
index 000000000..2657704a7
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/VarTest-config.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/routines/checkdigit/IBANtests.txt b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/routines/checkdigit/IBANtests.txt
new file mode 100644
index 000000000..c4b47599a
--- /dev/null
+++ b/Java-base/commons-validator/src/src/test/resources/org/apache/commons/validator/routines/checkdigit/IBANtests.txt
@@ -0,0 +1,113 @@
+# 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.
+
+# Derived from:
+# http://www.sparkasse.at/oberoesterreich/Firmenkunden/Produkte/auslandsgeschaeft/auslaendischer-zahlungsverkehr/IBAN-laenderliste
+#
+
+AL47 2121 1009 0000 0002 3569 8741
+AD12 0001 2030 2003 5910 0100
+BE68 5390 0754 7034
+BA39 1290 0794 0102 8494
+BG80 BNBG 9661 1020 3456 78
+DK50 0040 0440 1162 43
+FO62 6460 0001 6316 34
+GL89 6471 0001 0002 06
+DE89 3704 0044 0532 0130 00
+GB29 NWBK 6016 1331 9268 19
+EE38 2200 2210 2014 5685
+FI21 1234 5600 0007 85
+FR14 2004 1010 0505 0001 3M02 606
+GI75 NWBK 0000 0000 7099 453
+GR16 0110 1250 0000 0001 2300 695
+IE29 AIBK 9311 5212 3456 78
+IS14 0159 2600 7654 5510 7303 39
+IT60 X054 2811 1010 0000 0123 456
+HR12 1001 0051 8630 0016 0
+LV80 BANK 0000 4351 9500 1
+LI21 0881 0000 2324 013A A
+LT12 1000 0111 0100 1000
+LU28 0019 4006 4475 0000
+MT84 MALT 0110 0001 2345 MTLC AST0 01S
+MK07 2501 2000 0058 984
+MC58 11222 00001 0123456789030
+ME25 5050 0001 2345 6789 51
+NL91 ABNA 0417 1643 00
+NO93 8601 1117 947
+AT61 1904 3002 3457 3201
+PL61 1090 1014 0000 0712 1981 2874
+PT50 0002 0123 1234 5678 9015 4
+RO49 AAAA 1B31 0075 9384 0000
+SM86 U032 2509 8000 0000 0270 100
+SE45 5000 0000 0583 9825 7466
+CH93 0076 2011 6238 5295 7
+RS35 2600 0560 1001 6113 79
+SK31 1200 0000 1987 4263 7541
+SI56 1910 0000 0123 438
+ES91 2100 0418 4502 0005 1332
+CZ94 5500 0000 0010 1103 8930
+TR33 0006 1005 1978 6457 8413 26
+HU42 1177 3016 1111 1018 0000 0000
+CY17 0020 0128 0000 0012 0052 7600
+
+AO06 0006 0000 0100 0371 3117 4
+AZ21 NABZ 0000 0000 1370 1000 1944
+BH67 BMAG 0000 1299 1234 56
+BJ11 B006 1010 0400 2711 0119 2591
+BR97 0036 0305 0000 1000 9795 493P 1
+VG96 VPVG 0000 0123 4567 8901
+BF10 3013 4020 0154 0094 5000 643
+BI43 2010 1106 7444
+CR05 1520 2001 0262 8406 6
+DO28 BAGR 0000 0001 2124 5361 1324
+GE29 NB00 0000 0101 9049 17
+IR58 0540 1051 8002 1273 1130 07
+IL62 0108 0000 0009 9999 999
+
+# Does not appear to be a valid IBAN
+#JO99 BJOR 9999 1234 5678 9012 3456 78
+# This example from http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
+JO94 CBJO 0010 0000 0000 0131 0003 02
+
+CM21 1000 3001 0005 0000 0605 306
+CV64 0003 0000 4547 0691 1017 6
+KZ86 125K ZT50 0410 0100
+QA58 DOHB 0000 1234 5678 90AB CDEF G
+CG52 3001 1000 2021 5123 4567 890
+KW81 CBKU 0000 0000 0000 1234 5601 01
+LB62 0999 0000 0001 0019 0122 9114
+MG46 0000 5030 0101 0191 4016 056
+ML03 D008 9017 0001 0021 2000 0447
+MR13 0002 0001 0100 0012 3456 753
+MU17 BOMM 0101 1010 3030 0200 000M UR
+MD24 AG00 0225 1000 1310 4168
+MZ59 0001 0000 0011 8341 9415 7
+PK36 SCBL 0000 0011 2345 6702
+PS92 PALS 0000 0000 0400 1234 5670 2
+CI05 A000 6017 4100 1785 3001 1852
+SA03 8000 0000 6080 1016 7519
+PT50 0002 0000 0163 0993 1035 5
+SN12 K001 0015 2000 0256 9000 7542
+TN59 1000 6035 1835 9847 8831
+AE07 0331 2345 6789 0123 456
+FR76 3000 7000 1100 0997 0004 942
+
+# VALIDATOR-378
+CH59 09000 0001 7342 7712
+# This passes the checksum test, but the length is wrong (we don't check that)
+CH59 9000 0001 7342 7712
+# However this does fail the check digit test:
+# (a leading minus sign means the check should fail)
+-CH59 90000 0001 7342 7712
diff --git a/Java-base/directory-mavibot/Dockerfile b/Java-base/directory-mavibot/Dockerfile
new file mode 100644
index 000000000..e208c4890
--- /dev/null
+++ b/Java-base/directory-mavibot/Dockerfile
@@ -0,0 +1,28 @@
+FROM ubuntu:22.04
+
+RUN export DEBIAN_FRONTEND=noninteractive \
+ && apt-get update \
+ && apt-get install -y software-properties-common \
+ && add-apt-repository ppa:deadsnakes/ppa \
+ && apt-get update \
+ && apt-get install -y \
+ build-essential \
+ git \
+ vim \
+ jq \
+ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/list/*
+
+RUN apt-get -y install sudo \
+ openjdk-8-jdk \
+ maven
+
+RUN bash -c "echo 2 | update-alternatives --config java"
+
+COPY src /workspace
+WORKDIR /workspace
+
+RUN mvn install -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false
+
+RUN mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100
+
+ENV TZ=Asia/Seoul
diff --git a/Java-base/directory-mavibot/src/LICENSE b/Java-base/directory-mavibot/src/LICENSE
new file mode 100644
index 000000000..d64569567
--- /dev/null
+++ b/Java-base/directory-mavibot/src/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/Java-base/directory-mavibot/src/NOTICE b/Java-base/directory-mavibot/src/NOTICE
new file mode 100644
index 000000000..848822955
--- /dev/null
+++ b/Java-base/directory-mavibot/src/NOTICE
@@ -0,0 +1,5 @@
+Apache Mavibot
+Copyright 2012-2014 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/Java-base/directory-mavibot/src/distribution/pom.xml b/Java-base/directory-mavibot/src/distribution/pom.xml
new file mode 100644
index 000000000..c11f862c7
--- /dev/null
+++ b/Java-base/directory-mavibot/src/distribution/pom.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.directory.mavibot
+ mavibot-parent
+ 1.0.0-M9-SNAPSHOT
+
+
+ distribution
+ pom
+ Apache Mavibot Distribution
+
+
+ ${project.build.directory}/docs
+
+
+
+
+
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
+
+
+ ${project.groupId}
+ mavibot
+ ${project.version}
+
+
+
+
+
+ apache-release
+
+
+ mavibot-${project.version}
+
+
+
+ maven-assembly-plugin
+
+
+ src/main/assembly/bin.xml
+ src/main/assembly/src.xml
+
+ gnu
+
+
+
+
+ package
+
+ single
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/distribution/src/main/assembly/bin.xml b/Java-base/directory-mavibot/src/distribution/src/main/assembly/bin.xml
new file mode 100644
index 000000000..bdb9b0d72
--- /dev/null
+++ b/Java-base/directory-mavibot/src/distribution/src/main/assembly/bin.xml
@@ -0,0 +1,78 @@
+
+
+
+
+ bin
+
+ tar.gz
+ zip
+
+
+
+
+
+
+ ..
+
+
+ LICENSE
+ NOTICE
+
+
+
+
+
+ ../target/site
+ docs
+
+ apidocs*/**
+ xref*/**
+
+
+
+
+
+
+
+ dist
+
+
+ ${project.groupId}:*
+
+
+
+
+ *:sources
+
+
+
+
+
+ lib
+
+
+ ${project.groupId}:*
+
+
+ *:sources
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/distribution/src/main/assembly/src.xml b/Java-base/directory-mavibot/src/distribution/src/main/assembly/src.xml
new file mode 100644
index 000000000..c0eae3794
--- /dev/null
+++ b/Java-base/directory-mavibot/src/distribution/src/main/assembly/src.xml
@@ -0,0 +1,80 @@
+
+
+
+
+ src
+
+ tar.gz
+ tar.bz2
+ zip
+
+
+
+
+
+ ..
+
+
+ README*
+ LICENSE
+ NOTICE
+
+
+
+
+
+ ../target/site
+ docs
+
+ apidocs*/**
+ xref*/**
+
+
+
+
+
+ ..
+
+
+ **/*
+
+
+ .git/**
+ KEYS
+ LICENSE-bin
+ NOTICE
+ **/target
+ **/target/**
+ **/.settings
+ **/.settings/**
+ **/.classpath
+ **/.project
+ **/*.gen
+ **/.wtpmodules
+ **/surefire*
+ **/cobertura.ser
+ **/velocity.log
+ **/release.properties
+ **/pom.xml.releaseBackup
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/BTree.graphml b/Java-base/directory-mavibot/src/mavibot/img/BTree.graphml
new file mode 100644
index 000000000..ed6d1bbbf
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/BTree.graphml
@@ -0,0 +1,732 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree header 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ S
+I
+Z
+E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ S
+I
+Z
+E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ S
+I
+Z
+E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree header 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree header 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RootBT1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RootBT2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RootBT3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ info
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ info
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ info
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/BTree.png b/Java-base/directory-mavibot/src/mavibot/img/BTree.png
new file mode 100644
index 000000000..783abb529
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/BTree.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.graphml b/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.graphml
new file mode 100644
index 000000000..d33cc38fa
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.graphml
@@ -0,0 +1,195 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Element<T>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ AbstractElement<T>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SingleElement<V> ->
+AbstractElement<V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BtreeValue<V> ->
+AbstractValue<BTree<V, V>>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LeafValue<V> ->
+AbstractValue<Leaf<V, V>>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NodeValue<V> ->
+AbstractValue<Node<V, V>>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.png b/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.png
new file mode 100644
index 000000000..8e65d716b
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/ElementHolder.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/Leaf.graphml b/Java-base/directory-mavibot/src/mavibot/img/Leaf.graphml
new file mode 100644
index 000000000..a1fc9b134
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/Leaf.graphml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf
+
+
+
+
+
+
+
+
+
+
+ V[0..N] values
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <AbstractPage>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf prev
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf next
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/Leaf.png b/Java-base/directory-mavibot/src/mavibot/img/Leaf.png
new file mode 100644
index 000000000..2a2da0265
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/Leaf.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.graphml b/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.graphml
new file mode 100644
index 000000000..d4aa00ca1
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.graphml
@@ -0,0 +1,349 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ElementHolder<E, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ CacheHolder<E, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ MemoryHolder<E, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NodeCacheHolder<K, V> ->
+CacheHolder<NodeValue<K, V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LeafCacheHolder>K, V> ->
+CacheHolder<LeafValue<K, V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ValueCacheHolder<K, V> ->
+CacheHolder<SingleValue<V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NodeMemoryHolder<K, V> ->
+MemoryHolder<NodeValue<K, V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LeafMemoryHolder<K, V> ->
+MemoryHolder<LeafValue<K, V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ValueMemoryHolder<K, V> ->
+MemoryHolder<SingleValue<V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ MultipleValueCacheHolder<K, V> ->
+CacheHolder<BTreeValue<V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ MultipleValueMemoryHolder<K, V> ->
+MemoryHolder<BTreeValue<V>, K, V>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.png b/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.png
new file mode 100644
index 000000000..52f74ec8d
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/MavibotValue.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/Node.graphml b/Java-base/directory-mavibot/src/mavibot/img/Node.graphml
new file mode 100644
index 000000000..aeabe847f
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/Node.graphml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Node
+
+
+
+
+
+
+
+
+
+
+ Page[0..N+1] children
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <AbstractPage>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/Node.png b/Java-base/directory-mavibot/src/mavibot/img/Node.png
new file mode 100644
index 000000000..55da7cfa7
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/Node.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.graphml b/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.graphml
new file mode 100644
index 000000000..1d2c24f2f
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.graphml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ AbstractPage
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Node
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.png b/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.png
new file mode 100644
index 000000000..efb18b826
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/PageHierarchy.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.graphml b/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.graphml
new file mode 100644
index 000000000..d5e0dec4a
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.graphml
@@ -0,0 +1,386 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ S
+I
+Z
+E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ N
+E
+X
+T
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageIOs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Logical page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.png b/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.png
new file mode 100644
index 000000000..87f9054bc
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/PageIOLogical.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.graphml b/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.graphml
new file mode 100644
index 000000000..49f208d39
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.graphml
@@ -0,0 +1,2353 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D removal
+The right page
+has to be completed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Initial tree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ We merge the
+two siblings
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ And reorganize
+the pages
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ???
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.png b/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.png
new file mode 100644
index 000000000..d1e7a6c93
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/PageMergeDelete.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.graphml b/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.graphml
new file mode 100644
index 000000000..688c9dd59
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.graphml
@@ -0,0 +1,2686 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E removal
+The right page
+has to be completed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Initial tree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ We get one value
+from the left page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Resulting tree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.png b/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.png
new file mode 100644
index 000000000..6f08ed739
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/PageMergeMove.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R1-node.graphml b/Java-base/directory-mavibot/src/mavibot/img/R1-node.graphml
new file mode 100644
index 000000000..7eb08e72c
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/R1-node.graphml
@@ -0,0 +1,138 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R1-node.png b/Java-base/directory-mavibot/src/mavibot/img/R1-node.png
new file mode 100644
index 000000000..a3c416f41
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/R1-node.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R2-node.graphml b/Java-base/directory-mavibot/src/mavibot/img/R2-node.graphml
new file mode 100644
index 000000000..e931dc50f
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/R2-node.graphml
@@ -0,0 +1,295 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R2-node.png b/Java-base/directory-mavibot/src/mavibot/img/R2-node.png
new file mode 100644
index 000000000..d2f59e513
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/R2-node.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R3-node.graphml b/Java-base/directory-mavibot/src/mavibot/img/R3-node.graphml
new file mode 100644
index 000000000..67f66baed
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/R3-node.graphml
@@ -0,0 +1,697 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R3-node.png b/Java-base/directory-mavibot/src/mavibot/img/R3-node.png
new file mode 100644
index 000000000..12bba835f
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/R3-node.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R4-node-bis.png b/Java-base/directory-mavibot/src/mavibot/img/R4-node-bis.png
new file mode 100644
index 000000000..35a265430
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/R4-node-bis.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R4-node.graphml b/Java-base/directory-mavibot/src/mavibot/img/R4-node.graphml
new file mode 100644
index 000000000..9f0f1a62f
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/R4-node.graphml
@@ -0,0 +1,1121 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ I
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
+
+
+ copy
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/R4-node.png b/Java-base/directory-mavibot/src/mavibot/img/R4-node.png
new file mode 100644
index 000000000..5791b7820
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/R4-node.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/RMHeader.graphml b/Java-base/directory-mavibot/src/mavibot/img/RMHeader.graphml
new file mode 100644
index 000000000..784ac8e62
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/RMHeader.graphml
@@ -0,0 +1,854 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RecordManager Header
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbTree
+
+
+
+
+
+
+
+
+
+ PageSize
+
+
+
+
+
+
+
+
+
+ FirstFreePage
+
+
+
+
+
+
+
+
+
+ Current B-tree of B-trees offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Previous B-tree of B-trees offset
+
+
+
+
+
+
+
+
+
+ Current Copied Pages B-tree offset
+
+
+
+
+
+
+
+
+
+ Current Copied Pages B-tree offset
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/RMHeader.png b/Java-base/directory-mavibot/src/mavibot/img/RMHeader.png
new file mode 100644
index 000000000..937969db3
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/RMHeader.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.graphml b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.graphml
new file mode 100644
index 000000000..07b43243b
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.graphml
@@ -0,0 +1,1335 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ G
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ G
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ H
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vG
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vH
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Delete(G)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UC1.2.1 : The page has N/2 elements, sibling on the left with more than N/2 elements
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ J
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ M
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ z
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ J
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ K
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vJ
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vK
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ L
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vL
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.png b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.png
new file mode 100644
index 000000000..9e3d75086
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.1.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.graphml b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.graphml
new file mode 100644
index 000000000..d222948e2
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.graphml
@@ -0,0 +1,1778 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ y
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Delete(D)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ y
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ after deletion
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UC1.2 : The page has more than N/2 elements, the key is the first one
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Resulting tree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.png b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.png
new file mode 100644
index 000000000..47378ecad
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/UC1.2.2.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC11.graphml b/Java-base/directory-mavibot/src/mavibot/img/UC11.graphml
new file mode 100644
index 000000000..895b5ed1f
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/UC11.graphml
@@ -0,0 +1,1361 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Delete(C)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ after deletion
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UC1.1 : The page has more than N/2 elements, The key is not the first one
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Resulting tree
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/UC11.png b/Java-base/directory-mavibot/src/mavibot/img/UC11.png
new file mode 100644
index 000000000..8133c0fc9
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/UC11.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/abstractPage.graphml b/Java-base/directory-mavibot/src/mavibot/img/abstractPage.graphml
new file mode 100644
index 000000000..c0f709582
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/abstractPage.graphml
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ AbstractPage
+
+
+
+
+
+
+
+
+
+
+ K[0..N] keys
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree btree
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ long PageID
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ long revision
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int nbElems
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ long PhysicalID
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/abstractPage.png b/Java-base/directory-mavibot/src/mavibot/img/abstractPage.png
new file mode 100644
index 000000000..7c6668eb1
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/abstractPage.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.graphml b/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.graphml
new file mode 100644
index 000000000..3bcdca649
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.graphml
@@ -0,0 +1,986 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree Header
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbElems
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RootPageOffset
+
+
+
+
+
+
+
+
+
+ BTreeInfo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTreePageSize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree name
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ KeySerializer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ValueSerializer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ dupsAllowed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTreeInfoOffset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.png b/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.png
new file mode 100644
index 000000000..2bc53ae36
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/btreeHeader.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/datastructure.graphml b/Java-base/directory-mavibot/src/mavibot/img/datastructure.graphml
new file mode 100644
index 000000000..cae19df22
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/datastructure.graphml
@@ -0,0 +1,2824 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Page
+
+
+
+
+
+
+
+
+
+
+ Node
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[0]
+
+
+
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[nbElems]
+
+
+
+
+
+
+
+
+
+ NbElems
+
+
+
+
+
+
+
+
+
+ NbElems
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DataSize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DataSize
+
+
+
+
+
+
+
+
+
+ BTree Header
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbElems
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RootPageOffset
+
+
+
+
+
+
+
+
+
+ BTreeInfo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTreePageSize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTree name
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ KeySerializer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ValueSerializer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xyz...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ dupsAllowed
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BTreeInfoOffset
+
+
+
+
+
+
+
+
+
+ RecordManager Header
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbTree
+
+
+
+
+
+
+
+
+
+ PageSize
+
+
+
+
+
+
+
+
+
+ FirstFreePage
+
+
+
+
+
+
+
+
+
+ Current B-tree of B-trees offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Previous B-tree of B-trees offset
+
+
+
+
+
+
+
+
+
+ Current Copied Pages B-tree offset
+
+
+
+
+
+
+
+
+
+ Current Copied Pages B-tree offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/datastructure.png b/Java-base/directory-mavibot/src/mavibot/img/datastructure.png
new file mode 100644
index 000000000..524682968
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/datastructure.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/leaves.graphml b/Java-base/directory-mavibot/src/mavibot/img/leaves.graphml
new file mode 100644
index 000000000..dbc796ae9
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/leaves.graphml
@@ -0,0 +1,1173 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf with N/2 keys and values
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf with N keys and values
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Root Leaf with one key and value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Root Leaf with no key or value
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/leaves.png b/Java-base/directory-mavibot/src/mavibot/img/leaves.png
new file mode 100644
index 000000000..86a72bd6e
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/leaves.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.graphml b/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.graphml
new file mode 100644
index 000000000..820f3458b
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.graphml
@@ -0,0 +1,2661 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf Value sub-btree
+
+
+
+
+
+
+
+
+
+ Leaf Value array
+
+
+
+
+
+
+
+
+
+ Page
+
+
+
+
+
+
+
+
+
+
+ Node
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Leaf
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Data (if size > 0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[0]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[nbElems - 1]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Value[nbElems]
+
+
+
+
+
+
+
+
+
+ NbElems < 0
+
+
+
+
+
+
+
+
+
+ NbElems > 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DataSize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DataSize
+
+
+
+
+
+
+
+
+
+ empty root page
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Revision
+
+
+
+
+
+
+
+
+
+ NbElems = 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SubBTree offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[0] offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[0] last offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbValues > 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[0] length
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[0] (if length > 0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[1] offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[1] last offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[1] length
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[1] (if length > 0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[NbElems - 1] offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PageRef[NbElems - 1] last offset
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[n-1] length
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Key[n-1] (if length > 0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Data size
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NbValues < 0
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.png b/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.png
new file mode 100644
index 000000000..6a61b20f1
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/nodeLeaf.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/nodes.graphml b/Java-base/directory-mavibot/src/mavibot/img/nodes.graphml
new file mode 100644
index 000000000..0ef2aa036
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/nodes.graphml
@@ -0,0 +1,468 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Node with N/2 keys
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Node with N keys
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Root Node with one key
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/nodes.png b/Java-base/directory-mavibot/src/mavibot/img/nodes.png
new file mode 100644
index 000000000..19dbb7d98
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/nodes.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/trans1.graphml b/Java-base/directory-mavibot/src/mavibot/img/trans1.graphml
new file mode 100644
index 000000000..e1e400fd3
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/trans1.graphml
@@ -0,0 +1,236 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 25
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RMHeader
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ currentBOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/trans1.png b/Java-base/directory-mavibot/src/mavibot/img/trans1.png
new file mode 100644
index 000000000..e1a581d1c
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/trans1.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/trans2.graphml b/Java-base/directory-mavibot/src/mavibot/img/trans2.graphml
new file mode 100644
index 000000000..0ac569e77
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/trans2.graphml
@@ -0,0 +1,407 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 25
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RMHeader
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ currentBOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 15
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 27
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/trans2.png b/Java-base/directory-mavibot/src/mavibot/img/trans2.png
new file mode 100644
index 000000000..3577130ad
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/trans2.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/transko.graphml b/Java-base/directory-mavibot/src/mavibot/img/transko.graphml
new file mode 100644
index 000000000..0b94f2cf1
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/transko.graphml
@@ -0,0 +1,332 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 25
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RMHeader
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ currentBOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 15
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 27
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/transko.png b/Java-base/directory-mavibot/src/mavibot/img/transko.png
new file mode 100644
index 000000000..9bae17ac8
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/transko.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/img/transok.graphml b/Java-base/directory-mavibot/src/mavibot/img/transok.graphml
new file mode 100644
index 000000000..0ab932103
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/img/transok.graphml
@@ -0,0 +1,374 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 25
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ RMHeader
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ currentBOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 15
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ B-tree B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ r 27
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BOB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/img/transok.png b/Java-base/directory-mavibot/src/mavibot/img/transok.png
new file mode 100644
index 000000000..8ac423ff9
Binary files /dev/null and b/Java-base/directory-mavibot/src/mavibot/img/transok.png differ
diff --git a/Java-base/directory-mavibot/src/mavibot/pom.xml b/Java-base/directory-mavibot/src/mavibot/pom.xml
new file mode 100644
index 000000000..bcd87efc4
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/pom.xml
@@ -0,0 +1,108 @@
+
+
+
+ 4.0.0
+
+
+ org.apache.directory.mavibot
+ mavibot-parent
+ 1.0.0-M9-SNAPSHOT
+
+
+ mavibot
+ ApacheDS MVCC BTree implementation
+ bundle
+
+ A MVCC BTree Implementation
+
+
+
+ junit
+ junit
+ test
+
+
+
+ commons-collections
+ commons-collections
+ ${commons.collections.version}
+
+
+
+ commons-io
+ commons-io
+ ${commons.io.version}
+ test
+
+
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4j.log4j12.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ META-INF/MANIFEST.MF
+ false
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+ true
+
+ META-INF
+
+ ${project.groupId}.mavibot
+
+ org.apache.directory.mavibot.btree;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.comparator;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.exception;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.memory;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.persisted;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.serializer;version=${project.version};-noimport:=true,
+ org.apache.directory.mavibot.btree.util;version=${project.version};-noimport:=true
+
+
+
+
+
+
+
+
+
diff --git a/Java-base/directory-mavibot/src/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java b/Java-base/directory-mavibot/src/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
new file mode 100644
index 000000000..7b50c04df
--- /dev/null
+++ b/Java-base/directory-mavibot/src/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
@@ -0,0 +1,1119 @@
+/*
+ * 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.directory.mavibot.btree;
+
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.directory.mavibot.btree.exception.BTreeCreationException;
+import org.apache.directory.mavibot.btree.exception.DuplicateValueNotAllowedException;
+import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
+import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+
+
+/**
+ * A BTree abstract class containing the methods shared by the PersistedBTree or the InMemoryBTree
+ * implementations.
+ *
+ * @param The Key type
+ * @param The Value type
+ *
+ * @author Apache Directory Project
+ */
+/* No qualifier*/abstract class AbstractBTree implements BTree
+{
+ /** The read transaction timeout */
+ protected long readTimeOut = DEFAULT_READ_TIMEOUT;
+
+ /** The current Header for a managed BTree */
+ protected BTreeHeader currentBtreeHeader;
+
+ /** The Key serializer used for this tree.*/
+ protected ElementSerializer keySerializer;
+
+ /** The Value serializer used for this tree. */
+ protected ElementSerializer valueSerializer;
+
+ /** The list of read transactions being executed */
+ protected ConcurrentLinkedQueue> readTransactions;
+
+ /** The size of the buffer used to write data in disk */
+ protected int writeBufferSize;
+
+ /** Flag to enable duplicate key support */
+ protected boolean allowDuplicates;
+
+ /** The number of elements in a page for this B-tree */
+ protected int pageSize;
+
+ /** The BTree name */
+ protected String name;
+
+ /** The FQCN of the Key serializer */
+ protected String keySerializerFQCN;
+
+ /** The FQCN of the Value serializer */
+ protected String valueSerializerFQCN;
+
+ /** The thread responsible for the cleanup of timed out reads */
+ protected Thread readTransactionsThread;
+
+ /** The BTree type : either in-memory, disk backed or persisted */
+ protected BTreeTypeEnum btreeType;
+
+ /** The current transaction */
+ protected AtomicBoolean transactionStarted = new AtomicBoolean( false );
+
+ /** The map of all the used BtreeHeaders */
+ protected Map> btreeRevisions = new ConcurrentHashMap>();
+
+ /** The current revision */
+ protected AtomicLong currentRevision = new AtomicLong( 0L );
+
+ /** The TransactionManager used for this BTree */
+ protected TransactionManager transactionManager;
+
+ /** The size of the stack to use to manage tree searches */
+ private final static int MAX_STACK_DEPTH = 32;
+
+
+ /**
+ * Starts a Read Only transaction. If the transaction is not closed, it will be
+ * automatically closed after the timeout
+ *
+ * @return The created transaction
+ */
+ protected abstract ReadTransaction beginReadTransaction();
+
+
+ /**
+ * Starts a Read Only transaction. If the transaction is not closed, it will be
+ * automatically closed after the timeout
+ *
+ * @return The created transaction
+ */
+ protected abstract ReadTransaction beginReadTransaction( long revision );
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TupleCursor browse() throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction();
+
+ if ( transaction == null )
+ {
+ return new EmptyTupleCursor();
+ }
+ else
+ {
+ ParentPos[] stack = ( ParentPos[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
+
+ TupleCursor cursor = getRootPage().browse( transaction, stack, 0 );
+
+ // Set the position before the first element
+ cursor.beforeFirst();
+
+ return cursor;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TupleCursor browse( long revision ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction( revision );
+
+ if ( transaction == null )
+ {
+ return new EmptyTupleCursor();
+ }
+ else
+ {
+ ParentPos[] stack = ( ParentPos[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
+
+ // And get the cursor
+ TupleCursor cursor = getRootPage( transaction.getRevision() ).browse( transaction, stack, 0 );
+
+ return cursor;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TupleCursor browseFrom( K key ) throws IOException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction();
+
+ ParentPos[] stack = ( ParentPos[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
+
+ try
+ {
+ TupleCursor cursor = getRootPage( transaction.getRevision() ).browse( key, transaction, stack, 0 );
+
+ return cursor;
+ }
+ catch ( KeyNotFoundException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public TupleCursor browseFrom( long revision, K key ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction( revision );
+
+ if ( transaction == null )
+ {
+ return new EmptyTupleCursor();
+ }
+ else
+ {
+ ParentPos[] stack = ( ParentPos[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
+
+ // And get the cursor
+ TupleCursor cursor = getRootPage( transaction.getRevision() ).browse( key, transaction, stack, 0 );
+
+ return cursor;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains( K key, V value ) throws IOException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction();
+
+ if ( transaction == null )
+ {
+ return false;
+ }
+ else
+ {
+ try
+ {
+ return getRootPage( transaction.getRevision() ).contains( key, value );
+ }
+ catch ( KeyNotFoundException knfe )
+ {
+ throw new IOException( knfe.getMessage() );
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains( long revision, K key, V value ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ // Fetch the root page for this revision
+ ReadTransaction transaction = beginReadTransaction( revision );
+
+ if ( transaction == null )
+ {
+ return false;
+ }
+ else
+ {
+ try
+ {
+ return getRootPage( transaction.getRevision() ).contains( key, value );
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Tuple delete( K key ) throws IOException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ if ( key == null )
+ {
+ throw new IllegalArgumentException( "Key must not be null" );
+ }
+
+ // Take the lock if it's not already taken by another thread
+ transactionManager.beginTransaction();
+
+ try
+ {
+ Tuple deleted = delete( key, currentRevision.get() + 1 );
+
+ // Commit now
+ transactionManager.commit();
+
+ return deleted;
+ }
+ catch ( IOException ioe )
+ {
+ // We have had an exception, we must rollback the transaction
+ transactionManager.rollback();
+
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Tuple delete( K key, V value ) throws IOException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ if ( key == null )
+ {
+ throw new IllegalArgumentException( "Key must not be null" );
+ }
+
+ if ( value == null )
+ {
+ throw new IllegalArgumentException( "Value must not be null" );
+ }
+
+ transactionManager.beginTransaction();
+
+ try
+ {
+ Tuple deleted = delete( key, value, currentRevision.get() + 1 );
+
+ transactionManager.commit();
+
+ return deleted;
+ }
+ catch ( IOException ioe )
+ {
+ transactionManager.rollback();
+
+ throw ioe;
+ }
+ }
+
+
+ /**
+ * Delete the entry which key is given as a parameter. If the entry exists, it will
+ * be removed from the tree, the old tuple will be returned. Otherwise, null is returned.
+ *
+ * @param key The key for the entry we try to remove
+ * @return A Tuple containing the removed entry, or null if it's not found.
+ */
+ /*no qualifier*/Tuple delete( K key, long revision ) throws IOException
+ {
+ return delete( key, null, revision );
+ }
+
+
+ /*no qualifier*/abstract Tuple delete( K key, V value, long revision ) throws IOException;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public V insert( K key, V value ) throws IOException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ V existingValue = null;
+
+ if ( key == null )
+ {
+ throw new IllegalArgumentException( "Key must not be null" );
+ }
+
+ // Take the lock if it's not already taken by another thread and if we
+ // aren't on a sub-btree
+ if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+ {
+ transactionManager.beginTransaction();
+ }
+
+ try
+ {
+ InsertResult result = insert( key, value, -1L );
+
+ if ( result instanceof ExistsResult )
+ {
+ existingValue = value;
+ }
+ else if ( result instanceof ModifyResult )
+ {
+ existingValue = ( ( ModifyResult ) result ).getModifiedValue();
+ }
+
+ // Commit now if it's not a sub-btree
+ if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+ {
+ //FIXME when result type is ExistsResult then we should avoid writing the headers
+ transactionManager.commit();
+ }
+
+ return existingValue;
+ }
+ catch ( IOException ioe )
+ {
+ // We have had an exception, we must rollback the transaction
+ // if it's not a sub-btree
+ if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+ {
+ transactionManager.rollback();
+ }
+
+ return null;
+ }
+ catch ( DuplicateValueNotAllowedException e )
+ {
+ // We have had an exception, we must rollback the transaction
+ // if it's not a sub-btree
+ if ( btreeType != BTreeTypeEnum.PERSISTED_SUB )
+ {
+ transactionManager.rollback();
+ }
+
+ throw e;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ /* no qualifier */abstract InsertResult insert( K key, V value, long revision ) throws IOException;
+
+
+ /**
+ * Flush the latest revision to disk. We will replace the current file by the new one, as
+ * we flush in a temporary file.
+ */
+ public void flush() throws IOException
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public V get( K key ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction();
+
+ if ( transaction == null )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return getRootPage( transaction.getRevision() ).get( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public V get( long revision, K key ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction( revision );
+
+ if ( transaction == null )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return getRootPage( transaction.getRevision() ).get( key );
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract Page getRootPage();
+
+
+ /**
+ * {@inheritDoc}
+ */
+ /* no qualifier */abstract void setRootPage( Page root );
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueCursor getValues( K key ) throws IOException, KeyNotFoundException
+ {
+ // Check that we have a TransactionManager
+ if ( transactionManager == null )
+ {
+ throw new BTreeCreationException( "We don't have a transactionLManager" );
+ }
+
+ ReadTransaction transaction = beginReadTransaction();
+
+ if ( transaction == null )
+ {
+ return new EmptyValueCursor