Author: hardy.ferentschik
Date: 2009-08-20 06:39:03 -0400 (Thu, 20 Aug 2009)
New Revision: 17374
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConfigurationDefinedTraversableResolver.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TraversableResolverSpecifiedInValidationXmlTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlDefinedTraversableResolver.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-TraversableResolverSpecifiedInValidationXmlTest.xml
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-EmptyXmlConfigurationTest.xml
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
Log:
xml config tests
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConfigurationDefinedTraversableResolver.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConfigurationDefinedTraversableResolver.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConfigurationDefinedTraversableResolver.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -0,0 +1,38 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConfigurationDefinedTraversableResolver implements TraversableResolver {
+ public static int numberOfIsReachableCalls = 0;
+
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ numberOfIsReachableCalls++;
+ return true;
+ }
+
+ public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return true;
+ }
+}
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java 2009-08-19
21:10:09 UTC (rev 17373)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/EmptyXmlConfigurationTest.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -1,51 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.
-*/
-package org.hibernate.jsr303.tck.tests.xmlconfiguration;
-
-
-import javax.validation.Validator;
-
-import org.jboss.testharness.AbstractTest;
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.testharness.impl.packaging.ArtifactType;
-import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.testharness.impl.packaging.Resource;
-import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
-import static org.testng.Assert.assertFalse;
-import org.testng.annotations.Test;
-
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
-@ValidationXml(value = "validation-EmptyXmlConfigurationTest.xml")
-@Resource(source = "order-constraints-no-additional-config.xml",
- destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml")
-public class EmptyXmlConfigurationTest extends AbstractTest {
-
- @Test
- public void testNoDefinedConstraints() {
- Validator validator = TestUtil.getValidatorUnderTest();
- assertFalse(
- validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean
should be unconstrained"
- );
- }
-}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java 2009-08-19
21:10:09 UTC (rev 17373)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/Order.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -29,4 +29,19 @@
private List<OrderLine> orderLines;
+ public Date getOrderDate() {
+ return orderDate;
+ }
+
+ public void setOrderDate(Date orderDate) {
+ this.orderDate = orderDate;
+ }
+
+ public List<OrderLine> getOrderLines() {
+ return orderLines;
+ }
+
+ public void setOrderLines(List<OrderLine> orderLines) {
+ this.orderLines = orderLines;
+ }
}
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TraversableResolverSpecifiedInValidationXmlTest.java
(from rev 17361,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/MessageInterpolatorSpecifiedInValidationXmlTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TraversableResolverSpecifiedInValidationXmlTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/TraversableResolverSpecifiedInValidationXmlTest.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -0,0 +1,93 @@
+// $Id: InvalidXmlConfigurationTest.java 17352 2009-08-18 17:08:59Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class,
+ TestUtil.PathImpl.class,
+ TestUtil.NodeImpl.class,
+ TCKValidationProvider.class,
+ TCKValidatorConfiguration.class,
+ TCKValidationProvider.DummyValidatorFactory.class
+})
+@ValidationXml(value =
"validation-TraversableResolverSpecifiedInValidationXmlTest.xml")
+public class TraversableResolverSpecifiedInValidationXmlTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "4.4.6", id = "h")
+ public void testTraversableResolverSpecifiedInValidationXml() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+
+ User user = new User();
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertTrue(
+ XmlDefinedTraversableResolver.numberOfIsReachableCalls > 0,
+ "The resolver should have been called at least once if it was properly picked up
by xml configuration."
+ );
+
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4.6", id = "e"),
+ @SpecAssertion(section = "4.4.6", id = "h")
+ })
+ public void testMessageInterpolatorSpecifiedInValidationXmlCanBeOverridden() {
+ Configuration<?> configuration = Validation
+ .byDefaultProvider()
+ .configure();
+
+ configuration = configuration.traversableResolver( new
ConfigurationDefinedTraversableResolver() );
+ Validator validator = configuration.buildValidatorFactory().getValidator();
+
+ User user = new User();
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertTrue(
+ ConfigurationDefinedTraversableResolver.numberOfIsReachableCalls > 0,
+ "The resolver should have been called at least once if configuration settings
were applied."
+ );
+ }
+}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java 2009-08-19
21:10:09 UTC (rev 17373)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlConfigurationTest.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -17,6 +17,7 @@
*/
package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+import java.io.InputStream;
import java.util.Set;
import javax.validation.Configuration;
import javax.validation.ConstraintViolation;
@@ -35,6 +36,7 @@
import org.jboss.testharness.impl.packaging.Resources;
import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
@@ -53,9 +55,12 @@
@Resource(source = "user-constraints.xml",
destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml"),
@Resource(source = "order-constraints.xml",
- destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml")
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints.xml"),
+ @Resource(source = "order-constraints.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml")
}
)
+
public class XmlConfigurationTest extends AbstractTest {
@Test
@@ -227,4 +232,35 @@
descriptor = constraintDescriptors.iterator().next();
assertTrue( descriptor.getAnnotation() instanceof Pattern );
}
+
+
+ @Test
+ @SpecAssertion(section = "4.4.6", id = "m")
+ public void testMappingFilesAddedViaConfigurationGetAddedToXMlConfiguredMappings() {
+ Validator validator = TestUtil.getValidatorUnderTest();
+
+ assertFalse(
+ validator.getConstraintsForClass( Order.class ).isBeanConstrained(),
+ "Without additional mapping Order should be unconstrained"
+ );
+
+
+ Configuration<?> config = TestUtil.getConfigurationUnderTest();
+ config.addMapping(
+ getStream(
+ "/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml"
+ )
+ );
+ validator = config.buildValidatorFactory().getValidator();
+
+ assertTrue(
+ validator.getConstraintsForClass( Order.class ).isBeanConstrained(),
+ "With additional mapping Order should be constrained"
+ );
+ }
+
+ private InputStream getStream(String fileName) {
+ InputStream in = this.getClass().getResourceAsStream( fileName );
+ return in;
+ }
}
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlDefinedTraversableResolver.java
(from rev 17359,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlDefinedMessageInterpolator.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlDefinedTraversableResolver.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/XmlDefinedTraversableResolver.java 2009-08-20
10:39:03 UTC (rev 17374)
@@ -0,0 +1,38 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.
+*/
+package org.hibernate.jsr303.tck.tests.xmlconfiguration;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlDefinedTraversableResolver implements TraversableResolver {
+ public static int numberOfIsReachableCalls = 0;
+
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ numberOfIsReachableCalls++;
+ return true;
+ }
+
+ public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return true;
+ }
+}
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml
(from rev 17359,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/user-constraints.xml)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-XmlConfigurationTest.xml 2009-08-20
10:39:03 UTC (rev 17374)
@@ -0,0 +1,11 @@
+<constraint-mappings
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
+
<default-package>org.hibernate.jsr303.tck.tests.xmlconfiguration</default-package>
+ <bean class="Order" ignore-annotations="false">
+ <field name="orderDate">
+ <constraint
annotation="javax.validation.constraints.NotNull">
+ </constraint>
+ </field>
+ </bean>
+</constraint-mappings>
Deleted:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml 2009-08-19
21:10:09 UTC (rev 17373)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml 2009-08-20
10:39:03 UTC (rev 17374)
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<constraint-mappings
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd"
-
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
-
-
<default-package>org.hibernate.jsr303.tck.tests.xmlconfiguration</default-package>
-
- <bean class="Order" ignore-annotations="false">
- </bean>
-
-</constraint-mappings>
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-EmptyXmlConfigurationTest.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-EmptyXmlConfigurationTest.xml 2009-08-19
21:10:09 UTC (rev 17373)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-EmptyXmlConfigurationTest.xml 2009-08-20
10:39:03 UTC (rev 17374)
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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/configu...
validation-configuration-1.0.xsd">
-
-
<constraint-mapping>org/hibernate/jsr303/tck/tests/xmlconfiguration/order-constraints-no-additional-config.xml</constraint-mapping>
-</validation-config>
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-TraversableResolverSpecifiedInValidationXmlTest.xml
(from rev 17356,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-MessageInterpolatorSpecifiedInValidationXmlTest.xml)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-TraversableResolverSpecifiedInValidationXmlTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/xmlconfiguration/validation-TraversableResolverSpecifiedInValidationXmlTest.xml 2009-08-20
10:39:03 UTC (rev 17374)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/configu...
validation-configuration-1.0.xsd">
+
<traversable-resolver>org.hibernate.jsr303.tck.tests.xmlconfiguration.XmlDefinedTraversableResolver</traversable-resolver>
+</validation-config>
\ No newline at end of file