Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HV-595: Adding some tests for illegal validation.xml files

  • Loading branch information...
commit 2f6cfe959659056aa9b2dfcc7d695d90674d58a6 1 parent 0d7df01
@gunnarmorling authored
View
37 engine/src/test/java/org/hibernate/validator/test/internal/xml/XmlMappingTest.java
@@ -24,6 +24,7 @@
import javax.validation.Configuration;
import javax.validation.ConfigurationSource;
import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.groups.Default;
@@ -192,7 +193,7 @@ public void run() {
public void testLoadingOfBv10ValidationXml() {
runWithCustomValidationXml(
- "hv-1.0-validation.xml", new Runnable() {
+ "bv-1.0-validation.xml", new Runnable() {
@Override
public void run() {
@@ -210,6 +211,40 @@ public void run() {
);
}
+ @Test(
+ expectedExceptions = ValidationException.class,
+ expectedExceptionsMessageRegExp = "HV000122: Unsupported schema version for file META-INF/validation.xml: 2\\.0\\."
+ )
+ public void shouldFailToLoadValidationXmlWithUnsupportedVersion() {
+
+ runWithCustomValidationXml(
+ "unsupported-validation.xml", new Runnable() {
+
+ @Override
+ public void run() {
+ ValidatorUtil.getConfiguration().getConfigurationSource();
+ }
+ }
+ );
+ }
+
+ @Test(
+ expectedExceptions = ValidationException.class,
+ expectedExceptionsMessageRegExp = "HV000100: Unable to parse META-INF/validation.xml."
+ )
+ public void shouldFailToLoad10ValidationXmlWithParameterNameProvider() {
+
+ runWithCustomValidationXml(
+ "invalid-bv-1.0-validation.xml", new Runnable() {
+
+ @Override
+ public void run() {
+ ValidatorUtil.getConfiguration().getConfigurationSource();
+ }
+ }
+ );
+ }
+
/**
* Executes the given runnable, using the specified file as replacement for
* {@code META-INF/validation.xml}.
View
0  ...validator/test/internal/xml/hv-1.0-validation.xml → ...validator/test/internal/xml/bv-1.0-validation.xml
File renamed without changes
View
24 engine/src/test/resources/org/hibernate/validator/test/internal/xml/invalid-bv-1.0-validation.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss, Home of Professional Open Source
+ ~ Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors
+ ~ by the @authors tag. See the copyright.txt in the distribution for a
+ ~ full listing of individual contributors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<validation-config
+ xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd">
+
+ <parameter-name-provider>org.hibernate.validator.test.internal.xml.CustomParameterNameProvider</parameter-name-provider>
+</validation-config>
View
24 engine/src/test/resources/org/hibernate/validator/test/internal/xml/unsupported-validation.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss, Home of Professional Open Source
+ ~ Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual contributors
+ ~ by the @authors tag. See the copyright.txt in the distribution for a
+ ~ full listing of individual contributors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<validation-config
+ xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-2.0.xsd"
+ version="2.0">
+
+</validation-config>
Please sign in to comment.
Something went wrong with that request. Please try again.