You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by dw...@apache.org on 2010/05/19 22:03:53 UTC
svn commit: r946365 - in /incubator/bval/trunk:
bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java
bval-tck/pom.xml
Author: dwoods
Date: Wed May 19 20:03:53 2010
New Revision: 946365
URL: http://svn.apache.org/viewvc?rev=946365&view=rev
Log:
BVAL-49 Missed adding new test
Added:
incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java (with props)
Modified:
incubator/bval/trunk/bval-tck/pom.xml
Added: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java?rev=946365&view=auto
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java (added)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java Wed May 19 20:03:53 2010
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.bval.jsr303;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.Payload;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import org.apache.bval.jsr303.CustomConstraintValidatorFactoryTest.GoodPerson.GoodPersonValidator;
+
+import junit.framework.TestCase;
+
+/**
+ * Checks that overriding the default {@link ConstraintValidatorFactory} works
+ * as expected.
+ *
+ * @author Carlos Vara
+ */
+public class CustomConstraintValidatorFactoryTest extends TestCase {
+
+ /**
+ * If the custom ConstraintValidatorFactory returns <code>null</code> for a
+ * valid {@link ConstraintValidatorFactory#getInstance(Class)} call, a
+ * validation exception should be thrown.
+ */
+ public void testValidationExceptionWhenFactoryReturnsNullValidator() {
+
+ ConstraintValidatorFactory customFactory = new ConstraintValidatorFactory() {
+ @Override
+ public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+ return null; // always return null
+ }
+ };
+
+ // Create a validator with this factory
+ ApacheValidatorConfiguration customConfig = Validation.byProvider(ApacheValidationProvider.class).configure().constraintValidatorFactory(customFactory);
+ Validator validator = customConfig.buildValidatorFactory().getValidator();
+
+ try {
+ validator.validate(new Person());
+ fail("ValidationException must be thrown when factory returns a null constraint validator.");
+ } catch (ValidationException e) {
+ // correct
+ }
+ }
+
+ @GoodPerson
+ public static class Person {
+ }
+
+ @Constraint(validatedBy = { GoodPersonValidator.class })
+ @Target({ METHOD, FIELD, ANNOTATION_TYPE, TYPE })
+ @Retention(RUNTIME)
+ @Documented
+ public static @interface GoodPerson {
+
+ String message() default "Not a good person";
+ Class<?>[] groups() default { };
+ Class<? extends Payload>[] payload() default {};
+
+ public static class GoodPersonValidator implements ConstraintValidator<GoodPerson, Person> {
+ @Override
+ public void initialize(GoodPerson constraintAnnotation) {
+ }
+
+ @Override
+ public boolean isValid(Person value, ConstraintValidatorContext context) {
+ return true;
+ }
+ }
+ }
+
+}
Propchange: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/CustomConstraintValidatorFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/bval/trunk/bval-tck/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-tck/pom.xml?rev=946365&r1=946364&r2=946365&view=diff
==============================================================================
--- incubator/bval/trunk/bval-tck/pom.xml (original)
+++ incubator/bval/trunk/bval-tck/pom.xml Wed May 19 20:03:53 2010
@@ -34,6 +34,11 @@
<dependencies>
<dependency>
<groupId>org.apache.bval</groupId>
+ <artifactId>bval-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>${project.version}</version>
</dependency>
@@ -149,12 +154,36 @@
<outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
</artifactItem>
<artifactItem>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
+ </artifactItem>
+ <artifactItem>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
+ </artifactItem>
+ <artifactItem>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
+ </artifactItem>
+ <artifactItem>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
</artifactItem>
<artifactItem>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/dependency/lib</outputDirectory>
+ </artifactItem>
+ <artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<overWrite>true</overWrite>