Author: hardy.ferentschik
Date: 2009-07-21 08:24:39 -0400 (Tue, 21 Jul 2009)
New Revision: 17178
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Person.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
TraversableResolver tck tests
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-07-21
10:53:12 UTC (rev 17177)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-07-21
12:24:39 UTC (rev 17178)
@@ -21,18 +21,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.lang.annotation.ElementType;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Set;
-import javax.validation.Configuration;
import javax.validation.ConstraintViolation;
import javax.validation.MessageInterpolator;
-import javax.validation.Path;
-import javax.validation.TraversableResolver;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
@@ -127,35 +123,6 @@
);
}
- @Test
- @SpecAssertion(section = "3.5.2", id = "b")
- public void testCustomTraversableResolverViaConfiguration() {
-
- // get a new factory using a custom configuration
- Configuration<?> configuration = Validation.byDefaultProvider().configure();
- configuration.traversableResolver( new DummyTraversableResolver() );
- ValidatorFactory factory = configuration.buildValidatorFactory();
- Validator validator = factory.getValidator();
-
- assertCustomTrversableResolverUsed( validator );
- }
-
- @Test
- @SpecAssertion(section = "3.5.2", id = "b")
- public void testCustomTraversableResolverViaValidatorContext() {
- ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
- DummyTraversableResolver DummyTraversableResolver = new DummyTraversableResolver();
- Validator validator = factory.usingContext().traversableResolver(
DummyTraversableResolver ).getValidator();
-
- assertCustomTrversableResolverUsed( validator );
- }
-
- private void assertCustomTrversableResolverUsed(Validator validator) {
- Person person = new Person();
- Set<ConstraintViolation<Person>> constraintViolations = validator.validate(
person );
- assertCorrectNumberOfViolations( constraintViolations, 0 );
- }
-
private List<ValidationProvider> readBeanValidationServiceFile() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
if ( classloader == null ) {
@@ -238,15 +205,4 @@
throw new UnsupportedOperationException( "No specific locale is possible"
);
}
}
-
- private static class DummyTraversableResolver implements TraversableResolver {
-
- public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
- return false;
- }
-
- public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
- return false;
- }
- }
}
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Person.java
(from rev 17143,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Person.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Person.java 2009-07-21
12:24:39 UTC (rev 17178)
@@ -0,0 +1,60 @@
+// $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.traversableresolver;
+
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Person {
+ @NotNull
+ private String firstName;
+
+ @NotNull
+ private String lastName;
+
+ @Digits(integer = 10, fraction = 0)
+ private long personalNumber;
+
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public long getPersonalNumber() {
+ return personalNumber;
+ }
+
+ public void setPersonalNumber(long personalNumber) {
+ this.personalNumber = personalNumber;
+ }
+}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java 2009-07-21
10:53:12 UTC (rev 17177)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java 2009-07-21
12:24:39 UTC (rev 17178)
@@ -17,21 +17,24 @@
*/
package org.hibernate.jsr303.tck.tests.traversableresolver;
+import javax.validation.GroupSequence;
+import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
-import javax.validation.Valid;
-import javax.validation.GroupSequence;
import javax.validation.groups.Default;
/**
* @author Emmanuel Bernard
*/
-@GroupSequence( {Suit.class, Cloth.class })
+@GroupSequence({ Suit.class, Cloth.class })
public class Suit {
- @Max(value=50, groups = { Default.class, Cloth.class})
+ @Max(value = 50, groups = { Default.class, Cloth.class })
@Min(1)
private Integer size;
- @Valid private Trousers trousers;
+
+ @Valid
+ private Trousers trousers;
+
private Jacket jacket;
public Trousers getTrousers() {
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java 2009-07-21
10:53:12 UTC (rev 17177)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java 2009-07-21
12:24:39 UTC (rev 17178)
@@ -17,22 +17,29 @@
*/
package org.hibernate.jsr303.tck.tests.traversableresolver;
+import java.lang.annotation.ElementType;
+import java.util.Set;
import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
import javax.validation.Validation;
+import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
-import javax.validation.ValidationException;
import javax.validation.groups.Default;
+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.test.audit.annotations.SpecAssertion;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
* @author Emmanuel Bernard
@@ -42,7 +49,11 @@
@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class TraversableResolverTest extends AbstractTest {
@Test
- public void testCorrectPathsAreRequested() {
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.2", id = "a"),
+ @SpecAssertion(section = "3.5.2", id = "b")
+ })
+ public void testCorrectNumberOfCallsToIsReachableAndIsCascadable() {
Suit suit = new Suit();
suit.setTrousers( new Trousers() );
suit.setJacket( new Jacket() );
@@ -67,8 +78,24 @@
assertEquals( resolver.getCascadePaths().size(), 2 );
}
+ @Test
+ @SpecAssertion(section = "3.5.2", id = "d")
+ public void testCustomTraversableResolverViaConfiguration() {
+
+ // get a new factory using a custom configuration
+ Configuration<?> configuration = Validation.byDefaultProvider().configure();
+ configuration.traversableResolver( new DummyTraversableResolver() );
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ Validator validator = factory.getValidator();
+
+ Person person = new Person();
+ Set<ConstraintViolation<Person>> constraintViolations = validator.validate(
person );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+
@Test(expectedExceptions = ValidationException.class)
- @SpecAssertion(section = "3.5.2", id = "c")
+ @SpecAssertion(section = "3.5.2", id = "e")
public void testResolverExceptionsGetWrappedInValidationException() {
ExceptionThrowingTraversableResolver resolver = new
ExceptionThrowingTraversableResolver();
Configuration<?> config = ( Configuration<?> )
Validation.byDefaultProvider()
@@ -80,4 +107,15 @@
v.validate( new Suit() );
}
+
+ private static class DummyTraversableResolver implements TraversableResolver {
+
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return false;
+ }
+
+ public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return false;
+ }
+ }
}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java 2009-07-21
10:53:12 UTC (rev 17177)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java 2009-07-21
12:24:39 UTC (rev 17178)
@@ -17,16 +17,16 @@
*/
package org.hibernate.jsr303.tck.tests.traversableresolver;
+import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
-import javax.validation.constraints.Max;
import javax.validation.groups.Default;
/**
* @author Emmanuel Bernard
*/
public class Trousers {
- @Min(value=70, groups = {Default.class, Cloth.class})
- @Max(value=220)
+ @Min(value = 70, groups = { Default.class, Cloth.class })
+ @Max(value = 220)
private Integer length;
public Integer getLength() {
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-21
10:53:12 UTC (rev 17177)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-21
12:24:39 UTC (rev 17178)
@@ -452,28 +452,34 @@
</section>
<section id="3.5.2" title="Traversable property">
<assertion id="a">
+ <text>isReachable is called for every property about to be accessed
either for validation or for cascading</text>
+ </assertion>
+ <assertion id="b">
+ <text>isCascadable is called for every property about to be cascaded
(ie. marked as @Valid)</text>
+ </assertion>
+ <assertion id="c">
<text>isCascadable for a given property is only called if isReachable
returns true. In
other words, isReachable is always called before isCascadable for a
given
property</text>
- </assertion>
- <assertion id="b">
+ </assertion>
+ <assertion id="d">
<text>The Bean Validation provider must not access the state of a
property, nor validate
its constraints if the property is not traversable. A property is
traversable if
TraversableResolver returns true for this property</text>
</assertion>
- <assertion id="c">
+ <assertion id="e">
<text>If an exception occurs when the TraversableResolver is called,
the exception is
wrapped into a ValidationException</text>
</assertion>
- <assertion id="d">
+ <assertion id="f" testable="false">
<text>If Java Persistence is available in the runtime environment, a
property is
considered reachable if Java Persistence considers the property as
loaded</text>
</assertion>
- <assertion id="d">
+ <assertion id="g" testable="false">
<text>If Java Persistence is not available in the runtime environment,
all properties
are considered reachable</text>
</assertion>
- <assertion id="e">
+ <assertion id="h" testable="false">
<text>If Java Persistence is not available in the runtime environment,
all properties are considered cascadable</text>
</assertion>
</section>