Author: hardy.ferentschik
Date: 2010-05-19 11:40:07 -0400 (Wed, 19 May 2010)
New Revision: 19547
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/HibernateValidatorConfigurationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ClassValidatorWithTypeVariableTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Cloneable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/CloneableConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintValidatorContextTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Coordinate.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Elevator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Interval.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Item.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Object.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ObjectConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/PostCodeList.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Serializable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SerializableConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEnd.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEndImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SubType.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Suburb.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperType.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArray.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArrayValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ValidatorResolutionTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/CompositeConstraintTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/Person.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidName.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidNameSingleViolation.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertFalseValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertTrueValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/BlankValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/CreditCardNumberValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DateHolder.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/EmailValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/LengthValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NotNullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PatternValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/ScriptAssertValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/SizeValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/URLValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/PathImplTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/ValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/CustomErrorMessageTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/DummyTestClass.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValid.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValidValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Address.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence1.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence2.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/First.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupA.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupB.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainGeneratorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupsTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Last.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Second.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/TestSequence.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Try.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceChecker.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/User.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/A.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/B.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/ProxyTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/ConstraintViolationSerializationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/CustomConstraintSerializableTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/DummyEmailValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/Email.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/SerializableClass.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/UnSerializableClass.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Author.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/AuthorBusinessRules.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Book.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/BookBusinessRules.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/CachedTraversableResolverTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Cloth.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Jacket.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/JpaTraversableResolverTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Suit.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Trousers.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ElementDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Engine.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Person.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateBundleTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/BoundariesConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/DummyTraversableResolver.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/IdentitySetTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/Positive.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/PositiveConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ValidatorTypeTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/AnnotationFactoryTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterface.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterfaceImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Person.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Properties.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/XmlMappingTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/ICompetition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/IFixture.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/InheritanceMappingsTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Competition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Fixture.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Game.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/GameDetail.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/PersonCompetition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/TeamCompetition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Competition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Fixture.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Game.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/GameDetail.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/PersonCompetition.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/TeamCompetition.java
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle1.properties
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle2.properties
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/empty-my-interface-mapping.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mapping.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/annotation-mappings.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/xml-mappings.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-impl-mapping.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-mapping.xml
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/properties-mapping.xml
Removed:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/HibernateValidatorConfigurationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/bootstrap/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/resourceloading/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml
Log:
HV-274 Refactoring - Moved the tests into a test sub-package
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/HibernateValidatorConfigurationTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/HibernateValidatorConfigurationTest.java 2010-05-19
04:25:19 UTC (rev 19546)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/HibernateValidatorConfigurationTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -1,43 +0,0 @@
-/*
- * $Id$
- *
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator;
-
-import javax.validation.Validation;
-
-import org.testng.annotations.Test;
-
-import org.hibernate.validator.resourceloading.ResourceBundleLocator;
-
-import static org.testng.Assert.assertNotNull;
-
-/**
- * Test for {@link HibernateValidatorConfiguration}.
- *
- * @author Gunnar Morling
- */
-public class HibernateValidatorConfigurationTest {
-
- @Test
- public void defaultResourceBundleLocatorCanBeRetrieved() {
- HibernateValidatorConfiguration configure = Validation.byProvider(
HibernateValidator.class ).configure();
- ResourceBundleLocator defaultResourceBundleLocator =
configure.getDefaultResourceBundleLocator();
-
- assertNotNull( defaultResourceBundleLocator );
- }
-}
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/HibernateValidatorConfigurationTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/HibernateValidatorConfigurationTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/HibernateValidatorConfigurationTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/HibernateValidatorConfigurationTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test;
+
+import javax.validation.Validation;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.HibernateValidator;
+import org.hibernate.validator.HibernateValidatorConfiguration;
+import org.hibernate.validator.resourceloading.ResourceBundleLocator;
+
+import static org.testng.Assert.assertNotNull;
+
+/**
+ * Test for {@link org.hibernate.validator.HibernateValidatorConfiguration}.
+ *
+ * @author Gunnar Morling
+ */
+public class HibernateValidatorConfigurationTest {
+
+ @Test
+ public void defaultResourceBundleLocatorCanBeRetrieved() {
+ HibernateValidatorConfiguration configure = Validation.byProvider(
HibernateValidator.class ).configure();
+ ResourceBundleLocator defaultResourceBundleLocator =
configure.getDefaultResourceBundleLocator();
+
+ assertNotNull( defaultResourceBundleLocator );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/HibernateValidatorConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/bootstrap)
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Customer.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/bootstrap/Customer.java 2010-05-14
06:55:33 UTC (rev 19511)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Customer.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validator.bootstrap;
+package org.hibernate.validator.test.bootstrap;
import java.util.HashSet;
import java.util.Set;
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Order.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/bootstrap/Order.java 2010-05-14
06:55:33 UTC (rev 19511)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/Order.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validator.bootstrap;
+package org.hibernate.validator.test.bootstrap;
import javax.validation.constraints.NotNull;
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/ValidationTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/bootstrap/ValidationTest.java 2010-05-14
06:55:33 UTC (rev 19511)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/bootstrap/ValidationTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.hibernate.validator.bootstrap;
+package org.hibernate.validator.test.bootstrap;
import java.util.Set;
import javax.validation.Configuration;
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ClassValidatorWithTypeVariableTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/ClassValidatorWithTypeVariableTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ClassValidatorWithTypeVariableTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ClassValidatorWithTypeVariableTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,127 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Valid;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+import static org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintTypes;
+import static org.hibernate.validator.test.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * HV-250
+ */
+public class ClassValidatorWithTypeVariableTest {
+
+ private Validator validator;
+
+ @BeforeClass
+ public void setUp() {
+ validator = TestUtil.getValidator();
+ }
+
+ @Test
+ public void offersNull() {
+ Batch batch = new Batch( null );
+
+ Set<ConstraintViolation<Batch>> violations = validator.validate( batch );
+ assertNumberOfViolations( violations, 1 );
+ assertCorrectPropertyPaths( violations, "offers" );
+ assertCorrectConstraintTypes( violations, NotNull.class );
+ }
+
+ @Test
+ public void offerItemNull() {
+ ItemAOffer offer = new ItemAOffer( null );
+ Set<ItemOffer<? extends Item>> offers = new HashSet<ItemOffer<?
extends Item>>();
+ offers.add( offer );
+ Batch batch = new Batch( offers );
+
+ Set<ConstraintViolation<Batch>> violations = validator.validate( batch );
+ assertNumberOfViolations( violations, 1 );
+ assertCorrectPropertyPaths( violations, "offers[].item" );
+ assertCorrectConstraintTypes( violations, NotNull.class );
+ }
+
+ @Test
+ public void offerItemDateNull() {
+ ItemA item = new ItemA( null );
+ ItemOffer<? extends Item> offer = new ItemAOffer( item );
+ Set<ItemOffer<? extends Item>> offers = new HashSet<ItemOffer<?
extends Item>>();
+ offers.add( offer );
+ Batch batch = new Batch( offers );
+
+ Set<ConstraintViolation<Batch>> violations = validator.validate( batch );
+ assertNumberOfViolations( violations, 1 );
+ assertCorrectPropertyPaths( violations, "offers[].item.date" );
+ assertCorrectConstraintTypes( violations, NotNull.class );
+ }
+
+ private class Batch {
+ @NotNull
+ @Valid
+ private Set<ItemOffer<? extends Item>> offers = new
HashSet<ItemOffer<? extends Item>>();
+
+ public Batch(Set<ItemOffer<? extends Item>> offers) {
+ this.offers = offers;
+ }
+ }
+
+ private abstract class Item {
+ @NotNull
+ private Date date;
+
+ public Item(Date date) {
+ this.date = date;
+ }
+ }
+
+ private abstract class ItemOffer<T extends Item> {
+ @NotNull
+ @Valid
+ private T item;
+
+ public ItemOffer(T item) {
+ this.item = item;
+ }
+ }
+
+ private class ItemA extends Item {
+ public ItemA(Date date) {
+ super( date );
+ }
+ }
+
+ private class ItemAOffer extends ItemOffer<ItemA> {
+ public ItemAOffer(ItemA item) {
+ super( item );
+ }
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ClassValidatorWithTypeVariableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Cloneable.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Cloneable.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Cloneable.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Cloneable.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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;
+import javax.validation.Payload;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { CloneableConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Cloneable {
+ public abstract String message() default
"{org.hibernate.validator.constraints.Cloneable.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Cloneable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/CloneableConstraintValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/CloneableConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/CloneableConstraintValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/CloneableConstraintValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CloneableConstraintValidator implements
ConstraintValidator<org.hibernate.validator.test.constraints.Cloneable,
java.lang.Cloneable> {
+
+ public void initialize(org.hibernate.validator.test.constraints.Cloneable annotation) {
+ }
+
+ public boolean isValid(java.lang.Cloneable value, ConstraintValidatorContext
constraintValidatorContext) {
+ return true;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/CloneableConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/ConstraintTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,68 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+import static org.hibernate.validator.test.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintTest {
+
+ @Test
+ public void testRangeConstraint() {
+ Validator validator = TestUtil.getValidator();
+
+ Elevator elevator = new Elevator();
+ elevator.setCurrentFloor( -3 );
+ Set<ConstraintViolation<Elevator>> constraintViolations =
validator.validate( elevator );
+
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation( constraintViolations.iterator().next(), "Invalid
floor" );
+
+ elevator.setCurrentFloor( -2 );
+ constraintViolations = validator.validate( elevator );
+
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ elevator.setCurrentFloor( 45 );
+ constraintViolations = validator.validate( elevator );
+
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ elevator.setCurrentFloor( 50 );
+ constraintViolations = validator.validate( elevator );
+
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ elevator.setCurrentFloor( 51 );
+ constraintViolations = validator.validate( elevator );
+
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation( constraintViolations.iterator().next(), "Invalid
floor" );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintValidatorContextTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/ConstraintValidatorContextTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintValidatorContextTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintValidatorContextTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,160 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.util.List;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.ConstraintValidatorContextImpl;
+import org.hibernate.validator.engine.MessageAndPath;
+import org.hibernate.validator.engine.PathImpl;
+import org.hibernate.validator.test.util.TestUtil;
+
+import static org.hibernate.validator.test.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintValidatorContextTest {
+
+ /**
+ * HV-198
+ */
+ @Test
+ public void testCorrectSubNodePath() {
+ Validator validator = TestUtil.getValidator();
+
+ Item item = new Item();
+ item.interval = new Interval();
+ item.interval.start = 10;
+ item.interval.end = 5;
+
+ Set<ConstraintViolation<Item>> constraintViolations = validator.validate(
item );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "interval.start" );
+ }
+
+ /**
+ * HV-208
+ */
+ @Test
+ public void testCorrectPath() {
+ Validator validator = TestUtil.getValidator();
+
+ Item item = new Item();
+ Interval interval = new Interval();
+ item.interval = interval;
+ item.interval.start = 10;
+ item.interval.end = 5;
+
+ Set<ConstraintViolation<Interval>> constraintViolations =
validator.validate( interval );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "start" );
+ }
+
+ @Test
+ public void testDifferentPaths() {
+ String message = "message";
+ ConstraintValidatorContextImpl context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message )
+ .addNode( "foo" )
+ .addNode( "bar" ).inIterable().atIndex( 3 )
+ .addConstraintViolation();
+
+ List<MessageAndPath> messageAndPathList = context.getMessageAndPathList();
+ assertMessageAndPath( messageAndPathList.get( 0 ), message, "foo[3].bar" );
+
+
+ context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message )
+ .addNode( "foo" )
+ .addNode( null ).inIterable().atKey( "test" )
+ .addConstraintViolation();
+
+ messageAndPathList = context.getMessageAndPathList();
+ assertMessageAndPath( messageAndPathList.get( 0 ), message, "foo[test]" );
+
+ context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message )
+ .addNode( "foo" )
+ .addNode( "bar" ).inIterable().atKey( "test" )
+ .addNode( "fubar" )
+ .addConstraintViolation();
+
+ messageAndPathList = context.getMessageAndPathList();
+ assertMessageAndPath( messageAndPathList.get( 0 ), message,
"foo[test].bar.fubar" );
+
+ context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message )
+ .addNode( "foo" )
+ .addNode( "bar" ).inIterable().atKey( "test" )
+ .addNode( "fubar" ).inIterable().atIndex( 10 )
+ .addConstraintViolation();
+
+ messageAndPathList = context.getMessageAndPathList();
+ assertMessageAndPath( messageAndPathList.get( 0 ), message,
"foo[test].bar[10].fubar" );
+
+ context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message )
+ .addNode( "foo" )
+ .addNode( "bar" ).inIterable().atKey( "test" )
+ .addNode( "fubar" ).inIterable()
+ .addConstraintViolation();
+
+ messageAndPathList = context.getMessageAndPathList();
+ assertMessageAndPath( messageAndPathList.get( 0 ), message,
"foo[test].bar[].fubar" );
+ }
+
+ @Test
+ public void testMultipleMessages() {
+ String message1 = "message1";
+ String message2 = "message2";
+ ConstraintValidatorContextImpl context = createEmptyConstraintValidatorContextImpl();
+ context.buildConstraintViolationWithTemplate( message1 )
+ .addNode( "foo" )
+ .addNode( "bar" ).inIterable().atKey( "key" )
+ .addConstraintViolation();
+ context.buildConstraintViolationWithTemplate( message2 )
+ .addConstraintViolation();
+
+ List<MessageAndPath> messageAndPathList = context.getMessageAndPathList();
+ assertTrue( messageAndPathList.size() == 2 );
+ assertMessageAndPath( messageAndPathList.get( 0 ), message1, "foo[key].bar"
);
+ assertMessageAndPath( messageAndPathList.get( 1 ), message2, "" );
+ }
+
+ private ConstraintValidatorContextImpl createEmptyConstraintValidatorContextImpl() {
+ ConstraintValidatorContextImpl context = new ConstraintValidatorContextImpl(
+ PathImpl.createNewPath( null ), null
+ );
+ context.disableDefaultConstraintViolation();
+ return context;
+ }
+
+ private void assertMessageAndPath(MessageAndPath messageAndPath, String expectedMessage,
String expectedPath) {
+ assertEquals( messageAndPath.getPath(), PathImpl.createPathFromString( expectedPath ),
"Wrong path" );
+ assertEquals( messageAndPath.getMessage(), expectedMessage, "Wrong message"
);
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ConstraintValidatorContextTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Coordinate.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Coordinate.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Coordinate.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Coordinate.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,35 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+/**
+ * @author Hardy Ferentschik
+ */
+/**
+ * @author Hardy Ferentschik
+ */
+public class Coordinate {
+
+ long longitude;
+ long latitude;
+
+ public Coordinate(long longitude, long latitude) {
+ this.longitude = longitude;
+ this.latitude = latitude;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Coordinate.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Elevator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Elevator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Elevator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Elevator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import org.hibernate.validator.constraints.Range;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Elevator {
+
+ @Range(min = -2, max = 50, message = "Invalid floor")
+ private int currentFloor;
+
+ public int getCurrentFloor() {
+ return currentFloor;
+ }
+
+ public void setCurrentFloor(int currentFloor) {
+ this.currentFloor = currentFloor;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Elevator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Interval.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Interval.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Interval.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Interval.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,28 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@StartLessThanEnd
+class Interval
+{
+ int start;
+ int end;
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Interval.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Item.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Item.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Item.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Item.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,28 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+class Item {
+ @Valid
+ Interval interval;
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Item.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Object.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Object.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Object.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Object.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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;
+import javax.validation.Payload;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { ObjectConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Object {
+ String message() default
"{org.hibernate.validator.constraints.Object.message}";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Object.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ObjectConstraintValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/ObjectConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ObjectConstraintValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ObjectConstraintValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ObjectConstraintValidator implements
ConstraintValidator<org.hibernate.validator.test.constraints.Object,
java.lang.Object> {
+
+ public void initialize(org.hibernate.validator.test.constraints.Object annotation) {
+ }
+
+ public boolean isValid(java.lang.Object value, ConstraintValidatorContext
constraintValidatorContext) {
+ return true;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ObjectConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/PostCodeList.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/PostCodeList.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/PostCodeList.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/PostCodeList.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,72 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.util.Collection;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * A test constraint which can lead to a error when trying to reslove the validator.
+ *
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = {
+ PostCodeList.PostCodeListValidatorForString.class,
PostCodeList.PostCodeListValidatorForNumber.class
+})
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface PostCodeList {
+ public abstract String message() default "foobar";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default {};
+
+ public class PostCodeListValidatorForNumber
+ implements ConstraintValidator<PostCodeList, Collection<? extends Number>>
{
+ public void initialize(PostCodeList constraintAnnotation) {
+ }
+
+ public boolean isValid(Collection<? extends Number> value,
ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+ }
+
+ public class PostCodeListValidatorForString implements
ConstraintValidator<PostCodeList, Collection<String>> {
+ public void initialize(PostCodeList constraintAnnotation) {
+ }
+
+ public boolean isValid(Collection<String> value, ConstraintValidatorContext
constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ return false;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/PostCodeList.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Serializable.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Serializable.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Serializable.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Serializable.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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;
+import javax.validation.Payload;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { SerializableConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Serializable {
+ public abstract String message() default
"{org.hibernate.validator.constraints.Serializable.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Serializable.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SerializableConstraintValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/SerializableConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SerializableConstraintValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SerializableConstraintValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SerializableConstraintValidator implements
ConstraintValidator<Serializable, java.io.Serializable > {
+
+ public void initialize(Serializable annotation) {
+ }
+
+ public boolean isValid( java.io.Serializable value, ConstraintValidatorContext
constraintValidatorContext) {
+ return true;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SerializableConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEnd.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/StartLessThanEnd.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEnd.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEnd.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,41 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+@Constraint(validatedBy = StartLessThanEndImpl.class)
+public @interface StartLessThanEnd {
+ String message() default "x";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEnd.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEndImpl.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/StartLessThanEndImpl.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEndImpl.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEndImpl.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class StartLessThanEndImpl implements ConstraintValidator<StartLessThanEnd,
Interval> {
+
+ public void initialize(StartLessThanEnd constraintAnnotation) {
+ }
+
+ public boolean isValid(Interval value, ConstraintValidatorContext c) {
+ if ( value.start > value.end ) {
+ c.disableDefaultConstraintViolation();
+ c.buildConstraintViolationWithTemplate( c.getDefaultConstraintMessageTemplate()
).addNode( "start" ).addConstraintViolation();
+ return false;
+ }
+ return true;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/StartLessThanEndImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SubType.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/SubType.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SubType.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SubType.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SubType extends SuperType {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SubType.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Suburb.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/Suburb.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Suburb.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Suburb.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,96 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Suburb {
+ public enum Facility {
+ SHOPPING_MALL, BUS_TERMINAL
+ }
+
+ @Size(min = 5, max = 10, message = "size must be between {min} and {max}")
+ private String name;
+
+ @Size(min = 2, max = 2, message = "size must be between {min} and {max}")
+ private Map<Facility, Boolean> facilities;
+
+ @Size(min = 2, message = "size must be between {min} and {max}")
+ private Set<String> streetNames;
+
+ @Size(min = 4, max = 1000, message = "size must be between {min} and {max}")
+ private Coordinate[] boundingBox;
+
+ @PostCodeList
+ private Collection<? extends Number> includedPostCodes;
+
+ public void setIncludedPostCodes(Collection<? extends Number> includedPostCodes)
{
+ this.includedPostCodes = includedPostCodes;
+ }
+
+ public Collection<? extends Number> getIncludedPostcodes() {
+ return includedPostCodes;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Map<Facility, Boolean> getFacilities() {
+ return facilities;
+ }
+
+ public void addFacility(Facility f, Boolean exist) {
+ if ( facilities == null ) {
+ facilities = new HashMap<Facility, Boolean>();
+ }
+ facilities.put( f, exist );
+ }
+
+ public Set<String> getStreetNames() {
+ return streetNames;
+ }
+
+ public void addStreetName(String streetName) {
+ if ( streetNames == null ) {
+ streetNames = new HashSet<String>();
+ }
+ streetNames.add( streetName );
+ }
+
+ public Coordinate[] getBoundingBox() {
+ return boundingBox;
+ }
+
+ public void setBoundingBox(Coordinate[] boundingBox) {
+ this.boundingBox = boundingBox;
+ }
+}
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/Suburb.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperType.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/SuperType.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperType.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperType.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SuperType {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperType.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArray.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/SuperTypeArray.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArray.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArray.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+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;
+import javax.validation.Payload;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = { SuperTypeArrayValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface SuperTypeArray {
+ public abstract String message() default
"{org.hibernate.validator.constraints.SuperTypeArray.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArray.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArrayValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/SuperTypeArrayValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArrayValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArrayValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SuperTypeArrayValidator implements ConstraintValidator<SuperTypeArray,
SuperType[]> {
+
+ public void initialize(SuperTypeArray annotation) {
+ }
+
+ public boolean isValid(SuperType[] value, ConstraintValidatorContext
constraintValidatorContext) {
+ return true;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/SuperTypeArrayValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ValidatorResolutionTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/ValidatorResolutionTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ValidatorResolutionTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ValidatorResolutionTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,213 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints;
+
+import java.lang.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+import static org.hibernate.validator.test.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ValidatorResolutionTest {
+
+ @Test
+ public void testResolutionOfMultipleSizeValidators() {
+ Validator validator = TestUtil.getValidator();
+
+ Suburb suburb = new Suburb();
+
+ List<Integer> postcodes = new ArrayList<Integer>();
+ postcodes.add( 12345 );
+ suburb.setIncludedPostCodes( postcodes );
+
+ // all values are null and should pass
+ Set<ConstraintViolation<Suburb>> constraintViolations = validator.validate(
suburb );
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ suburb.setName( "" );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), "size must be between 5 and 10",
Suburb.class, "", "name"
+ );
+
+ suburb.setName( "Hoegsbo" );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ suburb.addFacility( Suburb.Facility.SHOPPING_MALL, false );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ "size must be between 2 and 2",
+ Suburb.class,
+ suburb.getFacilities(),
+ "facilities"
+ );
+
+ suburb.addFacility( Suburb.Facility.BUS_TERMINAL, true );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ suburb.addStreetName( "Sikelsgatan" );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ "size must be between 2 and 2147483647",
+ Suburb.class,
+ suburb.getStreetNames(),
+ "streetNames"
+ );
+
+ suburb.addStreetName( "Marklandsgatan" );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 0 );
+
+ Coordinate[] boundingBox = new Coordinate[3];
+ boundingBox[0] = new Coordinate( 0l, 0l );
+ boundingBox[1] = new Coordinate( 0l, 1l );
+ boundingBox[2] = new Coordinate( 1l, 0l );
+ suburb.setBoundingBox( boundingBox );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ "size must be between 4 and 1000",
+ Suburb.class,
+ suburb.getBoundingBox(),
+ "boundingBox"
+ );
+
+ boundingBox = new Coordinate[4];
+ boundingBox[0] = new Coordinate( 0l, 0l );
+ boundingBox[1] = new Coordinate( 0l, 1l );
+ boundingBox[2] = new Coordinate( 1l, 0l );
+ boundingBox[3] = new Coordinate( 1l, 1l );
+ suburb.setBoundingBox( boundingBox );
+ constraintViolations = validator.validate( suburb );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ /**
+ * HV-233
+ */
+ @Test
+ public void testObjectArraysAndPrimitiveArraysAreSubtypesOfObject() {
+ Validator validator = TestUtil.getValidator();
+
+ Foo testEntity = new Foo( new org.hibernate.validator.test.constraints.Object[] { },
new int[] { } );
+ Set<ConstraintViolation<Foo>> constraintViolations = validator.validate(
testEntity );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ /**
+ * HV-233
+ */
+ @Test
+ public void testObjectArraysAndPrimitiveArraysAreSubtypesOfClonable() {
+ Validator validator = TestUtil.getValidator();
+
+ Bar testEntity = new Bar( new org.hibernate.validator.test.constraints.Object[] { },
new int[] { } );
+ Set<ConstraintViolation<Bar>> constraintViolations = validator.validate(
testEntity );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ /**
+ * HV-233
+ */
+ @Test
+ public void testObjectArraysAndPrimitiveArraysAreSubtypesOfSerializable() {
+ Validator validator = TestUtil.getValidator();
+
+ Fubar testEntity = new Fubar( new org.hibernate.validator.test.constraints.Object[] {
}, new int[] { } );
+ Set<ConstraintViolation<Fubar>> constraintViolations = validator.validate(
testEntity );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ /**
+ * HV-233
+ */
+ @Test
+ public void testSubTypeArrayIsSubtypeOfSuperTypeArray() {
+ Validator validator = TestUtil.getValidator();
+
+ SubTypeEntity testEntity = new SubTypeEntity( new SubType[] { } );
+ Set<ConstraintViolation<SubTypeEntity>> constraintViolations =
validator.validate( testEntity );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ public class Foo {
+ @org.hibernate.validator.test.constraints.Object
+ private org.hibernate.validator.test.constraints.Object[] objectArray;
+
+ @org.hibernate.validator.test.constraints.Object
+ private int[] intArray;
+
+ public Foo(org.hibernate.validator.test.constraints.Object[] objectArray, int[]
intArray) {
+ this.objectArray = objectArray;
+ this.intArray = intArray;
+ }
+ }
+
+ public class Bar {
+ @org.hibernate.validator.test.constraints.Cloneable
+ private org.hibernate.validator.test.constraints.Object[] objectArray;
+
+ @org.hibernate.validator.test.constraints.Cloneable
+ private int[] intArray;
+
+ public Bar(org.hibernate.validator.test.constraints.Object[] objectArray, int[]
intArray) {
+ this.objectArray = objectArray;
+ this.intArray = intArray;
+ }
+ }
+
+ public class Fubar {
+ @Serializable
+ private org.hibernate.validator.test.constraints.Object[] objectArray;
+
+ @Serializable
+ private int[] intArray;
+
+ public Fubar(org.hibernate.validator.test.constraints.Object[] objectArray, int[]
intArray) {
+ this.objectArray = objectArray;
+ this.intArray = intArray;
+ }
+ }
+
+ public class SubTypeEntity {
+ @SuperTypeArray
+ private SubType[] subTypeArray;
+
+ public SubTypeEntity(SubType[] subTypeArray) {
+ this.subTypeArray = subTypeArray;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/ValidatorResolutionTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/CompositeConstraintTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/composition/CompositeConstraintTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/CompositeConstraintTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/CompositeConstraintTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,101 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.composition;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+import static org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintTypes;
+import static
org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Gerhard Petracek
+ * @author Hardy Ferentschik
+ */
+public class CompositeConstraintTest {
+
+ /**
+ * HV-182
+ */
+ @Test
+ public void testCorrectAnnotationTypeForWithReportAsSingleViolation() {
+
+ Validator currentValidator = TestUtil.getValidator();
+
+ for ( int i = 0; i < 100; i++ ) {
+ Set<ConstraintViolation<Person>> constraintViolations =
currentValidator.validate(
+ new Person(
+ null, "Gerhard"
+ )
+ );
+
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, ValidNameSingleViolation.class );
+ assertCorrectConstraintViolationMessages( constraintViolations, "invalid
name" );
+
+ constraintViolations = currentValidator.validate(
+ new Person(
+ "G", "Gerhard"
+ )
+ );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, ValidNameSingleViolation.class );
+ assertCorrectConstraintViolationMessages( constraintViolations, "invalid
name" );
+ }
+ }
+
+ /**
+ * HV-182
+ */
+ @Test
+ public void testCorrectAnnotationTypeReportMultipleViolations() {
+
+ Validator currentValidator = TestUtil.getValidator();
+
+ for ( int i = 0; i < 100; i++ ) {
+ Set<ConstraintViolation<Person>> constraintViolations =
currentValidator.validate(
+ new Person(
+ "Gerd", null
+ )
+ );
+
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+ assertCorrectConstraintViolationMessages( constraintViolations, "may not be
null" );
+
+ constraintViolations = currentValidator.validate(
+ new Person(
+ "Gerd", "G"
+ )
+ );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, Size.class );
+ assertCorrectConstraintViolationMessages( constraintViolations, "size must be
between 2 and 10" );
+ }
+ }
+}
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/CompositeConstraintTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/Person.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/composition/Person.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/Person.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/Person.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,54 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.composition;
+
+/**
+ * Test mode for HV-182.
+ *
+ * @author Gerhard Petracek
+ * @author Hardy Ferentschik
+ */
+
+public class Person {
+ @ValidNameSingleViolation
+ private String nickName;
+
+ @ValidName
+ private String name;
+
+ public Person(String nickName, String name) {
+ this.nickName = nickName;
+ this.name = name;
+ }
+
+ public String getNickName() {
+ return nickName;
+ }
+
+ public void setNickName(String nickName) {
+ this.nickName = nickName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidName.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/composition/ValidName.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidName.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidName.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.composition;
+
+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;
+import javax.validation.Payload;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Test constraint for HV-182.
+ *
+ * @author Gerhard Petracek
+ * @author Hardy Ferentschik
+ */
+@NotNull
+@Size(min = 2, max = 10)
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+@Constraint(validatedBy = { })
+public @interface ValidName {
+ public abstract String message() default "invalid name";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidName.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidNameSingleViolation.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/composition/ValidNameSingleViolation.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidNameSingleViolation.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidNameSingleViolation.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,49 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.composition;
+
+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;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Test constraint for HV-182.
+ *
+ * @author Gerhard Petracek
+ * @author Hardy Ferentschik
+ */
+@NotNull
+@Size(min = 2, max = 10)
+@ReportAsSingleViolation
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+@Constraint(validatedBy = { })
+public @interface ValidNameSingleViolation {
+ String message() default "invalid name";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/composition/ValidNameSingleViolation.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertFalseValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/AssertFalseValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertFalseValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertFalseValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,47 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.AssertFalseValidator;
+
+/**
+ * @author Alaa Nassef
+ */
+public class AssertFalseValidatorTest {
+
+ private static AssertFalseValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new AssertFalseValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( false, null ) );
+ assertTrue( constraint.isValid( Boolean.FALSE, null ) );
+ assertFalse( constraint.isValid( true, null ) );
+ assertFalse( constraint.isValid( Boolean.TRUE, null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertFalseValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertTrueValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/AssertTrueValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertTrueValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertTrueValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.AssertTrueValidator;
+
+/**
+ * @author Alaa Nassef
+ */
+public class AssertTrueValidatorTest {
+
+ private static AssertTrueValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new AssertTrueValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( true, null ) );
+ assertTrue( constraint.isValid( Boolean.TRUE, null ) );
+ assertFalse( constraint.isValid( false, null ) );
+ assertFalse( constraint.isValid( Boolean.FALSE, null ) );
+ }
+}
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/AssertTrueValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/BlankValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/BlankValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/BlankValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/BlankValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,84 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.NotBlank;
+import org.hibernate.validator.constraints.impl.NotBlankValidator;
+
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+import static org.hibernate.validator.test.util.TestUtil.getValidator;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class BlankValidatorTest {
+ @Test
+ public void testConstraintValidator() {
+ NotBlankValidator constraintValidator = new NotBlankValidator();
+
+ assertTrue( constraintValidator.isValid( "a", null ) );
+ assertTrue( constraintValidator.isValid( null, null ) );
+ assertFalse( constraintValidator.isValid( "", null ) );
+ assertFalse( constraintValidator.isValid( " ", null ) );
+ assertFalse( constraintValidator.isValid( "\t", null ) );
+ assertFalse( constraintValidator.isValid( "\n", null ) );
+ }
+
+ @Test
+ public void testNotBlank() {
+ Validator validator = getValidator();
+ Foo foo = new Foo();
+
+ Set<ConstraintViolation<Foo>> constraintViolations = validator.validate(
foo );
+ assertNumberOfViolations( constraintViolations, 1 );
+
+ foo.name = "";
+ constraintViolations = validator.validate( foo );
+ assertNumberOfViolations( constraintViolations, 1 );
+
+ foo.name = " ";
+ constraintViolations = validator.validate( foo );
+ assertNumberOfViolations( constraintViolations, 1 );
+
+ foo.name = "\t";
+ constraintViolations = validator.validate( foo );
+ assertNumberOfViolations( constraintViolations, 1 );
+
+ foo.name = "\n";
+ constraintViolations = validator.validate( foo );
+ assertNumberOfViolations( constraintViolations, 1 );
+
+ foo.name = "john doe";
+ constraintViolations = validator.validate( foo );
+ assertNumberOfViolations( constraintViolations, 0 );
+ }
+
+ class Foo {
+ @NotBlank
+ String name;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/BlankValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/CreditCardNumberValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/CreditCardNumberValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/CreditCardNumberValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/CreditCardNumberValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,54 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.CreditCardNumberValidator;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CreditCardNumberValidatorTest {
+
+ private static CreditCardNumberValidator validator;
+
+ @BeforeClass
+ public static void init() {
+ validator = new CreditCardNumberValidator();
+ }
+
+ @Test
+ public void testInvalidCreditCardNumber() throws Exception {
+ assertFalse( validator.isValid( "1234567890123456", null ) );
+ }
+
+ @Test
+ public void testValidCreditCardNumber() throws Exception {
+ assertTrue( validator.isValid( "541234567890125", null ) );
+ }
+
+ @Test
+ public void testNullValue() throws Exception {
+ assertTrue( validator.isValid( null, null ) );
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/CreditCardNumberValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DateHolder.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/DateHolder.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DateHolder.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DateHolder.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,67 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Calendar;
+import java.util.Date;
+import javax.validation.constraints.Future;
+import javax.validation.constraints.Past;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class DateHolder {
+
+ @Past
+ private Calendar calendarWithPastDate;
+
+ @Future
+ private Calendar calendarWithFutureDate;
+
+ @Past
+ private Date past;
+
+ @Past
+ private Date future;
+
+ public DateHolder() {
+ calendarWithPastDate = Calendar.getInstance();
+ calendarWithPastDate.add( Calendar.YEAR, -1 );
+ past = calendarWithPastDate.getTime();
+
+ calendarWithFutureDate = Calendar.getInstance();
+ calendarWithFutureDate.add( Calendar.YEAR, 1 );
+ future = calendarWithFutureDate.getTime();
+ }
+
+ public Calendar getCalendarWithPastDate() {
+ return calendarWithPastDate;
+ }
+
+ public Calendar getCalendarWithFutureDate() {
+ return calendarWithFutureDate;
+ }
+
+ public Date getPast() {
+ return past;
+ }
+
+ public Date getFuture() {
+ return future;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DateHolder.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForNumberTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/DigitsValidatorForNumberTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForNumberTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForNumberTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,125 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.math.BigDecimal;
+import javax.validation.constraints.Digits;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DigitsValidatorForNumber;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class DigitsValidatorForNumberTest {
+
+ @Test
+ public void testIsValid() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 5 );
+ descriptor.setValue( "fraction", 2 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
+ constraint.initialize( p );
+
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( Byte.valueOf( "0" ), null ) );
+ assertTrue( constraint.isValid( Double.valueOf( "500.2" ), null ) );
+
+ assertTrue( constraint.isValid( new BigDecimal( "-12345.12" ), null ) );
+ assertFalse( constraint.isValid( new BigDecimal( "-123456.12" ), null ) );
+ assertFalse( constraint.isValid( new BigDecimal( "-123456.123" ), null ) );
+ assertFalse( constraint.isValid( new BigDecimal( "-12345.123" ), null ) );
+ assertFalse( constraint.isValid( new BigDecimal( "12345.123" ), null ) );
+
+ assertTrue( constraint.isValid( Float.valueOf( "-000000000.22" ), null ) );
+ assertFalse( constraint.isValid( Integer.valueOf( "256874" ), null ) );
+ assertFalse( constraint.isValid( Double.valueOf( "12.0001" ), null ) );
+ }
+
+ @Test
+ public void testIsValidZeroLength() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 0 );
+ descriptor.setValue( "fraction", 0 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
+ constraint.initialize( p );
+
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( Byte.valueOf( "0" ), null ) );
+ assertFalse( constraint.isValid( Double.valueOf( "500.2" ), null ) );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeIntegerLength() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", -1 );
+ descriptor.setValue( "fraction", 1 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
+ constraint.initialize( p );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeFractionLength() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 1 );
+ descriptor.setValue( "fraction", -1 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
+ constraint.initialize( p );
+ }
+
+ @Test
+ public void testTrailingZerosAreTrimmed() {
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 12 );
+ descriptor.setValue( "fraction", 3 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
+ constraint.initialize( p );
+
+ assertTrue( constraint.isValid( 0.001d, null ) );
+ assertTrue( constraint.isValid( 0.00100d, null ) );
+ assertFalse( constraint.isValid( 0.0001d, null ) );
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForNumberTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForStringTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/DigitsValidatorForStringTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForStringTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForStringTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,90 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import javax.validation.constraints.Digits;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DigitsValidatorForString;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ */
+public class DigitsValidatorForStringTest {
+
+ private static DigitsValidatorForString constraint;
+
+ @BeforeClass
+ public static void init() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 5 );
+ descriptor.setValue( "fraction", 2 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ constraint = new DigitsValidatorForString();
+ constraint.initialize( p );
+ }
+
+ @Test
+ public void testIsValid() {
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "0", null ) );
+ assertTrue( constraint.isValid( "500.2", null ) );
+ assertTrue( constraint.isValid( "-12456.22", null ) );
+ assertTrue( constraint.isValid( "-000000000.22", null ) );
+ //should throw number format exception
+ assertFalse( constraint.isValid( "", null ) );
+ assertFalse( constraint.isValid( "256874.0", null ) );
+ assertFalse( constraint.isValid( "12.0001", null ) );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeIntegerLength() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", -1 );
+ descriptor.setValue( "fraction", 1 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForString constraint = new DigitsValidatorForString();
+ constraint.initialize( p );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeFractionLength() {
+
+ AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>(
Digits.class );
+ descriptor.setValue( "integer", 1 );
+ descriptor.setValue( "fraction", -1 );
+ descriptor.setValue( "message", "{validator.digits}" );
+ Digits p = AnnotationFactory.create( descriptor );
+
+ DigitsValidatorForString constraint = new DigitsValidatorForString();
+ constraint.initialize( p );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/DigitsValidatorForStringTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/EmailValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/EmailValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/EmailValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/EmailValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,64 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.EmailValidator;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class EmailValidatorTest {
+
+ private static EmailValidator validator;
+
+ @BeforeClass
+ public static void init() {
+ validator = new EmailValidator();
+ }
+
+ @Test
+ public void testEmail() throws Exception {
+ isRightEmail( "emmanuel(a)hibernate.org" );
+ isRightEmail( "" );
+ isRightEmail( null );
+ isRightEmail( "emmanuel@hibernate" );
+ isRightEmail( "emma-n_uel@hibernate" );
+ isRightEmail( "emma+nuel(a)hibernate.org" );
+ isRightEmail( "emma=nuel(a)hibernate.org" );
+ isRightEmail( "emmanuel(a)[123.12.2.11]" );
+ isWrongEmail( "emmanuel.hibernate.org" );
+ isWrongEmail( "emma nuel(a)hibernate.org" );
+ isWrongEmail( "emma(nuel(a)hibernate.org" );
+ isWrongEmail( "emmanuel@" );
+ isWrongEmail( "emma\nnuel(a)hibernate.org" );
+ isWrongEmail( "emma@nuel(a)hibernate.org" );
+ }
+
+ private void isRightEmail(String email) {
+ assertTrue( validator.isValid( email, null ), "Expected a valid email." );
+ }
+
+ private void isWrongEmail(String email) {
+ assertFalse( validator.isValid( email, null ), "Expected a invalid email."
);
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/EmailValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForCalendarTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/FutureValidatorForCalendarTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForCalendarTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForCalendarTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,65 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Calendar;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.FutureValidatorForCalendar;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class FutureValidatorForCalendarTest {
+
+ private static FutureValidatorForCalendar constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new FutureValidatorForCalendar();
+ }
+
+ @Test
+ public void testIsValid() {
+ Calendar futureDate = getFutureDate();
+ Calendar pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( futureDate, null ) );
+ assertFalse( constraint.isValid( pastDate, null ) );
+ }
+
+ private Calendar getFutureDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year + 1 );
+ return cal;
+ }
+
+ private Calendar getPastDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year - 1 );
+ return cal;
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForCalendarTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForDateTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/FutureValidatorForDateTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForDateTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForDateTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,62 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Date;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.FutureValidatorForDate;
+
+public class FutureValidatorForDateTest {
+
+ private static FutureValidatorForDate constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new FutureValidatorForDate();
+ }
+
+ @Test
+ public void testIsValid() {
+ Date futureDate = getFutureDate();
+ Date pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( futureDate, null ) );
+ assertFalse( constraint.isValid( new Date(), null ) );
+ assertFalse( constraint.isValid( pastDate, null ) );
+ }
+
+ private Date getFutureDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp + 31557600000l );
+ return date;
+ }
+
+ private Date getPastDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp - 31557600000l );
+ return date;
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorForDateTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/FutureValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class FutureValidatorTest {
+
+ /**
+ * HV-158
+ */
+ @Test
+ public void testFutureAndPast() {
+ Validator validator = TestUtil.getValidator();
+ DateHolder dateHolder = new DateHolder();
+ Set<ConstraintViolation<DateHolder>> constraintViolations =
validator.validate( dateHolder );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/FutureValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/LengthValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/LengthValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/LengthValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/LengthValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,88 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.Length;
+import org.hibernate.validator.constraints.impl.LengthValidator;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * Tests the <code>LengthConstraint</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class LengthValidatorTest {
+
+ @Test
+ public void testIsValid() {
+ AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>(
Length.class );
+ descriptor.setValue( "min", 1 );
+ descriptor.setValue( "max", 3 );
+ descriptor.setValue( "message", "{validator.length}" );
+ Length l = AnnotationFactory.create( descriptor );
+ LengthValidator constraint = new LengthValidator();
+ constraint.initialize( l );
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( "", null ) );
+ assertTrue( constraint.isValid( "f", null ) );
+ assertTrue( constraint.isValid( "fo", null ) );
+ assertTrue( constraint.isValid( "foo", null ) );
+ assertFalse( constraint.isValid( "foobar", null ) );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeMinValue() {
+ AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>(
Length.class );
+ descriptor.setValue( "min", -1 );
+ descriptor.setValue( "max", 1 );
+ descriptor.setValue( "message", "{validator.length}" );
+ Length p = AnnotationFactory.create( descriptor );
+
+ LengthValidator constraint = new LengthValidator();
+ constraint.initialize( p );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeMaxValue() {
+ AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>(
Length.class );
+ descriptor.setValue( "min", 1 );
+ descriptor.setValue( "max", -1 );
+ descriptor.setValue( "message", "{validator.length}" );
+ Length p = AnnotationFactory.create( descriptor );
+
+ LengthValidator constraint = new LengthValidator();
+ constraint.initialize( p );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeLength() {
+ AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>(
Length.class );
+ descriptor.setValue( "min", 5 );
+ descriptor.setValue( "max", 4 );
+ descriptor.setValue( "message", "{validator.length}" );
+ Length p = AnnotationFactory.create( descriptor );
+
+ LengthValidator constraint = new LengthValidator();
+ constraint.initialize( p );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/LengthValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForNumberTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/MaxValidatorForNumberTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForNumberTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForNumberTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,104 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.Max;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DecimalMaxValidatorForNumber;
+import org.hibernate.validator.constraints.impl.MaxValidatorForNumber;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class MaxValidatorForNumberTest {
+
+ @Test
+ public void testIsValidMax() {
+
+ AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>(
Max.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.max}" );
+ Max m = AnnotationFactory.create( descriptor );
+
+ MaxValidatorForNumber constraint = new MaxValidatorForNumber();
+ constraint.initialize( m );
+ testMaxValidator( constraint );
+ }
+
+ @Test
+ public void testIsValidDecimalMax() {
+
+ AnnotationDescriptor<DecimalMax> descriptor = new
AnnotationDescriptor<DecimalMax>( DecimalMax.class );
+ descriptor.setValue( "value", "15.0E0" );
+ descriptor.setValue( "message", "{validator.max}" );
+ DecimalMax m = AnnotationFactory.create( descriptor );
+
+ DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
+ constraint.initialize( m );
+ testMaxValidator( constraint );
+ }
+
+ @Test
+ public void testInitializeDecimalMaxWithInvalidValue() {
+
+ AnnotationDescriptor<DecimalMax> descriptor = new
AnnotationDescriptor<DecimalMax>( DecimalMax.class );
+ descriptor.setValue( "value", "foobar" );
+ descriptor.setValue( "message", "{validator.max}" );
+ DecimalMax m = AnnotationFactory.create( descriptor );
+
+ DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
+ try {
+ constraint.initialize( m );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ private void testMaxValidator(ConstraintValidator<?, Number> constraint) {
+ byte b = 1;
+ Byte bWrapper = 127;
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( b, null ) );
+ assertTrue( constraint.isValid( 15l, null ) );
+ assertTrue( constraint.isValid( 15, null ) );
+ assertTrue( constraint.isValid( 15.0, null ) );
+ assertTrue( constraint.isValid( BigDecimal.valueOf( -156000000000.0 ), null ) );
+ assertTrue( constraint.isValid( BigInteger.valueOf( -10000000l ), null ) );
+ assertTrue( constraint.isValid( 10, null ) );
+ assertTrue( constraint.isValid( 14.99, null ) );
+ assertTrue( constraint.isValid( -14.99, null ) );
+ assertFalse( constraint.isValid( 20, null ) );
+ assertFalse( constraint.isValid( bWrapper, null ) );
+ assertFalse( constraint.isValid( BigDecimal.valueOf( 156000000000.0 ), null ) );
+ assertFalse( constraint.isValid( BigInteger.valueOf( 10000000l ), null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForNumberTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForStringTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/MaxValidatorForStringTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForStringTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForStringTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,95 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.Max;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DecimalMaxValidatorForNumber;
+import org.hibernate.validator.constraints.impl.DecimalMaxValidatorForString;
+import org.hibernate.validator.constraints.impl.MaxValidatorForString;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MaxValidatorForStringTest {
+
+ @Test
+ public void testIsValidMax() {
+
+ AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>(
Max.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.max}" );
+ Max m = AnnotationFactory.create( descriptor );
+
+ MaxValidatorForString constraint = new MaxValidatorForString();
+ constraint.initialize( m );
+ testMaxValidator( constraint );
+ }
+
+ @Test
+ public void testIsValidDecimalMax() {
+
+ AnnotationDescriptor<DecimalMax> descriptor = new
AnnotationDescriptor<DecimalMax>( DecimalMax.class );
+ descriptor.setValue( "value", "15.0E0" );
+ descriptor.setValue( "message", "{validator.max}" );
+ DecimalMax m = AnnotationFactory.create( descriptor );
+
+ DecimalMaxValidatorForString constraint = new DecimalMaxValidatorForString();
+ constraint.initialize( m );
+ testMaxValidator( constraint );
+ }
+
+ @Test
+ public void testInitializeDecimalMaxWithInvalidValue() {
+
+ AnnotationDescriptor<DecimalMax> descriptor = new
AnnotationDescriptor<DecimalMax>( DecimalMax.class );
+ descriptor.setValue( "value", "foobar" );
+ descriptor.setValue( "message", "{validator.max}" );
+ DecimalMax m = AnnotationFactory.create( descriptor );
+
+ DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
+ try {
+ constraint.initialize( m );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ private void testMaxValidator(ConstraintValidator<?, String> constraint) {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "15", null ) );
+ assertTrue( constraint.isValid( "15.0", null ) );
+ assertTrue( constraint.isValid( "10", null ) );
+ assertTrue( constraint.isValid( "14.99", null ) );
+ assertTrue( constraint.isValid( "-14.99", null ) );
+ assertFalse( constraint.isValid( "20", null ) );
+ //number format exception
+ assertFalse( constraint.isValid( "15l", null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MaxValidatorForStringTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForNumberTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/MinValidatorForNumberTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForNumberTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForNumberTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,102 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Min;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DecimalMinValidatorForNumber;
+import org.hibernate.validator.constraints.impl.MinValidatorForNumber;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class MinValidatorForNumberTest {
+
+ @Test
+ public void testIsValidMinValidator() {
+ AnnotationDescriptor<Min> descriptor = new AnnotationDescriptor<Min>(
Min.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.min}" );
+ Min m = AnnotationFactory.create( descriptor );
+
+ MinValidatorForNumber constraint = new MinValidatorForNumber();
+ constraint.initialize( m );
+ testMinValidator( constraint );
+ }
+
+ @Test
+ public void testIsValidDecimalMinValidator() {
+ AnnotationDescriptor<DecimalMin> descriptor = new
AnnotationDescriptor<DecimalMin>( DecimalMin.class );
+ descriptor.setValue( "value", "1500E-2" );
+ descriptor.setValue( "message", "{validator.min}" );
+ DecimalMin m = AnnotationFactory.create( descriptor );
+
+ DecimalMinValidatorForNumber constraint = new DecimalMinValidatorForNumber();
+ constraint.initialize( m );
+ testMinValidator( constraint );
+ }
+
+ @Test
+ public void testInitializeDecimalMaxWithInvalidValue() {
+
+ AnnotationDescriptor<DecimalMin> descriptor = new
AnnotationDescriptor<DecimalMin>( DecimalMin.class );
+ descriptor.setValue( "value", "foobar" );
+ descriptor.setValue( "message", "{validator.min}" );
+ DecimalMin m = AnnotationFactory.create( descriptor );
+
+ DecimalMinValidatorForNumber constraint = new DecimalMinValidatorForNumber();
+ try {
+ constraint.initialize( m );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ private void testMinValidator(ConstraintValidator<?, Number> constraint) {
+ byte b = 1;
+ Byte bWrapper = 127;
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( bWrapper, null ) );
+ assertTrue( constraint.isValid( 20, null ) );
+ assertTrue( constraint.isValid( 15l, null ) );
+ assertTrue( constraint.isValid( 15, null ) );
+ assertTrue( constraint.isValid( 15.0, null ) );
+ assertTrue( constraint.isValid( BigDecimal.valueOf( 156000000000.0 ), null ) );
+ assertTrue( constraint.isValid( BigInteger.valueOf( 10000000l ), null ) );
+ assertFalse( constraint.isValid( b, null ) );
+ assertFalse( constraint.isValid( BigDecimal.valueOf( -156000000000.0 ), null ) );
+ assertFalse( constraint.isValid( BigInteger.valueOf( -10000000l ), null ) );
+ assertFalse( constraint.isValid( 10, null ) );
+ assertFalse( constraint.isValid( 14.99, null ) );
+ assertFalse( constraint.isValid( -14.99, null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForNumberTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForStringTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/MinValidatorForStringTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForStringTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForStringTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,94 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Min;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.DecimalMinValidatorForNumber;
+import org.hibernate.validator.constraints.impl.DecimalMinValidatorForString;
+import org.hibernate.validator.constraints.impl.MinValidatorForString;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class MinValidatorForStringTest {
+
+ @Test
+ public void testIsValidMinValidator() {
+ AnnotationDescriptor<Min> descriptor = new AnnotationDescriptor<Min>(
Min.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.min}" );
+ Min m = AnnotationFactory.create( descriptor );
+
+ MinValidatorForString constraint = new MinValidatorForString();
+ constraint.initialize( m );
+ testMinValidator( constraint );
+ }
+
+ @Test
+ public void testIsValidDecimalMinValidator() {
+ AnnotationDescriptor<DecimalMin> descriptor = new
AnnotationDescriptor<DecimalMin>( DecimalMin.class );
+ descriptor.setValue( "value", "1500E-2" );
+ descriptor.setValue( "message", "{validator.min}" );
+ DecimalMin m = AnnotationFactory.create( descriptor );
+
+ DecimalMinValidatorForString constraint = new DecimalMinValidatorForString();
+ constraint.initialize( m );
+ testMinValidator( constraint );
+ }
+
+ @Test
+ public void testInitializeDecimalMaxWithInvalidValue() {
+
+ AnnotationDescriptor<DecimalMin> descriptor = new
AnnotationDescriptor<DecimalMin>( DecimalMin.class );
+ descriptor.setValue( "value", "foobar" );
+ descriptor.setValue( "message", "{validator.min}" );
+ DecimalMin m = AnnotationFactory.create( descriptor );
+
+ DecimalMinValidatorForNumber constraint = new DecimalMinValidatorForNumber();
+ try {
+ constraint.initialize( m );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ private void testMinValidator(ConstraintValidator<?, String> constraint) {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "20", null ) );
+ assertTrue( constraint.isValid( "15", null ) );
+ assertTrue( constraint.isValid( "15.0", null ) );
+ assertFalse( constraint.isValid( "10", null ) );
+ assertFalse( constraint.isValid( "14.99", null ) );
+ assertFalse( constraint.isValid( "-14.99", null ) );
+ //number format exception
+ assertFalse( constraint.isValid( "15l", null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/MinValidatorForStringTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NotNullValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/NotNullValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NotNullValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NotNullValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,38 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.NotNullValidator;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NotNullValidatorTest {
+
+ @Test
+ public void testIsValid() {
+ NotNullValidator constraint = new NotNullValidator();
+
+ assertFalse( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( new Object(), null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NotNullValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NullValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/NullValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NullValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NullValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.NullValidator;
+
+/**
+ * @author Alaa Nassef
+ */
+public class NullValidatorTest {
+
+ private static NullValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new NullValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( new Object(), null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/NullValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForCalendarTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/PastValidatorForCalendarTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForCalendarTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForCalendarTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,64 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Calendar;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.PastValidatorForCalendar;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class PastValidatorForCalendarTest {
+
+ private static PastValidatorForCalendar constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new PastValidatorForCalendar();
+ }
+
+ @Test
+ public void testIsValid() {
+ Calendar futureDate = getFutureDate();
+ Calendar pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( pastDate, null ) );
+ assertFalse( constraint.isValid( futureDate, null ) );
+ }
+
+ private Calendar getFutureDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year + 1 );
+ return cal;
+ }
+
+ private Calendar getPastDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year - 1 );
+ return cal;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForCalendarTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForDateTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/PastValidatorForDateTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForDateTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForDateTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,62 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Date;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.PastValidatorForDate;
+
+public class PastValidatorForDateTest {
+
+ private static PastValidatorForDate constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new PastValidatorForDate();
+ }
+
+ @Test
+ public void testIsValid() {
+ Date futureDate = getFutureDate();
+ Date pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( pastDate, null ) );
+ assertFalse( constraint.isValid( new Date(), null ) );
+ assertFalse( constraint.isValid( futureDate, null ) );
+ }
+
+ private Date getFutureDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp + 31557600000l );
+ return date;
+ }
+
+ private Date getPastDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp - 31557600000l );
+ return date;
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PastValidatorForDateTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PatternValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/PatternValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PatternValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PatternValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,78 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import javax.validation.constraints.Pattern;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.PatternValidator;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PatternValidatorTest {
+
+ @Test
+ public void testIsValid() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ descriptor.setValue( "regexp", "foobar" );
+ descriptor.setValue( "message", "pattern does not match" );
+ Pattern p = AnnotationFactory.create( descriptor );
+
+ PatternValidator constraint = new PatternValidator();
+ constraint.initialize( p );
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( "", null ) );
+ assertFalse( constraint.isValid( "bla bla", null ) );
+ assertFalse( constraint.isValid( "This test is not foobar", null ) );
+ }
+
+ @Test
+ public void testIsValidForEmptyStringRegexp() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ descriptor.setValue( "regexp", "|^.*foo$" );
+ descriptor.setValue( "message", "pattern does not match" );
+ Pattern p = AnnotationFactory.create( descriptor );
+
+ PatternValidator constraint = new PatternValidator();
+ constraint.initialize( p );
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "", null ) );
+ assertFalse( constraint.isValid( "bla bla", null ) );
+ assertTrue( constraint.isValid( "foo", null ) );
+ assertTrue( constraint.isValid( "a b c foo", null ) );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testInvalidRegularExpression() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ descriptor.setValue( "regexp", "(unbalanced parentheses" );
+ descriptor.setValue( "message", "pattern does not match" );
+ Pattern p = AnnotationFactory.create( descriptor );
+
+ PatternValidator constraint = new PatternValidator();
+ constraint.initialize( p );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/PatternValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/ScriptAssertValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/ScriptAssertValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/ScriptAssertValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/ScriptAssertValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,203 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+import javax.validation.ConstraintDeclarationException;
+import javax.validation.ConstraintValidator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.ScriptAssert;
+import org.hibernate.validator.constraints.impl.ScriptAssertValidator;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Unit test for {@link org.hibernate.validator.constraints.impl.ScriptAssertValidator}.
+ *
+ * @author Gunnar Morling
+ */
+public class ScriptAssertValidatorTest {
+
+ @Test
+ public void scriptEvaluatesToTrue() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
"javascript", "true" );
+
+ assertTrue( validator.isValid( new Object(), null ) );
+ }
+
+ @Test
+ public void scriptEvaluatesToFalse() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
"javascript", "false" );
+
+ assertFalse( validator.isValid( new Object(), null ) );
+ }
+
+ @Test
+ public void scriptExpressionReferencingAnnotatedObject() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
+ "javascript", "_this.startDate.before(_this.endDate)"
+ );
+
+ Date startDate = new GregorianCalendar( 2009, 8, 20 ).getTime();
+ Date endDate = new GregorianCalendar( 2009, 8, 21 ).getTime();
+
+ assertTrue( validator.isValid( new CalendarEvent( startDate, endDate ), null ) );
+ assertFalse( validator.isValid( new CalendarEvent( endDate, startDate ), null ) );
+ }
+
+ @Test
+ public void scriptExpressionUsingCustomizedAlias() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
+ "javascript", "_.startDate.before(_.endDate)", "_"
+ );
+
+ Date startDate = new GregorianCalendar( 2009, 8, 20 ).getTime();
+ Date endDate = new GregorianCalendar( 2009, 8, 21 ).getTime();
+
+ assertFalse( validator.isValid( new CalendarEvent( endDate, startDate ), null ) );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void emptyLanguageNameRaisesException() throws Exception {
+
+ getInitializedValidator( "", "script" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void emptyScriptRaisesException() throws Exception {
+
+ getInitializedValidator( "lang", "" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void emptyAliasRaisesException() throws Exception {
+
+ getInitializedValidator( "lang", "script", "" );
+ }
+
+ @Test(expectedExceptions = ConstraintDeclarationException.class)
+ public void unknownLanguageNameRaisesException() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
"foo", "script" );
+
+ validator.isValid( new Object(), null );
+ }
+
+ @Test(expectedExceptions = ConstraintDeclarationException.class)
+ public void illegalScriptExpressionRaisesException() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
"javascript", "foo" );
+
+ validator.isValid( new Object(), null );
+ }
+
+ @Test(expectedExceptions = ConstraintDeclarationException.class)
+ public void scriptExpressionReturningNullRaisesException() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
"javascript", "null" );
+
+ validator.isValid( new Object(), null );
+ }
+
+ @Test(expectedExceptions = ConstraintDeclarationException.class)
+ public void scriptExpressionReturningNoBooleanRaisesException() throws Exception {
+
+ ConstraintValidator<ScriptAssert, Object> validator = getInitializedValidator(
+ "javascript", "new java.util.Date()"
+ );
+
+ validator.isValid( new Object(), null );
+ }
+
+ /**
+ * Returns a {@link org.hibernate.validator.constraints.impl.ScriptAssertValidator}
initialized with a {@link ScriptAssert} with the given values.
+ */
+ private ConstraintValidator<ScriptAssert, Object> getInitializedValidator(String
lang, String script, String name) {
+
+ ConstraintValidator<ScriptAssert, Object> validator = new
ScriptAssertValidator();
+ validator.initialize( getScriptAssert( lang, script, name ) );
+
+ return validator;
+ }
+
+ /**
+ * Returns a {@link ScriptAssertValidator} initialized with a {@link ScriptAssert} with
the given values.
+ */
+ private ConstraintValidator<ScriptAssert, Object> getInitializedValidator(String
lang, String script) {
+
+ ConstraintValidator<ScriptAssert, Object> validator = new
ScriptAssertValidator();
+ validator.initialize( getScriptAssert( lang, script, null ) );
+
+ return validator;
+ }
+
+ /**
+ * Returns a {@link ScriptAssert} initialized with the given values.
+ */
+ private ScriptAssert getScriptAssert(String lang, String script, String name) {
+
+ AnnotationDescriptor<ScriptAssert> descriptor = AnnotationDescriptor.getInstance(
ScriptAssert.class );
+
+ descriptor.setValue( "lang", lang );
+ descriptor.setValue( "script", script );
+ if ( name != null ) {
+ descriptor.setValue( "alias", name );
+ }
+
+ return AnnotationFactory.create( descriptor );
+ }
+
+ /**
+ * An exemplary model class used in tests.
+ *
+ * @author Gunnar Morling
+ */
+ private static class CalendarEvent {
+
+ private Date startDate;
+
+ private Date endDate;
+
+ public CalendarEvent(Date startDate, Date endDate) {
+
+ this.startDate = startDate;
+ this.endDate = endDate;
+ }
+
+ @SuppressWarnings("unused")
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ @SuppressWarnings("unused")
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/ScriptAssertValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/SizeValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/SizeValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/SizeValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/SizeValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,184 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.constraints.impl;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+import javax.validation.constraints.Size;
+
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.impl.SizeValidatorForArray;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfBoolean;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfByte;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfChar;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfDouble;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfFloat;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfInt;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfLong;
+import org.hibernate.validator.constraints.impl.SizeValidatorForArraysOfShort;
+import org.hibernate.validator.constraints.impl.SizeValidatorForCollection;
+import org.hibernate.validator.constraints.impl.SizeValidatorForMap;
+import org.hibernate.validator.constraints.impl.SizeValidatorForString;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ */
+public class SizeValidatorTest {
+
+
+ @Test
+ public void testIsValidObjectArray() throws Exception {
+ ConstraintValidator<Size, Object[]> validator = getValidator(
SizeValidatorForArray.class );
+ assertSizes( validator, Object[].class );
+ }
+
+ @Test
+ public void testIsValidBooleanArray() throws Exception {
+ ConstraintValidator<Size, boolean[]> validator = getValidator(
SizeValidatorForArraysOfBoolean.class );
+ assertSizes( validator, boolean[].class );
+ }
+
+ @Test
+ public void testIsValidByteArray() throws Exception {
+ ConstraintValidator<Size, byte[]> validator = getValidator(
SizeValidatorForArraysOfByte.class );
+ assertSizes( validator, byte[].class );
+ }
+
+ @Test
+ public void testIsValidCharArray() throws Exception {
+ ConstraintValidator<Size, char[]> validator = getValidator(
SizeValidatorForArraysOfChar.class );
+ assertSizes( validator, char[].class );
+ }
+
+ @Test
+ public void testIsValidDoubleArray() throws Exception {
+ ConstraintValidator<Size, double[]> validator = getValidator(
SizeValidatorForArraysOfDouble.class );
+ assertSizes( validator, double[].class );
+ }
+
+ @Test
+ public void testIsValidFloatArray() throws Exception {
+ ConstraintValidator<Size, float[]> validator = getValidator(
SizeValidatorForArraysOfFloat.class );
+ assertSizes( validator, float[].class );
+ }
+
+ @Test
+ public void testIsValidIntArray() throws Exception {
+ ConstraintValidator<Size, int[]> validator = getValidator(
SizeValidatorForArraysOfInt.class );
+ assertSizes( validator, int[].class );
+ }
+
+ @Test
+ public void testIsValidLongArray() throws Exception {
+ ConstraintValidator<Size, long[]> validator = getValidator(
SizeValidatorForArraysOfLong.class );
+ assertSizes( validator, long[].class );
+ }
+
+ @Test
+ public void testIsValidShortArray() throws Exception {
+ ConstraintValidator<Size, short[]> validator = getValidator(
SizeValidatorForArraysOfShort.class );
+ assertSizes( validator, short[].class );
+ }
+
+ @Test
+ public void testIsValidCollection() throws Exception {
+ ConstraintValidator<Size, Collection> validator = getValidator(
SizeValidatorForCollection.class );
+
+ assertTrue( validator.isValid( null, null ) );
+
+ Collection<String> collection = new ArrayList<String>();
+ assertFalse( validator.isValid( collection, null ) );
+
+ collection.add( "firstItem" );
+ assertTrue( validator.isValid( collection, null ) );
+
+ collection.add( "secondItem" );
+ assertTrue( validator.isValid( collection, null ) );
+
+ collection.add( "thirdItem" );
+ assertFalse( validator.isValid( collection, null ) );
+ }
+
+ @Test
+ public void testIsValidMap() throws Exception {
+ ConstraintValidator<Size, Map> validator = getValidator(
SizeValidatorForMap.class );
+
+ assertTrue( validator.isValid( null, null ) );
+
+ Map<String, String> map = new HashMap<String, String>();
+ assertFalse( validator.isValid( map, null ) );
+
+ map.put( "key1", "firstItem" );
+ assertTrue( validator.isValid( map, null ) );
+
+ map.put( "key3", "secondItem" );
+ assertTrue( validator.isValid( map, null ) );
+
+ map.put( "key2", "thirdItem" );
+ assertFalse( validator.isValid( map, null ) );
+ }
+
+ @Test
+ public void testIsValiString() throws Exception {
+ ConstraintValidator<Size, String> validator = getValidator(
SizeValidatorForString.class );
+
+ assertTrue( validator.isValid( null, null ) );
+ assertFalse( validator.isValid( "", null ) );
+ assertTrue( validator.isValid( "a", null ) );
+ assertTrue( validator.isValid( "ab", null ) );
+ assertFalse( validator.isValid( "abc", null ) );
+ }
+
+ private <T> ConstraintValidator<Size, T> getValidator(Class<?>
validatorClass) throws Exception {
+ AnnotationDescriptor<Size> descriptor = new AnnotationDescriptor<Size>(
Size.class );
+ descriptor.setValue( "min", 1 );
+ descriptor.setValue( "max", 2 );
+ descriptor.setValue( "message", "{validator.max}" );
+ Size m = AnnotationFactory.create( descriptor );
+ @SuppressWarnings("unchecked")
+ ConstraintValidator<Size, T> validator = ( ConstraintValidator<Size, T> )
validatorClass.newInstance();
+ validator.initialize( m );
+ return validator;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> void assertSizes(ConstraintValidator<Size, T> validator,
Class<T> arrayType) {
+ assertTrue( validator.isValid( null, null ) );
+
+ T array = ( T ) Array.newInstance( arrayType.getComponentType(), 0 );
+ assertFalse( validator.isValid( array, null ) );
+
+ array = ( T ) Array.newInstance( arrayType.getComponentType(), 1 );
+ assertTrue( validator.isValid( array, null ) );
+
+ array = ( T ) Array.newInstance( arrayType.getComponentType(), 2 );
+ assertTrue( validator.isValid( array, null ) );
+
+ array = ( T ) Array.newInstance( arrayType.getComponentType(), 3 );
+ assertFalse( validator.isValid( array, null ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/SizeValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/URLValidatorTest.java
(from rev 19527,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/URLValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/URLValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/URLValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,122 @@
+// $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.validator.test.constraints.impl;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.URL;
+import org.hibernate.validator.constraints.impl.URLValidator;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Tests the {@code URL} constraint. See HV-229
+ *
+ * @author Hardy Ferentschik
+ */
+public class URLValidatorTest {
+
+ @Test
+ public void testIsValidUrl() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertTrue( validator.isValid( null, null ) );
+ assertFalse( validator.isValid( "http", null ) );
+ assertFalse( validator.isValid( "ftp//abc.de", null ) );
+ assertTrue( validator.isValid( "ftp://abc.de", null ) );
+ }
+
+
+ @Test
+ public void testIsValidUrlWithProtocolSpecified() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ descriptor.setValue( "protocol", "http" );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertFalse( validator.isValid( "ftp://abc.de", null ) );
+ assertTrue( validator.isValid( "http://abc.de", null ) );
+
+ descriptor = new AnnotationDescriptor<URL>( URL.class );
+ descriptor.setValue( "protocol", "file" );
+ url = AnnotationFactory.create( descriptor );
+ validator = new URLValidator();
+ validator.initialize( url );
+ assertFalse( validator.isValid( "http://abc.de", null ) );
+ assertTrue( validator.isValid( "file://Users/foobar/tmp", null ) );
+ }
+
+ @Test
+ public void testIsValidUrlWithPortSpecified() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ descriptor.setValue( "port", 21 );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertFalse( validator.isValid( "ftp://abc.de", null ) );
+ assertTrue( validator.isValid( "ftp://abc.de:21", null ) );
+ }
+
+ @Test
+ public void testIsValidUrlWithHostSpecified() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ descriptor.setValue( "host", "foobar.com" );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertFalse( validator.isValid( "http://fubar.com/this/is/foobar.html", null
) );
+ assertTrue( validator.isValid( "http://foobar.com/this/is/foobar.html", null
) );
+ }
+
+ @Test
+ public void testIsValidUrlWithProtocolHostAndPort() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ descriptor.setValue( "protocol", "http" );
+ descriptor.setValue( "host", "www.hibernate.org" );
+ descriptor.setValue( "port", 80 );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertFalse( validator.isValid( "ftp://www#hibernate#org:80", null ) );
+ assertTrue( validator.isValid( "http://www.hibernate.org:80", null ) );
+ }
+
+ @Test
+ public void testIsValidEmptyString() {
+ // HV-323
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>(
URL.class );
+ descriptor.setValue( "protocol", "http" );
+ descriptor.setValue( "host", "www.hibernate.org" );
+ descriptor.setValue( "port", 80 );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+
+ assertTrue( validator.isValid( "", null ) );
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/constraints/impl/URLValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/PathImplTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/PathImplTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/PathImplTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/PathImplTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,113 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine;
+
+import java.util.Iterator;
+import javax.validation.Path;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.PathImpl;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PathImplTest {
+
+ @Test
+ public void testParsing() {
+ String property = "order[3].deliveryAddress.addressline[1]";
+ Path path = PathImpl.createPathFromString( property );
+ Iterator<Path.Node> propIter = path.iterator();
+
+ assertTrue( propIter.hasNext() );
+ Path.Node elem = propIter.next();
+ assertEquals( "order", elem.getName() );
+ assertTrue( elem.isInIterable() );
+ assertEquals( new Integer( 3 ), elem.getIndex() );
+
+ assertTrue( propIter.hasNext() );
+ elem = propIter.next();
+ assertEquals( "deliveryAddress", elem.getName() );
+ assertFalse( elem.isInIterable() );
+ assertEquals( null, elem.getIndex() );
+
+ assertTrue( propIter.hasNext() );
+ elem = propIter.next();
+ assertEquals( "addressline", elem.getName() );
+ assertTrue( elem.isInIterable() );
+ assertEquals( new Integer( 1 ), elem.getIndex() );
+
+ assertFalse( propIter.hasNext() );
+ }
+
+ @Test
+ public void testParseMapBasedProperty() {
+ String property = "order[foo].deliveryAddress";
+ Path path = PathImpl.createPathFromString( property );
+ Iterator<Path.Node> propIter = path.iterator();
+
+ assertTrue( propIter.hasNext() );
+ Path.Node elem = propIter.next();
+ assertEquals( "order", elem.getName() );
+ assertTrue( elem.isInIterable() );
+ assertEquals( "foo", elem.getKey() );
+
+ assertTrue( propIter.hasNext() );
+ elem = propIter.next();
+ assertEquals( "deliveryAddress", elem.getName() );
+ assertFalse( elem.isInIterable() );
+ assertEquals( null, elem.getIndex() );
+
+ assertFalse( propIter.hasNext() );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNull() {
+ PathImpl.createPathFromString( null );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testUnbalancedBraces() {
+ PathImpl.createPathFromString( "foo[.bar" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testIndexInMiddleOfProperty() {
+ PathImpl.createPathFromString( "f[1]oo.bar" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testTrailingPathSeperator() {
+ PathImpl.createPathFromString( "foo.bar." );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testLeadingPathSeperator() {
+ PathImpl.createPathFromString( ".foo.bar" );
+ }
+
+ @Test
+ public void testEmptyString() {
+ Path path = PathImpl.createPathFromString( "" );
+ assertTrue( path.iterator().hasNext() );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/PathImplTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/ValidatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/ValidatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/ValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/ValidatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,74 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.NotNull;
+import javax.validation.metadata.BeanDescriptor;
+
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+import static org.hibernate.validator.test.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ValidatorTest {
+
+ /**
+ * HV-208
+ */
+ @Test
+ public void testPropertyPathDoesNotStartWithLeadingDot() {
+ Validator validator = TestUtil.getValidator();
+ A testInstance = new A();
+ Set<ConstraintViolation<A>> constraintViolations = validator.validate(
testInstance );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "b" );
+ }
+
+ /**
+ * HV-132 - supper hasBoolean format
+ */
+ @Test
+ public void testHasBoolean() {
+ Validator validator = TestUtil.getValidator();
+ BeanDescriptor beanDescr = validator.getConstraintsForClass( B.class );
+ assertTrue( beanDescr.isBeanConstrained() );
+ }
+
+ class A {
+ @NotNull
+ String b;
+ }
+
+ class B {
+ private boolean b;
+
+ @AssertTrue
+ public boolean hasB() {
+ return b;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/ValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/CustomErrorMessageTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/CustomErrorMessageTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/CustomErrorMessageTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/CustomErrorMessageTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,47 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.customerror;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import static
org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.validator.test.util.TestUtil.getValidator;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class CustomErrorMessageTest {
+ /**
+ * HV-297
+ *
+ * @throws Exception in case the test fails.
+ */
+ @Test
+ public void testReportAsSingleViolationDoesNotInfluenceCustomError() throws Exception {
+ Validator validator = getValidator();
+ DummyTestClass dummyTestClass = new DummyTestClass();
+
+ Set<ConstraintViolation<DummyTestClass>> constraintViolations =
validator.validate( dummyTestClass );
+ assertCorrectConstraintViolationMessages( constraintViolations,
IsValidValidator.message );
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/CustomErrorMessageTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/DummyTestClass.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/DummyTestClass.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/DummyTestClass.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/DummyTestClass.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.customerror;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@IsValid
+public class DummyTestClass {
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/DummyTestClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValid.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValid.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValid.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValid.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.customerror;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@NotNull
+@Target(TYPE)
+@Retention(RUNTIME)
+@Constraint(validatedBy = IsValidValidator.class)
+@ReportAsSingleViolation
+public @interface IsValid {
+ Class<?>[] groups() default { };
+
+ String message() default "Default error message";
+
+ Class<? extends Payload>[] payload() default { };
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValid.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValidValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/customerror/IsValidValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValidValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValidValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ *
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.customerror;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class IsValidValidator implements ConstraintValidator<IsValid,
DummyTestClass> {
+
+ public static final String message = "Custom error message";
+
+
+ public void initialize(IsValid isValid) {
+ }
+
+ public boolean isValid(DummyTestClass dummyTestClass, ConstraintValidatorContext
constraintValidatorContext) {
+ constraintValidatorContext.disableDefaultConstraintViolation();
+ constraintValidatorContext.buildConstraintViolationWithTemplate( message )
+ .addConstraintViolation();
+ return false;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/customerror/IsValidValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Address.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/Address.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Address.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Address.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,81 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@GroupSequence({ Address.class, Address.HighLevelCoherence.class })
+@ZipCodeCoherenceChecker(groups = Address.HighLevelCoherence.class)
+public class Address {
+ @NotNull
+ @Size(max = 50)
+ private String street;
+
+ @NotNull
+ @Size(max = 5)
+ private String zipcode;
+
+ @NotNull
+ @Size(max = 30)
+ private String city;
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getZipcode() {
+ return zipcode;
+ }
+
+ public void setZipcode(String zipcode) {
+ this.zipcode = zipcode;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ /**
+ * Check conherence on the overall object
+ * Needs basic checking to be green first
+ */
+ public interface HighLevelCoherence {
+ }
+
+ /**
+ * Check both basic constraints and high level ones.
+ * High level constraints are not checked if basic constraints fail.
+ */
+ @GroupSequence(value = { Default.class, HighLevelCoherence.class })
+ public interface Complete {
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Address.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/CyclicGroupSequence.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence.class)
+public interface CyclicGroupSequence {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence1.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/CyclicGroupSequence1.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence1.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence1.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence2.class)
+public interface CyclicGroupSequence1 {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence1.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence2.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/CyclicGroupSequence2.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence2.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence2.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@GroupSequence(value = CyclicGroupSequence1.class)
+public interface CyclicGroupSequence2 {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/CyclicGroupSequence2.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/First.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/First.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/First.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/First.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,26 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+/**
+ * Group executed first in the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface First {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/First.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupA.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupA.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupA.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,10 @@
+// $Id:$
+package org.hibernate.validator.test.engine.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+interface GroupA {
+}
+
+
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupB.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupB.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupB.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,10 @@
+// $Id:$
+package org.hibernate.validator.test.engine.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+interface GroupB {
+}
+
+
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainGeneratorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/GroupChainGeneratorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainGeneratorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainGeneratorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,175 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.validation.GroupDefinitionException;
+import javax.validation.GroupSequence;
+import javax.validation.ValidationException;
+import javax.validation.groups.Default;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.groups.Group;
+import org.hibernate.validator.engine.groups.GroupChain;
+import org.hibernate.validator.engine.groups.GroupChainGenerator;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GroupChainGeneratorTest {
+
+ GroupChainGenerator generator;
+
+ @BeforeTest
+ public void init() {
+ generator = new GroupChainGenerator();
+ }
+
+ @Test(expectedExceptions = ValidationException.class)
+ public void testGroupChainForNonInterface() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( String.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testGroupChainForNull() {
+ generator.getGroupChainFor( null );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testGroupChainForEmptySet() {
+ generator.getGroupChainFor( new HashSet<Class<?>>() );
+ }
+
+ @Test(expectedExceptions = ValidationException.class)
+ public void testCyclicGroupSequences() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( CyclicGroupSequence1.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test(expectedExceptions = ValidationException.class)
+ public void testCyclicGroupSequence() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( CyclicGroupSequence.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test
+ public void testGroupDuplicates() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( First.class );
+ groups.add( Second.class );
+ groups.add( Last.class );
+ GroupChain chain = generator.getGroupChainFor( groups );
+ int count = countGroups( chain );
+ assertEquals( count, 3, "Wrong number of groups" );
+
+ groups.clear();
+ groups.add( First.class );
+ groups.add( First.class );
+ chain = generator.getGroupChainFor( groups );
+ count = countGroups( chain );
+ assertEquals( count, 1, "Wrong number of groups" );
+
+ groups.clear();
+ groups.add( First.class );
+ groups.add( Last.class );
+ groups.add( First.class );
+ chain = generator.getGroupChainFor( groups );
+ count = countGroups( chain );
+ assertEquals( count, 2, "Wrong number of groups" );
+ }
+
+ @Test(expectedExceptions = GroupDefinitionException.class)
+ public void testGroupDefiningSequencePartOfGroupComposingSequence() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( Sequence1.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test(expectedExceptions = GroupDefinitionException.class)
+ public void testUnexpandableSequence() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( Sequence3.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test
+ public void testExpandableSequenceWithInheritance() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( Sequence4.class );
+ generator.getGroupChainFor( groups );
+ }
+
+ @Test
+ public void testSequenceResolution() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add( Address.Complete.class );
+ GroupChain chain = generator.getGroupChainFor( groups );
+ Iterator<List<Group>> sequences = chain.getSequenceIterator();
+ List<Group> sequence = sequences.next();
+
+ assertEquals( sequence.get( 0 ).getGroup(), Default.class, "Wrong group" );
+ assertEquals( sequence.get( 1 ).getGroup(), Address.HighLevelCoherence.class,
"Wrong group" );
+ }
+
+ private int countGroups(GroupChain chain) {
+ Iterator<Group> groupIterator = chain.getGroupIterator();
+ int count = 0;
+ while ( groupIterator.hasNext() ) {
+ groupIterator.next();
+ count++;
+ }
+ return count;
+ }
+
+
+ interface GroupA extends Default {
+ }
+
+ interface GroupB {
+ }
+
+ interface GroupC extends Sequence2 {
+ }
+
+ @GroupSequence({ GroupA.class, GroupC.class })
+ interface Sequence1 {
+ }
+
+ @GroupSequence({ GroupB.class, GroupA.class })
+ interface Sequence2 {
+ }
+
+ @GroupSequence({ Sequence2.class, GroupB.class })
+ interface Sequence3 {
+ }
+
+ @GroupSequence({ Sequence2.class, GroupA.class })
+ interface Sequence4 {
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainGeneratorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupChainTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+// $Id:$
+package org.hibernate.validator.test.engine.groups;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.GroupDefinitionException;
+import javax.validation.groups.Default;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.groups.Group;
+import org.hibernate.validator.engine.groups.GroupChain;
+
+import static org.testng.FileAssert.fail;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GroupChainTest {
+ @Test
+ public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence() {
+ // create a dummy sequence
+ Group a = new Group( GroupA.class, TestSequence.class );
+ Group b = new Group( GroupB.class, TestSequence.class );
+ Group c = new Group( GroupC.class, TestSequence.class );
+ Group defaultGroup = new Group(
+ Default.class, TestSequence.class
+ );
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add( a );
+ sequence.add( b );
+ sequence.add( c );
+ sequence.add( defaultGroup );
+
+ GroupChain chain = new GroupChain();
+ chain.insertSequence( sequence );
+
+ // create test default sequence
+ List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupA.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupA.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupC.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupC.class );
+ defaultSequence.add( Default.class );
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ }
+
+
+ @Test
+ public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence()
{
+ // create a dummy sequence
+ Group a = new Group( GroupA.class, TestSequence.class );
+ Group b = new Group( GroupB.class, TestSequence.class );
+ Group c = new Group( GroupC.class, TestSequence.class );
+ Group defaultGroup = new Group(
+ Default.class, TestSequence.class
+ );
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add( defaultGroup );
+ sequence.add( a );
+ sequence.add( b );
+ sequence.add( c );
+
+ GroupChain chain = new GroupChain();
+ chain.insertSequence( sequence );
+
+ // create test default sequence
+ List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupA.class );
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupA.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( Default.class );
+ defaultSequence.add( GroupC.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add( GroupC.class );
+ defaultSequence.add( Default.class );
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable( defaultSequence );
+ fail();
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+ }
+}
+
+interface GroupC {
+}
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupsTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/GroupsTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupsTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupsTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+import static
org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintViolationMessages;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GroupsTest {
+
+ /**
+ * HV-288
+ */
+ @Test
+ public void testGroupInheritance() {
+ Validator validator = TestUtil.getValidator();
+ Try tryMe = new Try();
+ tryMe.field2 = "foo";
+ tryMe.field3 = "bar";
+
+ Set<ConstraintViolation<Try>> violations = validator.validate( tryMe,
Try.GlobalCheck.class );
+ assertCorrectConstraintViolationMessages(violations, "field1");
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/GroupsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Last.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/Last.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Last.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Last.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,26 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+/**
+ * Group executed Last in the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Last {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Last.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Second.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/Second.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Second.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Second.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,26 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+/**
+ * Group executed second during the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Second {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Second.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/TestSequence.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/TestSequence.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/TestSequence.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,10 @@
+// $Id:$
+package org.hibernate.validator.test.engine.groups;
+
+/**
+ * @author Hardy Ferentschik
+ */
+interface TestSequence {
+}
+
+
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Try.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/Try.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Try.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Try.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,50 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Try {
+ @NotNull(message = "field1", groups = BaseComponent.class)
+ public String field1;
+
+ @NotNull(message = "field2", groups = Component.class)
+ public String field2;
+
+ @NotNull(message = "field3", groups = OtherComponent.class)
+ public String field3;
+
+ public interface BaseComponent {
+ }
+
+ public interface Component extends BaseComponent {
+ }
+
+ public interface OtherComponent {
+ }
+
+ @GroupSequence({ Component.class, OtherComponent.class })
+ public interface GlobalCheck {
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/Try.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceChecker.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/ZipCodeCoherenceChecker.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceChecker.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceChecker.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Target({ TYPE, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+@Constraint(validatedBy = ZipCodeCoherenceValidator.class)
+public @interface ZipCodeCoherenceChecker {
+ public abstract String message() default
"{validator.zipCodeCoherenceChecker}";
+
+ public abstract Class<?>[] groups() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceChecker.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/groups/ZipCodeCoherenceValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,34 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.groups;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ZipCodeCoherenceValidator implements
ConstraintValidator<ZipCodeCoherenceChecker, Address> {
+
+ public void initialize(ZipCodeCoherenceChecker parameters) {
+ }
+
+ public boolean isValid(Address value, ConstraintValidatorContext
constraintValidatorContext) {
+ return false;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/groups/ZipCodeCoherenceValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,121 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.messageinterpolation;
+
+import java.io.ByteArrayInputStream;
+import java.util.Locale;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+import org.hibernate.validator.resourceloading.ResourceBundleLocator;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Tests for HV-184
+ *
+ * @author Hardy Ferentschik
+ */
+public class MessageInterpolationTest {
+ private Validator validator;
+
+ @BeforeClass
+ public void createValidator() throws Exception {
+ final StringBuilder lines = new StringBuilder();
+ lines.append( "bar=Message is \\\\{escaped\\\\}" ).append( "\r\n"
);
+ lines.append( "baz=Message is US$ {value}" ).append( "\r\n" );
+ lines.append( "qux=Message is {missing}" ).append( "\r\n" );
+ lines.append( "escaped=wrong" ).append( "\r\n" );
+ final ResourceBundle bundle = new PropertyResourceBundle(
+ new ByteArrayInputStream( lines.toString().getBytes() )
+ );
+ Configuration<?> config = Validation.byDefaultProvider()
+ .configure()
+ .messageInterpolator(
+ new ResourceBundleMessageInterpolator(
+ new ResourceBundleLocator() {
+
+ public ResourceBundle getResourceBundle(
+ Locale locale) {
+ return bundle;
+ }
+
+ }
+ )
+ );
+
+ ValidatorFactory factory = config.buildValidatorFactory();
+ validator = factory.getValidator();
+ }
+
+ @Test
+ public void testCurlyBracesEscapingShouldBeRespected() {
+ final ConstraintViolation<Foo> violation = validator.validate( new Foo(),
Bar.class ).iterator().next();
+ assertEquals( violation.getMessage(), "Message is {escaped}" );
+ }
+
+ @Test
+ public void testAppendReplacementNeedsToEscapeBackslashAndDollarSign() {
+ final ConstraintViolation<Foo> violation = validator.validate( new Foo(),
Baz.class ).iterator().next();
+ assertEquals( violation.getMessage(), "Message is US$ 5" );
+ }
+
+ @Test
+ public void testUnknownParametersShouldBePreserved() {
+ final ConstraintViolation<Foo> violation = validator.validate( new Foo(),
Qux.class ).iterator().next();
+ assertEquals( violation.getMessage(), "Message is {missing}" );
+ }
+
+ public static interface Bar {
+ }
+
+ public static interface Baz {
+ }
+
+ public static interface Qux {
+ }
+
+ public static class Foo {
+ @NotNull(message = "{bar}", groups = { Bar.class })
+ public String getBar() {
+ return null;
+ }
+
+ @Min(value = 5, message = "{baz}", groups = { Baz.class })
+ public int getBaz() {
+ return 0;
+ }
+
+
+ @NotNull(message = "{qux}", groups = { Qux.class })
+ public String getQux() {
+ return null;
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,152 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.messageinterpolation;
+
+import java.util.Locale;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+import org.hibernate.validator.test.util.TestUtil;
+
+import static
org.hibernate.validator.test.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * Tests for correct message interpolation for messages from the default bundle.
+ *
+ * @author Hardy Ferentschik
+ * @author Gunnar Morling
+ */
+public class MessageInterpolationWithDefaultBundleTest {
+ private Locale defaultLocale;
+
+ @BeforeClass
+ public void storeDefaultLocale() {
+ defaultLocale = Locale.getDefault();
+ }
+
+ @AfterClass
+ public void restoreDefaultLocale() {
+ Locale.setDefault( defaultLocale );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageEnglishLocale() {
+ Locale.setDefault( Locale.ENGLISH );
+ Configuration<?> config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "not a well-formed email address", "must be
between 18 and 21"
+ );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageGermanLocale() {
+ Locale.setDefault( Locale.GERMAN );
+ Configuration<?> config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "keine g\u00FCltige E-Mail-Adresse", "muss
zwischen 18 und 21 liegen"
+ );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageFrenchLocale() {
+ Locale.setDefault( Locale.FRENCH );
+ Configuration<?> config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "Addresse email mal form\u00E9e", "doit
\u00EAtre entre 18 et 21"
+ );
+ }
+
+ /**
+ * HV-306. If English is explicitly set as locale for message interpolation, it
+ * must take precedence over the system's default locale.
+ */
+ @Test
+ public void testThatExplicitlySetEnglishLocaleHasPrecedenceOverDefaultLocale() {
+
+ Locale.setDefault( Locale.FRENCH );
+ Configuration<?> config = TestUtil.getConfiguration();
+ config.messageInterpolator( new LocalizedMessageInterpolator( Locale.ENGLISH ) );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "not a well-formed email address", "must be
between 18 and 21"
+ );
+ }
+
+ /**
+ * A message interpolator that enforces one given locale to be used for message
+ * interpolation.
+ *
+ * @author Gunnar Morling
+ */
+ private static class LocalizedMessageInterpolator extends
ResourceBundleMessageInterpolator {
+
+ private Locale locale;
+
+ public LocalizedMessageInterpolator(Locale locale) {
+ this.locale = locale;
+ }
+
+ @Override
+ public String interpolate(String messageTemplate, Context context) {
+ return interpolate( messageTemplate, context, this.locale );
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,319 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.messageinterpolation;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.ResourceBundle;
+import javax.validation.MessageInterpolator;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.MessageInterpolatorContext;
+import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+import org.hibernate.validator.metadata.ConstraintHelper;
+import org.hibernate.validator.resourceloading.ResourceBundleLocator;
+import org.hibernate.validator.metadata.ConstraintDescriptorImpl;
+import org.hibernate.validator.metadata.ConstraintOrigin;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Tests for message interpolation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ResourceBundleMessageInterpolatorTest {
+
+ private ResourceBundleMessageInterpolator interpolator;
+ private NotNull notNull;
+ private ConstraintDescriptorImpl<NotNull> notNullDescriptor;
+ private Size size;
+ private ConstraintDescriptorImpl<Size> sizeDescriptor;
+
+ @BeforeTest
+ public void setUp() {
+ // Create some annotations for testing using AnnotationProxies
+ AnnotationDescriptor<NotNull> descriptor = new
AnnotationDescriptor<NotNull>( NotNull.class );
+ notNull = AnnotationFactory.create( descriptor );
+ notNullDescriptor = new ConstraintDescriptorImpl<NotNull>(
+ notNull,
+ new ConstraintHelper(),
+ java.lang.annotation.ElementType.FIELD,
+ ConstraintOrigin.DEFINED_LOCALLY
+ );
+
+ AnnotationDescriptor<Size> sizeAnnotationDescriptor = new
AnnotationDescriptor<Size>( Size.class );
+ size = AnnotationFactory.create( sizeAnnotationDescriptor );
+ sizeDescriptor = new ConstraintDescriptorImpl<Size>(
+ size, new ConstraintHelper(), java.lang.annotation.ElementType.FIELD,
ConstraintOrigin.DEFINED_LOCALLY
+ );
+ }
+
+ @Test
+ public void testSuccessfulInterpolation() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+ String expected = "message interpolation successful";
+ String actual = interpolator.interpolate( "{simple.key}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "message interpolation successful message interpolation
successful";
+ actual = interpolator.interpolate( "{simple.key} {simple.key}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "The message interpolation successful completed";
+ actual = interpolator.interpolate( "The {simple.key} completed", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "{{simple.key}}";
+ actual = interpolator.interpolate( "{{simple.key}}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testMessageLiterals() {
+
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "{";
+ String actual = interpolator.interpolate( "\\{", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "}";
+ actual = interpolator.interpolate( "\\}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "\\";
+ actual = interpolator.interpolate( "\\", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testUnSuccessfulInterpolation() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "foo"; // missing {}
+ String actual = interpolator.interpolate( "foo", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "#{foo {}";
+ actual = interpolator.interpolate( "#{foo {}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testUnknownTokenInterpolation() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "{bar}"; // unknown token {}
+ String actual = interpolator.interpolate( "{bar}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testKeyWithDashes() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "message interpolation successful"; // unknown token {}
+ String actual = interpolator.interpolate( "{key-with-dashes}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testKeyWithSpaces() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "message interpolation successful"; // unknown token {}
+ String actual = interpolator.interpolate( "{key with spaces}", context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testDefaultInterpolation() {
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "may not be null";
+ String actual = interpolator.interpolate( notNull.message(), context );
+ assertEquals( actual, expected, "Wrong substitution" );
+
+ expected = "size must be between 0 and 2147483647"; // unknown token {}
+ context = new MessageInterpolatorContext( sizeDescriptor, null );
+ actual = interpolator.interpolate( size.message(), context );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testMessageInterpolationWithLocale() {
+ interpolator = new ResourceBundleMessageInterpolator();
+
+ String expected = "kann nicht null sein";
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+ String actual = interpolator.interpolate( notNull.message(), context, Locale.GERMAN );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ @Test
+ public void testUserResourceBundle() {
+ interpolator = new ResourceBundleMessageInterpolator();
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
notNullDescriptor, null );
+
+ String expected = "no puede ser null";
+ String actual = interpolator.interpolate( notNull.message(), context, new Locale(
"es", "ES" ) );
+ assertEquals( actual, expected, "Wrong substitution" );
+ }
+
+ /**
+ * HV-102
+ */
+ @Test
+ public void testRecursiveMessageInterpolation() {
+ AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>(
Max.class );
+ descriptor.setValue( "message", "{replace.in.user.bundle1}" );
+ descriptor.setValue( "value", 10l );
+ Max max = AnnotationFactory.create( descriptor );
+
+
+ ConstraintDescriptorImpl<Max> constraintDescriptor = new
ConstraintDescriptorImpl<Max>(
+ max, new ConstraintHelper(), java.lang.annotation.ElementType.FIELD,
ConstraintOrigin.DEFINED_LOCALLY
+ );
+
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
constraintDescriptor, null );
+
+ String expected = "{replace.in.default.bundle2}";
+ String actual = interpolator.interpolate( max.message(), context );
+ assertEquals(
+ actual, expected, "Within default bundle replacement parameter evaluation should
not be recursive!"
+ );
+ }
+
+ /**
+ * HV-182
+ */
+ @Test
+ public void testCorrectMessageInterpolationIfParameterCannotBeReplaced() {
+ AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>(
Max.class );
+ String message = "Message should stay unchanged since {fubar} is not
replaceable";
+ descriptor.setValue( "message", message );
+ descriptor.setValue( "value", 10l );
+ Max max = AnnotationFactory.create( descriptor );
+
+
+ ConstraintDescriptorImpl<Max> constraintDescriptor = new
ConstraintDescriptorImpl<Max>(
+ max, new ConstraintHelper(), java.lang.annotation.ElementType.FIELD,
ConstraintOrigin.DEFINED_LOCALLY
+ );
+
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator()
+ );
+
+ MessageInterpolator.Context context = new MessageInterpolatorContext(
constraintDescriptor, null );
+
+ String actual = interpolator.interpolate( max.message(), context );
+ assertEquals(
+ actual, message, "The message should not have changed."
+ );
+ }
+
+ /**
+ * A dummy locator always returning a {@link TestResourceBundle}.
+ */
+ private static class TestResourceBundleLocator implements ResourceBundleLocator {
+
+ private TestResourceBundle resourceBundle = new TestResourceBundle();
+
+ public ResourceBundle getResourceBundle(Locale locale) {
+ return resourceBundle;
+ }
+ }
+
+ /**
+ * A dummy resource bundle which can be passed to the constructor of
ResourceBundleMessageInterpolator to replace
+ * the user specified resource bundle.
+ */
+ private static class TestResourceBundle extends ResourceBundle implements
Enumeration<String> {
+ private Map<String, String> testResources;
+ Iterator<String> iter;
+
+ public TestResourceBundle() {
+ testResources = new HashMap<String, String>();
+ // add some test messages
+ testResources.put( "simple.key", "message interpolation
successful" );
+ testResources.put( "key-with-dashes", "message interpolation
successful" );
+ testResources.put( "key with spaces", "message interpolation
successful" );
+ testResources.put( "replace.in.user.bundle1",
"{replace.in.user.bundle2}" );
+ testResources.put( "replace.in.user.bundle2",
"{replace.in.default.bundle1}" );
+
+ iter = testResources.keySet().iterator();
+ }
+
+ public Object handleGetObject(String key) {
+ return testResources.get( key );
+ }
+
+ public Enumeration<String> getKeys() {
+ return this;
+ }
+
+ public boolean hasMoreElements() {
+ return iter.hasNext();
+ }
+
+ public String nextElement() {
+ if ( hasMoreElements() ) {
+ return iter.next();
+ }
+ else {
+ throw new NoSuchElementException();
+ }
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/User.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/User.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/User.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/User.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,50 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.messageinterpolation;
+
+import org.hibernate.validator.constraints.Email;
+import org.hibernate.validator.constraints.Range;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+ @Email
+ private String email;
+
+ @Range(min = 18, max = 21)
+ private int age;
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/User.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/A.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/proxy/A.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/A.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/A.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,29 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.proxy;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.Size;
+
+interface A {
+ @Min(5)
+ public Integer getInteger();
+
+ @Size(min = 2)
+ public String getString();
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/A.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/B.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/proxy/B.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/B.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/B.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,21 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.proxy;
+
+public interface B extends A {
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/B.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/ProxyTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/proxy/ProxyTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/ProxyTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/ProxyTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,83 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * See HV-257
+ *
+ * @author Hardy Ferentschik
+ */
+public class ProxyTest {
+ @Test
+ public void testValidateA() {
+ InvocationHandler handler = new CustomInvocationHandler( "some object" );
+
+ A a = ( A ) Proxy.newProxyInstance( getClass().getClassLoader(), new Class<?>[] {
A.class }, handler );
+ assertEquals( Integer.valueOf( 0 ), a.getInteger() );
+
+ Validator validator = TestUtil.getValidator();
+ Set<ConstraintViolation<A>> violations = validator.validate( a );
+ assertNumberOfViolations( violations, 2 );
+ }
+
+ @Test
+ public void testValidateB() {
+ InvocationHandler handler = new CustomInvocationHandler( "some object" );
+
+ B b = ( B ) Proxy.newProxyInstance( getClass().getClassLoader(), new Class<?>[] {
B.class }, handler );
+ assertEquals( Integer.valueOf( 0 ), b.getInteger() );
+
+ Validator validator = TestUtil.getValidator();
+ Set<ConstraintViolation<B>> violations = validator.validate( b );
+ assertNumberOfViolations( violations, 2 );
+ }
+
+ private class CustomInvocationHandler implements InvocationHandler {
+ private Object o;
+
+ public CustomInvocationHandler(Object o) {
+ this.o = o;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ( method.getName().equals( "getInteger" ) ) {
+ method.setAccessible( true );
+ return 0;
+ }
+ if ( method.getName().equals( "getString" ) ) {
+ return "a";
+ }
+ return method.invoke( o, args );
+ }
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/proxy/ProxyTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/ConstraintViolationSerializationTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/ConstraintViolationSerializationTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/ConstraintViolationSerializationTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/ConstraintViolationSerializationTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,86 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.serialization;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.NotSerializableException;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+import static org.hibernate.validator.test.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintViolationSerializationTest {
+
+ /**
+ * HV-245
+ */
+ @Test
+ public void testSuccessfulSerialization() throws Exception {
+ Validator validator = TestUtil.getValidator();
+ SerializableClass testInstance = new SerializableClass();
+ Set<ConstraintViolation<SerializableClass>> constraintViolations =
validator.validate( testInstance );
+
+ byte[] bytes = serialize( constraintViolations );
+ Set<ConstraintViolation<?>> deserializedViolations = deserialize( bytes );
+ assertNumberOfViolations( deserializedViolations, 1 );
+ }
+
+ /**
+ * HV-245
+ */
+ @Test(expectedExceptions = NotSerializableException.class)
+ public void testUnSuccessfulSerialization() throws Exception {
+ Validator validator = TestUtil.getValidator();
+ UnSerializableClass testInstance = new UnSerializableClass();
+ Set<ConstraintViolation<UnSerializableClass>> constraintViolations =
validator.validate( testInstance );
+
+ serialize( constraintViolations );
+ }
+
+ private byte[] serialize(Object o) throws Exception {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutput out = new ObjectOutputStream( stream );
+ out.writeObject( o );
+ out.close();
+ byte[] serialized = stream.toByteArray();
+ stream.close();
+ return serialized;
+
+ }
+
+ private Set<ConstraintViolation<?>> deserialize(byte[] byteData) throws
Exception {
+ ByteArrayInputStream byteIn = new ByteArrayInputStream( byteData );
+ ObjectInputStream in = new ObjectInputStream( byteIn );
+ Set<ConstraintViolation<?>> deserializedViolations = (
Set<ConstraintViolation<?>> ) in.readObject();
+ in.close();
+ byteIn.close();
+ return deserializedViolations;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/ConstraintViolationSerializationTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/CustomConstraintSerializableTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/CustomConstraintSerializableTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/CustomConstraintSerializableTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/CustomConstraintSerializableTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,99 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.serialization;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+
+/**
+ * A <b>sscce</b> (Short, Self Contained, Correct Example) showing that the
+ * simple custom Email validation constraint taken from <a
href="http://blog.jteam.nl/2009/08/04/bean-validation-integrating-jsr-303-with-spring/"
+ * >this blog</a> gives a validation result that is not Serializable with
+ * Hibernate Validator 4.0.2.GA with underlying cause that
+ * <p/>
+ *
<code>org.hibernate.validator.util.annotationfactory.AnnotationProxy</code>
+ * <p/>
+ * <p/>
+ * Note that Hibernate Validator does not guarantee at all that a
+ * {@link ConstraintViolation} is Serializable because an entity need not be
+ * Serializable, but otherwise there should not be much of a problem (right?).
+ *
+ * @author Henno Vermeulen
+ * @author Hardy Ferentschik
+ */
+public class CustomConstraintSerializableTest {
+
+ @Test
+ public void testSerializeHibernateEmail() throws Exception {
+ Validator validator = TestUtil.getValidator();
+
+ HibernateEmail invalidHibernateEmail = new HibernateEmail();
+ invalidHibernateEmail.email = "test@";
+
+ Set<ConstraintViolation<HibernateEmail>> constraintViolations =
validator.validate( invalidHibernateEmail );
+ doSerialize( constraintViolations.iterator().next() );
+ }
+
+ /**
+ * HV-291
+ *
+ * @throws Exception in case the test fails
+ */
+ @Test
+ public void testSerializeCustomEmail() throws Exception {
+ Validator validator = TestUtil.getValidator();
+
+ CustomEmail invalidCustomEmail = new CustomEmail();
+ invalidCustomEmail.email = "test@";
+ Set<ConstraintViolation<CustomEmail>> constraintViolations =
validator.validate( invalidCustomEmail );
+ doSerialize( constraintViolations.iterator().next() );
+ }
+
+ public static byte[] doSerialize(Object obj) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( 512 );
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ out.writeObject( obj );
+ out.close();
+ return baos.toByteArray();
+ }
+
+ static class CustomEmail implements Serializable {
+ private static final long serialVersionUID = -9095271389455131159L;
+
+ @Email
+ String email;
+
+ }
+
+ static class HibernateEmail implements Serializable {
+ private static final long serialVersionUID = 7206154160792549270L;
+
+ @org.hibernate.validator.constraints.Email
+ String email;
+ }
+}
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/CustomConstraintSerializableTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/DummyEmailValidator.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/DummyEmailValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/DummyEmailValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/DummyEmailValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,35 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.serialization;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class DummyEmailValidator implements ConstraintValidator<Email, String> {
+ public void initialize(Email annotation) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ return false;
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/DummyEmailValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/Email.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/Email.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/Email.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/Email.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,52 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.serialization;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.Pattern;
+
+/**
+ * Denotes that a field should contain a valid email address.
+ * <p/>
+ * <p/>
+ * Taken from <a
href="http://blog.jteam.nl/2009/08/04/bean-validation-integrating-jsr-303-with-spring/"
+ * >this blog</a>.
+ *
+ * @author Hardy Ferentschik
+ */
+@Documented
+@Constraint(validatedBy = { DummyEmailValidator.class })
+@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE })
+(a)Retention(RetentionPolicy.RUNTIME)
+@Pattern(regexp = ".+@.+\\.[a-z]+")
+@ReportAsSingleViolation
+public @interface Email {
+
+ public abstract String message() default
"{org.hibernate.validator.engine.serialization.Email.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/Email.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/SerializableClass.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/SerializableClass.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/SerializableClass.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/SerializableClass.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,29 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.validator.test.engine.serialization;
+
+import java.io.Serializable;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SerializableClass implements Serializable {
+ @NotNull
+ private String foo;
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/SerializableClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/UnSerializableClass.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/serialization/UnSerializableClass.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/UnSerializableClass.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/UnSerializableClass.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,28 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.validator.test.engine.serialization;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class UnSerializableClass {
+ @NotNull
+ private String foo;
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/serialization/UnSerializableClass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Author.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Author.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Author.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Author.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,42 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@AuthorBusinessRules
+public class Author {
+ @Id
+ public Long id;
+
+ @Valid
+ @OneToMany(mappedBy = "author")
+ public List<Book> books = new ArrayList<Book>();
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Author.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/AuthorBusinessRules.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/AuthorBusinessRules.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/AuthorBusinessRules.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/AuthorBusinessRules.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,38 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+@Constraint(validatedBy = {})
+@Documented
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface AuthorBusinessRules {
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/AuthorBusinessRules.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Book.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Book.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Book.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Book.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@BookBusinessRules
+@Entity
+public class Book {
+ @Id
+ public Long id;
+
+ @ManyToOne
+ public Author author;
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Book.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/BookBusinessRules.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/BookBusinessRules.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/BookBusinessRules.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/BookBusinessRules.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+@Constraint(validatedBy = {})
+@Documented
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface BookBusinessRules {
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/BookBusinessRules.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/CachedTraversableResolverTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/CachedTraversableResolverTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/CachedTraversableResolverTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/CachedTraversableResolverTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,138 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import java.lang.annotation.ElementType;
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.TraversableResolver;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.Path;
+import javax.validation.groups.Default;
+
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+/**
+ * @author Emmanuel Bernard
+ */
+//this test is specific to Hibernate Validator
+public class CachedTraversableResolverTest {
+ @Test
+ public void testCache() {
+ TraversableResolver resolver = new AskOnceTR();
+ Configuration<?> config = (Configuration<?>)
Validation.byDefaultProvider()
+ .configure()
+ .traversableResolver( resolver );
+ ValidatorFactory factory = config.buildValidatorFactory();
+ Suit suit = new Suit();
+ suit.setTrousers( new Trousers() );
+ suit.setJacket( new Jacket() );
+ suit.setSize( 3333 );
+ suit.getTrousers().setLength( 32321 );
+ suit.getJacket().setWidth( 432432 );
+ Validator v = factory.getValidator();
+ try {
+ v.validate( suit, Default.class, Cloth.class );
+ }
+ catch ( IllegalStateException e ) {
+ fail( "Traversable Called several times for a given object" );
+ }
+
+ v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
+ try {
+ v.validateProperty( suit, "size", Default.class, Cloth.class );
+ }
+ catch ( IllegalStateException e ) {
+ fail( "Traversable Called several times for a given object" );
+ }
+
+ v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
+ try {
+ v.validateValue( Suit.class, "size", 2, Default.class, Cloth.class );
+ }
+ catch ( IllegalStateException e ) {
+ fail( "Traversable Called several times for a given object" );
+ }
+ }
+
+ private static class AskOnceTR implements TraversableResolver {
+ private Set<Holder> askedReach = new HashSet<Holder>();
+ private Set<Holder> askedCascade = new HashSet<Holder>();
+
+ private boolean isTraversable(Set<Holder> asked, Object traversableObject,
Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject,
ElementType elementType) {
+ Holder h = new Holder( traversableObject, traversableProperty );
+ if ( asked.contains( h ) ) {
+ throw new IllegalStateException( "Called twice" );
+ }
+ asked.add( h );
+ return true;
+ }
+
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return isTraversable(
+ askedReach,
+ traversableObject,
+ traversableProperty,
+ rootBeanType,
+ pathToTraversableObject,
+ elementType
+ );
+ }
+
+ public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return isTraversable(
+ askedCascade,
+ traversableObject,
+ traversableProperty,
+ rootBeanType,
+ pathToTraversableObject,
+ elementType
+ );
+ }
+
+ public static class Holder {
+ Object NULL = new Object();
+ Object to;
+ Path.Node tp;
+
+ public Holder(Object traversableObject, Path.Node traversableProperty) {
+ to = traversableObject == null ? NULL : traversableObject;
+ tp = traversableProperty;
+ }
+
+ @Override
+ public int hashCode() {
+ return to.hashCode() + tp.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( !( obj instanceof Holder ) ) {
+ return false;
+ }
+ Holder that = ( Holder ) obj;
+
+ return to != NULL && to == that.to && tp.equals( that.tp );
+ }
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/CachedTraversableResolverTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Cloth.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Cloth.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Cloth.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Cloth.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Cloth {
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Cloth.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Jacket.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Jacket.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Jacket.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Jacket.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import javax.validation.constraints.Max;
+
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Jacket {
+ Integer width;
+
+ @Max(30)
+ public Integer getWidth() {
+ return width;
+ }
+
+ public void setWidth(Integer width) {
+ this.width = width;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Jacket.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/JpaTraversableResolverTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/JpaTraversableResolverTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/JpaTraversableResolverTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/JpaTraversableResolverTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,67 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.resolver.DefaultTraversableResolver;
+import org.hibernate.validator.test.util.TestUtil;
+
+import static org.testng.Assert.assertTrue;
+
+
+/**
+ * See HV-305
+ *
+ * @author Hardy Ferentschik
+ */
+public class JpaTraversableResolverTest {
+ private Validator validator;
+
+ @BeforeTest
+ public void setUp() {
+ Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.traversableResolver( new DefaultTraversableResolver() );
+ validator = configuration.buildValidatorFactory().getValidator();
+ }
+
+ @Test
+ public void testWithBooks() {
+ Author author = new Author();
+ author.books.add( new Book() );
+ Set<ConstraintViolation<Author>> results = validator.validate( author );
+ assertTrue( results.isEmpty() );
+ }
+
+ @Test
+ public void testWithoutBooks() {
+ Author author = new Author();
+
+ // If the "books" collection is empty, everything works as expected.
+ Set<ConstraintViolation<Author>> results = validator.validate( author );
+ assertTrue( results.isEmpty() );
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/JpaTraversableResolverTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Suit.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Suit.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Suit.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Suit.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,61 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+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 })
+public class Suit {
+ @Max(value=50, groups = { Default.class, Cloth.class})
+ @Min(1)
+ private Integer size;
+ @Valid private Trousers trousers;
+ private Jacket jacket;
+
+ public Trousers getTrousers() {
+ return trousers;
+ }
+
+ public void setTrousers(Trousers trousers) {
+ this.trousers = trousers;
+ }
+
+ @Valid
+ public Jacket getJacket() {
+ return jacket;
+ }
+
+ public void setJacket(Jacket jacket) {
+ this.jacket = jacket;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Suit.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Trousers.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/traversableresolver/Trousers.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Trousers.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Trousers.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.engine.traversableresolver;
+
+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)
+ private Integer length;
+
+ public Integer getLength() {
+ return length;
+ }
+
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/traversableresolver/Trousers.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/ConstraintHelperTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,78 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.util.List;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.metadata.ConstraintHelper;
+import org.hibernate.validator.util.SetAccessibility;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintHelperTest {
+
+ private static ConstraintHelper constraintHelper;
+
+ @BeforeClass
+ public static void init() {
+ constraintHelper = new ConstraintHelper();
+ }
+
+ @Test
+ public void testGetMultiValueConstraints() throws Exception {
+ Engine engine = new Engine();
+ Field[] fields = engine.getClass().getDeclaredFields();
+ assertNotNull( fields );
+ assertTrue( fields.length == 1 );
+ setAccessibility( fields[0] );
+
+ Annotation annotation = fields[0].getAnnotation( Pattern.List.class );
+ assertNotNull( annotation );
+ List<Annotation> multiValueConstraintAnnotations =
constraintHelper.getMultiValueConstraints( annotation );
+ assertTrue( multiValueConstraintAnnotations.size() == 2, "There should be two
constraint annotations" );
+ assertTrue( multiValueConstraintAnnotations.get( 0 ) instanceof Pattern, "Wrong
constraint annotation" );
+ assertTrue( multiValueConstraintAnnotations.get( 1 ) instanceof Pattern, "Wrong
constraint annotation" );
+
+
+ Order order = new Order();
+ fields = order.getClass().getDeclaredFields();
+ assertNotNull( fields );
+ assertTrue( fields.length == 1 );
+ setAccessibility( fields[0] );
+
+ annotation = fields[0].getAnnotation( NotNull.class );
+ assertNotNull( annotation );
+ multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints( annotation
);
+ assertTrue( multiValueConstraintAnnotations.size() == 0, "There should be no
constraint annotations" );
+ }
+
+ void setAccessibility(Member member) {
+ SetAccessibility.action( member ).run();
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ConstraintHelperTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Customer.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/Customer.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Customer.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Customer.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,67 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Customer implements Person {
+
+ private String firstName;
+ private String middleName;
+ private String lastName;
+
+ @Valid
+ private List<Order> orderList = new ArrayList<Order>();
+
+ public void addOrder(Order order) {
+ orderList.add( order );
+ }
+
+ public List<Order> getOrderList() {
+ return orderList;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Customer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ElementDescriptorTest.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/ElementDescriptorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ElementDescriptorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ElementDescriptorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,87 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import java.util.Set;
+import javax.validation.Validator;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ElementDescriptorTest {
+
+
+ @Test
+ public void testGetTypeForConstrainedBean() {
+ Validator validator = TestUtil.getValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
+ assertEquals( beanDescriptor.getElementClass(), Customer.class, "Wrong type."
);
+ }
+
+ @Test
+ public void testGetTypeForConstrainedProperty() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
+ assertEquals( elementDescriptor.getElementClass(), Integer.class, "Wrong
type." );
+ }
+
+ /**
+ * HV-95
+ */
+ @Test
+ public void testElementDescriptorForProperty() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
+ Set<ConstraintDescriptor<?>> constraintDescriptors =
elementDescriptor.getConstraintDescriptors();
+ assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor"
);
+ }
+
+ /**
+ * HV-95
+ */
+ @Test
+ public void testElementDescriptorImmutable() {
+ ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
+ Set<ConstraintDescriptor<?>> constraintDescriptors =
elementDescriptor.getConstraintDescriptors();
+
+ try {
+ constraintDescriptors.add( null );
+ fail( "Set should be immutable" );
+ }
+ catch ( UnsupportedOperationException e ) {
+ // success
+ }
+
+ try {
+ constraintDescriptors.remove( null );
+ fail( "Set should be immutable" );
+ }
+ catch ( UnsupportedOperationException e ) {
+ // success
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/ElementDescriptorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Engine.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/Engine.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Engine.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Engine.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,41 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import javax.validation.constraints.Pattern;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Engine {
+ @Pattern.List({
+ @Pattern(regexp = "^[A-Z0-9-]+$",
+ message = "must contain alphabetical characters only"),
+ @Pattern(regexp = "^....-....-....$", message = "must match
....-....-....")
+ })
+ private String serialNumber;
+
+ public String getSerialNumber() {
+ return serialNumber;
+ }
+
+ public void setSerialNumber(String serialNumber) {
+ this.serialNumber = serialNumber;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Engine.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Order.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/Order.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Order.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Order.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,36 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+ @NotNull(message = "Order number must be specified")
+ Integer orderNumber;
+
+ public Integer getOrderNumber() {
+ return orderNumber;
+ }
+
+ public void setOrderNumber(Integer orderNumber) {
+ this.orderNumber = orderNumber;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Order.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Person.java
(from rev 19511,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/metadata/Person.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Person.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Person.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,36 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.metadata;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+ @NotEmpty(groups = PersonValidation.class)
+ String getFirstName();
+
+ String getMiddleName();
+
+ @NotEmpty
+ String getLastName();
+
+ public interface PersonValidation {
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/metadata/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateBundleTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/resourceloading/AggregateBundleTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateBundleTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateBundleTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,99 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.resourceloading;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import org.testng.annotations.Test;
+
+import
org.hibernate.validator.resourceloading.AggregateResourceBundleLocator.AggregateBundle;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Test for {@link AggregateBundle}.
+ *
+ * @author Gunnar Morling
+ */
+public class AggregateBundleTest {
+
+ private final static String BUNDLE_NAME_1 =
AggregateResourceBundleLocatorTest.class.getPackage()
+ .getName() + ".AggregateResourceBundleLocatorTestBundle1";
+
+ private final static String BUNDLE_NAME_2 =
AggregateResourceBundleLocatorTest.class.getPackage()
+ .getName() + ".AggregateResourceBundleLocatorTestBundle2";
+
+ @Test
+ public void aggregateBundleContainsKeysOfAllSourceBundles() {
+ ResourceBundle bundle_1 = ResourceBundle.getBundle( BUNDLE_NAME_1 );
+ ResourceBundle bundle_2 = ResourceBundle.getBundle( BUNDLE_NAME_2 );
+
+ ResourceBundle aggregateBundle = new AggregateBundle( Arrays.asList( bundle_1, bundle_2
) );
+
+ Set<String> actualKeys = getAsSet( aggregateBundle.getKeys() );
+ Set<String> expectedKeys = new HashSet<String>( Arrays.asList(
"key_1", "key_2", "key_3" ) );
+
+ assertEquals( actualKeys, expectedKeys );
+ }
+
+ @Test
+ public void aggregateBundleWithNoSourceBundlesContainsNoKeys() {
+ ResourceBundle aggregateBundle = new AggregateBundle(
Collections.<ResourceBundle>emptyList() );
+ assertTrue( getAsSet( aggregateBundle.getKeys() ).isEmpty() );
+ }
+
+ @Test
+ public void valuesProperlyRetrievedFromAggregateBundle() {
+ ResourceBundle bundle_1 = ResourceBundle.getBundle( BUNDLE_NAME_1 );
+ ResourceBundle bundle_2 = ResourceBundle.getBundle( BUNDLE_NAME_2 );
+
+ ResourceBundle aggregateBundle = new AggregateBundle( Arrays.asList( bundle_1, bundle_2
) );
+
+ assertEquals(
+ aggregateBundle.getString( "key_1" ),
+ "value 1 from bundle 1",
+ "Value for key_1 should be retrieved from bundle 1"
+ );
+ assertEquals(
+ aggregateBundle.getString( "key_2" ),
+ "value 2 from bundle 1",
+ "Value for key_2 should be retrieved from bundle 1"
+ );
+ assertEquals(
+ aggregateBundle.getString( "key_3" ),
+ "value 3 from bundle 2",
+ "Value for key_3 should be retrieved from bundle 2"
+ );
+ }
+
+ private Set<String> getAsSet(Enumeration<String> e) {
+ Set<String> theValue = new HashSet<String>();
+
+ while ( e.hasMoreElements() ) {
+ theValue.add( e.nextElement() );
+ }
+
+ return theValue;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateBundleTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/resourceloading/AggregateResourceBundleLocatorTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,100 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.resourceloading;
+
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.resourceloading.AggregateResourceBundleLocator;
+import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator;
+import org.hibernate.validator.resourceloading.ResourceBundleLocator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+/**
+ * Test for {@link
org.hibernate.validator.resourceloading.AggregateResourceBundleLocator}.
+ *
+ * @author Gunnar Morling
+ */
+public class AggregateResourceBundleLocatorTest {
+
+ private final static String BUNDLE_NAME_1 =
+ AggregateResourceBundleLocatorTest.class.getPackage()
+ .getName() + ".AggregateResourceBundleLocatorTestBundle1";
+
+ private final static String BUNDLE_NAME_2 =
+ AggregateResourceBundleLocatorTest.class.getPackage()
+ .getName() + ".AggregateResourceBundleLocatorTestBundle2";
+
+ @Test
+ public void valuesAreRetrievedFromBothSourceBundles() {
+
+ ResourceBundleLocator locator =
+ new AggregateResourceBundleLocator( Arrays.asList( BUNDLE_NAME_1, BUNDLE_NAME_2 ) );
+
+ ResourceBundle resourceBundle = locator.getResourceBundle( Locale.getDefault() );
+
+ assertNotNull( resourceBundle );
+
+ //contained in bundle 1
+ assertEquals( resourceBundle.getString( "key_1" ), "value 1 from bundle
1" );
+
+ //contained in both bundles, bundle 1 comes first
+ assertEquals( resourceBundle.getString( "key_2" ), "value 2 from bundle
1" );
+
+ //contained in bundle 2
+ assertEquals( resourceBundle.getString( "key_3" ), "value 3 from bundle
2" );
+ }
+
+ @Test
+ public void valuesAreRetrievedFromDelegate() {
+
+ ResourceBundleLocator locator =
+ new AggregateResourceBundleLocator(
+ Arrays.asList( BUNDLE_NAME_1 ),
+ new PlatformResourceBundleLocator( BUNDLE_NAME_2 )
+ );
+
+ ResourceBundle resourceBundle = locator.getResourceBundle( Locale.ENGLISH );
+
+ assertNotNull( resourceBundle );
+
+ //contained in bundle 1
+ assertEquals( resourceBundle.getString( "key_1" ), "value 1 from bundle
1" );
+
+ //contained in both bundles, but bundle 1 is queried before bundle 2 (delegate)
+ assertEquals( resourceBundle.getString( "key_2" ), "value 2 from bundle
1" );
+
+ //contained in bundle 2
+ assertEquals( resourceBundle.getString( "key_3" ), "value 3 from bundle
2" );
+ }
+
+ @Test
+ public void nullReturnedAsBundleDoesNotExist() {
+
+ ResourceBundleLocator locator = new AggregateResourceBundleLocator( Arrays.asList(
"foo" ) );
+ ResourceBundle resourceBundle = locator.getResourceBundle( Locale.ENGLISH );
+
+ assertNull( resourceBundle );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/BoundariesConstraintValidator.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/BoundariesConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/BoundariesConstraintValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/BoundariesConstraintValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.lang.annotation.Annotation;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class BoundariesConstraintValidator<T extends Annotation>
implements ConstraintValidator<T, Integer> {
+ private int low;
+ private int high;
+
+ protected void initialize(int low, int high) {
+ this.low = low;
+ this.high = high;
+ }
+
+ public boolean isValid(Integer value, ConstraintValidatorContext
constraintValidatorContext) {
+ return value >= low && value <= high;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/BoundariesConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/DummyTraversableResolver.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/DummyTraversableResolver.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/DummyTraversableResolver.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/DummyTraversableResolver.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.lang.annotation.ElementType;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+
+/**
+ * A dummy traversable resolver which returns always {@code true}. This resolver is used
by default by all test cases.
+ *
+ * @author Hardy Ferentschik
+ */
+public class DummyTraversableResolver implements TraversableResolver {
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return true;
+ }
+
+ public boolean isCascadable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+ return true;
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/DummyTraversableResolver.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/IdentitySetTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/IdentitySetTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/IdentitySetTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/IdentitySetTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,78 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.util.IdentitySet;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class IdentitySetTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAddIdenticalInstance() {
+ Set identitySet = new IdentitySet();
+ Set hashSet = new HashSet();
+ assertTrue( identitySet.size() == 0 );
+ assertTrue( hashSet.size() == 0 );
+
+ Object o1 = new Object() {
+ int counter = 0;
+
+ public int hashCode() {
+ return counter++;
+ }
+
+ public boolean equals() {
+ return false;
+ }
+ };
+ identitySet.add( o1 );
+ hashSet.add( o1 );
+ assertTrue( identitySet.size() == 1 );
+ assertTrue( hashSet.size() == 1 );
+
+ identitySet.add( o1 );
+ hashSet.add( o1 );
+ assertTrue( identitySet.size() == 1 );
+ assertTrue( hashSet.size() == 2 );
+
+ Object o2 = new Object() {
+ int counter = 0;
+
+ public int hashCode() {
+ return counter++;
+ }
+
+ public boolean equals() {
+ return false;
+ }
+ };
+ identitySet.add( o2 );
+ hashSet.add( o2 );
+ assertTrue( identitySet.size() == 2 );
+ assertTrue( hashSet.size() == 3 );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/IdentitySetTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/Positive.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/Positive.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/Positive.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/Positive.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Documented;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import javax.validation.Constraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Constraint( validatedBy = { PositiveConstraintValidator.class })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Positive {
+ public abstract String message() default "{validation.positive}";
+ public abstract Class<?>[] groups() default {};
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/Positive.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/PositiveConstraintValidator.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/PositiveConstraintValidator.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/PositiveConstraintValidator.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/PositiveConstraintValidator.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class PositiveConstraintValidator extends
BoundariesConstraintValidator<Positive> {
+ public void initialize(Positive constraintAnnotation) {
+ super.initialize( 0, Integer.MAX_VALUE );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/PositiveConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/ReflectionHelperTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,180 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeSet;
+import javax.validation.Payload;
+import javax.validation.ValidationException;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.util.ReflectionHelper;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+/**
+ * Tests for the <code>ReflectionHelper</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ReflectionHelperTest {
+
+ @Test
+ public void testIsIterable() throws Exception {
+ Type type = TestTypes.class.getField( "stringList" ).getGenericType();
+ assertTrue( ReflectionHelper.isIterable( type ) );
+
+ assertTrue( ReflectionHelper.isIterable( TreeSet.class ) );
+
+ assertTrue( ReflectionHelper.isIterable( List.class ) );
+ assertTrue( ReflectionHelper.isIterable( HashSet.class ) );
+ assertTrue( ReflectionHelper.isIterable( Iterable.class ) );
+ assertTrue( ReflectionHelper.isIterable( Collection.class ) );
+
+ assertFalse( ReflectionHelper.isIterable( null ) );
+ assertFalse( ReflectionHelper.isIterable( Object.class ) );
+ }
+
+ @Test
+ public void testIsMap() throws Exception {
+ assertTrue( ReflectionHelper.isMap( Map.class ) );
+ assertTrue( ReflectionHelper.isMap( SortedMap.class ) );
+
+ Type type = TestTypes.class.getField( "objectMap" ).getGenericType();
+ assertTrue( ReflectionHelper.isMap( type ) );
+
+ assertFalse( ReflectionHelper.isMap( null ) );
+ assertFalse( ReflectionHelper.isMap( Object.class ) );
+ }
+
+ @Test
+ public void testGetIndexedType() throws Exception {
+ Type type = TestTypes.class.getField( "stringList" ).getGenericType();
+ assertEquals( String.class, ReflectionHelper.getIndexedType( type ) );
+
+ type = TestTypes.class.getField( "objectMap" ).getGenericType();
+ assertEquals( Object.class, ReflectionHelper.getIndexedType( type ) );
+
+ type = TestTypes.class.getField( "stringArray" ).getGenericType();
+ assertEquals( String.class, ReflectionHelper.getIndexedType( type ) );
+ }
+
+ @Test
+ public void testGetIndexedValueForMap() {
+ Map<String, Object> map = new HashMap<String, Object>();
+ Object testObject = new Object();
+ String key = "key";
+ map.put( key, testObject );
+
+ Object value = ReflectionHelper.getMappedValue( map, key );
+ assertEquals( value, testObject, "We should be able to retrieve the indexed
object" );
+
+ value = ReflectionHelper.getMappedValue( map, "foo" );
+ assertNull( value, "A non existent index should return the null value" );
+
+ value = ReflectionHelper.getMappedValue( map, "2" );
+ assertNull( value, "A non existent index should return the null value" );
+ }
+
+ @Test
+ public void testGetIndexedValueForList() {
+ List<Object> list = new ArrayList<Object>();
+ Object testObject = new Object();
+ list.add( testObject );
+
+ Object value = ReflectionHelper.getIndexedValue( list, 0 );
+ assertEquals( value, testObject, "We should be able to retrieve the indexed
object" );
+
+ value = ReflectionHelper.getIndexedValue( list, 2 );
+ assertNull( value, "A non existent index should return the null value" );
+ }
+
+ @Test
+ public void testGetIndexedValueForNull() {
+ Object value = ReflectionHelper.getIndexedValue( null, 0 );
+ assertNull( value );
+ }
+
+ @Test
+ public void testGetMessageParameter() {
+ NotNull testAnnotation = new NotNull() {
+ public String message() {
+ return "test";
+ }
+
+ public Class<?>[] groups() {
+ return new Class<?>[] { Default.class };
+ }
+
+ public Class<? extends Payload>[] payload() {
+ @SuppressWarnings("unchecked")
+ Class<? extends Payload>[] classes = new Class[] { };
+ return classes;
+ }
+
+ public Class<? extends Annotation> annotationType() {
+ return this.getClass();
+ }
+ };
+ String message = ReflectionHelper.getAnnotationParameter( testAnnotation,
"message", String.class );
+ assertEquals( "test", message, "Wrong message" );
+
+ Class<?>[] group = ReflectionHelper.getAnnotationParameter( testAnnotation,
"groups", Class[].class );
+ assertEquals( group[0], Default.class, "Wrong message" );
+
+ try {
+ ReflectionHelper.getAnnotationParameter( testAnnotation, "message",
Integer.class );
+ fail();
+ }
+ catch ( ValidationException e ) {
+ assertTrue( e.getMessage().startsWith( "Wrong parameter type." ),
"Wrong exception message" );
+ }
+
+ try {
+ ReflectionHelper.getAnnotationParameter( testAnnotation, "foo",
Integer.class );
+ fail();
+ }
+ catch ( ValidationException e ) {
+ assertTrue(
+ e.getMessage().startsWith( "The specified annotation defines no parameter"
),
+ "Wrong exception message"
+ );
+ }
+ }
+
+ public class TestTypes {
+ public List<String> stringList;
+ public Map<String, Object> objectMap;
+ public String[] stringArray;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ReflectionHelperTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/TestUtil.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,307 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Path;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+import javax.validation.spi.ValidationProvider;
+
+import org.slf4j.Logger;
+
+import org.hibernate.validator.HibernateValidator;
+import org.hibernate.validator.HibernateValidatorConfiguration;
+import org.hibernate.validator.engine.PathImpl;
+import org.hibernate.validator.util.LoggerFactory;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.FileAssert.fail;
+
+/**
+ * Tests for the <code>ReflectionHelper</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class TestUtil {
+ private static final Logger log = LoggerFactory.make();
+
+ private static Validator hibernateValidator;
+
+ private TestUtil() {
+ }
+
+ public static Validator getValidator() {
+ if ( hibernateValidator == null ) {
+ Configuration configuration = getConfiguration();
+ configuration.traversableResolver( new DummyTraversableResolver() );
+ hibernateValidator = configuration.buildValidatorFactory().getValidator();
+ }
+ return hibernateValidator;
+ }
+
+ public static Configuration<HibernateValidatorConfiguration> getConfiguration() {
+ return Validation.byProvider( HibernateValidator.class ).configure();
+ }
+
+ public static <T extends Configuration<T>, U extends
ValidationProvider<T>> T getConfiguration(Class<U> type) {
+ return Validation.byProvider( type ).configure();
+ }
+
+ /**
+ * @param path The path to the xml file which should server as
<code>validation.xml</code> for the returned
+ * <code>Validator</code>.
+ *
+ * @return A <code>Validator</code> instance which respects the
configuration specified in the file with the path
+ * <code>path</code>.
+ */
+ public static Validator getValidatorWithCustomConfiguration(String path) {
+ Thread.currentThread().setContextClassLoader( new CustomValidationXmlClassLoader( path
) );
+
+ HibernateValidatorConfiguration configuration = Validation
+ .byProvider( HibernateValidator.class )
+ .configure();
+ return configuration.buildValidatorFactory().getValidator();
+ }
+
+ /**
+ * @return A <code>Validator</code> instance which ignores
<i>validation.xml</code>.
+ */
+ public static Validator getValidatorIgnoringValidationXml() {
+ Thread.currentThread().setContextClassLoader( new IgnoringValidationXmlClassLoader()
);
+
+ HibernateValidatorConfiguration configuration = Validation
+ .byProvider( HibernateValidator.class )
+ .configure();
+ return configuration.buildValidatorFactory().getValidator();
+ }
+
+ public static ConstraintDescriptor<?>
getSingleConstraintDescriptorFor(Class<?> clazz, String property) {
+ Set<ConstraintDescriptor<?>> constraintDescriptors =
getConstraintDescriptorsFor( clazz, property );
+ assertTrue(
+ constraintDescriptors.size() == 1, "This method should only be used when there
is a single constraint"
+ );
+ return constraintDescriptors.iterator().next();
+ }
+
+ public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String
property) {
+ Validator validator = getValidator();
+ return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property
);
+ }
+
+ public static Set<ConstraintDescriptor<?>>
getConstraintDescriptorsFor(Class<?> clazz, String property) {
+ ElementDescriptor elementDescriptor = getPropertyDescriptor( clazz, property );
+ return elementDescriptor.getConstraintDescriptors();
+ }
+
+ public static <T> void
assertCorrectConstraintViolationMessages(Set<ConstraintViolation<T>>
violations, String... messages) {
+ List<String> actualMessages = new ArrayList<String>();
+ for ( ConstraintViolation<?> violation : violations ) {
+ actualMessages.add( violation.getMessage() );
+ }
+
+ assertEquals( actualMessages.size(), messages.length, "Wrong number of error
messages" );
+
+ for ( String expectedMessage : messages ) {
+ assertTrue(
+ actualMessages.contains( expectedMessage ),
+ "The message '" + expectedMessage + "' should have been in
the list of actual messages: " + actualMessages
+ );
+ actualMessages.remove( expectedMessage );
+ }
+ assertTrue(
+ actualMessages.isEmpty(), "Actual messages contained more messages as specified
expected messages"
+ );
+ }
+
+ public static <T> void
assertCorrectConstraintTypes(Set<ConstraintViolation<T>> violations,
Class<?>... expectedConstraintTypes) {
+ List<String> actualConstraintTypes = new ArrayList<String>();
+ for ( ConstraintViolation<?> violation : violations ) {
+ actualConstraintTypes.add(
+ ( ( Annotation ) violation.getConstraintDescriptor().getAnnotation()
).annotationType().getName()
+ );
+ }
+
+ assertEquals(
+ expectedConstraintTypes.length, actualConstraintTypes.size(), "Wrong number of
constraint types."
+ );
+
+ for ( Class<?> expectedConstraintType : expectedConstraintTypes ) {
+ assertTrue(
+ actualConstraintTypes.contains( expectedConstraintType.getName() ),
+ "The constraint type " + expectedConstraintType.getName() + " should
have been violated."
+ );
+ }
+ }
+
+ public static <T> void
assertCorrectPropertyPaths(Set<ConstraintViolation<T>> violations, String...
propertyPaths) {
+ List<Path> propertyPathsOfViolations = new ArrayList<Path>();
+ for ( ConstraintViolation<?> violation : violations ) {
+ propertyPathsOfViolations.add( violation.getPropertyPath() );
+ }
+
+ for ( String propertyPath : propertyPaths ) {
+ Path expectedPath = PathImpl.createPathFromString( propertyPath );
+ boolean containsPath = false;
+ for ( Path actualPath : propertyPathsOfViolations ) {
+ if ( assertEqualPaths( expectedPath, actualPath ) ) {
+ containsPath = true;
+ break;
+ }
+ }
+ if ( !containsPath ) {
+ fail( expectedPath + " is not in the list of path instances contained in the
actual constraint violations: " + propertyPathsOfViolations );
+ }
+ }
+ }
+
+ public static void assertConstraintViolation(ConstraintViolation violation, String
errorMessage, Class rootBean, Object invalidValue, String propertyPath, Class leafBean) {
+ assertEquals(
+
+ violation.getLeafBean().getClass(),
+ leafBean,
+ "Wrong leaf bean type"
+ );
+ assertConstraintViolation( violation, errorMessage, rootBean, invalidValue,
propertyPath );
+ }
+
+ public static void assertConstraintViolation(ConstraintViolation violation, String
errorMessage, Class rootBean, Object invalidValue, String propertyPath) {
+ assertEquals(
+ violation.getPropertyPath(),
+ PathImpl.createPathFromString( propertyPath ),
+ "Wrong propertyPath"
+ );
+ assertConstraintViolation( violation, errorMessage, rootBean, invalidValue );
+ }
+
+ public static void assertConstraintViolation(ConstraintViolation violation, String
errorMessage, Class rootBean, Object invalidValue) {
+ assertEquals(
+ violation.getInvalidValue(),
+ invalidValue,
+ "Wrong invalid value"
+ );
+ assertConstraintViolation( violation, errorMessage, rootBean );
+ }
+
+ public static void assertConstraintViolation(ConstraintViolation violation, String
errorMessage, Class rootBean) {
+ assertEquals(
+ violation.getRootBean().getClass(),
+ rootBean,
+ "Wrong root bean type"
+ );
+ assertConstraintViolation( violation, errorMessage );
+ }
+
+ public static void assertConstraintViolation(ConstraintViolation violation, String
message) {
+ assertEquals( violation.getMessage(), message, "Wrong message" );
+ }
+
+ public static void assertNumberOfViolations(Set violations, int expectedViolations) {
+ assertEquals( violations.size(), expectedViolations, "Wrong number of constraint
violations" );
+ }
+
+ public static boolean assertEqualPaths(Path p1, Path p2) {
+ Iterator<Path.Node> p1Iterator = p1.iterator();
+ Iterator<Path.Node> p2Iterator = p2.iterator();
+ while ( p1Iterator.hasNext() ) {
+ Path.Node p1Node = p1Iterator.next();
+ if ( !p2Iterator.hasNext() ) {
+ return false;
+ }
+ Path.Node p2Node = p2Iterator.next();
+
+ // do the comparison on the node values
+ if ( p2Node.getName() == null ) {
+ if ( p1Node.getName() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getName().equals( p1Node.getName() ) ) {
+ return false;
+ }
+
+ if ( p2Node.isInIterable() != p1Node.isInIterable() ) {
+ return false;
+ }
+
+
+ if ( p2Node.getIndex() == null ) {
+ if ( p1Node.getIndex() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getIndex().equals( p1Node.getIndex() ) ) {
+ return false;
+ }
+
+ if ( p2Node.getKey() == null ) {
+ if ( p1Node.getKey() != null ) {
+ return false;
+ }
+ }
+ else if ( !p2Node.getKey().equals( p1Node.getKey() ) ) {
+ return false;
+ }
+ }
+
+ return !p2Iterator.hasNext();
+ }
+
+ private static class CustomValidationXmlClassLoader extends ClassLoader {
+ private final String customValidationXmlPath;
+
+ CustomValidationXmlClassLoader(String pathToCustomValidationXml) {
+ super( CustomValidationXmlClassLoader.class.getClassLoader() );
+ customValidationXmlPath = pathToCustomValidationXml;
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ String finalPath = path;
+ if ( "META-INF/validation.xml".equals( path ) ) {
+ log.info( "Using {} as validation.xml", customValidationXmlPath );
+ finalPath = customValidationXmlPath;
+ }
+ return super.getResourceAsStream( finalPath );
+ }
+ }
+
+ private static class IgnoringValidationXmlClassLoader extends ClassLoader {
+ IgnoringValidationXmlClassLoader() {
+ super( IgnoringValidationXmlClassLoader.class.getClassLoader() );
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ if ( "META-INF/validation.xml".equals( path ) ) {
+ log.info( "Ignoring call to load validation.xml" );
+ return null;
+ }
+ return super.getResourceAsStream( path );
+ }
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/TestUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ValidatorTypeTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/ValidatorTypeTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ValidatorTypeTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ValidatorTypeTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,50 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.validation.ConstraintValidator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.util.ValidatorTypeHelper;
+
+/**
+ * Tests for message resolution.
+ *
+ * @author Emmanuel Bernard
+ */
+public class ValidatorTypeTest {
+
+ @Test
+ public void testTypeDiscovery() {
+ List<Class<? extends ConstraintValidator<Positive, ?>>> validators =
+ new ArrayList<Class<? extends ConstraintValidator<Positive,
?>>>();
+ validators.add( PositiveConstraintValidator.class );
+ Map<Type, Class<? extends ConstraintValidator<?, ?>>> validatorsTypes
= ValidatorTypeHelper
+ .getValidatorsTypes( validators );
+
+ assertEquals( validatorsTypes.get( Integer.class ), PositiveConstraintValidator.class
);
+ assertNull( validatorsTypes.get( String.class ) );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/ValidatorTypeTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/AnnotationFactoryTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/util/annotationfactory/AnnotationFactoryTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/AnnotationFactoryTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/AnnotationFactoryTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,62 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.util.annotationfactory;
+
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AnnotationFactoryTest {
+
+ @Test
+ public void createAnnotationProxy() {
+ AnnotationDescriptor<Size> descriptor = new AnnotationDescriptor<Size>(
Size.class );
+ descriptor.setValue( "min", 5 );
+ descriptor.setValue( "max", 10 );
+
+ Size size = AnnotationFactory.create( descriptor );
+
+ assertEquals( size.min(), 5, "Wrong parameter value" );
+ assertEquals( size.max(), 10, "Wrong parameter value" );
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void createAnnotationProxyMissingRequiredParamter() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ AnnotationFactory.create( descriptor );
+ }
+
+ @Test
+ public void createAnnotationProxyWithRequiredParamter() {
+ AnnotationDescriptor<Pattern> descriptor = new
AnnotationDescriptor<Pattern>( Pattern.class );
+ descriptor.setValue( "regexp", ".*" );
+
+ Pattern pattern = AnnotationFactory.create( descriptor );
+
+ assertEquals( ".*", pattern.regexp(), "Wrong parameter value" );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/util/annotationfactory/AnnotationFactoryTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Customer.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/Customer.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Customer.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Customer.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,71 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Customer implements Person {
+ private String firstName;
+ private String middleName;
+ private String lastName;
+
+ private String customerId;
+
+ private String password;
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(final String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return this.middleName;
+ }
+
+ public void setMiddleName(final String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(final String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getCustomerId() {
+ return this.customerId;
+ }
+
+ public void setCustomerId(final String customerId) {
+ this.customerId = customerId;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ public void setPassword(final String password) {
+ this.password = password;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Customer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterface.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/MyInterface.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterface.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterface.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,27 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface MyInterface {
+ Integer getId();
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterface.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterfaceImpl.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/MyInterfaceImpl.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterfaceImpl.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterfaceImpl.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,28 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MyInterfaceImpl implements MyInterface {
+ public Integer getId() {
+ return null;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/MyInterfaceImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Person.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/Person.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Person.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Person.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,30 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+
+ String getFirstName();
+
+ String getMiddleName();
+
+ String getLastName();
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Properties.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/Properties.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Properties.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Properties.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,37 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Properties {
+ private List<String> listOfString;
+
+ public List<String> getListOfString() {
+ return listOfString;
+ }
+
+ public void setListOfString(List<String> listOfString) {
+ this.listOfString = listOfString;
+ }
+}
+
+
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/Properties.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/XmlMappingTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/XmlMappingTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/XmlMappingTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/XmlMappingTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,127 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlMappingTest {
+
+ @Test
+ /**
+ * HV-214
+ */
+ public void testConstraintInheritanceWithXmlConfiguration() {
+
+ final Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.addMapping( XmlMappingTest.class.getResourceAsStream(
"mapping.xml" ) );
+
+ final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ final Validator validator = validatorFactory.getValidator();
+
+ final Set<ConstraintViolation<Customer>> violations = validator.validate(
new Customer(), Default.class );
+
+ assertEquals( violations.size(), 1 );
+ }
+
+ @Test
+ /**
+ * HV-252
+ */
+ public void testListOfString() {
+
+ final Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.addMapping( XmlMappingTest.class.getResourceAsStream(
"properties-mapping.xml" ) );
+
+ final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ final Validator validator = validatorFactory.getValidator();
+
+ List<String> listOfString = new ArrayList<String>();
+ listOfString.add( "one" );
+ listOfString.add( "two" );
+ listOfString.add( "three" );
+
+ final Set<ConstraintViolation<Properties>> violations =
validator.validateValue(
+ Properties.class, "listOfString", listOfString
+ );
+
+ assertEquals( violations.size(), 0 );
+ }
+
+ @Test
+ /**
+ * HV-262
+ */
+ public void testInterfaceConfiguration() {
+
+ final Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.addMapping( XmlMappingTest.class.getResourceAsStream(
"my-interface-mapping.xml" ) );
+
+ final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ final Validator validator = validatorFactory.getValidator();
+ final Set<ConstraintViolation<MyInterfaceImpl>> violations =
validator.validate( new MyInterfaceImpl() );
+
+ assertEquals( violations.size(), 1 );
+ }
+
+ @Test
+ /**
+ * HV-262
+ */
+ public void testInterfaceImplementationConfiguration() {
+
+ final Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.addMapping( XmlMappingTest.class.getResourceAsStream(
"my-interface-impl-mapping.xml" ) );
+
+ final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ final Validator validator = validatorFactory.getValidator();
+ final Set<ConstraintViolation<MyInterfaceImpl>> violations =
validator.validate( new MyInterfaceImpl() );
+
+ assertEquals( violations.size(), 1 );
+ }
+
+ @Test
+ /**
+ * HV-263
+ */
+ public void testEmptyInterfaceConfiguration() {
+
+ final Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.addMapping( XmlMappingTest.class.getResourceAsStream(
"empty-my-interface-mapping.xml" ) );
+
+ final ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ final Validator validator = validatorFactory.getValidator();
+ final Set<ConstraintViolation<MyInterfaceImpl>> violations =
validator.validate( new MyInterfaceImpl() );
+
+ assertEquals( violations.size(), 0 );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/XmlMappingTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/ICompetition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/ICompetition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/ICompetition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/ICompetition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,20 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration;
+
+public interface ICompetition {}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/ICompetition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/IFixture.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/IFixture.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/IFixture.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/IFixture.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,22 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration;
+
+public interface IFixture {
+ ICompetition getCompetition();
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/IFixture.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/InheritanceMappingsTest.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/InheritanceMappingsTest.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/InheritanceMappingsTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/InheritanceMappingsTest.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,133 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.test.util.DummyTraversableResolver;
+import org.hibernate.validator.test.util.TestUtil;
+import org.hibernate.validator.test.xml.mixedconfiguration.annotation.Competition;
+import org.hibernate.validator.test.xml.mixedconfiguration.annotation.Fixture;
+import org.hibernate.validator.test.xml.mixedconfiguration.annotation.PersonCompetition;
+import org.hibernate.validator.test.xml.mixedconfiguration.annotation.TeamCompetition;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.FileAssert.fail;
+
+
+/**
+ * See HV-265
+ *
+ * @author Hardy Ferentschik
+ */
+public class InheritanceMappingsTest {
+
+ @Test
+ public void defaultConfigurationNoExplicitAnnotationDefinition1() {
+ validateAnnotatedFixture(
+ new PersonCompetition(),
+ TestUtil.getValidator()
+ );
+ }
+
+ @Test
+ public void defaultConfigurationNoExplicitAnnotationDefinition2() {
+ validateAnnotatedFixture(
+ new TeamCompetition(),
+ TestUtil.getValidator()
+ );
+ }
+
+ @Test
+ public void customConfigurationNoExplicitAnnotationDefinition1() {
+ validateAnnotatedFixture(
+ new PersonCompetition(),
+ configure( "annotation-mappings.xml" )
+ );
+ }
+
+ @Test
+ public void customConfigurationNoExplicitAnnotationDefinition2() {
+ validateAnnotatedFixture(
+ new TeamCompetition(),
+ configure( "annotation-mappings.xml" )
+ );
+ }
+
+ @Test
+ public void customConfigurationExplicitXmlDefinition() {
+ validateXmlDefinedFixture(
+ new org.hibernate.validator.test.xml.mixedconfiguration.xml.PersonCompetition(),
+ configure( "xml-mappings.xml" )
+ );
+ }
+
+ @Test
+ public void customConfigurationNoExplicitXmlDefinition() {
+ validateXmlDefinedFixture(
+ new org.hibernate.validator.test.xml.mixedconfiguration.xml.TeamCompetition(),
+ configure( "xml-mappings.xml" )
+ );
+ }
+
+ private Validator configure(String mappingsUrl) {
+ Configuration<?> configuration = TestUtil.getConfiguration();
+ configuration.traversableResolver( new DummyTraversableResolver() );
+ configuration.addMapping( InheritanceMappingsTest.class.getResourceAsStream(
mappingsUrl ) );
+
+ ValidatorFactory validatorFactory = configuration.buildValidatorFactory();
+ return validatorFactory.getValidator();
+ }
+
+ private void validateFixture(IFixture fixture, Validator validator) {
+ Set<ConstraintViolation<IFixture>> violations = validator.validate( fixture
);
+
+ for ( ConstraintViolation<IFixture> violation : violations ) {
+ if ( violation.getLeafBean() instanceof ICompetition
+ && "detail.competition.name".equals(
violation.getPropertyPath().toString() ) ) {
+ assertEquals( violation.getLeafBean(), fixture.getCompetition() );
+ Annotation annotation = ( ( Annotation )
violation.getConstraintDescriptor().getAnnotation() );
+ assertEquals( annotation.annotationType(), NotNull.class );
+ return;
+ }
+ }
+ fail( "@NotNull constraint violation for 'detail.competition.name' not
detected" );
+ }
+
+ private void validateAnnotatedFixture(Competition competition,
+ Validator validator) {
+ Fixture fixture = new Fixture();
+ fixture.setCompetition( competition );
+ validateFixture( fixture, validator );
+ }
+
+ private void
validateXmlDefinedFixture(org.hibernate.validator.test.xml.mixedconfiguration.xml.Competition
competition,
+ Validator validator) {
+ org.hibernate.validator.test.xml.mixedconfiguration.xml.Fixture fixture = new
org.hibernate.validator.test.xml.mixedconfiguration.xml.Fixture();
+ fixture.setCompetition( competition );
+ validateFixture( fixture, validator );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/InheritanceMappingsTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Competition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/Competition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Competition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Competition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,46 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import org.hibernate.validator.test.xml.mixedconfiguration.ICompetition;
+
+public abstract class Competition implements ICompetition {
+
+ @NotNull
+ @Size(min = 1)
+ private String name;
+
+ public Competition() {
+ super();
+ }
+
+ public Competition(String name) {
+ setName( name );
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Competition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Fixture.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/Fixture.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Fixture.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Fixture.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,31 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+import org.hibernate.validator.test.xml.mixedconfiguration.IFixture;
+
+public class Fixture extends Game implements IFixture {
+
+ public Fixture() {
+ super();
+ }
+
+ public Fixture(Competition competition) {
+ super( competition );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Fixture.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Game.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/Game.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Game.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Game.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,48 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+public abstract class Game {
+
+ @NotNull
+ @Valid
+ private GameDetail detail;
+
+ private Game(GameDetail detail) {
+ this.detail = detail;
+ }
+
+ public Game() {
+ this( new GameDetail() );
+ }
+
+ public Game(Competition competition) {
+ this( new GameDetail( competition ) );
+ }
+
+ public Competition getCompetition() {
+ return detail.getCompetition();
+ }
+
+ public void setCompetition(Competition competition) {
+ detail.setCompetition( competition );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/Game.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/GameDetail.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/GameDetail.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/GameDetail.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/GameDetail.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,44 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+public class GameDetail {
+
+ @NotNull
+ @Valid
+ private Competition competition;
+
+ public GameDetail() {
+ super();
+ }
+
+ public GameDetail(Competition competition) {
+ setCompetition( competition );
+ }
+
+ public Competition getCompetition() {
+ return competition;
+ }
+
+ public void setCompetition(Competition competition) {
+ this.competition = competition;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/GameDetail.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/PersonCompetition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/PersonCompetition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/PersonCompetition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/PersonCompetition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,29 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+public class PersonCompetition extends Competition {
+
+ public PersonCompetition() {
+ super();
+ }
+
+ public PersonCompetition(String name) {
+ super( name );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/PersonCompetition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/TeamCompetition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/annotation/TeamCompetition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/TeamCompetition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/TeamCompetition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,28 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.annotation;
+
+public class TeamCompetition extends Competition {
+ public TeamCompetition() {
+ super();
+ }
+
+ public TeamCompetition(String name) {
+ super( name );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/annotation/TeamCompetition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Competition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/Competition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Competition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Competition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,41 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+import org.hibernate.validator.test.xml.mixedconfiguration.ICompetition;
+
+public abstract class Competition implements ICompetition {
+
+ private String name;
+
+ public Competition() {
+ super();
+ }
+
+ public Competition(String name) {
+ setName( name );
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Competition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Fixture.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/Fixture.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Fixture.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Fixture.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,36 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+import org.hibernate.validator.test.xml.mixedconfiguration.IFixture;
+
+public class Fixture extends Game implements IFixture {
+
+ public Fixture() {
+ super();
+ }
+
+ public Fixture(Competition competition) {
+ super( competition );
+ }
+
+ @Override
+ public void setCompetition(Competition competition) {
+ super.setCompetition( competition );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Fixture.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Game.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/Game.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Game.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Game.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+public abstract class Game {
+
+ private GameDetail detail;
+
+ private Game(GameDetail detail) {
+ this.detail = detail;
+ }
+
+ public Game() {
+ this( new GameDetail() );
+ }
+
+ public Game(Competition competition) {
+ this( new GameDetail( competition ) );
+ }
+
+ public Competition getCompetition() {
+ return detail.getCompetition();
+ }
+
+ public void setCompetition(Competition competition) {
+ detail.setCompetition( competition );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/Game.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/GameDetail.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/GameDetail.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/GameDetail.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/GameDetail.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+public class GameDetail {
+
+ private Competition competition;
+
+ public GameDetail() {
+ super();
+ }
+
+ public GameDetail(Competition competition) {
+ setCompetition( competition );
+ }
+
+ public Competition getCompetition() {
+ return competition;
+ }
+
+ public void setCompetition(Competition competition) {
+ this.competition = competition;
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/GameDetail.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/PersonCompetition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/PersonCompetition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/PersonCompetition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/PersonCompetition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,29 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+public class PersonCompetition extends Competition {
+
+ public PersonCompetition() {
+ super();
+ }
+
+ public PersonCompetition(String name) {
+ super( name );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/PersonCompetition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/TeamCompetition.java
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/xml/mixedconfiguration/xml/TeamCompetition.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/TeamCompetition.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/TeamCompetition.java 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,29 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.validator.test.xml.mixedconfiguration.xml;
+
+public class TeamCompetition extends Competition {
+
+ public TeamCompetition() {
+ super();
+ }
+
+ public TeamCompetition(String name) {
+ super( name );
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/xml/mixedconfiguration/xml/TeamCompetition.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle1.properties
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/resourceloading/AggregateResourceBundleLocatorTestBundle1.properties)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle1.properties
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle1.properties 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,2 @@
+key_1=value 1 from bundle 1
+key_2=value 2 from bundle 1
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle2.properties
(from rev 19546,
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/resourceloading/AggregateResourceBundleLocatorTestBundle2.properties)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle2.properties
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/resourceloading/AggregateResourceBundleLocatorTestBundle2.properties 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,2 @@
+key_2=value 2 from bundle 2
+key_3=value 3 from bundle 2
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/empty-my-interface-mapping.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/empty-my-interface-mapping.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/empty-my-interface-mapping.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/empty-my-interface-mapping.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,7 @@
+<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">
+ <default-package>org.hibernate.validator.xml</default-package>
+ <bean class="org.hibernate.validator.test.xml.MyInterface"
ignore-annotations="true">
+ </bean>
+</constraint-mappings>
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mapping.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/mapping.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mapping.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mapping.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,16 @@
+<constraint-mappings
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation=
+ "http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd">
+
+ <default-package>org.hibernate.validator.xml</default-package>
+
+ <bean class="org.hibernate.validator.test.xml.Person"
ignore-annotations="false">
+ <getter name="firstName">
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ </getter>
+ </bean>
+
+ <bean class="org.hibernate.validator.test.xml.Customer"
ignore-annotations="false"/>
+</constraint-mappings>
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/annotation-mappings.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/mixedconfiguration/annotation-mappings.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/annotation-mappings.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/annotation-mappings.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<constraint-mappings
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+
http://jboss.org/xml/ns/javax/validation/mapping
+ validation-mapping-1.0.xsd">
+
+</constraint-mappings>
Property changes on:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/annotation-mappings.xml
___________________________________________________________________
Name: svn:executable
+ *
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/xml-mappings.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/mixedconfiguration/xml-mappings.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/xml-mappings.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/xml-mappings.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<constraint-mappings
+
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+
http://jboss.org/xml/ns/javax/validation/mapping
+ validation-mapping-1.0.xsd">
+
+
<default-package>org.hibernate.validator.xml.mixedconfiguration.xml</default-package>
+
+ <bean
class="org.hibernate.validator.test.xml.mixedconfiguration.xml.Competition"
ignore-annotations="true">
+ <field name="name">
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ <constraint annotation="javax.validation.constraints.Size">
+ <element name="min">1</element>
+ </constraint>
+ </field>
+ </bean>
+ <bean
class="org.hibernate.validator.test.xml.mixedconfiguration.xml.PersonCompetition"
ignore-annotations="true"/>
+ <!--bean class="TeamCompetition"/-->
+
+ <bean
class="org.hibernate.validator.test.xml.mixedconfiguration.xml.Game"
ignore-annotations="true">
+ <field name="detail">
+ <valid/>
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ </field>
+ </bean>
+
+ <bean
class="org.hibernate.validator.test.xml.mixedconfiguration.xml.GameDetail"
ignore-annotations="true">
+ <field name="competition">
+ <valid/>
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ </field>
+ </bean>
+ <bean
class="org.hibernate.validator.test.xml.mixedconfiguration.xml.Fixture"/>
+
+</constraint-mappings>
Property changes on:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/mixedconfiguration/xml-mappings.xml
___________________________________________________________________
Name: svn:executable
+ *
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-impl-mapping.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/my-interface-impl-mapping.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-impl-mapping.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-impl-mapping.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,10 @@
+<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">
+ <default-package>org.hibernate.validator.xml</default-package>
+ <bean class="org.hibernate.validator.test.xml.MyInterfaceImpl"
ignore-annotations="true">
+ <getter name="id" ignore-annotations="true">
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ </getter>
+ </bean>
+</constraint-mappings>
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-mapping.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/my-interface-mapping.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-mapping.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/my-interface-mapping.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,10 @@
+<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">
+ <default-package>org.hibernate.validator.xml</default-package>
+ <bean class="org.hibernate.validator.test.xml.MyInterface"
ignore-annotations="true">
+ <getter name="id" ignore-annotations="true">
+ <constraint
annotation="javax.validation.constraints.NotNull"/>
+ </getter>
+ </bean>
+</constraint-mappings>
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/properties-mapping.xml
(from rev 19546,
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/xml/properties-mapping.xml)
===================================================================
---
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/properties-mapping.xml
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/properties-mapping.xml 2010-05-19
15:40:07 UTC (rev 19547)
@@ -0,0 +1,11 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<constraint-mappings
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping
validation-mapping-1.0.xsd">
+ <default-package>org.hibernate.validator.xml</default-package>
+ <bean class="org.hibernate.validator.test.xml.Properties"
ignore-annotations="true">
+ <getter name="listOfString"
ignore-annotations="true">
+ <constraint annotation="javax.validation.constraints.NotNull"
/>
+ </getter>
+ </bean>
+</constraint-mappings>
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/test/resources/org/hibernate/validator/test/xml/properties-mapping.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml
===================================================================
--- validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml 2010-05-19 04:25:19
UTC (rev 19546)
+++ validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml 2010-05-19 15:40:07
UTC (rev 19547)
@@ -3,20 +3,25 @@
<suite name="Hibernate Validator Unit Tests" verbose="1">
<test name="Unit tests">
<packages>
- <package name="org.hibernate.validator.bootstrap"/>
- <package name="org.hibernate.validator.constraints"/>
- <package name="org.hibernate.validator.constraints.impl"/>
- <package
name="org.hibernate.validator.constraints.composition"/>
- <package name="org.hibernate.validator.engine"/>
- <package name="org.hibernate.validator.engine.groups"/>
- <package
name="org.hibernate.validator.engine.messageinterpolation"/>
- <package
name="org.hibernate.validator.engine.serialization"/>
- <package
name="org.hibernate.validator.engine.traversableresolver"/>
- <package name="org.hibernate.validator.metadata"/>
- <package name="org.hibernate.validator.util"/>
- <package
name="org.hibernate.validator.util.annotationfactory"/>
- <package name="org.hibernate.validator.xml"/>
- <package
name="org.hibernate.validator.xml.mixedconfiguration"/>
+ <package name="org.hibernate.validator.test"/>
+ <package name="org.hibernate.validator.test.bootstrap"/>
+ <package name="org.hibernate.validator.test.cfg"/>
+ <package name="org.hibernate.validator.test.constraints"/>
+ <package
name="org.hibernate.validator.test.constraints.impl"/>
+ <package
name="org.hibernate.validator.test.constraints.composition"/>
+ <package name="org.hibernate.validator.test.engine"/>
+ <package
name="org.hibernate.validator.test.engine.customerror"/>
+ <package name="org.hibernate.validator.test.engine.groups"/>
+ <package
name="org.hibernate.validator.test.engine.messageinterpolation"/>
+ <package name="org.hibernate.validator.test.engine.proxy"/>
+ <package
name="org.hibernate.validator.test.engine.serialization"/>
+ <package
name="org.hibernate.validator.test.engine.traversableresolver"/>
+ <package name="org.hibernate.validator.test.metadata"/>
+ <package
name="org.hibernate.validator.test.resourceloading"/>
+ <package name="org.hibernate.validator.test.util"/>
+ <package
name="org.hibernate.validator.test.util.annotationfactory"/>
+ <package name="org.hibernate.validator.test.xml"/>
+ <package
name="org.hibernate.validator.test.xml.mixedconfiguration"/>
</packages>
</test>
</suite>
\ No newline at end of file