├── .asf.yaml
├── .checkstyle
├── .gitattributes
├── .github
├── GH-ROBOTS.txt
├── dependabot.yml
├── pull_request_template.md
└── workflows
│ ├── codeql-analysis.yml
│ ├── data-source-check.yml
│ ├── dependency-review.yml
│ ├── maven.yml
│ └── scorecards-analysis.yml
├── .gitignore
├── BUILDING.txt
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── NOTICE.txt
├── PROPOSAL.html
├── README.md
├── RELEASE-NOTES.txt
├── SECURITY.md
├── pom.xml
└── src
├── assembly
├── bin.xml
└── src.xml
├── changes
├── changes.xml
└── release-notes.vm
├── conf
├── checkstyle
│ ├── checkstyle-header.txt
│ ├── checkstyle-suppressions.xml
│ └── checkstyle.xml
└── spotbugs-exclude-filter.xml
├── example
└── org
│ └── apache
│ └── commons
│ └── validator
│ └── example
│ ├── ValidateBean.java
│ ├── ValidateExample.java
│ ├── applicationResources.properties
│ └── validator-example.xml
├── main
├── java
│ └── org
│ │ └── apache
│ │ └── commons
│ │ └── validator
│ │ ├── Arg.java
│ │ ├── CreditCardValidator.java
│ │ ├── DateValidator.java
│ │ ├── EmailValidator.java
│ │ ├── Field.java
│ │ ├── Form.java
│ │ ├── FormSet.java
│ │ ├── FormSetFactory.java
│ │ ├── GenericTypeValidator.java
│ │ ├── GenericValidator.java
│ │ ├── ISBNValidator.java
│ │ ├── Msg.java
│ │ ├── UrlValidator.java
│ │ ├── Validator.java
│ │ ├── ValidatorAction.java
│ │ ├── ValidatorException.java
│ │ ├── ValidatorResources.java
│ │ ├── ValidatorResult.java
│ │ ├── ValidatorResults.java
│ │ ├── Var.java
│ │ ├── package-info.java
│ │ ├── routines
│ │ ├── AbstractCalendarValidator.java
│ │ ├── AbstractFormatValidator.java
│ │ ├── AbstractNumberValidator.java
│ │ ├── BigDecimalValidator.java
│ │ ├── BigIntegerValidator.java
│ │ ├── ByteValidator.java
│ │ ├── CalendarValidator.java
│ │ ├── CodeValidator.java
│ │ ├── CreditCardValidator.java
│ │ ├── CurrencyValidator.java
│ │ ├── DateValidator.java
│ │ ├── DomainValidator.java
│ │ ├── DoubleValidator.java
│ │ ├── EmailValidator.java
│ │ ├── FloatValidator.java
│ │ ├── IBANValidator.java
│ │ ├── IBANValidatorStatus.java
│ │ ├── ISBNValidator.java
│ │ ├── ISINValidator.java
│ │ ├── ISSNValidator.java
│ │ ├── InetAddressValidator.java
│ │ ├── IntegerValidator.java
│ │ ├── LongValidator.java
│ │ ├── PercentValidator.java
│ │ ├── RegexValidator.java
│ │ ├── ShortValidator.java
│ │ ├── TimeValidator.java
│ │ ├── UrlValidator.java
│ │ ├── checkdigit
│ │ │ ├── ABANumberCheckDigit.java
│ │ │ ├── AbstractCheckDigit.java
│ │ │ ├── CASNumberCheckDigit.java
│ │ │ ├── CUSIPCheckDigit.java
│ │ │ ├── CheckDigit.java
│ │ │ ├── CheckDigitException.java
│ │ │ ├── EAN13CheckDigit.java
│ │ │ ├── ECNumberCheckDigit.java
│ │ │ ├── IBANCheckDigit.java
│ │ │ ├── ISBN10CheckDigit.java
│ │ │ ├── ISBNCheckDigit.java
│ │ │ ├── ISINCheckDigit.java
│ │ │ ├── ISSNCheckDigit.java
│ │ │ ├── LuhnCheckDigit.java
│ │ │ ├── ModulusCheckDigit.java
│ │ │ ├── ModulusTenCheckDigit.java
│ │ │ ├── SedolCheckDigit.java
│ │ │ ├── VerhoeffCheckDigit.java
│ │ │ └── package-info.java
│ │ └── package-info.java
│ │ └── util
│ │ ├── Flags.java
│ │ ├── ValidatorUtils.java
│ │ └── package-info.java
└── resources
│ └── org
│ └── apache
│ └── commons
│ └── validator
│ ├── digester-rules.xml
│ └── resources
│ ├── validator_1_0.dtd
│ ├── validator_1_0_1.dtd
│ ├── validator_1_1.dtd
│ ├── validator_1_1_3.dtd
│ ├── validator_1_2_0.dtd
│ ├── validator_1_3_0.dtd
│ └── validator_1_4_0.dtd
├── site
├── resources
│ ├── download_validator.cgi
│ ├── images
│ │ └── logo.png
│ └── profile.jacoco
├── site.xml
└── xdoc
│ ├── building.xml
│ ├── community.xml
│ ├── download_validator.xml
│ ├── index.xml
│ ├── issue-tracking.xml
│ ├── mail-lists.xml
│ ├── tasks.xml
│ └── validator_2_0_0_proposal.dtd
└── test
├── java
└── org
│ └── apache
│ └── commons
│ └── validator
│ ├── AbstractCommonTest.java
│ ├── AbstractNumberTest.java
│ ├── ByteTest.java
│ ├── CreditCardValidatorTest.java
│ ├── CustomValidatorResourcesTest.java
│ ├── DateTest.java
│ ├── DoubleTest.java
│ ├── EmailTest.java
│ ├── EntityImportTest.java
│ ├── ExceptionTest.java
│ ├── ExtensionTest.java
│ ├── FieldTest.java
│ ├── FloatTest.java
│ ├── GenericTypeValidatorImpl.java
│ ├── GenericTypeValidatorTest.java
│ ├── GenericValidatorImpl.java
│ ├── GenericValidatorTest.java
│ ├── ISBNValidatorTest.java
│ ├── IntegerTest.java
│ ├── LocaleTest.java
│ ├── LongTest.java
│ ├── MultipleConfigFilesTest.java
│ ├── MultipleTest.java
│ ├── NameBean.java
│ ├── ParameterTest.java
│ ├── ParameterValidatorImpl.java
│ ├── RequiredIfTest.java
│ ├── RequiredNameTest.java
│ ├── ResultPair.java
│ ├── RetrieveFormTest.java
│ ├── ShortTest.java
│ ├── TypeBean.java
│ ├── UrlTest.java
│ ├── ValidatorResourcesTest.java
│ ├── ValidatorResultsTest.java
│ ├── ValidatorTest.java
│ ├── ValueBean.java
│ ├── VarTest.java
│ ├── custom
│ └── CustomValidatorResources.java
│ ├── routines
│ ├── AbstractCalendarValidatorTest.java
│ ├── AbstractNumberValidatorTest.java
│ ├── BigDecimalValidatorTest.java
│ ├── BigIntegerValidatorTest.java
│ ├── ByteValidatorTest.java
│ ├── CalendarValidatorTest.java
│ ├── CodeValidatorTest.java
│ ├── CreditCardValidatorTest.java
│ ├── CurrencyValidatorTest.java
│ ├── DateValidatorTest.java
│ ├── DomainValidatorStartupTest.java
│ ├── DomainValidatorTest.java
│ ├── DoubleValidatorTest.java
│ ├── EmailValidatorTest.java
│ ├── FloatValidatorTest.java
│ ├── IBANValidatorTest.java
│ ├── ISBNValidatorTest.java
│ ├── ISINValidatorTest.java
│ ├── ISSNValidatorTest.java
│ ├── InetAddressValidatorTest.java
│ ├── IntegerValidatorTest.java
│ ├── LongValidatorTest.java
│ ├── PercentValidatorTest.java
│ ├── RegexValidatorTest.java
│ ├── ShortValidatorTest.java
│ ├── TimeValidatorTest.java
│ ├── UrlValidatorTest.java
│ └── checkdigit
│ │ ├── ABANumberCheckDigitTest.java
│ │ ├── AbstractCheckDigitTest.java
│ │ ├── CASNumberCheckDigitTest.java
│ │ ├── CUSIPCheckDigitTest.java
│ │ ├── EAN13CheckDigitTest.java
│ │ ├── ECNumberCheckDigitTest.java
│ │ ├── IBANCheckDigitTest.java
│ │ ├── ISBN10CheckDigitTest.java
│ │ ├── ISBNCheckDigitTest.java
│ │ ├── ISINCheckDigitTest.java
│ │ ├── ISSNCheckDigitTest.java
│ │ ├── LuhnCheckDigitTest.java
│ │ ├── ModulusTenABACheckDigitTest.java
│ │ ├── ModulusTenCUSIPCheckDigitTest.java
│ │ ├── ModulusTenEAN13CheckDigitTest.java
│ │ ├── ModulusTenLuhnCheckDigitTest.java
│ │ ├── ModulusTenSedolCheckDigitTest.java
│ │ ├── SedolCheckDigitTest.java
│ │ └── VerhoeffCheckDigitTest.java
│ └── util
│ ├── FlagsTest.java
│ ├── TestTimeZones.java
│ └── ValidatorUtilsTest.java
└── resources
└── org
└── apache
└── commons
└── validator
├── DateTest-config.xml
├── EmailTest-config.xml
├── EntityImportTest-byteform.xml
├── EntityImportTest-config.xml
├── ExceptionTest-config.xml
├── ExtensionTest-config.xml
├── GenericTypeValidatorTest-config.xml
├── LocaleTest-config.xml
├── MultipleConfigFilesTest-1-config.xml
├── MultipleConfigFilesTest-2-config.xml
├── MultipleTests-config.xml
├── ParameterTest-config.xml
├── RequiredIfTest-config.xml
├── RequiredNameTest-config.xml
├── RetrieveFormTest-config.xml
├── TestNumber-config.xml
├── ValidatorResultsTest-config.xml
├── VarTest-config.xml
└── routines
├── checkdigit
└── IBANtests.txt
└── iban_registry_v99.txt
/.asf.yaml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | github:
17 | description: "Apache Commons Validator"
18 | homepage: https://commons.apache.org/validator/
19 |
20 | notifications:
21 | commits: commits@commons.apache.org
22 | issues: issues@commons.apache.org
23 | pullrequests: issues@commons.apache.org
24 | jira_options: link label
25 | jobs: notifications@commons.apache.org
26 | issues_bot_dependabot: notifications@commons.apache.org
27 | pullrequests_bot_dependabot: notifications@commons.apache.org
28 | issues_bot_codecov-commenter: notifications@commons.apache.org
29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org
30 |
--------------------------------------------------------------------------------
/.checkstyle:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | * text=auto
17 | *.patch -text
18 |
--------------------------------------------------------------------------------
/.github/GH-ROBOTS.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | # Keeps on creating FUD PRs in test code
17 | # Does not follow Apache disclosure policies
18 | User-agent: JLLeitschuh/security-research
19 | Disallow: *
20 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | version: 2
17 | updates:
18 | - package-ecosystem: "maven"
19 | directory: "/"
20 | schedule:
21 | interval: "weekly"
22 | day: "friday"
23 | - package-ecosystem: "github-actions"
24 | directory: "/"
25 | schedule:
26 | interval: "weekly"
27 | day: "friday"
28 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
19 |
20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated!
21 |
22 | Before you push a pull request, review this list:
23 |
24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
25 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
26 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
27 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
28 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.
29 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | name: "CodeQL"
17 |
18 | on:
19 | push:
20 | branches: [ master ]
21 | pull_request:
22 | # The branches below must be a subset of the branches above
23 | branches: [ master ]
24 | schedule:
25 | - cron: '33 9 * * 4'
26 |
27 | permissions:
28 | contents: read
29 |
30 | jobs:
31 | analyze:
32 | name: Analyze
33 | runs-on: ubuntu-latest
34 | permissions:
35 | actions: read
36 | contents: read
37 | security-events: write
38 |
39 | strategy:
40 | fail-fast: false
41 | matrix:
42 | language: [ 'java' ]
43 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
44 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
45 |
46 | steps:
47 | - name: Checkout repository
48 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
49 | with:
50 | persist-credentials: false
51 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
52 | with:
53 | path: ~/.m2/repository
54 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
55 | restore-keys: |
56 | ${{ runner.os }}-maven-
57 |
58 | # Initializes the CodeQL tools for scanning.
59 | - name: Initialize CodeQL
60 | uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
61 | with:
62 | languages: ${{ matrix.language }}
63 | # If you wish to specify custom queries, you can do so here or in a config file.
64 | # By default, queries listed here will override any specified in a config file.
65 | # Prefix the list here with "+" to use these queries and those in the config file.
66 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
67 |
68 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
69 | # If this step fails, then you should remove it and run the build manually (see below)
70 | - name: Autobuild
71 | uses: github/codeql-action/autobuild@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
72 |
73 | # ℹ️ Command-line programs to run using the OS shell.
74 | # 📚 https://git.io/JvXDl
75 |
76 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
77 | # and modify them (or add more) to build your code if your project
78 | # uses a compiled language
79 |
80 | #- run: |
81 | # make bootstrap
82 | # make release
83 |
84 | - name: Perform CodeQL Analysis
85 | uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
86 |
--------------------------------------------------------------------------------
/.github/workflows/data-source-check.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache license, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the license for the specific language governing permissions and
14 | # limitations under the license.
15 |
16 | name: "Data source check"
17 |
18 | on:
19 | workflow_dispatch:
20 | schedule:
21 | - cron: "30 1 * 1 *" # min hr day mon dow: monthly on 1st
22 |
23 | jobs:
24 |
25 | datacheck:
26 |
27 | runs-on: ubuntu-latest
28 |
29 | steps:
30 |
31 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32 | with:
33 | persist-credentials: false
34 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
35 | with:
36 | path: ~/.m2/repository
37 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
38 | restore-keys: |
39 | ${{ runner.os }}-datacheck-
40 | - name: Set up JDK
41 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
42 | with:
43 | distribution: 'temurin'
44 | java-version: 8
45 | - name: Build with Maven
46 | run: |
47 | mvn --errors --show-version --batch-mode clean compile test-compile
48 | mvn --batch-mode -PDomainValidatorTest
49 |
--------------------------------------------------------------------------------
/.github/workflows/dependency-review.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | name: 'Dependency Review'
19 | on: [pull_request]
20 |
21 | permissions:
22 | contents: read
23 |
24 | jobs:
25 | dependency-review:
26 | runs-on: ubuntu-latest
27 | steps:
28 | - name: 'Checkout Repository'
29 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30 | - name: 'Dependency Review PR'
31 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1
32 |
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | name: Java CI
17 |
18 | on: [push, pull_request]
19 |
20 | permissions:
21 | contents: read
22 |
23 | jobs:
24 | build:
25 |
26 | runs-on: ubuntu-latest
27 | continue-on-error: ${{ matrix.experimental }}
28 | strategy:
29 | matrix:
30 | java: [ 8, 11, 17, 21, 24 ]
31 | experimental: [false]
32 | include:
33 | - java: 25-ea
34 | experimental: true
35 |
36 | steps:
37 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38 | with:
39 | persist-credentials: false
40 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
41 | with:
42 | path: ~/.m2/repository
43 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
44 | restore-keys: |
45 | ${{ runner.os }}-maven-
46 | - name: Set up JDK ${{ matrix.java }}
47 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
48 | with:
49 | distribution: 'temurin'
50 | java-version: ${{ matrix.java }}
51 | - name: Build with Maven
52 | run: mvn --errors --show-version --batch-mode --no-transfer-progress -Ddoclint=all
53 |
--------------------------------------------------------------------------------
/.github/workflows/scorecards-analysis.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache license, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the license for the specific language governing permissions and
14 | # limitations under the license.
15 |
16 | name: "Scorecards supply-chain security"
17 |
18 | on:
19 | branch_protection_rule:
20 | schedule:
21 | - cron: "30 1 * * 6" # Weekly on Saturdays
22 | push:
23 | branches: [ "master" ]
24 |
25 | permissions: read-all
26 |
27 | jobs:
28 |
29 | analysis:
30 |
31 | name: "Scorecards analysis"
32 | runs-on: ubuntu-latest
33 | permissions:
34 | # Needed to upload the results to the code-scanning dashboard.
35 | security-events: write
36 | actions: read
37 | id-token: write # This is required for requesting the JWT
38 | contents: read # This is required for actions/checkout
39 |
40 | steps:
41 |
42 | - name: "Checkout code"
43 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44 | with:
45 | persist-credentials: false
46 |
47 | - name: "Run analysis"
48 | uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # 2.4.2
49 | with:
50 | results_file: results.sarif
51 | results_format: sarif
52 | # A read-only PAT token, which is sufficient for the action to function.
53 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188
54 | repo_token: ${{ secrets.GITHUB_TOKEN }}
55 | # Publish the results for public repositories to enable scorecard badges.
56 | # For more details: https://github.com/ossf/scorecard-action#publishing-results
57 | publish_results: true
58 |
59 | - name: "Upload artifact"
60 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
61 | with:
62 | name: SARIF file
63 | path: results.sarif
64 | retention-days: 5
65 |
66 | - name: "Upload to code-scanning"
67 | uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # 3.28.19
68 | with:
69 | sarif_file: results.sarif
70 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /.settings/
3 | /.classpath
4 | /.project
5 | /site-content/
6 | /.vscode/
7 | /commons-validator.iml
8 | /.idea/
9 |
--------------------------------------------------------------------------------
/BUILDING.txt:
--------------------------------------------------------------------------------
1 | The code requires at least Java 1.6 to build.
2 |
3 | However, current versions of Maven tend to require at least Java 7.
4 |
5 | If you want to build and test the code using Java 1.6, use the profile -Pjava-1.6, e.g.
6 |
7 | mvn clean test -Pjava-1.6
8 |
9 | For setting up your Maven installation to enable the use of the profile, please see:
10 |
11 | http://commons.apache.org/commons-parent-pom.html#Testing_with_different_Java_versions
12 |
13 | Building the site will also generally require at least Java 7 to run Maven.
14 | To build the site from scratch, you can use:
15 |
16 | mvn clean site [-Pjava-1.6]
17 |
18 | Also, ensure Maven has enough memory when using Java 7:
19 |
20 | export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m" # Unix
21 | set MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m" # Windows
22 |
23 | For Java 8+, the MaxPermSize option should be removed:
24 |
25 | export MAVEN_OPTS="-Xmx512m" # Unix
26 | set MAVEN_OPTS="-Xmx512m" # Windows
27 |
28 | There can be problems building the site using Maven 3.0.5 or earlier;
29 | if so please use a later version.
30 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html).
18 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | Apache Commons Validator
2 | Copyright 2002-2025 The Apache Software Foundation
3 |
4 | This product includes software developed at
5 | The Apache Software Foundation (https://www.apache.org/).
6 |
--------------------------------------------------------------------------------
/PROPOSAL.html:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 | Proposal for Validator Library Package
20 |
21 |
22 |
23 |
24 |
Proposal for Validator Package
25 |
26 |
27 | (0) Rationale
28 |
29 | There is a need for the validation of JavaBeans to validate
30 | user input from forms and validate business rules. There is also a
31 | need to define different validation rules and error messages based on
32 | the user's locale.
33 |
34 |
35 | The Validator package will provide the capability to configure
36 | validators (validation methods) with different method signatures.
37 | So the basic framework can have an interface built on it to deal
38 | with validations on web layers, ejb layers, etc.
39 |
40 |
41 | (1) Scope of the Package
42 |
43 | The package shall create and maintain a package that provides
44 | basic validation functionality.
45 |
46 |
47 |
48 | The package should :
49 |
50 | - Provide in an easy way to define validations for fields
51 | - Provide internationalization support for validation rules and error messages.
52 | - Provide an easy way to define validators
53 | - Provide a way to store information in a validator definition so JavaScript client
54 | side validation can be auto-generated matching the server side validation.
55 |
56 |
57 |
58 |
59 | Non-goals:
60 |
61 | - This package does not auto-generate JavaScript client side code.
62 |
63 |
64 |
65 | (1.5) Interaction With Other Packages
66 |
67 | Validator relies on:
68 |
69 |
70 |
73 |
74 | (2) Required Jakarta-Commons Resources
75 |
76 |
77 | - Commons BeanUtils
78 | - Commons Collections
79 | - Commons Digester
80 |
81 |
82 |
83 | - CVS Repository - New directory
validator
in the
84 | jakarta-commons
CVS repository.
85 |
86 | - Initial Committers - The list is provided below.
87 |
88 | - Mailing List - Discussions will take place on the general
89 | dev@commons.apache.org mailing list. To help list
90 | subscribers identify messages of interest, it is suggested that the
91 | message subject of messages about this component be prefixed with
92 | [Validator].
93 |
94 | - Bugzilla - New component "Validator" under the "Commons" product
95 | category, with appropriate version identifiers as needed.
96 |
97 | - Jyve FAQ - New category "commons-validator" (when available).
98 |
99 |
100 |
101 | (4) Initial Committers
102 |
103 | The initial committers on the Validator component shall be:
104 |
105 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html).
18 |
--------------------------------------------------------------------------------
/src/assembly/bin.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 | bin
21 |
22 | tar.gz
23 | zip
24 |
25 | false
26 |
27 |
28 |
29 | LICENSE.txt
30 | NOTICE.txt
31 | RELEASE-NOTES.txt
32 | README.md
33 |
34 |
35 |
36 | target
37 |
38 |
39 | *.jar
40 |
41 | 644
42 |
43 |
44 | target
45 |
46 |
47 | *.js
48 |
49 |
50 |
51 | target/site/apidocs
52 | apidocs
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/assembly/src.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 | src
21 |
22 | tar.gz
23 | zip
24 |
25 | ${artifactId}-${version}-src
26 |
27 |
28 |
29 | BUILDING.txt
30 | build.properties.sample
31 | build.xml
32 | checkstyle*.xml
33 | CONTRIBUTING.md
34 | LICENSE.txt
35 | license-header.txt
36 | NOTICE.txt
37 | pom.xml
38 | RELEASE-NOTES.txt
39 | README.md
40 |
41 |
42 |
43 | etc
44 |
45 |
46 | src
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/conf/checkstyle/checkstyle-header.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
--------------------------------------------------------------------------------
/src/conf/checkstyle/checkstyle-suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/conf/spotbugs-exclude-filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/example/org/apache/commons/validator/example/ValidateBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.example;
18 |
19 | /**
20 | * A simple bean to use with the Validator Example.
21 | */
22 | public class ValidateBean {
23 |
24 | String lastName, firstName, street1, street2, city, state, postalCode, age;
25 |
26 | public void setLastName(String lastName) {
27 | this.lastName = lastName;
28 | }
29 |
30 | public void setFirstName(String firstName) {
31 | this.firstName = firstName;
32 | }
33 |
34 | public void setStreet1(String street1) {
35 | this.street1 = street1;
36 | }
37 |
38 | public void setStreet2(String street2) {
39 | this.street2 = street2;
40 | }
41 |
42 | public void setCity(String city) {
43 | this.city = city;
44 | }
45 |
46 | public void setState(String state) {
47 | this.state = state;
48 | }
49 |
50 | public void setPostalCode(String postalCode) {
51 | this.postalCode = postalCode;
52 | }
53 |
54 | public void setAge(String age) {
55 | this.age = age;
56 | }
57 |
58 | public String getLastName() {
59 | return this.lastName;
60 | }
61 |
62 | public String getFirstName() {
63 | return this.firstName;
64 | }
65 |
66 | public String getStreet1() {
67 | return this.street1;
68 | }
69 |
70 | public String getStreet2() {
71 | return this.street2;
72 | }
73 |
74 | public String getCity() {
75 | return this.city;
76 | }
77 |
78 | public String getState() {
79 | return this.state;
80 | }
81 |
82 | public String getPostalCode() {
83 | return this.postalCode;
84 | }
85 |
86 | public String getAge() {
87 | return this.age;
88 | }
89 |
90 | public String toString() {
91 | return "{lastname="
92 | + this.lastName
93 | + ", firstname="
94 | + this.firstName
95 | + ", street1="
96 | + this.street1
97 | + ",\n street2="
98 | + this.street2
99 | + ", "
100 | + "city="
101 | + this.city
102 | + ", state="
103 | + this.state
104 | + ",\n postalcode="
105 | + this.postalCode
106 | + ", age="
107 | + this.age
108 | + "}";
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/src/example/org/apache/commons/validator/example/applicationResources.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one or more
2 | # contributor license agreements. See the NOTICE file distributed with
3 | # this work for additional information regarding copyright ownership.
4 | # The ASF licenses this file to You under the Apache License, Version 2.0
5 | # (the "License"); you may not use this file except in compliance with
6 | # the License. You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | # The error messages for the Validation Actions
17 | errors.required=The {0} field is required.
18 | errors.int=The {0} field is not an integer.
19 |
20 | # The formatted names of the properties
21 | nameForm.age.displayname=Age
22 | nameForm.lastname.displayname=Last Name
23 | nameForm.firstname.displayname=First Name
24 | nameForm.city.displayname=City
25 | nameForm.state.displayname=State
26 | nameForm.postalCode.displayname=Postal Code
27 | nameForm.street1.displayname=Street Address
28 |
29 |
--------------------------------------------------------------------------------
/src/example/org/apache/commons/validator/example/validator-example.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
35 |
36 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/ISBNValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * A class for validating 10 digit ISBN codes.
21 | * Based on this
22 | *
23 | * algorithm
24 | *
25 | * NOTE: This has been replaced by the new
26 | * {@link org.apache.commons.validator.routines.ISBNValidator}.
27 | *
28 | * @since 1.2.0
29 | * @deprecated Use the new ISBNValidator in the routines package
30 | */
31 | @Deprecated
32 | public class ISBNValidator {
33 |
34 | /**
35 | * Constructs a new instance.
36 | */
37 | public ISBNValidator() {
38 | }
39 |
40 | /**
41 | * If the ISBN is formatted with space or dash separators its format is
42 | * validated. Then the digits in the number are weighted, summed, and
43 | * divided by 11 according to the ISBN algorithm. If the result is zero,
44 | * the ISBN is valid. This method accepts formatted or raw ISBN codes.
45 | *
46 | * @param isbn Candidate ISBN number to be validated. {@code null} is
47 | * considered invalid.
48 | * @return true if the string is a valid ISBN code.
49 | */
50 | public boolean isValid(final String isbn) {
51 | return org.apache.commons.validator.routines.ISBNValidator.getInstance().isValidISBN10(isbn);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/ValidatorException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * The base exception for the Validator Framework. All other
21 | * {@code Exception}s thrown during calls to
22 | * {@code Validator.validate()} are considered errors.
23 | */
24 | public class ValidatorException extends Exception {
25 |
26 | private static final long serialVersionUID = 1025759372615616964L;
27 |
28 | /**
29 | * Constructs an Exception with no specified detail message.
30 | */
31 | public ValidatorException() {
32 | }
33 |
34 | /**
35 | * Constructs an Exception with the specified detail message.
36 | *
37 | * @param message The error message.
38 | */
39 | public ValidatorException(final String message) {
40 | super(message);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/IBANValidatorStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines;
18 |
19 | /**
20 | * Statuses of IBAN validation.
21 | *
22 | * @since 1.10.0
23 | */
24 | public enum IBANValidatorStatus {
25 | /**
26 | * IBAN is valid
27 | */
28 | VALID,
29 |
30 | /**
31 | * IBAN validator for given country is not registered
32 | */
33 | UNKNOWN_COUNTRY,
34 |
35 | /**
36 | * Length for given IBAN is wrong
37 | */
38 | INVALID_LENGTH,
39 |
40 | /**
41 | * Pattern for given IBAN is not match
42 | */
43 | INVALID_PATTERN,
44 |
45 | /**
46 | * Checksum for given IBAN is invalid
47 | */
48 | INVALID_CHECKSUM
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/ABANumberCheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | /**
20 | * Modulus 10 ABA Number (or Routing Transit Number (RTN)) Check Digit
21 | * calculation/validation.
22 | *
23 | *
24 | * ABA Numbers (or Routing Transit Numbers) are a nine digit numeric code used
25 | * to identify American financial institutions for things such as checks or deposits
26 | * (ABA stands for the American Bankers Association).
27 | *
28 | *
29 | * Check digit calculation is based on modulus 10 with digits being weighted
30 | * based on their position (from right to left) as follows:
31 | *
32 | *
33 | * - Digits 1, 4 and & 7 are weighted 1
34 | * - Digits 2, 5 and & 8 are weighted 7
35 | * - Digits 3, 6 and & 9 are weighted 3
36 | *
37 | *
38 | *
39 | * For further information see
40 | * Wikipedia -
41 | * Routing transit number.
42 | *
43 | *
44 | * @since 1.4
45 | */
46 | public final class ABANumberCheckDigit extends ModulusCheckDigit {
47 |
48 | private static final long serialVersionUID = -8255937433810380145L;
49 |
50 | /** Singleton Routing Transit Number Check Digit instance */
51 | public static final CheckDigit ABAN_CHECK_DIGIT = new ABANumberCheckDigit();
52 |
53 | /** Weighting given to digits depending on their right position */
54 | private static final int[] POSITION_WEIGHT = {3, 1, 7};
55 |
56 | /**
57 | * Constructs a modulus 10 Check Digit routine for ABA Numbers.
58 | */
59 | public ABANumberCheckDigit() {
60 | }
61 |
62 | /**
63 | * Calculates the weighted value of a character in the
64 | * code at a specified position.
65 | *
66 | * ABA Routing numbers are weighted in the following manner:
67 | *
{@code
68 | * left position: 1 2 3 4 5 6 7 8 9
69 | * weight: 3 7 1 3 7 1 3 7 1
70 | * }
71 | *
72 | * @param charValue The numeric value of the character.
73 | * @param leftPos The position of the character in the code, counting from left to right
74 | * @param rightPos The position of the character in the code, counting from right to left
75 | * @return The weighted value of the character.
76 | */
77 | @Override
78 | protected int weightedValue(final int charValue, final int leftPos, final int rightPos) {
79 | final int weight = POSITION_WEIGHT[rightPos % 3]; // CHECKSTYLE IGNORE MagicNumber
80 | return charValue * weight;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/AbstractCheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.commons.validator.routines.checkdigit;
19 |
20 | /**
21 | * Abstracts CheckDigit.
22 | */
23 | abstract class AbstractCheckDigit implements CheckDigit {
24 | // Empty
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/CheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.apache.commons.validator.routines.CodeValidator;
20 |
21 | /**
22 | * Check Digit calculation and validation.
23 | *
24 | * The logic for validating check digits has previously been
25 | * embedded within the logic for specific code validation, which
26 | * includes other validations such as verifying the format
27 | * or length of a code. {@link CheckDigit} provides for separating out
28 | * the check digit calculation logic enabling it to be more easily
29 | * tested and reused.
30 | *
31 | *
32 | * Although Commons Validator is primarily concerned with validation,
33 | * {@link CheckDigit} also defines behavior for calculating/generating check
34 | * digits, since it makes sense that users will want to (re-)use the
35 | * same logic for both. The {@link org.apache.commons.validator.routines.ISBNValidator}
36 | * makes specific use of this feature by providing the facility to validate ISBN-10 codes
37 | * and then convert them to the new ISBN-13 standard.
38 | *
39 | *
40 | * CheckDigit is used by the new generic {@link CodeValidator} implementation.
41 | *
42 | *
43 | * Implementations
44 | * See the
45 | * Package Summary for a full
46 | * list of implementations provided within Commons Validator.
47 | *
48 | * @see org.apache.commons.validator.routines.CodeValidator
49 | * @since 1.4
50 | */
51 | public interface CheckDigit {
52 |
53 | /**
54 | * Calculates the Check Digit for a code.
55 | *
56 | * @param code The code to calculate the Check Digit for.
57 | * The string must not include the check digit
58 | * @return The calculated Check Digit
59 | * @throws CheckDigitException if an error occurs.
60 | */
61 | String calculate(String code) throws CheckDigitException;
62 |
63 | /**
64 | * Validates the check digit for the code.
65 | *
66 | * @param code The code to validate, the string must include the check digit.
67 | * @return {@code true} if the check digit is valid, otherwise
68 | * {@code false}.
69 | */
70 | boolean isValid(String code);
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/CheckDigitException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | /**
20 | * Check Digit calculation/validation error.
21 | *
22 | * @since 1.4
23 | */
24 | public class CheckDigitException extends Exception {
25 |
26 | private static final long serialVersionUID = -3519894732624685477L;
27 |
28 | /**
29 | * Constructs an Exception with no message.
30 | */
31 | public CheckDigitException() {
32 | }
33 |
34 | /**
35 | * Constructs an Exception with a message.
36 | *
37 | * @param msg The error message.
38 | */
39 | public CheckDigitException(final String msg) {
40 | super(msg);
41 | }
42 |
43 | /**
44 | * Constructs an Exception with a message and
45 | * the underlying cause.
46 | *
47 | * @param msg The error message.
48 | * @param cause The underlying cause of the error
49 | */
50 | public CheckDigitException(final String msg, final Throwable cause) {
51 | super(msg, cause);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/EAN13CheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | /**
20 | * Modulus 10 EAN-13 / UPC / ISBN-13 Check Digit
21 | * calculation/validation.
22 | *
23 | * Check digit calculation is based on modulus 10 with digits in
24 | * an odd position (from right to left) being weighted 1 and even
25 | * position digits being weighted 3.
26 | *
27 | * For further information see:
28 | *
39 | *
40 | * @since 1.4
41 | */
42 | public final class EAN13CheckDigit extends ModulusCheckDigit {
43 |
44 | private static final long serialVersionUID = 1726347093230424107L;
45 |
46 | /** Singleton EAN-13 Check Digit instance */
47 | public static final CheckDigit EAN13_CHECK_DIGIT = new EAN13CheckDigit();
48 |
49 | /** Weighting given to digits depending on their right position */
50 | private static final int[] POSITION_WEIGHT = {3, 1};
51 |
52 | /**
53 | * Constructs a modulus 10 Check Digit routine for EAN/UPC.
54 | */
55 | public EAN13CheckDigit() {
56 | }
57 |
58 | /**
59 | * Calculates the weighted value of a character in the
60 | * code at a specified position.
61 | *
62 | * For EAN-13 (from right to left) odd digits are weighted
63 | * with a factor of one and even digits with a factor
64 | * of three.
65 | *
66 | * @param charValue The numeric value of the character.
67 | * @param leftPos The position of the character in the code, counting from left to right
68 | * @param rightPos The position of the character in the code, counting from right to left
69 | * @return The weighted value of the character.
70 | */
71 | @Override
72 | protected int weightedValue(final int charValue, final int leftPos, final int rightPos) {
73 | return charValue * POSITION_WEIGHT[rightPos % 2];
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/ISSNCheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | /**
20 | * International Standard Serial Number (ISSN)
21 | * is an eight-digit serial number used to
22 | * uniquely identify a serial publication.
23 | *
24 | * The format is:
25 | *
26 | * ISSN dddd-dddC
27 | * where:
28 | * d = decimal digit (0-9)
29 | * C = checksum (0-9 or X)
30 | *
31 | * The checksum is formed by adding the first 7 digits multiplied by
32 | * the position in the entire number (counting from the right).
33 | * For example, abcd-efg would be 8a + 7b + 6c + 5d + 4e +3f +2g.
34 | * The check digit is modulus 11, where the value 10 is represented by 'X'
35 | * For example:
36 | * ISSN 0317-8471
37 | * ISSN 1050-124X
38 | *
39 | *
40 | * Note: This class expects the input to be numeric only,
41 | * with all formatting removed.
42 | * For example:
43 | *
44 | * 03178471
45 | * 1050124X
46 | *
47 | * @since 1.5.0
48 | */
49 | public final class ISSNCheckDigit extends ModulusCheckDigit {
50 |
51 | private static final long serialVersionUID = 1L;
52 |
53 | /** Singleton ISSN Check Digit instance */
54 | public static final CheckDigit ISSN_CHECK_DIGIT = new ISSNCheckDigit();
55 |
56 | /**
57 | * Creates the instance using a checkdigit modulus of 11.
58 | */
59 | public ISSNCheckDigit() {
60 | super(MODULUS_11);
61 | }
62 |
63 | @Override
64 | protected String toCheckDigit(final int charValue) throws CheckDigitException {
65 | if (charValue == 10) { // CHECKSTYLE IGNORE MagicNumber
66 | return "X";
67 | }
68 | return super.toCheckDigit(charValue);
69 | }
70 |
71 | @Override
72 | protected int toInt(final char character, final int leftPos, final int rightPos)
73 | throws CheckDigitException {
74 | if (rightPos == 1 && character == 'X') {
75 | return 10; // CHECKSTYLE IGNORE MagicNumber
76 | }
77 | return super.toInt(character, leftPos, rightPos);
78 | }
79 |
80 | @Override
81 | protected int weightedValue(final int charValue, final int leftPos, final int rightPos) throws CheckDigitException {
82 | return charValue * (9 - leftPos); // CHECKSTYLE IGNORE MagicNumber
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/LuhnCheckDigit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | /**
20 | * Modulus 10 Luhn Check Digit calculation/validation.
21 | *
22 | * Luhn check digits are used, for example, by:
23 | *
28 | * Check digit calculation is based on modulus 10 with digits in
29 | * an odd position (from right to left) being weighted 1 and even
30 | * position digits being weighted 2 (weighted values greater than 9 have 9 subtracted).
31 | *
32 | *
33 | * See Wikipedia
34 | * for more details.
35 | *
36 | *
37 | * @since 1.4
38 | */
39 | public final class LuhnCheckDigit extends ModulusCheckDigit {
40 |
41 | private static final long serialVersionUID = -2976900113942875999L;
42 |
43 | /** Singleton Luhn Check Digit instance */
44 | public static final CheckDigit LUHN_CHECK_DIGIT = new LuhnCheckDigit();
45 |
46 | /** Weighting given to digits depending on their right position */
47 | private static final int[] POSITION_WEIGHT = {2, 1};
48 |
49 | /**
50 | * Constructs a modulus 10 Luhn Check Digit routine.
51 | */
52 | public LuhnCheckDigit() {
53 | }
54 |
55 | /**
56 | * Calculates the weighted value of a character in the
57 | * code at a specified position.
58 | *
59 | * For Luhn (from right to left) odd digits are weighted
60 | * with a factor of one and even digits with a factor
61 | * of two. Weighted values > 9, have 9 subtracted
62 | *
63 | * @param charValue The numeric value of the character.
64 | * @param leftPos The position of the character in the code, counting from left to right
65 | * @param rightPos The position of the character in the code, counting from right to left
66 | * @return The weighted value of the character.
67 | */
68 | @Override
69 | protected int weightedValue(final int charValue, final int leftPos, final int rightPos) {
70 | final int weight = POSITION_WEIGHT[rightPos % 2]; // CHECKSTYLE IGNORE MagicNumber
71 | final int weightedValue = charValue * weight;
72 | return weightedValue > 9 ? weightedValue - 9 : weightedValue; // CHECKSTYLE IGNORE MagicNumber
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/routines/checkdigit/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * This package contains Check Digit validation/calculation routines.
20 | *
21 | * Note that these do not validate the input for length or syntax. Such validation is performed by the org.apache.commons.validator.routines.XYZValidator
22 | * classes.
23 | *
24 | */
25 | package org.apache.commons.validator.routines.checkdigit;
--------------------------------------------------------------------------------
/src/main/java/org/apache/commons/validator/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * This package contains utility classes used by Commons Validator.
20 | */
21 | package org.apache.commons.validator.util;
--------------------------------------------------------------------------------
/src/site/resources/download_validator.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Just call the standard mirrors.cgi script. It will use download.html
3 | # as the input template.
4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $*
--------------------------------------------------------------------------------
/src/site/resources/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/commons-validator/30327416cb186ebd2cc08f3c7021f19cefa82e2e/src/site/resources/images/logo.png
--------------------------------------------------------------------------------
/src/site/resources/profile.jacoco:
--------------------------------------------------------------------------------
1 | // Licensed to the Apache Software Foundation (ASF) under one
2 | // or more contributor license agreements. See the NOTICE file
3 | // distributed with this work for additional information
4 | // regarding copyright ownership. The ASF licenses this file
5 | // to you under the Apache License, Version 2.0 (the
6 | // "License"); you may not use this file except in compliance
7 | // with the License. You may obtain a copy of the License at
8 | //
9 | // https://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
39 |
40 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/site/xdoc/building.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
21 |
22 | Building
23 | Apache Commons Team
24 |
25 |
26 |
27 |
28 |
29 | Commons Validator uses Maven or
30 | Ant as a build system.
31 |
32 |
33 |
34 |
35 |
36 | To build a jar file, change into Validator's root directory and run
37 | maven jar
.
38 | The result will be in the "target" subdirectory.
39 |
40 |
41 | To build the Javadocs, run maven javadoc
.
42 | The result will be in "target/docs/apidocs".
43 |
44 |
45 | To build the full website, run maven site
.
46 |
47 | The result will be in "target/docs".
48 |
49 |
50 | Further details can be found in the
51 | commons build instructions.
52 |
53 |
54 |
55 |
56 |
57 | To build a jar file and the javadocs, change into Validator's root directory
58 | and run ant dist
.
59 | The result will be in the "dist" subdirectory.
60 |
61 |
62 |
63 |
64 |
65 |
66 | Nightly Builds
67 | are built once a day from the current SVN HEAD. These are provided purely for test purposes and are NOT
68 | official releases of the Apache Software Foundation - Released versions of Commons Validator are
69 | available here.
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/src/site/xdoc/community.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
22 |
23 | Community
24 |
25 |
26 |
27 |
28 |
29 | The Apache Wiki is a Wiki run by Apache for the Apache community. The Validator Wiki home page is
30 | here.
31 |
32 |
33 | Anyone is welcome to create new content about Validator providing that they
34 | observe the usual rules of netiquette.
35 |
36 |
37 |
38 |
39 |
40 | Struts Console is a free
41 | standalone Java Swing application for managing
42 | Struts related configuration files, including Commons Validator config files.
43 | Struts Console also plugs into several popular Java IDEs for seamless
44 | management of config files from one central development tool.
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/site/xdoc/tasks.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
22 |
23 | TODO
24 |
25 |
26 |
27 |
28 |
29 | The following is a list of items that need to be completed in
30 | Validator. Contributions are welcome!
31 |
32 |
33 |
34 | -
35 | Change the validation.xml file semantics to match a more general "bean" validation usage.
36 | Currently, the <form-validation>, <formset>, <form>, and <field> elements
37 | require a form-centric view of validations. Changing these to <bean-validation> or <validator-config>,
38 | <beans>, <bean>, and <property> respectively would allow Validator to be used more easily in
39 | non-form based environments. See the 2.0 DTD proposal for specifics.
40 |
41 | -
42 | The above changes to validation.xml could only apply to Validator's native configuration format. We
43 | could add a ValidatorResources constructor that accepts a digester-rules file to allow parsing any
44 | XML format into Validator configuration objects. This would allow higher level frameworks like Struts
45 | to use configuration semantics specific to their domain.
46 |
47 | -
48 | ValidatorException is only thrown to indicate configuration and programmer errors
49 | yet is a checked exception. ValidatorException should be converted to a RuntimeException to match its
50 | real purpose. Furthermore, the exception handling for pluggable validations (ValidatorActions)
51 | is not well defined or documented. RuntimeExceptions thrown from ValidatorActions should be propagated
52 | out of the Validator framework as is because they indicate programmer error. Checked exceptions thrown
53 | from a ValidatorAction should stop validation and be propogated out of the framework for handling as these
54 | indicate an unrecoverable system failure. Validation method implementation becomes easier because they
55 | can throw SQLException, IOException, etc. instead of wrapping the exception or defining it as a rule failure.
56 | This allows clients to reliably distinguish between a normal validation failure (invalid data) and exceptional
57 | conditions.
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/AbstractCommonTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | import org.xml.sax.SAXException;
23 |
24 | /**
25 | * Consolidates reading in XML config file into parent class.
26 | */
27 | public abstract class AbstractCommonTest {
28 |
29 | /**
30 | * Resources used for validation tests.
31 | */
32 | protected ValidatorResources resources;
33 | protected String name;
34 |
35 | /**
36 | * Load {@code ValidatorResources} from validator-numeric.xml.
37 | */
38 | protected void loadResources(final String file) throws IOException, SAXException {
39 | // Load resources
40 | try (InputStream in = this.getClass().getResourceAsStream(file)) {
41 | resources = new ValidatorResources(in);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/AbstractNumberTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertNotNull;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import java.io.IOException;
23 |
24 | import org.junit.jupiter.api.AfterEach;
25 | import org.junit.jupiter.api.BeforeEach;
26 | import org.junit.jupiter.api.Test;
27 | import org.xml.sax.SAXException;
28 |
29 | /**
30 | * Abstracts number unit tests methods.
31 | */
32 | public abstract class AbstractNumberTest extends AbstractCommonTest {
33 |
34 | /**
35 | * The key used to retrieve the set of validation rules from the xml file.
36 | */
37 | protected String formKey;
38 |
39 | /**
40 | * The key used to retrieve the validator action.
41 | */
42 | protected String action;
43 |
44 | /**
45 | * Load {@code ValidatorResources} from validator-numeric.xml.
46 | */
47 | @BeforeEach
48 | protected void setUp() throws IOException, SAXException {
49 | // Load resources
50 | loadResources("TestNumber-config.xml");
51 | }
52 |
53 | @AfterEach
54 | protected void tearDown() {
55 | }
56 |
57 | /**
58 | * Tests the number validation.
59 | */
60 | @Test
61 | void testNumber() throws ValidatorException {
62 | // Create bean to run test on.
63 | final ValueBean info = new ValueBean();
64 | info.setValue("0");
65 | valueTest(info, true);
66 | }
67 |
68 | /**
69 | * Tests the float validation failure.
70 | */
71 | @Test
72 | void testNumberFailure() throws ValidatorException {
73 | // Create bean to run test on.
74 | final ValueBean info = new ValueBean();
75 | valueTest(info, false);
76 | }
77 |
78 | /**
79 | * Utility class to run a test on a value.
80 | *
81 | * @param info Value to run test on.
82 | * @param passed Whether or not the test is expected to pass.
83 | */
84 | protected void valueTest(final Object info, final boolean passed) throws ValidatorException {
85 | // Construct validator based on the loaded resources
86 | // and the form key
87 | final Validator validator = new Validator(resources, formKey);
88 | // add the name bean to the validator as a resource
89 | // for the validations to be performed on.
90 | validator.setParameter(Validator.BEAN_PARAM, info);
91 |
92 | // Get results of the validation.
93 | // throws ValidatorException,
94 | // but we aren't catching for testing
95 | // since no validation methods we use
96 | // throw this
97 | final ValidatorResults results = validator.validate();
98 |
99 | assertNotNull(results, "Results are null.");
100 |
101 | final ValidatorResult result = results.getValidatorResult("value");
102 |
103 | assertNotNull(result, action + " value ValidatorResult should not be null.");
104 | assertTrue(result.containsAction(action), action + " value ValidatorResult should contain the '" + action + "' action.");
105 | assertTrue(passed ? result.isValid(action) : !result.isValid(action),
106 | action + " value ValidatorResult for the '" + action + "' action should have " + (passed ? "passed" : "failed") + ".");
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ByteTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code byte} validations.
23 | */
24 | class ByteTest extends AbstractNumberTest {
25 |
26 | ByteTest() {
27 | action = "byte";
28 | formKey = "byteForm";
29 | }
30 |
31 | /**
32 | * Tests the byte validation.
33 | */
34 | @Test
35 | void testByte() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue("0");
39 |
40 | valueTest(info, true);
41 | }
42 |
43 | /**
44 | * Tests the byte validation failure.
45 | */
46 | @Test
47 | void testByteBeyondMax() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 | info.setValue(Byte.MAX_VALUE + "1");
51 |
52 | valueTest(info, false);
53 | }
54 |
55 | /**
56 | * Tests the byte validation failure.
57 | */
58 | @Test
59 | void testByteBeyondMin() throws ValidatorException {
60 | // Create bean to run test on.
61 | final ValueBean info = new ValueBean();
62 | info.setValue(Byte.MIN_VALUE + "1");
63 |
64 | valueTest(info, false);
65 | }
66 |
67 | /**
68 | * Tests the byte validation failure.
69 | */
70 | @Test
71 | void testByteFailure() throws ValidatorException {
72 | // Create bean to run test on.
73 | final ValueBean info = new ValueBean();
74 |
75 | valueTest(info, false);
76 | }
77 |
78 | /**
79 | * Tests the byte validation.
80 | */
81 | @Test
82 | void testByteMax() throws ValidatorException {
83 | // Create bean to run test on.
84 | final ValueBean info = new ValueBean();
85 | info.setValue(Byte.toString(Byte.MAX_VALUE));
86 |
87 | valueTest(info, true);
88 | }
89 |
90 | /**
91 | * Tests the byte validation.
92 | */
93 | @Test
94 | void testByteMin() throws ValidatorException {
95 | // Create bean to run test on.
96 | final ValueBean info = new ValueBean();
97 | info.setValue(Byte.toString(Byte.MIN_VALUE));
98 |
99 | valueTest(info, true);
100 | }
101 |
102 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/CreditCardValidatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * Test the CreditCardValidator class.
26 | *
27 | * @deprecated this test can be removed when the deprecated class is removed
28 | */
29 | @Deprecated
30 | class CreditCardValidatorTest {
31 |
32 | /**
33 | * Test a custom implementation of CreditCardType.
34 | */
35 | private static class DinersClub implements CreditCardValidator.CreditCardType {
36 | private static final String PREFIX = "300,301,302,303,304,305,";
37 |
38 | @Override
39 | public boolean matches(final String card) {
40 | final String prefix = card.substring(0, 3) + ",";
41 | return PREFIX.contains(prefix) && card.length() == 14;
42 | }
43 | }
44 |
45 | private static final String VALID_VISA = "4417123456789113";
46 | private static final String VALID_SHORT_VISA = "4222222222222";
47 | private static final String VALID_AMEX = "378282246310005";
48 | private static final String VALID_MASTERCARD = "5105105105105100";
49 | private static final String VALID_DISCOVER = "6011000990139424";
50 |
51 | private static final String VALID_DINERS = "30569309025904";
52 |
53 | @Test
54 | void testAddAllowedCardType() {
55 | final CreditCardValidator ccv = new CreditCardValidator(CreditCardValidator.NONE);
56 | // Turned off all cards so even valid numbers should fail
57 | assertFalse(ccv.isValid(VALID_VISA));
58 | assertFalse(ccv.isValid(VALID_AMEX));
59 | assertFalse(ccv.isValid(VALID_MASTERCARD));
60 | assertFalse(ccv.isValid(VALID_DISCOVER));
61 |
62 | // test our custom type
63 | ccv.addAllowedCardType(new DinersClub());
64 | assertTrue(ccv.isValid(VALID_DINERS));
65 | }
66 |
67 | @Test
68 | void testIsValid() {
69 | CreditCardValidator ccv = new CreditCardValidator();
70 |
71 | assertFalse(ccv.isValid(null));
72 | assertFalse(ccv.isValid(""));
73 | assertFalse(ccv.isValid("123456789012")); // too short
74 | assertFalse(ccv.isValid("12345678901234567890")); // too long
75 | assertFalse(ccv.isValid("4417123456789112"));
76 | assertFalse(ccv.isValid("4417q23456w89113"));
77 | assertTrue(ccv.isValid(VALID_VISA));
78 | assertTrue(ccv.isValid(VALID_SHORT_VISA));
79 | assertTrue(ccv.isValid(VALID_AMEX));
80 | assertTrue(ccv.isValid(VALID_MASTERCARD));
81 | assertTrue(ccv.isValid(VALID_DISCOVER));
82 |
83 | // disallow Visa so it should fail even with good number
84 | ccv = new CreditCardValidator(CreditCardValidator.AMEX);
85 | assertFalse(ccv.isValid("4417123456789113"));
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/CustomValidatorResourcesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.fail;
20 |
21 | import java.io.InputStream;
22 |
23 | import org.junit.jupiter.api.AfterEach;
24 | import org.junit.jupiter.api.BeforeEach;
25 | import org.junit.jupiter.api.Test;
26 |
27 | /**
28 | * Test custom ValidatorResources.
29 | */
30 | class CustomValidatorResourcesTest {
31 |
32 | /**
33 | * Sets up.
34 | */
35 | @BeforeEach
36 | protected void setUp() {
37 | }
38 |
39 | /**
40 | * Tear Down
41 | */
42 | @AfterEach
43 | protected void tearDown() {
44 | }
45 |
46 | /**
47 | * Test creating a custom validator resources.
48 | */
49 | @Test
50 | void testCustomResources() {
51 | // Load resources
52 | InputStream in = null;
53 | try {
54 | in = this.getClass().getResourceAsStream("TestNumber-config.xml");
55 | } catch (final Exception e) {
56 | fail("Error loading resources: " + e);
57 | } finally {
58 | try {
59 | if (in != null) {
60 | in.close();
61 | }
62 | } catch (final Exception ignore) {
63 | // ignore
64 | }
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/DateTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertNotNull;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import java.io.IOException;
23 | import java.util.Locale;
24 |
25 | import org.junit.jupiter.api.BeforeEach;
26 | import org.junit.jupiter.api.Test;
27 | import org.xml.sax.SAXException;
28 |
29 | /**
30 | * Abstracts date unit tests methods.
31 | */
32 | class DateTest extends AbstractCommonTest {
33 |
34 | /**
35 | * The key used to retrieve the set of validation rules from the xml file.
36 | */
37 | protected static final String FORM_KEY = "dateForm";
38 |
39 | /**
40 | * The key used to retrieve the validator action.
41 | */
42 | protected static final String ACTION = "date";
43 |
44 | /**
45 | * Load {@code ValidatorResources} from validator-numeric.xml.
46 | */
47 | @BeforeEach
48 | protected void setUp() throws IOException, SAXException {
49 | // Load resources
50 | loadResources("DateTest-config.xml");
51 | }
52 |
53 | /**
54 | * Tests the date validation.
55 | */
56 | @Test
57 | void testInvalidDate() throws ValidatorException {
58 | // Create bean to run test on.
59 | final ValueBean info = new ValueBean();
60 | info.setValue("12/01as/2005");
61 | valueTest(info, false);
62 | }
63 |
64 | /**
65 | * Tests the date validation.
66 | */
67 | @Test
68 | void testValidDate() throws ValidatorException {
69 | // Create bean to run test on.
70 | final ValueBean info = new ValueBean();
71 | info.setValue("12/01/2005");
72 | valueTest(info, true);
73 | }
74 |
75 | /**
76 | * Utility class to run a test on a value.
77 | *
78 | * @param info Value to run test on.
79 | * @param passed Whether or not the test is expected to pass.
80 | */
81 | protected void valueTest(final Object info, final boolean passed) throws ValidatorException {
82 | // Construct validator based on the loaded resources
83 | // and the form key
84 | final Validator validator = new Validator(resources, FORM_KEY);
85 | // add the name bean to the validator as a resource
86 | // for the validations to be performed on.
87 | validator.setParameter(Validator.BEAN_PARAM, info);
88 | validator.setParameter(Validator.LOCALE_PARAM, Locale.US);
89 |
90 | // Get results of the validation.
91 | // throws ValidatorException,
92 | // but we aren't catching for testing
93 | // since no validation methods we use
94 | // throw this
95 | final ValidatorResults results = validator.validate();
96 |
97 | assertNotNull(results, "Results are null.");
98 |
99 | final ValidatorResult result = results.getValidatorResult("value");
100 |
101 | assertNotNull(result, ACTION + " value ValidatorResult should not be null.");
102 | assertTrue(result.containsAction(ACTION), ACTION + " value ValidatorResult should contain the '" + ACTION + "' action.");
103 | assertTrue(passed ? result.isValid(ACTION) : !result.isValid(ACTION),
104 | ACTION + " value ValidatorResult for the '" + ACTION + "' action should have " + (passed ? "passed" : "failed") + ".");
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/DoubleTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code double} validations.
23 | */
24 | class DoubleTest extends AbstractNumberTest {
25 |
26 | DoubleTest() {
27 | action = "double";
28 | formKey = "doubleForm";
29 | }
30 |
31 | /**
32 | * Tests the double validation.
33 | */
34 | @Test
35 | void testDouble() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue("0");
39 |
40 | valueTest(info, true);
41 | }
42 |
43 | /**
44 | * Tests the double validation failure.
45 | */
46 | @Test
47 | void testDoubleFailure() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 |
51 | valueTest(info, false);
52 | }
53 |
54 | /**
55 | * Tests the double validation.
56 | */
57 | @Test
58 | void testDoubleMax() throws ValidatorException {
59 | // Create bean to run test on.
60 | final ValueBean info = new ValueBean();
61 | info.setValue(Double.toString(Double.MAX_VALUE));
62 |
63 | valueTest(info, true);
64 | }
65 |
66 | /**
67 | * Tests the double validation.
68 | */
69 | @Test
70 | void testDoubleMin() throws ValidatorException {
71 | // Create bean to run test on.
72 | final ValueBean info = new ValueBean();
73 | info.setValue(Double.toString(Double.MIN_VALUE));
74 |
75 | valueTest(info, true);
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/EntityImportTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertNotNull;
20 |
21 | import java.net.URL;
22 | import java.util.Locale;
23 |
24 | import org.junit.jupiter.api.Test;
25 |
26 | /**
27 | * Tests entity imports.
28 | */
29 | class EntityImportTest extends AbstractCommonTest {
30 |
31 | /**
32 | * Tests the entity import loading the {@code byteForm} form.
33 | */
34 | @Test
35 | void testEntityImport() throws Exception {
36 | final URL url = getClass().getResource("EntityImportTest-config.xml");
37 | final ValidatorResources resources = new ValidatorResources(url.toExternalForm());
38 | assertNotNull(resources.getForm(Locale.getDefault(), "byteForm"), "Form should be found");
39 | }
40 |
41 | /**
42 | * Tests loading ValidatorResources from a URL
43 | */
44 | @Test
45 | void testParseURL() throws Exception {
46 | final URL url = getClass().getResource("EntityImportTest-config.xml");
47 | final ValidatorResources resources = new ValidatorResources(url);
48 | assertNotNull(resources.getForm(Locale.getDefault(), "byteForm"), "Form should be found");
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/FloatTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code float} validations.
23 | */
24 | class FloatTest extends AbstractNumberTest {
25 |
26 | FloatTest() {
27 | action = "float";
28 | formKey = "floatForm";
29 | }
30 |
31 | /**
32 | * Tests the float validation.
33 | */
34 | @Test
35 | void testFloat() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue("0");
39 |
40 | valueTest(info, true);
41 | }
42 |
43 | /**
44 | * Tests the float validation failure.
45 | */
46 | @Test
47 | void testFloatFailure() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 |
51 | valueTest(info, false);
52 | }
53 |
54 | /**
55 | * Tests the float validation.
56 | */
57 | @Test
58 | void testFloatMax() throws ValidatorException {
59 | // Create bean to run test on.
60 | final ValueBean info = new ValueBean();
61 | info.setValue(Float.toString(Float.MAX_VALUE));
62 |
63 | valueTest(info, true);
64 | }
65 |
66 | /**
67 | * Tests the float validation.
68 | */
69 | @Test
70 | void testFloatMin() throws ValidatorException {
71 | // Create bean to run test on.
72 | final ValueBean info = new ValueBean();
73 | info.setValue(Float.toString(Float.MIN_VALUE));
74 |
75 | valueTest(info, true);
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/GenericValidatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * Test the GenericValidator class.
26 | */
27 | class GenericValidatorTest {
28 |
29 | @Test
30 | void testMaxLength() {
31 |
32 | // Use 0 for line end length
33 | assertFalse(GenericValidator.maxLength("12345\n\r", 4, 0), "Max=4 End=0");
34 | assertTrue(GenericValidator.maxLength("12345\n\r", 5, 0), "Max=5 End=0");
35 | assertTrue(GenericValidator.maxLength("12345\n\r", 6, 0), "Max=6 End=0");
36 | assertTrue(GenericValidator.maxLength("12345\n\r", 7, 0), "Max=7 End=0");
37 |
38 | // Use 1 for line end length
39 | assertFalse(GenericValidator.maxLength("12345\n\r", 4, 1), "Max=4 End=1");
40 | assertFalse(GenericValidator.maxLength("12345\n\r", 5, 1), "Max=5 End=1");
41 | assertTrue(GenericValidator.maxLength("12345\n\r", 6, 1), "Max=6 End=1");
42 | assertTrue(GenericValidator.maxLength("12345\n\r", 7, 1), "Max=7 End=1");
43 |
44 | // Use 2 for line end length
45 | assertFalse(GenericValidator.maxLength("12345\n\r", 4, 2), "Max=4 End=2");
46 | assertFalse(GenericValidator.maxLength("12345\n\r", 5, 2), "Max=5 End=2");
47 | assertFalse(GenericValidator.maxLength("12345\n\r", 6, 2), "Max=6 End=2");
48 | assertTrue(GenericValidator.maxLength("12345\n\r", 7, 2), "Max=7 End=2");
49 | }
50 |
51 | @Test
52 | void testMinLength() {
53 |
54 | // Use 0 for line end length
55 | assertTrue(GenericValidator.minLength("12345\n\r", 5, 0), "Min=5 End=0");
56 | assertFalse(GenericValidator.minLength("12345\n\r", 6, 0), "Min=6 End=0");
57 | assertFalse(GenericValidator.minLength("12345\n\r", 7, 0), "Min=7 End=0");
58 | assertFalse(GenericValidator.minLength("12345\n\r", 8, 0), "Min=8 End=0");
59 |
60 | // Use 1 for line end length
61 | assertTrue(GenericValidator.minLength("12345\n\r", 5, 1), "Min=5 End=1");
62 | assertTrue(GenericValidator.minLength("12345\n\r", 6, 1), "Min=6 End=1");
63 | assertFalse(GenericValidator.minLength("12345\n\r", 7, 1), "Min=7 End=1");
64 | assertFalse(GenericValidator.minLength("12345\n\r", 8, 1), "Min=8 End=1");
65 |
66 | // Use 2 for line end length
67 | assertTrue(GenericValidator.minLength("12345\n\r", 5, 2), "Min=5 End=2");
68 | assertTrue(GenericValidator.minLength("12345\n\r", 6, 2), "Min=6 End=2");
69 | assertTrue(GenericValidator.minLength("12345\n\r", 7, 2), "Min=7 End=2");
70 | assertFalse(GenericValidator.minLength("12345\n\r", 8, 2), "Min=8 End=2");
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * Tests {@link ISBNValidator}.
26 | *
27 | * @deprecated to be removed when the org.apache.commons.validator.ISBNValidator class is removed
28 | */
29 | @Deprecated
30 | class ISBNValidatorTest {
31 |
32 | private static final String VALID_ISBN_RAW = "1930110995";
33 | private static final String VALID_ISBN_DASHES = "1-930110-99-5";
34 | private static final String VALID_ISBN_SPACES = "1 930110 99 5";
35 | private static final String VALID_ISBN_X = "0-201-63385-X";
36 | private static final String INVALID_ISBN = "068-556-98-45";
37 |
38 | @Test
39 | void testIsValid() throws Exception {
40 | final ISBNValidator validator = new ISBNValidator();
41 | assertFalse(validator.isValid(null));
42 | assertFalse(validator.isValid(""));
43 | assertFalse(validator.isValid("1"));
44 | assertFalse(validator.isValid("12345678901234"));
45 | assertFalse(validator.isValid("dsasdsadsads"));
46 | assertFalse(validator.isValid("535365"));
47 | assertFalse(validator.isValid("I love sparrows!"));
48 | assertFalse(validator.isValid("--1 930110 99 5"));
49 | assertFalse(validator.isValid("1 930110 99 5--"));
50 | assertFalse(validator.isValid("1 930110-99 5-"));
51 |
52 | assertTrue(validator.isValid(VALID_ISBN_RAW));
53 | assertTrue(validator.isValid(VALID_ISBN_DASHES));
54 | assertTrue(validator.isValid(VALID_ISBN_SPACES));
55 | assertTrue(validator.isValid(VALID_ISBN_X));
56 | assertFalse(validator.isValid(INVALID_ISBN));
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/IntegerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code int} validations.
23 | */
24 | class IntegerTest extends AbstractNumberTest {
25 |
26 | IntegerTest() {
27 | formKey = "intForm";
28 | action = "int";
29 | }
30 |
31 | /**
32 | * Tests the int validation.
33 | */
34 | @Test
35 | void testInt() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue("0");
39 |
40 | valueTest(info, true);
41 | }
42 |
43 | /**
44 | * Tests the int validation failure.
45 | */
46 | @Test
47 | void testIntBeyondMax() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 | info.setValue(Integer.MAX_VALUE + "1");
51 |
52 | valueTest(info, false);
53 | }
54 |
55 | /**
56 | * Tests the int validation failure.
57 | */
58 | @Test
59 | void testIntBeyondMin() throws ValidatorException {
60 | // Create bean to run test on.
61 | final ValueBean info = new ValueBean();
62 | info.setValue(Integer.MIN_VALUE + "1");
63 |
64 | valueTest(info, false);
65 | }
66 |
67 | /**
68 | * Tests the int validation.
69 | */
70 | @Test
71 | void testIntegerMax() throws ValidatorException {
72 | // Create bean to run test on.
73 | final ValueBean info = new ValueBean();
74 | info.setValue(Integer.toString(Integer.MAX_VALUE));
75 |
76 | valueTest(info, true);
77 | }
78 |
79 | /**
80 | * Tests the int validation failure.
81 | */
82 | @Test
83 | void testIntFailure() throws ValidatorException {
84 | // Create bean to run test on.
85 | final ValueBean info = new ValueBean();
86 |
87 | valueTest(info, false);
88 | }
89 |
90 | /**
91 | * Tests the int validation.
92 | */
93 | @Test
94 | void testIntMin() throws ValidatorException {
95 | // Create bean to run test on.
96 | final ValueBean info = new ValueBean();
97 | info.setValue(Integer.toString(Integer.MIN_VALUE));
98 |
99 | valueTest(info, true);
100 | }
101 |
102 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/LongTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code long} validations.
23 | */
24 | class LongTest extends AbstractNumberTest {
25 |
26 | LongTest() {
27 | formKey = "longForm";
28 | action = "long";
29 | }
30 |
31 | /**
32 | * Tests the long validation.
33 | */
34 | @Test
35 | void testLong() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue("0");
39 |
40 | valueTest(info, true);
41 | }
42 |
43 | /**
44 | * Tests the long validation failure.
45 | */
46 | @Test
47 | void testLongBeyondMax() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 | info.setValue(Long.MAX_VALUE + "1");
51 |
52 | valueTest(info, false);
53 | }
54 |
55 | /**
56 | * Tests the long validation failure.
57 | */
58 | @Test
59 | void testLongBeyondMin() throws ValidatorException {
60 | // Create bean to run test on.
61 | final ValueBean info = new ValueBean();
62 | info.setValue(Long.MIN_VALUE + "1");
63 |
64 | valueTest(info, false);
65 | }
66 |
67 | /**
68 | * Tests the long validation failure.
69 | */
70 | @Test
71 | void testLongFailure() throws ValidatorException {
72 | // Create bean to run test on.
73 | final ValueBean info = new ValueBean();
74 |
75 | valueTest(info, false);
76 | }
77 |
78 | /**
79 | * Tests the long validation.
80 | */
81 | @Test
82 | void testLongMax() throws ValidatorException {
83 | // Create bean to run test on.
84 | final ValueBean info = new ValueBean();
85 | info.setValue(Long.toString(Long.MAX_VALUE));
86 |
87 | valueTest(info, true);
88 | }
89 |
90 | /**
91 | * Tests the long validation.
92 | */
93 | @Test
94 | void testLongMin() throws ValidatorException {
95 | // Create bean to run test on.
96 | final ValueBean info = new ValueBean();
97 | info.setValue(Long.toString(Long.MIN_VALUE));
98 |
99 | valueTest(info, true);
100 | }
101 |
102 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/NameBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * Value object that contains a first name and last name.
21 | */
22 | public class NameBean {
23 |
24 | protected String firstName;
25 |
26 | protected String middleName;
27 |
28 | protected String lastName;
29 |
30 | public String getFirstName() {
31 | return firstName;
32 | }
33 |
34 | public String getLastName() {
35 | return lastName;
36 | }
37 |
38 | public String getMiddleName() {
39 | return middleName;
40 | }
41 |
42 | public void setFirstName(final String firstName) {
43 | this.firstName = firstName;
44 | }
45 |
46 | public void setLastName(final String lastName) {
47 | this.lastName = lastName;
48 | }
49 |
50 | public void setMiddleName(final String middleName) {
51 | this.middleName = middleName;
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ParameterValidatorImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * Contains validation methods for different unit tests.
21 | */
22 | public class ParameterValidatorImpl {
23 |
24 | /**
25 | * ValidatorParameter is valid.
26 | */
27 | public static boolean validateParameter(final java.lang.Object bean, final org.apache.commons.validator.Form form,
28 | final org.apache.commons.validator.Field field, final org.apache.commons.validator.Validator validator,
29 | final org.apache.commons.validator.ValidatorAction action, final org.apache.commons.validator.ValidatorResults results,
30 | final java.util.Locale locale) throws Exception {
31 |
32 | return true;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ResultPair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * Groups tests and expected results.
21 | */
22 | public class ResultPair {
23 | public final String item;
24 | public final boolean valid;
25 |
26 | public ResultPair(final String item, final boolean valid) {
27 | this.item = item;
28 | this.valid = valid; // Whether the individual part of URL is valid.
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ShortTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | /**
22 | * Performs Validation Test for {@code short} validations.
23 | */
24 | class ShortTest extends AbstractNumberTest {
25 |
26 | ShortTest() {
27 | formKey = "shortForm";
28 | action = "short";
29 | }
30 |
31 | /**
32 | * Tests the short validation failure.
33 | */
34 | @Test
35 | void testShortBeyondMax() throws ValidatorException {
36 | // Create bean to run test on.
37 | final ValueBean info = new ValueBean();
38 | info.setValue(Short.MAX_VALUE + "1");
39 |
40 | valueTest(info, false);
41 | }
42 |
43 | /**
44 | * Tests the short validation failure.
45 | */
46 | @Test
47 | void testShortBeyondMin() throws ValidatorException {
48 | // Create bean to run test on.
49 | final ValueBean info = new ValueBean();
50 | info.setValue(Short.MIN_VALUE + "1");
51 |
52 | valueTest(info, false);
53 | }
54 |
55 | /**
56 | * Tests the short validation.
57 | */
58 | @Test
59 | void testShortMax() throws ValidatorException {
60 | // Create bean to run test on.
61 | final ValueBean info = new ValueBean();
62 | info.setValue(Short.toString(Short.MAX_VALUE));
63 |
64 | valueTest(info, true);
65 | }
66 |
67 | /**
68 | * Tests the short validation.
69 | */
70 | @Test
71 | void testShortMin() throws ValidatorException {
72 | // Create bean to run test on.
73 | final ValueBean info = new ValueBean();
74 | info.setValue(Short.toString(Short.MIN_VALUE));
75 |
76 | valueTest(info, true);
77 | }
78 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/TypeBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * Value object that contains different fields to test type conversion validation.
21 | */
22 | public class TypeBean {
23 |
24 | private String sByte;
25 | private String sShort;
26 | private String sInteger;
27 | private String sLong;
28 | private String sFloat;
29 | private String sDouble;
30 | private String sDate;
31 | private String sCreditCard;
32 |
33 | public String getByte() {
34 | return sByte;
35 | }
36 |
37 | public String getCreditCard() {
38 | return sCreditCard;
39 | }
40 |
41 | public String getDate() {
42 | return sDate;
43 | }
44 |
45 | public String getDouble() {
46 | return sDouble;
47 | }
48 |
49 | public String getFloat() {
50 | return sFloat;
51 | }
52 |
53 | public String getInteger() {
54 | return sInteger;
55 | }
56 |
57 | public String getLong() {
58 | return sLong;
59 | }
60 |
61 | public String getShort() {
62 | return sShort;
63 | }
64 |
65 | public void setByte(final String sByte) {
66 | this.sByte = sByte;
67 | }
68 |
69 | public void setCreditCard(final String sCreditCard) {
70 | this.sCreditCard = sCreditCard;
71 | }
72 |
73 | public void setDate(final String sDate) {
74 | this.sDate = sDate;
75 | }
76 |
77 | public void setDouble(final String sDouble) {
78 | this.sDouble = sDouble;
79 | }
80 |
81 | public void setFloat(final String sFloat) {
82 | this.sFloat = sFloat;
83 | }
84 |
85 | public void setInteger(final String sInteger) {
86 | this.sInteger = sInteger;
87 | }
88 |
89 | public void setLong(final String sLong) {
90 | this.sLong = sLong;
91 | }
92 |
93 | public void setShort(final String sShort) {
94 | this.sShort = sShort;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ValidatorResourcesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertThrows;
20 |
21 | import java.io.InputStream;
22 |
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * Test ValidatorResources.
27 | */
28 | class ValidatorResourcesTest {
29 |
30 | /**
31 | * Test null Input Stream for Validator Resources.
32 | */
33 | @Test
34 | void testNullInputStream() {
35 | assertThrows(IllegalArgumentException.class, () -> new ValidatorResources((InputStream) null));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/ValueBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator;
18 |
19 | /**
20 | * Value object for storing a value to run tests on.
21 | */
22 | public class ValueBean {
23 |
24 | protected String value;
25 |
26 | /**
27 | * Gets the value.
28 | */
29 | public String getValue() {
30 | return value;
31 | }
32 |
33 | /**
34 | * Sets the value.
35 | */
36 | public void setValue(final String value) {
37 | this.value = value;
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/custom/CustomValidatorResources.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.custom;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | import org.apache.commons.validator.ValidatorResources;
23 | import org.xml.sax.SAXException;
24 |
25 | /**
26 | * Custom ValidatorResources implementation.
27 | */
28 | public class CustomValidatorResources extends ValidatorResources {
29 |
30 | private static final long serialVersionUID = 1272843199141974642L;
31 |
32 | /**
33 | * Create a custom ValidatorResources object from an uri
34 | *
35 | * @param in InputStream for the validation.xml configuration file.
36 | * @throws SAXException if the validation XML files are not valid or well formed.
37 | * @throws IOException if an I/O error occurs processing the XML files
38 | */
39 | public CustomValidatorResources(final InputStream in) throws IOException, SAXException {
40 | super(in);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/ISINValidatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * Tests {@link ISINValidator}.
26 | */
27 | class ISINValidatorTest {
28 |
29 | private static final ISINValidator VALIDATOR_TRUE = ISINValidator.getInstance(true);
30 |
31 | private static final ISINValidator VALIDATOR_FALSE = ISINValidator.getInstance(false);
32 |
33 | // @formatter:off
34 | private final String[] validFormat = {
35 | "US0378331005",
36 | "BMG8571G1096",
37 | "AU0000XVGZA3",
38 | "GB0002634946",
39 | "FR0004026250",
40 | "DK0009763344",
41 | "GB00B03MLX29",
42 | "US7562071065",
43 | "US56845T3059",
44 | "LU0327357389",
45 | "US032511BN64",
46 | "INE112A01023",
47 | "EZ0000000003", // Invented; for use in ISINValidator
48 | "EU000A0VUCF1",
49 | "XA2053913989",
50 | "XB0000000008",
51 | "XC0009698371",
52 | "XD0000000006",
53 | "XF0000000004",
54 | "QS0000000008",
55 | "QT0000000007",
56 | "QW0000000002",
57 | "XS0000000009",
58 | "EU0009652783",
59 | "XAC8614YAB92",
60 | "XC0001458477",
61 | "XD0209061296",
62 | "AN8068571086",
63 | };
64 |
65 | private final String[] invalidFormat = { null, "", // empty
66 | " ", // empty
67 | "US037833100O", // proper check digit is '5', see above
68 | "BMG8571G109D", // proper check digit is '6', see above
69 | "AU0000XVGZAD", // proper check digit is '3', see above
70 | "GB000263494I", // proper check digit is '6', see above
71 | "FR000402625C", // proper check digit is '0', see above
72 | "DK000976334H", // proper check digit is '4', see above
73 | "3133EHHF3", // see VALIDATOR-422 Valid check-digit, but not valid ISIN
74 | "AU0000xvgzA3", // disallow lower case NSIN
75 | "gb0002634946", // disallow lower case ISO code
76 | };
77 |
78 | // Invalid codes if country checking is enabled
79 | private final String[] invalidFormatTrue = { "AB0000000006", // Invalid country code
80 | };
81 |
82 | @Test
83 | void testInvalidFalse() {
84 | for (final String f : invalidFormat) {
85 | assertFalse(VALIDATOR_FALSE.isValid(f), f);
86 | }
87 | }
88 |
89 | @Test
90 | void testInvalidTrue() {
91 | for (final String f : invalidFormat) {
92 | assertFalse(VALIDATOR_TRUE.isValid(f), f);
93 | }
94 | for (final String f : invalidFormatTrue) {
95 | assertFalse(VALIDATOR_TRUE.isValid(f), f);
96 | }
97 | }
98 |
99 | @Test
100 | void testIsValidFalse() {
101 | for (final String f : validFormat) {
102 | assertTrue(VALIDATOR_FALSE.isValid(f), f);
103 | }
104 | }
105 |
106 | @Test
107 | void testIsValidTrue() {
108 | for (final String f : validFormat) {
109 | assertTrue(VALIDATOR_TRUE.isValid(f), f);
110 | }
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ABANumberCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ABA Number Check Digit Test.
23 | */
24 | class ABANumberCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = ABANumberCheckDigit.ABAN_CHECK_DIGIT;
32 | valid = new String[] { "123456780", "123123123", "011000015", "111000038", "231381116", "121181976" };
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/CASNumberCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * CAS Number Check Digit Tests.
23 | */
24 | class CASNumberCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | private static final String MIN = "00-01-1"; // theoretical
27 | private static final String WATER = "7732-18-5";
28 | private static final String ETHANOL = "64-17-5";
29 | private static final String ASPIRIN = "50-78-2";
30 | private static final String COFFEIN = "58-08-2";
31 | private static final String FORMALDEHYDE = "50-00-0";
32 | private static final String DEXAMETHASONE = "50-02-2";
33 | private static final String ARSENIC = "7440-38-2";
34 | private static final String ASBESTOS = "1332-21-4";
35 | private static final String MAX = "9999999-99-5"; // theoretical
36 |
37 | /**
38 | * {@inheritDoc}
39 | */
40 | @Override
41 | protected String removeCheckDigit(final String code) {
42 | final String cde = (String) CASNumberCheckDigit.REGEX_VALIDATOR.validate(code);
43 | if (cde == null || cde.length() <= checkDigitLth) {
44 | return null;
45 | }
46 | return cde.substring(0, cde.length() - checkDigitLth);
47 | }
48 |
49 | /**
50 | * Sets up routine & valid codes.
51 | */
52 | @BeforeEach
53 | protected void setUp() {
54 | routine = CASNumberCheckDigit.getInstance();
55 | valid = new String[] {MIN, WATER, ETHANOL, ASPIRIN, COFFEIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/CUSIPCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.BeforeEach;
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * CUSIP Check Digit Test.
27 | */
28 | class CUSIPCheckDigitTest extends AbstractCheckDigitTest {
29 |
30 | private static final String[] INVALID_CHECK_DIGITS = { "DUS0421CW", "DUS0421CN", "DUS0421CE" };
31 |
32 | private static final String[] VALID_CHECK_DIGITS = { "DUS0421C5" };
33 |
34 | /**
35 | * Sets up routine & valid codes.
36 | */
37 | @BeforeEach
38 | protected void setUp() {
39 | routine = CUSIPCheckDigit.CUSIP_CHECK_DIGIT;
40 | valid = new String[] { "037833100", "931142103", "837649128", "392690QT3", "594918104", "86770G101", "Y8295N109", "G8572F100" };
41 | invalid = new String[] { "0378#3100" };
42 | }
43 |
44 | @Test
45 | void testValidator336InvalidCheckDigits() {
46 | for (final String invalidCheckDigit : INVALID_CHECK_DIGITS) {
47 | assertFalse(routine.isValid(invalidCheckDigit), "Should fail: " + invalidCheckDigit);
48 | }
49 | }
50 |
51 | @Test
52 | void testValidator336ValidCheckDigits() {
53 | for (final String validCheckDigit : VALID_CHECK_DIGITS) {
54 | assertTrue(routine.isValid(validCheckDigit), "Should fail: " + validCheckDigit);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/EAN13CheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * EAN-13 Check Digit Test.
23 | */
24 | class EAN13CheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = EAN13CheckDigit.EAN13_CHECK_DIGIT;
32 | valid = new String[] { "9780072129519", "9780764558313", "4025515373438", "0095673400332" };
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ECNumberCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * EC Number Check Digit Tests.
23 | */
24 | class ECNumberCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | private static final String MIN = "000-001-6"; // theoretical
27 | private static final String FORMALDEHYDE = "200-001-8"; // this is the first entry in EINECS
28 | private static final String DEXAMETHASONE = "200-003-9";
29 | private static final String ARSENIC = "231-148-6";
30 | private static final String ASBESTOS = "603-721-4";
31 | private static final String MAX = "999-999-2"; // theoretical
32 |
33 | /**
34 | * {@inheritDoc}
35 | */
36 | @Override
37 | protected String removeCheckDigit(final String code) {
38 | final String cde = (String) ECNumberCheckDigit.REGEX_VALIDATOR.validate(code);
39 | if (cde == null || cde.length() <= checkDigitLth) {
40 | return null;
41 | }
42 | return cde.substring(0, cde.length() - checkDigitLth);
43 | }
44 |
45 | /**
46 | * Sets up routine & valid codes.
47 | */
48 | @BeforeEach
49 | protected void setUp() {
50 | routine = ECNumberCheckDigit.getInstance();
51 | valid = new String[] {MIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBN10CheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ISBN-10 Check Digit Test.
23 | */
24 | class ISBN10CheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = ISBN10CheckDigit.ISBN10_CHECK_DIGIT;
32 | valid = new String[] { "1930110995", "020163385X", "1932394354", "1590596277" };
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ISBNCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertEquals;
20 | import static org.junit.jupiter.api.Assertions.assertFalse;
21 | import static org.junit.jupiter.api.Assertions.assertThrows;
22 |
23 | import org.junit.jupiter.api.BeforeEach;
24 | import org.junit.jupiter.api.Test;
25 |
26 | /**
27 | * ISBN-10/ISBN-13 Check Digit Test.
28 | */
29 | class ISBNCheckDigitTest extends AbstractCheckDigitTest {
30 |
31 | /**
32 | * Sets up routine & valid codes.
33 | */
34 | @BeforeEach
35 | protected void setUp() {
36 | routine = ISBNCheckDigit.ISBN_CHECK_DIGIT;
37 | valid = new String[] { "9780072129519", "9780764558313", "1930110995", "020163385X", "1590596277", // ISBN-10 Ubuntu Book
38 | "9781590596272" // ISBN-13 Ubuntu Book
39 | };
40 | missingMessage = "ISBN Code is missing";
41 | zeroSum = "000000000000";
42 | }
43 |
44 | /**
45 | * Sets up routine & valid codes.
46 | */
47 | @Test
48 | void testInvalidLength() {
49 | assertFalse(routine.isValid("123456789"), "isValid() Lth 9 ");
50 | assertFalse(routine.isValid("12345678901"), "isValid() Lth 11");
51 | assertFalse(routine.isValid("123456789012"), "isValid() Lth 12");
52 | assertFalse(routine.isValid("12345678901234"), "isValid() Lth 14");
53 |
54 | Exception e = assertThrows(CheckDigitException.class, () -> routine.calculate("12345678"), "calculate() Lth 8");
55 | assertEquals("Invalid ISBN Length = 8", e.getMessage(), "calculate() Lth 8");
56 |
57 | e = assertThrows(CheckDigitException.class, () -> routine.calculate("1234567890"), "calculate() Lth 10");
58 | assertEquals("Invalid ISBN Length = 10", e.getMessage(), "calculate() Lth 10");
59 |
60 | e = assertThrows(CheckDigitException.class, () -> routine.calculate("12345678901"), "calculate() Lth 11");
61 | assertEquals("Invalid ISBN Length = 11", e.getMessage(), "calculate() Lth 11");
62 |
63 | e = assertThrows(CheckDigitException.class, () -> routine.calculate("1234567890123"), "calculate() Lth 13");
64 | assertEquals("Invalid ISBN Length = 13", e.getMessage(), "calculate() Lth 13");
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ISINCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 |
21 | import org.junit.jupiter.api.BeforeEach;
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * ISIN Check Digit Test.
26 | */
27 | class ISINCheckDigitTest extends AbstractCheckDigitTest {
28 |
29 | private static final String[] INVALID_CHECK_DIGITS = { "US037833100O", // proper check digit is '5', see above
30 | "BMG8571G109D", // proper check digit is '6', see above
31 | "AU0000XVGZAD", // proper check digit is '3', see above
32 | "GB000263494I", // proper check digit is '6', see above
33 | "FR000402625C", // proper check digit is '0', see above
34 | "DK000976334H", // proper check digit is '4', see above
35 | };
36 |
37 | /**
38 | * Sets up routine & valid codes.
39 | */
40 | @BeforeEach
41 | protected void setUp() {
42 | routine = ISINCheckDigit.ISIN_CHECK_DIGIT;
43 | valid = new String[] { "US0378331005", "BMG8571G1096", "AU0000XVGZA3", "GB0002634946", "FR0004026250", "3133EHHF3", // see VALIDATOR-422 Valid
44 | // check-digit, but not valid ISIN
45 | "DK0009763344", "dk0009763344", // TODO lowercase is currently accepted, but is this valid?
46 | "AU0000xvgza3", // lowercase NSIN
47 | "EZ0000000003", // Invented; for use in ISINValidatorTest
48 | "XS0000000009", // ditto
49 | "AA0000000006", // ditto
50 | };
51 | invalid = new String[] { "0378#3100" };
52 | }
53 |
54 | @Test
55 | void testValidator345() {
56 | for (final String invalidCheckDigit : INVALID_CHECK_DIGITS) {
57 | assertFalse(routine.isValid(invalidCheckDigit), "Should fail: " + invalidCheckDigit);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ISSNCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ISSN Check Digit Test.
23 | */
24 | class ISSNCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = ISSNCheckDigit.ISSN_CHECK_DIGIT;
32 | valid = new String[] { "03178471", "1050124X", "15626865", "10637710", "17487188", "02642875", "17500095", "11881534", "19111479", "19111460",
33 | "00016772", "1365201X", };
34 | invalid = new String[] { "03178472", // wrong check
35 | "1050-124X", // format char
36 | " 1365201X", "1365201X ", " 1365201X ", };
37 | missingMessage = "Code is missing";
38 | zeroSum = "00000000";
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/LuhnCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * Luhn Check Digit Test.
23 | */
24 | class LuhnCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | private static final String VALID_VISA = "4417123456789113";
27 | private static final String VALID_SHORT_VISA = "4222222222222";
28 | private static final String VALID_AMEX = "378282246310005";
29 | private static final String VALID_MASTERCARD = "5105105105105100";
30 | private static final String VALID_DISCOVER = "6011000990139424";
31 | private static final String VALID_DINERS = "30569309025904";
32 |
33 | /**
34 | * Sets up routine & valid codes.
35 | */
36 | @BeforeEach
37 | protected void setUp() {
38 |
39 | routine = LuhnCheckDigit.LUHN_CHECK_DIGIT;
40 |
41 | valid = new String[] { VALID_VISA, VALID_SHORT_VISA, VALID_AMEX, VALID_MASTERCARD, VALID_DISCOVER, VALID_DINERS };
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenABACheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ModulusTenCheckDigit ABA Number Check Digit Test.
23 | */
24 | class ModulusTenABACheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = new ModulusTenCheckDigit(new int[] { 1, 7, 3 }, true);
32 | valid = new String[] { "123456780", "123123123", "011000015", "111000038", "231381116", "121181976" };
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenCUSIPCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | import org.junit.jupiter.api.BeforeEach;
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * ModulusTenCheckDigit CUSIP Test.
27 | */
28 | class ModulusTenCUSIPCheckDigitTest extends AbstractCheckDigitTest {
29 |
30 | private static final String[] INVALID_CHECK_DIGITS = { "DUS0421CW", "DUS0421CN", "DUS0421CE" };
31 |
32 | private static final String[] VALID_CHECK_DIGITS = { "DUS0421C5" };
33 |
34 | /**
35 | * Sets up routine & valid codes.
36 | */
37 | @BeforeEach
38 | protected void setUp() {
39 | routine = new ModulusTenCheckDigit(new int[] { 1, 2 }, true, true);
40 | valid = new String[] { "037833100", "931142103", "837649128", "392690QT3", "594918104", "86770G101", "Y8295N109", "G8572F100" };
41 | invalid = new String[] { "0378#3100" };
42 | }
43 |
44 | @Test
45 | void testValidator336InvalidCheckDigits() {
46 | for (final String invalidCheckDigit : INVALID_CHECK_DIGITS) {
47 | assertFalse(routine.isValid(invalidCheckDigit), "Should fail: " + invalidCheckDigit);
48 | }
49 | }
50 |
51 | @Test
52 | void testValidator336ValidCheckDigits() {
53 | for (final String validCheckDigit : VALID_CHECK_DIGITS) {
54 | assertTrue(routine.isValid(validCheckDigit), "Should fail: " + validCheckDigit);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenEAN13CheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ModulusTenCheckDigit EAN-13 Test.
23 | */
24 | class ModulusTenEAN13CheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | /**
27 | * Sets up routine & valid codes.
28 | */
29 | @BeforeEach
30 | protected void setUp() {
31 | routine = new ModulusTenCheckDigit(new int[] { 1, 3 }, true);
32 | valid = new String[] { "9780072129519", "9780764558313", "4025515373438", "0095673400332" };
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenLuhnCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 |
21 | /**
22 | * ModulusTenCheckDigit Luhn Test.
23 | */
24 | class ModulusTenLuhnCheckDigitTest extends AbstractCheckDigitTest {
25 |
26 | private static final String VALID_VISA = "4417123456789113";
27 | private static final String VALID_SHORT_VISA = "4222222222222";
28 | private static final String VALID_AMEX = "378282246310005";
29 | private static final String VALID_MASTERCARD = "5105105105105100";
30 | private static final String VALID_DISCOVER = "6011000990139424";
31 | private static final String VALID_DINERS = "30569309025904";
32 |
33 | /**
34 | * Sets up routine & valid codes.
35 | */
36 | @BeforeEach
37 | protected void setUp() {
38 | routine = new ModulusTenCheckDigit(new int[] { 1, 2 }, true, true);
39 |
40 | valid = new String[] { VALID_VISA, VALID_SHORT_VISA, VALID_AMEX, VALID_MASTERCARD, VALID_DISCOVER, VALID_DINERS };
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/ModulusTenSedolCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 |
21 | import org.junit.jupiter.api.BeforeEach;
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * ModulusTenCheckDigit SEDOL Test.
26 | */
27 | class ModulusTenSedolCheckDigitTest extends AbstractCheckDigitTest {
28 |
29 | private static final String[] INVALID_CHECK_DIGITS = { "026349E", // proper check digit is '4', see above
30 | "087061C", // proper check digit is '2', see above
31 | "B06LQ9H", // proper check digit is '7', see above
32 | "343757F", // proper check digit is '5', see above
33 | "B07LF5F", // proper check digit is '5', see above
34 | };
35 |
36 | /**
37 | * Sets up routine & valid codes.
38 | */
39 | @BeforeEach
40 | protected void setUp() {
41 | routine = new ModulusTenCheckDigit(new int[] { 1, 3, 1, 7, 3, 9, 1 });
42 | valid = new String[] { "0263494", "0870612", "B06LQ97", "3437575", "B07LF55", };
43 | invalid = new String[] { "123#567" };
44 | zeroSum = "0000000";
45 | }
46 |
47 | @Test
48 | void testValidator346() {
49 | for (final String invalidCheckDigit : INVALID_CHECK_DIGITS) {
50 | assertFalse(routine.isValid(invalidCheckDigit), "Should fail: " + invalidCheckDigit);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/SedolCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
20 |
21 | import org.junit.jupiter.api.BeforeEach;
22 | import org.junit.jupiter.api.Test;
23 |
24 | /**
25 | * ISIN Check Digit Test.
26 | */
27 | class SedolCheckDigitTest extends AbstractCheckDigitTest {
28 |
29 | private static final String[] INVALID_CHECK_DIGITS = { "026349E", // proper check digit is '4', see above
30 | "087061C", // proper check digit is '2', see above
31 | "B06LQ9H", // proper check digit is '7', see above
32 | "343757F", // proper check digit is '5', see above
33 | "B07LF5F", // proper check digit is '5', see above
34 | };
35 |
36 | /**
37 | * Sets up routine & valid codes.
38 | */
39 | @BeforeEach
40 | protected void setUp() {
41 | routine = SedolCheckDigit.SEDOL_CHECK_DIGIT;
42 | valid = new String[] { "0263494", "0870612", "B06LQ97", "3437575", "B07LF55", };
43 | invalid = new String[] { "123#567" };
44 | zeroSum = "0000000";
45 | }
46 |
47 | @Test
48 | void testValidator346() {
49 | for (final String invalidCheckDigit : INVALID_CHECK_DIGITS) {
50 | assertFalse(routine.isValid(invalidCheckDigit), "Should fail: " + invalidCheckDigit);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/routines/checkdigit/VerhoeffCheckDigitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.routines.checkdigit;
18 |
19 | import org.junit.jupiter.api.BeforeEach;
20 | import org.junit.jupiter.api.Test;
21 |
22 | /**
23 | * Verhoeff Check Digit Test.
24 | */
25 | class VerhoeffCheckDigitTest extends AbstractCheckDigitTest {
26 |
27 | /**
28 | * Sets up routine & valid codes.
29 | */
30 | @BeforeEach
31 | protected void setUp() {
32 | routine = VerhoeffCheckDigit.VERHOEFF_CHECK_DIGIT;
33 | valid = new String[] { "15", "1428570", "12345678902" };
34 | }
35 |
36 | /**
37 | * Test zero sum
38 | */
39 | @Override
40 | @Test
41 | void testZeroSum() {
42 | // ignore, don't run this test
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/util/FlagsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.validator.util;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertEquals;
20 | import static org.junit.jupiter.api.Assertions.assertFalse;
21 | import static org.junit.jupiter.api.Assertions.assertTrue;
22 |
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * Test the Flags class.
27 | */
28 | class FlagsTest {
29 |
30 | /**
31 | * Declare some flags for testing.
32 | */
33 | private static final long LONG_FLAG = 1;
34 | private static final long LONG_FLAG_2 = 2;
35 | private static final int INT_FLAG = 4;
36 |
37 | @Test
38 | void testClear() {
39 | final Flags f = new Flags(98432);
40 | f.clear();
41 | assertEquals(0, f.getFlags());
42 | }
43 |
44 | /**
45 | * Test for Object clone()
46 | */
47 | @Test
48 | void testClone() {
49 | }
50 |
51 | /**
52 | * Test for boolean equals(Object)
53 | */
54 | @Test
55 | void testEqualsObject() {
56 | }
57 |
58 | @Test
59 | void testGetFlags() {
60 | final Flags f = new Flags(45);
61 | assertEquals(f.getFlags(), 45);
62 | }
63 |
64 | @Test
65 | void testHashCode() {
66 | final Flags f = new Flags(45);
67 | assertEquals(f.hashCode(), 45);
68 | }
69 |
70 | @Test
71 | void testIsOnIsFalseWhenNotAllFlagsInArgumentAreOn() {
72 | final Flags first = new Flags(1);
73 | final long firstAndSecond = 3;
74 |
75 | assertFalse(first.isOn(firstAndSecond));
76 | }
77 |
78 | @Test
79 | void testIsOnIsTrueWhenHighOrderBitIsSetAndQueried() {
80 | final Flags allOn = new Flags(~0);
81 | final long highOrderBit = 0x8000000000000000L;
82 |
83 | assertTrue(allOn.isOn(highOrderBit));
84 | }
85 |
86 | @Test
87 | void testIsOnOff() {
88 | final Flags f = new Flags();
89 | f.turnOn(LONG_FLAG);
90 | f.turnOn(INT_FLAG);
91 | assertTrue(f.isOn(LONG_FLAG));
92 | assertFalse(f.isOff(LONG_FLAG));
93 |
94 | assertTrue(f.isOn(INT_FLAG));
95 | assertFalse(f.isOff(INT_FLAG));
96 |
97 | assertTrue(f.isOff(LONG_FLAG_2));
98 | }
99 |
100 | /**
101 | * Test for String toString()
102 | */
103 | @Test
104 | void testToString() {
105 | final Flags f = new Flags();
106 | String s = f.toString();
107 | assertEquals(64, s.length());
108 |
109 | f.turnOn(INT_FLAG);
110 | s = f.toString();
111 | assertEquals(64, s.length());
112 |
113 | assertEquals("0000000000000000000000000000000000000000000000000000000000000100", s);
114 | }
115 |
116 | @Test
117 | void testTurnOff() {
118 | }
119 |
120 | @Test
121 | void testTurnOffAll() {
122 | final Flags f = new Flags(98432);
123 | f.turnOffAll();
124 | assertEquals(0, f.getFlags());
125 | }
126 |
127 | @Test
128 | void testTurnOnAll() {
129 | final Flags f = new Flags();
130 | f.turnOnAll();
131 | assertEquals(~0, f.getFlags());
132 | }
133 |
134 | @Test
135 | void testTurnOnOff() {
136 | }
137 |
138 | }
139 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/util/TestTimeZones.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.commons.validator.util;
19 |
20 | import java.util.TimeZone;
21 |
22 | /**
23 | * TimeZone test fixtures.
24 | */
25 | public class TestTimeZones {
26 |
27 | public static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours
28 | public static final TimeZone EET = TimeZone.getTimeZone("EET"); // + 2 hours
29 | public static final TimeZone UTC = TimeZone.getTimeZone("UTC"); // 0 offset
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/commons/validator/util/ValidatorUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * https://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.commons.validator.util;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertEquals;
21 |
22 | import org.apache.commons.collections.FastHashMap;
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * Tests {@link ValidatorUtilsTest}.
27 | */
28 | class ValidatorUtilsTest {
29 |
30 | @Test
31 | void testCopyFastHashMap() {
32 | final FastHashMap original = new FastHashMap();
33 | original.put("key1", "value1");
34 | original.put("key2", "value2");
35 | original.put("key3", "value3");
36 | original.setFast(true);
37 | final FastHashMap copy = ValidatorUtils.copyFastHashMap(original);
38 | assertEquals(original, copy);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/DateTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
24 |
29 |
34 |
35 |
36 |
37 |
38 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/EmailTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/EntityImportTest-byteform.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/EntityImportTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 | ]>
21 |
22 |
23 |
24 |
29 |
30 |
31 | &byteform;
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/ExceptionTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
33 |
34 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/ExtensionTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
37 |
38 |
47 |
48 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/LocaleTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
38 |
39 |
40 |
51 |
52 |
53 |
61 |
62 |
63 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-1-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
25 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
41 |
42 |
43 | testConstName1
44 | testConstValue1
45 |
46 |
47 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | testConstName1_fr
66 | testConstValue1_fr
67 |
68 |
69 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/MultipleConfigFilesTest-2-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
24 |
25 |
26 |
27 |
28 | testConstName2
29 | testConstValue2
30 |
31 |
32 |
40 |
41 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | testConstName2_fr
60 | testConstValue2_fr
61 |
62 |
63 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/MultipleTests-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
40 |
41 |
42 |
43 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/ParameterTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
33 |
34 |
35 |
36 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/RequiredIfTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/RequiredNameTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/TestNumber-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
35 |
40 |
41 |
46 |
47 |
52 |
53 |
58 |
59 |
60 |
61 |
64 |
67 |
70 |
73 |
76 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/ValidatorResultsTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
40 |
41 |
42 |
43 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/VarTest-config.xml:
--------------------------------------------------------------------------------
1 |
17 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/test/resources/org/apache/commons/validator/routines/iban_registry_v99.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/commons-validator/30327416cb186ebd2cc08f3c7021f19cefa82e2e/src/test/resources/org/apache/commons/validator/routines/iban_registry_v99.txt
--------------------------------------------------------------------------------