Author: hardy.ferentschik
Date: 2009-06-17 08:29:31 -0400 (Wed, 17 Jun 2009)
New Revision: 16818
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/InvertedNotNullValidator.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml
Log:
Added missing builtin constraint tests.
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java 2009-06-17
12:29:31 UTC (rev 16818)
@@ -0,0 +1,74 @@
+// $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.constraints.builtinconstraints;
+
+import java.io.InputStream;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+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.Resource;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import static org.hibernate.jsr303.tck.util.TestUtil.getInputStreamForPath;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Resource(source = "builtin-constraints-override.xml",
+ destination =
"WEB-INF/classes/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml")
+public class BuiltinValidatorOverrideTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "6", id = "b")
+ public void testXmlConfiguredValidatorConfigurationHasPrecedence() {
+ Configuration<?> config = Validation.byDefaultProvider().configure();
+ InputStream in = getInputStreamForPath(
+ "org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml"
+ );
+ config.addMapping( in );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ DummyEntity dummy = new DummyEntity();
+ Set<ConstraintViolation<DummyEntity>> violation = validator.validate( dummy
);
+ assertTrue(
+ violation.isEmpty(),
+ "There should be no violation even though dummyProperty is null, because the
default validator got overriden in xml."
+ );
+
+ dummy.dummyProperty = "foobar";
+ violation = validator.validate( dummy );
+ assertTrue(
+ violation.size() == 1,
+ "There should be one violation due to the InvertedNotNullValidator."
+ );
+ }
+
+ class DummyEntity {
+ @NotNull
+ String dummyProperty;
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinValidatorOverrideTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/InvertedNotNullValidator.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/InvertedNotNullValidator.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/InvertedNotNullValidator.java 2009-06-17
12:29:31 UTC (rev 16818)
@@ -0,0 +1,34 @@
+// $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.constraints.builtinconstraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class InvertedNotNullValidator implements ConstraintValidator<NotNull,
Object> {
+ public void initialize(NotNull constraintAnnotation) {
+ }
+
+ public boolean isValid(Object value, ConstraintValidatorContext
constraintValidatorContext) {
+ return value == null;
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/InvertedNotNullValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml 2009-06-17
12:29:31 UTC (rev 16818)
@@ -0,0 +1,9 @@
+<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">
+ <constraint-definition
annotation="javax.validation.constraints.NotNull">
+ <validated-by include-existing-validators="false">
+
<value>org.hibernate.jsr303.tck.tests.constraints.builtinconstraints.InvertedNotNullValidator</value>
+ </validated-by>
+ </constraint-definition>
+</constraint-mappings>
Property changes on:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native