Author: hardy.ferentschik
Date: 2009-06-08 05:41:28 -0400 (Mon, 08 Jun 2009)
New Revision: 16716
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Started adding tests for built-in constraints
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-08
09:41:28 UTC (rev 16716)
@@ -0,0 +1,368 @@
+// $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.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.AssertFalse;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+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.AbstractTest;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+
+/**
+ * Tests for built-in constraints.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class BuiltinConstraintsTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "c")
+ })
+ public void testNullConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ NullDummyEntity dummy = new NullDummyEntity();
+ Object foo = new Object();
+ dummy.setProperty( foo );
+ Set<ConstraintViolation<NullDummyEntity>> constraintViolations =
validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), NullDummyEntity.class, foo,
"property"
+ );
+
+ dummy.setProperty( null );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "d")
+ })
+ public void testNotNullConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ NotNullDummyEntity dummy = new NotNullDummyEntity();
+ Set<ConstraintViolation<NotNullDummyEntity>> constraintViolations =
validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), NotNullDummyEntity.class, null,
"property"
+ );
+
+ dummy.setProperty( new Object() );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "e")
+ })
+ public void testAssertTrueConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ AssertTrueDummyEntity dummy = new AssertTrueDummyEntity();
+
+ Set<ConstraintViolation<AssertTrueDummyEntity>> constraintViolations =
validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertTrueDummyEntity.class, false,
"primitiveBoolean"
+ );
+
+ dummy.setPrimitiveBoolean( true );
+ dummy.setObjectBoolean( Boolean.FALSE );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertTrueDummyEntity.class, Boolean.FALSE,
"objectBoolean"
+ );
+
+ dummy.setObjectBoolean( Boolean.TRUE );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "f")
+ })
+ public void testAssertFalseConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ AssertFalseDummyEntity dummy = new AssertFalseDummyEntity();
+ dummy.setPrimitiveBoolean( true );
+
+ Set<ConstraintViolation<AssertFalseDummyEntity>> constraintViolations =
validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertFalseDummyEntity.class, true,
"primitiveBoolean"
+ );
+
+ dummy.setPrimitiveBoolean( false );
+ dummy.setObjectBoolean( Boolean.TRUE );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertFalseDummyEntity.class, Boolean.TRUE,
"objectBoolean"
+ );
+
+ dummy.setObjectBoolean( Boolean.FALSE );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "g")
+ })
+ public void testMinConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ MinDummyEntity dummy = new MinDummyEntity();
+
+ Set<ConstraintViolation<MinDummyEntity>> constraintViolations =
validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(constraintViolations, new String[]
{"bytePrimitive", "intPrimitive", "longPrimitive",
"shortPrimitive"});
+
+
+// dummy.setPrimitiveBoolean( false );
+// dummy.setObjectBoolean( Boolean.TRUE );
+//
+// constraintViolations = validator.validate( dummy );
+// assertCorrectNumberOfViolations( constraintViolations, 1 );
+// assertConstraintViolation(
+// constraintViolations.iterator().next(), MinDummyEntity.class, Boolean.TRUE,
"objectBoolean"
+// );
+//
+// dummy.setObjectBoolean( Boolean.FALSE );
+// constraintViolations = validator.validate( dummy );
+// assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "h")
+// })
+// public void testMaxConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "i")
+// })
+// public void testDecimalMinConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "j")
+// })
+// public void testDecimalMaxConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "k")
+// })
+// public void testSizeConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "l")
+// })
+// public void testDigitsConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "m")
+// })
+// public void testPastConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "n")
+// })
+// public void testFutureConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "o")
+// })
+// public void testPatternConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+
+
+ class NullDummyEntity {
+ @Null
+ Object property;
+
+ public Object getProperty() {
+ return property;
+ }
+
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+ }
+
+ class NotNullDummyEntity {
+ @NotNull
+ Object property;
+
+ public Object getProperty() {
+ return property;
+ }
+
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+ }
+
+ class AssertTrueDummyEntity {
+ @AssertTrue
+ boolean primitiveBoolean;
+
+ @AssertTrue
+ Boolean objectBoolean;
+
+ public boolean isPrimitiveBoolean() {
+ return primitiveBoolean;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean) {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public Boolean isObjectBoolean() {
+ return objectBoolean;
+ }
+
+ public void setObjectBoolean(Boolean objectBoolean) {
+ this.objectBoolean = objectBoolean;
+ }
+ }
+
+ class AssertFalseDummyEntity {
+ @AssertFalse
+ boolean primitiveBoolean;
+
+ @AssertFalse
+ Boolean objectBoolean;
+
+ public boolean isPrimitiveBoolean() {
+ return primitiveBoolean;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean) {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public Boolean isObjectBoolean() {
+ return objectBoolean;
+ }
+
+ public void setObjectBoolean(Boolean objectBoolean) {
+ this.objectBoolean = objectBoolean;
+ }
+ }
+
+ class MinDummyEntity {
+ @Min(101)
+ BigDecimal bigDecimal;
+
+ @Min(101)
+ BigInteger bigInteger;
+
+ @Min(101)
+ byte bytePrimitive;
+
+ @Min(101)
+ short shortPrimitive;
+
+ @Min(101)
+ int intPrimitive;
+
+ @Min(101)
+ long longPrimitive;
+
+ @Min(101)
+ Byte byteObject;
+
+ @Min(101)
+ Short shortObject;
+
+ @Min(101)
+ Integer intObject;
+
+ @Min(101)
+ Long longObject;
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-08
08:06:47 UTC (rev 16715)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-08
09:41:28 UTC (rev 16716)
@@ -982,13 +982,13 @@
<assertion id="l">
<text>@Digits constraint</text>
</assertion>
- <assertion id="i">
+ <assertion id="m">
<text>@Past constraint</text>
</assertion>
- <assertion id="j">
+ <assertion id="n">
<text>@Future constraint</text>
</assertion>
- <assertion id="l">
+ <assertion id="o">
<text>@Pattern constraint</text>
</assertion>
</section>