Author: hardy.ferentschik
Date: 2009-03-03 06:06:02 -0500 (Tue, 03 Mar 2009)
New Revision: 16058
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/Dummy.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyValidator.java
Removed:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageConstraintValidator.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
Log:
HV-114 Added test and some cleanup.
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-03-02
17:10:46 UTC (rev 16057)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -100,7 +100,7 @@
ConstraintValidator<A, V> validator = getInitalizedValidator(
value, executionContext.getConstraintValidatorFactory()
);
- executionContext.setConstraintDescriptor( descriptor );
+ executionContext.setCurrentConstraintDescriptor( descriptor );
if ( !validator.isValid( value, executionContext ) ) {
constraintViolations.addAll( executionContext.createConstraintViolations( value ) );
}
@@ -109,7 +109,7 @@
final String message = ( String ) getParent().getDescriptor().getParameters().get(
"message" );
final String property = executionContext.peekPropertyPath();
ExecutionContext<T>.ErrorMessage error = executionContext.new ErrorMessage(
message, property );
- constraintViolations.add(executionContext.createConstraintViolation( value, error ));
+ constraintViolations.add( executionContext.createConstraintViolation( value, error )
);
}
}
@@ -133,7 +133,6 @@
else {
validatorClass = findMatchingValidatorClass( value );
}
- //
@SuppressWarnings("unchecked")
ConstraintValidator<?, ?> constraintValidator =
constraintFactory.getInstance( validatorClass );
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-03-02
17:10:46 UTC (rev 16057)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -18,7 +18,6 @@
package org.hibernate.validation.engine;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -61,12 +60,12 @@
private final List<ConstraintViolationImpl<T>> failingConstraintViolations;
/**
- * Keep track of the property path/
+ * The current property based based from the root bean.
*/
private List<String> propertyPath;
/**
- * The current group which is getting processed.
+ * The current group we are validating.
*/
private Class<?> currentGroup;
@@ -77,9 +76,9 @@
private ValidatedProperty currentValidatedProperty;
/**
- * Stack for keeping track of the currently validated object.
+ * Stack for keeping track of the currently validated bean.
*/
- private Stack<Object> validatedBeanStack = new Stack<Object>();
+ private Stack<Object> beanStack = new Stack<Object>();
/**
* The message resolver which should be used in this context.
@@ -106,16 +105,12 @@
this.constraintValidatorFactory = constraintValidatorFactory;
this.traversableResolver = traversableResolver;
- validatedBeanStack.push( object );
+ beanStack.push( object );
processedObjects = new HashMap<Class<?>, IdentitySet>();
propertyPath = new ArrayList<String>();
failingConstraintViolations = new ArrayList<ConstraintViolationImpl<T>>();
}
- public MessageInterpolator getMessageResolver() {
- return messageResolver;
- }
-
public ConstraintValidatorFactory getConstraintValidatorFactory() {
return constraintValidatorFactory;
}
@@ -140,30 +135,25 @@
currentValidatedProperty.addError( message, property );
}
- public List<ErrorMessage> getErrorMessages() {
+ public void setCurrentConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
assert currentValidatedProperty != null;
- return currentValidatedProperty.getErrorMessages();
- }
-
- public void setConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
- assert currentValidatedProperty != null;
currentValidatedProperty.setConstraintDescriptor( constraintDescriptor );
}
- public Object peekValidatedBean() {
- return validatedBeanStack.peek();
+ public Object peekCurrentBean() {
+ return beanStack.peek();
}
- public Class<?> peekValidatedBeanType() {
- return validatedBeanStack.peek().getClass();
+ public Class<?> peekCurrentBeanType() {
+ return beanStack.peek().getClass();
}
- public void pushValidatedBean(Object validatedBean) {
- validatedBeanStack.push( validatedBean );
+ public void pushCurrentBean(Object validatedBean) {
+ beanStack.push( validatedBean );
}
- public void popValidatedBean() {
- validatedBeanStack.pop();
+ public void popCurrentBean() {
+ beanStack.pop();
}
public T getRootBean() {
@@ -180,11 +170,11 @@
public void markProcessedForCurrentGroup() {
if ( processedObjects.containsKey( currentGroup ) ) {
- processedObjects.get( currentGroup ).add( validatedBeanStack.peek() );
+ processedObjects.get( currentGroup ).add( beanStack.peek() );
}
else {
IdentitySet set = new IdentitySet();
- set.add( validatedBeanStack.peek() );
+ set.add( beanStack.peek() );
processedObjects.put( currentGroup, set );
}
}
@@ -194,7 +184,7 @@
return objectsProcessedInCurrentGroups != null &&
objectsProcessedInCurrentGroups.contains( value );
}
- public void addConstraintFailure(ConstraintViolationImpl<T>
failingConstraintViolation) {
+ private void addConstraintFailure(ConstraintViolationImpl<T>
failingConstraintViolation) {
int i = failingConstraintViolations.indexOf( failingConstraintViolation );
if ( i == -1 ) {
failingConstraintViolations.add( failingConstraintViolation );
@@ -211,10 +201,6 @@
return failingConstraintViolations;
}
- public void clearFailingConstraints() {
- failingConstraintViolations.clear();
- }
-
/**
* Adds a new level to the current property path of this context.
*
@@ -222,7 +208,7 @@
*/
public void pushProperty(String property) {
propertyPath.add( property );
- currentValidatedProperty = new ValidatedProperty( peekPropertyPath(), getCurrentGroup()
);
+ currentValidatedProperty = new ValidatedProperty( peekPropertyPath() );
}
/**
@@ -273,7 +259,7 @@
Class<?> rootBeanClass = rootBean == null ? null : rootBean.getClass();
return traversableResolver.isTraversable(
- peekValidatedBean(),
+ peekCurrentBean(),
peekProperty(),
rootBeanClass,
peekPropertyPath(),
@@ -292,16 +278,16 @@
public ConstraintViolationImpl<T> createConstraintViolation(Object value,
ErrorMessage error) {
ConstraintDescriptor descriptor = currentValidatedProperty.getConstraintDescriptor();
String messageTemplate = error.getMessage();
- String interpolatedMessage = getMessageResolver().interpolate(
+ String interpolatedMessage = messageResolver.interpolate(
messageTemplate,
descriptor,
- peekValidatedBean()
+ peekCurrentBean()
);
return new ConstraintViolationImpl<T>(
messageTemplate,
interpolatedMessage,
getRootBean(),
- peekValidatedBean(),
+ peekCurrentBean(),
value,
error.getProperty(),
descriptor
@@ -314,11 +300,10 @@
private ConstraintDescriptor constraintDescriptor;
private boolean defaultDisabled;
private String property;
- private Class<?> group;
- private ValidatedProperty(String property, Class<?> group) {
+
+ private ValidatedProperty(String property) {
this.property = property;
- this.group = group;
}
public void setConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
@@ -350,8 +335,7 @@
}
public List<ErrorMessage> getErrorMessages() {
- List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>(
errorMessages.size() + 1 );
- Collections.copy( returnedErrorMessages, errorMessages );
+ List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>(
errorMessages );
if ( !defaultDisabled ) {
returnedErrorMessages.add( new ErrorMessage( getDefaultErrorMessage(), property ) );
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-03-02
17:10:46 UTC (rev 16057)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -192,7 +192,7 @@
}
public <T> boolean validateConstraint(ExecutionContext<T> executionContext)
{
- final Object leafBeanInstance = executionContext.peekValidatedBean();
+ final Object leafBeanInstance = executionContext.peekCurrentBean();
Object value = getValue( leafBeanInstance );
List<ConstraintViolationImpl<T>> constraintViolations = new
ArrayList<ConstraintViolationImpl<T>>();
constraintTree.validateConstraints( value, executionContext, constraintViolations );
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-03-02
17:10:46 UTC (rev 16057)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -183,7 +183,7 @@
* @return List of invalid constraints.
*/
private <T> List<ConstraintViolationImpl<T>>
validateInContext(ExecutionContext<T> context, GroupChain groupChain) {
- if ( context.peekValidatedBean() == null ) {
+ if ( context.peekCurrentBean() == null ) {
return Collections.emptyList();
}
@@ -228,7 +228,7 @@
private <T> void validateConstraints(ExecutionContext<T> executionContext)
{
//casting rely on the fact that root object is at the top of the stack
@SuppressWarnings(" unchecked")
- BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> )
executionContext.peekValidatedBeanType() );
+ BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> )
executionContext.peekCurrentBeanType() );
if ( executionContext.getCurrentGroup().getName().equals( Default.class.getName() ) )
{
List<Class<?>> defaultGroupSequence =
beanMetaData.getDefaultGroupSequence();
if ( log.isTraceEnabled() && defaultGroupSequence.size() > 0 &&
defaultGroupSequence.get( 0 ) != Default.class ) {
@@ -275,12 +275,12 @@
}
private <T> void validateCascadedConstraints(ExecutionContext<T> context) {
- List<Member> cascadedMembers = getBeanMetaData( context.peekValidatedBeanType()
)
+ List<Member> cascadedMembers = getBeanMetaData( context.peekCurrentBeanType() )
.getCascadedMembers();
for ( Member member : cascadedMembers ) {
Type type = ReflectionHelper.typeOf( member );
context.pushProperty( ReflectionHelper.getPropertyName( member ) );
- Object value = ReflectionHelper.getValue( member, context.peekValidatedBean() );
+ Object value = ReflectionHelper.getValue( member, context.peekCurrentBean() );
if ( value == null ) {
continue;
}
@@ -343,12 +343,12 @@
if ( !context.isValidatedAgainstCurrentGroup( actualValue ) ) {
context.replacePropertyIndex( propertyIndex );
- context.pushValidatedBean( actualValue );
+ context.pushCurrentBean( actualValue );
validateInContext(
context,
groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] {
context.getCurrentGroup() } ) )
);
- context.popValidatedBean();
+ context.popCurrentBean();
}
i++;
}
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators
(from rev 16046,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete)
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java 2009-02-26
16:26:54 UTC (rev 16046)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validation.constraints.incomplete;
+package org.hibernate.validation.constraints.invalidvalidators;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.FIELD;
@@ -29,7 +29,7 @@
* @author Hardy Ferentschik
*/
@Documented
-@Constraint(validatedBy = NoGroupsConstraintValidator.class)
+@Constraint(validatedBy = NoGroupsValidator.class)
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
public @interface NoGroups {
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsConstraintValidator.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java 2009-02-26
16:26:54 UTC (rev 16046)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsConstraintValidator.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -1,34 +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.validation.constraints.incomplete;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NoGroupsConstraintValidator implements ConstraintValidator<NoGroups,
Object> {
-
- public void initialize(NoGroups parameters) {
- }
-
- public boolean isValid(Object object, ConstraintValidatorContext
constraintValidatorContext) {
- return false;
- }
-}
\ No newline at end of file
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -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.validation.constraints.invalidvalidators;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NoGroupsValidator implements ConstraintValidator<NoGroups, Object> {
+
+ public void initialize(NoGroups parameters) {
+ }
+
+ public boolean isValid(Object object, ConstraintValidatorContext
constraintValidatorContext) {
+ return false;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoMessage.java 2009-02-26
16:26:54 UTC (rev 16046)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validation.constraints.incomplete;
+package org.hibernate.validation.constraints.invalidvalidators;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.FIELD;
@@ -29,7 +29,7 @@
* @author Hardy Ferentschik
*/
@Documented
-@Constraint(validatedBy = NoMessageConstraintValidator.class)
+@Constraint(validatedBy = NoMessageValidator.class)
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
public @interface NoMessage {
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageConstraintValidator.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoMessageConstraintValidator.java 2009-02-26
16:26:54 UTC (rev 16046)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageConstraintValidator.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -1,34 +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.validation.constraints.incomplete;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NoMessageConstraintValidator implements ConstraintValidator<NoMessage,
Object> {
-
- public void initialize(NoMessage parameters) {
- }
-
- public boolean isValid(Object object, ConstraintValidatorContext
constraintValidatorContext) {
- return false;
- }
-}
\ No newline at end of file
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -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.validation.constraints.invalidvalidators;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NoMessageValidator implements ConstraintValidator<NoMessage, Object>
{
+
+ public void initialize(NoMessage parameters) {
+ }
+
+ public boolean isValid(Object object, ConstraintValidatorContext
constraintValidatorContext) {
+ return false;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/ValidProperty.java 2009-02-26
16:26:54 UTC (rev 16046)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validation.constraints.incomplete;
+package org.hibernate.validation.constraints.invalidvalidators;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.FIELD;
@@ -29,7 +29,7 @@
* @author Hardy Ferentschik
*/
@Documented
-@Constraint(validatedBy = NoGroupsConstraintValidator.class)
+@Constraint(validatedBy = NoGroupsValidator.class)
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
public @interface ValidProperty {
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -0,0 +1,78 @@
+// $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.validation.constraints.validatorcontext;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import org.hibernate.validation.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintValidatorContextTest {
+
+ @Test
+ public void testNoCustomization() {
+ Validator validator = TestUtil.getValidator();
+
+ DummyBean bean = new DummyBean( "foobar" );
+
+ Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
+ assertEquals( "Wrong number of constraints", 1, constraintViolations.size()
);
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( "Wrong message", "dummy message",
constraintViolation.getMessage() );
+ }
+
+ /**
+ * @todo Is this the right behaviour? The spec is not quite clear about this.
+ */
+ @Test
+ public void testDisableDefaultErrorWithoutCustomError() {
+ Validator validator = TestUtil.getValidator();
+
+ DummyBean bean = new DummyBean( "foobar" );
+ DummyValidator.disableDefaultError( true );
+
+ Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
+ assertEquals( "Wrong number of constraints", 0, constraintViolations.size()
);
+ }
+
+ @Test
+ public void testDisableDefaultErrorWithCustomErrors() {
+ Validator validator = TestUtil.getValidator();
+
+ DummyBean bean = new DummyBean( "foobar" );
+ DummyValidator.disableDefaultError( true );
+ Map<String, String> errors = new HashMap<String, String>();
+ errors.put( "message1", "property1" );
+ DummyValidator.setErrorMessages( errors );
+
+ Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
+ assertEquals( "Wrong number of constraints", 1, constraintViolations.size()
);
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertEquals( "Wrong message", "message1",
constraintViolation.getMessage() );
+ assertEquals( "Wrong property", "property1",
constraintViolation.getPropertyPath() );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/Dummy.java
(from rev 16046,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/Dummy.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/Dummy.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -0,0 +1,39 @@
+// $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.validation.constraints.validatorcontext;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Documented
+@Constraint(validatedBy = DummyValidator.class)
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Dummy {
+ String message() default "dummy message";
+
+ Class<?>[] groups() default { };
+}
\ No newline at end of file
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -0,0 +1,31 @@
+// $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.validation.constraints.validatorcontext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class DummyBean {
+
+ @Dummy
+ String value;
+
+ public DummyBean(String value) {
+ this.value = value;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyValidator.java
(from rev 16046,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyValidator.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -0,0 +1,58 @@
+// $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.validation.constraints.validatorcontext;
+
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class DummyValidator implements ConstraintValidator<Dummy, String> {
+
+ private static boolean disableDefaultError;
+
+ private static Map<String, String> errorMessages;
+
+
+ public void initialize(Dummy parameters) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext
constraintValidatorContext) {
+ if ( disableDefaultError ) {
+ constraintValidatorContext.disableDefaultError();
+ }
+
+ if ( errorMessages != null ) {
+ for ( Map.Entry<String, String> entry : errorMessages.entrySet() ) {
+ constraintValidatorContext.addError( entry.getKey(), entry.getValue() );
+ }
+ }
+
+ return false;
+ }
+
+ public static void disableDefaultError(boolean b) {
+ disableDefaultError = b;
+ }
+
+ public static void setErrorMessages(Map<String, String> errorMessages) {
+ DummyValidator.errorMessages = errorMessages;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java 2009-03-02
17:10:46 UTC (rev 16057)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java 2009-03-03
11:06:02 UTC (rev 16058)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -29,9 +29,9 @@
import org.junit.BeforeClass;
import org.junit.Test;
-import org.hibernate.validation.constraints.incomplete.NoGroups;
-import org.hibernate.validation.constraints.incomplete.NoMessage;
-import org.hibernate.validation.constraints.incomplete.ValidProperty;
+import org.hibernate.validation.constraints.invalidvalidators.NoGroups;
+import org.hibernate.validation.constraints.invalidvalidators.NoMessage;
+import org.hibernate.validation.constraints.invalidvalidators.ValidProperty;
import org.hibernate.validation.eg.Engine;
import org.hibernate.validation.eg.Order;
import org.hibernate.validation.util.ReflectionHelper;