Author: epbernard
Date: 2007-01-26 21:53:20 -0500 (Fri, 26 Jan 2007)
New Revision: 11109
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/
Removed:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java
Log:
ANN-545 eliminate dep on tests and core validator
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -28,10 +28,9 @@
import org.hibernate.AssertionFailure;
import org.hibernate.Hibernate;
import org.hibernate.MappingException;
-import org.hibernate.cfg.BinderHelper;
-import org.hibernate.cfg.annotations.Version;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Component;
import org.hibernate.reflection.Filter;
import org.hibernate.reflection.ReflectionManager;
import org.hibernate.reflection.XClass;
@@ -602,7 +601,7 @@
String propertyName = getPropertyName( getters.next() );
if ( validator instanceof PropertyConstraint ) {
try {
- Property property = BinderHelper.findPropertyByName(persistentClass, propertyName);
+ Property property = findPropertyByName(persistentClass, propertyName);
if (property != null) {
( (PropertyConstraint) validator ).apply( property );
}
@@ -654,4 +653,60 @@
reflectionManager = new JavaReflectionManager();
initValidator( reflectionManager.toXClass( beanClass ), new HashMap<XClass,
ClassValidator>() );
}
+
+ /**
+ * Retrieve the property by path in a recursive way, including IndetifierProperty in the
loop
+ * If propertyName is null or empty, the IdentifierProperty is returned
+ */
+ public static Property findPropertyByName(PersistentClass associatedClass, String
propertyName) {
+ Property property = null;
+ Property idProperty = associatedClass.getIdentifierProperty();
+ String idName = idProperty != null ? idProperty.getName() : null;
+ try {
+ if ( propertyName == null
+ || propertyName.length() == 0
+ || propertyName.equals( idName ) ) {
+ //default to id
+ property = idProperty;
+ }
+ else {
+ if ( propertyName.indexOf( idName + "." ) == 0 ) {
+ property = idProperty;
+ propertyName = propertyName.substring( idName.length() + 1 );
+ }
+ StringTokenizer st = new StringTokenizer( propertyName, ".", false );
+ while ( st.hasMoreElements() ) {
+ String element = (String) st.nextElement();
+ if ( property == null ) {
+ property = associatedClass.getProperty( element );
+ }
+ else {
+ if ( ! property.isComposite() ) return null;
+ property = ( (Component) property.getValue() ).getProperty( element );
+ }
+ }
+ }
+ }
+ catch (MappingException e) {
+ try {
+ //if we do not find it try to check the identifier mapper
+ if ( associatedClass.getIdentifierMapper() == null ) return null;
+ StringTokenizer st = new StringTokenizer( propertyName, ".", false );
+ while ( st.hasMoreElements() ) {
+ String element = (String) st.nextElement();
+ if ( property == null ) {
+ property = associatedClass.getIdentifierMapper().getProperty( element );
+ }
+ else {
+ if ( ! property.isComposite() ) return null;
+ property = ( (Component) property.getValue() ).getProperty( element );
+ }
+ }
+ }
+ catch (MappingException ee) {
+ return null;
+ }
+ }
+ return property;
+ }
}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/Version.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.validator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Hibernate Vaildator version
+ *
+ * @author Emmanuel Bernard
+ */
+public class Version {
+ public static final String VERSION = "3.2.2.GA";
+ private static Log log = LogFactory.getLog( Version.class );
+
+ static {
+ log.info( "Hibernate Validator " + VERSION );
+ }
+
+ public static void touch() {
+ }
+}
\ No newline at end of file
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Address.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,10 +1,6 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Transient;
-
import org.hibernate.validator.AssertTrue;
import org.hibernate.validator.Length;
import org.hibernate.validator.Min;
@@ -15,7 +11,6 @@
/**
* @author Gavin King
*/
-@Entity
public class Address {
@NotNull
public static String blacklistedZipCode;
@@ -79,13 +74,11 @@
}
@AssertTrue
- @Transient
public boolean isValid() {
return true;
}
@AssertTrue
- @Transient
private boolean isInternalValid() {
return internalValid;
}
@@ -94,7 +87,6 @@
this.internalValid = internalValid;
}
- @Id
@Min(1)
@Range(max = 2000)
public long getId() {
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Building.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,32 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import org.hibernate.validator.Length;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Building {
+ private Long id;
+
+ @Length( min = 1, message = "{notpresent.Key} and #{key.notPresent} and
{key.notPresent2} {min}" )
+ private String address;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
+
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Contact.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,15 +1,11 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Embeddable;
-
import org.hibernate.validator.NotNull;
/**
* @author Emmanuel Bernard
*/
-
-@Embeddable
public class Contact {
@NotNull
private String name;
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,174 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.mapping.Column;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.validator.InvalidStateException;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-
-/**
- * Test the validate framework integration with the Hibernate
- * metadata binding
- *
- * @author Emmanuel Bernard
- */
-public class HibernateAnnotationIntegrationTest extends TestCase {
- public void testApply() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages",
Locale.ENGLISH) ).apply( classMapping );
- Column stateColumn = (Column) classMapping.getProperty( "state"
).getColumnIterator().next();
- assertEquals( stateColumn.getLength(), 3 );
- Column zipColumn = (Column) classMapping.getProperty( "zip"
).getColumnIterator().next();
- assertEquals( zipColumn.getLength(), 5 );
- assertFalse( zipColumn.isNullable() );
- }
-
- public void testApplyOnIdColumn() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
- Column serialColumn = (Column)
classMapping.getIdentifierProperty().getColumnIterator().next();
- assertEquals( "Vaidator annotation not applied on ids", 2,
serialColumn.getLength() );
- }
-
- public void testApplyOnManyToOne() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
- Column serialColumn = (Column) classMapping.getProperty( "tv"
).getColumnIterator().next();
- assertEquals( "Validator annotations not applied on associations", false,
serialColumn.isNullable() );
- }
-
- public void testSingleTableAvoidNotNull() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Rock.class.getName() );
- Column serialColumn = (Column) classMapping.getProperty( "bit"
).getColumnIterator().next();
- assertTrue( "Notnull should not be applised on single tables",
serialColumn.isNullable() );
- }
-
- public void testEvents() throws Exception {
- Session s;
- Transaction tx;
- Address a = new Address();
- Address.blacklistedZipCode = "3232";
- a.setId( 12 );
- a.setCountry( "Country" );
- a.setLine1( "Line 1" );
- a.setZip( "nonnumeric" );
- a.setState( "NY" );
- s = openSession();
- tx = s.beginTransaction();
- try {
- s.persist( a );
- tx.commit();
- fail( "bean should have been validated" );
- }
- catch (InvalidStateException e) {
- //success
- assertEquals( 2, e.getInvalidValues().length );
- assertTrue( "Environment.MESSAGE_INTERPOLATOR_CLASS does not work",
- e.getInvalidValues()[0].getMessage().startsWith( "prefix_")
- );
- }
- finally {
- if ( tx != null ) tx.rollback();
- s.close();
- }
- s = openSession();
- tx = s.beginTransaction();
- a.setCountry( "Country" );
- a.setLine1( "Line 1" );
- a.setZip( "4343" );
- a.setState( "NY" );
- s.persist( a );
- a.setState( "TOOLONG" );
- try {
- s.flush();
- fail( "update should have been checked" );
- }
- catch (InvalidStateException e) {
- assertEquals( 1, e.getInvalidValues().length );
- }
- finally {
- if ( tx != null ) tx.rollback();
- s.close();
- }
- }
-
- public void testComponents() throws Exception {
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
- Martian martian = new Martian();
- MartianPk pk = new MartianPk();
- pk.setColony( "Liberal" ); //one failure
- pk.setName( "Biboudie" );
- MarsAddress address = new MarsAddress();
- address.setContinent( "cont" ); //one failure
- address.setCanal( "Plus" ); //one failure
- martian.setId( pk );
- martian.setAddress( address );
- s.persist( martian );
- try {
- s.flush();
- fail( "Components are not validated" );
- }
- catch (InvalidStateException e) {
- assertEquals( 2, e.getInvalidValues().length );
- }
- finally {
- tx.rollback();
- s.close();
- }
- }
-
- public void testIdClass() throws Exception {
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
- Venusian venus = new Venusian();
- venus.setName( "bibi" );
- venus.setRegion( "ts" );
- s.persist( venus );
- try {
- s.flush();
- fail( "test on embedded properties should have been done" );
- }
- catch (InvalidStateException e) {
- assertEquals( 1, e.getInvalidValues().length );
- }
- finally {
- tx.rollback();
- s.close();
- }
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS,
PrefixMessageInterpolator.class.getName() );
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidatePreUpdateEventListener()} );
- }
-
- protected Class[] getMappings() {
- return new Class[]{
- Address.class,
- Martian.class,
- Venusian.class,
- Tv.class,
- TvOwner.class,
- Music.class,
- Rock.class
- };
- }
-
- public HibernateAnnotationIntegrationTest(String x) {
- super( x );
- }
-}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/InterpolationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,36 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import java.util.MissingResourceException;
+
+import junit.framework.TestCase;
+import org.hibernate.validator.ClassValidator;
+import org.hibernate.validator.InvalidValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class InterpolationTest extends TestCase {
+ public void testMissingKey() {
+
+ Building b = new Building();
+ b.setAddress( "2323 Younge St");
+ ClassValidator<Building> validator = new
ClassValidator<Building>(Building.class);
+ try {
+ validator.getInvalidValues( b );
+ }
+ catch (MissingResourceException e) {
+ fail("message should be interpolated lazily in
DefaultMessageInterpolator");
+ }
+
+ b = new Building();
+ b.setAddress("");
+ boolean failure = false;
+ InvalidValue[] invalidValues = validator.getInvalidValues( b );
+ assertNotSame( "Should have a failure here", 0, invalidValues.length );
+ assertEquals( "Missing key should be left unchanged",
+ "{notpresent.Key} and #{key.notPresent} and {key.notPresent2}
1",
+ invalidValues[0].getMessage() );
+ }
+}
+
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MarsAddress.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,34 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Embeddable;
-
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotNull;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class MarsAddress {
- private String continent;
- private String canal;
-
- @NotNull
- public String getContinent() {
- return continent;
- }
-
- public void setContinent(String continent) {
- this.continent = continent;
- }
-
- @Length(min = 5)
- public String getCanal() {
- return canal;
- }
-
- public void setCanal(String canal) {
- this.canal = canal;
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Martian.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,32 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Martian {
- private MartianPk id;
- private MarsAddress address;
-
- @Id
- public MartianPk getId() {
- return id;
- }
-
- public void setId(MartianPk id) {
- this.id = id;
- }
-
- public MarsAddress getAddress() {
- return address;
- }
-
- public void setAddress(MarsAddress address) {
- this.address = address;
- }
-
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/MartianPk.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,52 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-import javax.persistence.Embeddable;
-
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class MartianPk implements Serializable {
- private String name;
- private String colony;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Length(max = 4)
- public String getColony() {
- return colony;
- }
-
- public void setColony(String colony) {
- this.colony = colony;
- }
-
- public boolean equals(Object o) {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- final MartianPk martianPk = (MartianPk) o;
-
- if ( !colony.equals( martianPk.colony ) ) return false;
- if ( !name.equals( martianPk.name ) ) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = name.hashCode();
- result = 29 * result + colony.hashCode();
- return result;
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Music.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,14 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Music {
- @Id
- public String name;
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,48 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test;
-
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Column;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-
-/**
- * Test the ability to disable DDL update
- *
- * @author Emmanuel Bernard
- */
-public class NonHibernateAnnotationsIntegrationTest extends TestCase {
- public void testNotApply() throws Exception {
- PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages",
Locale.ENGLISH) ).apply( classMapping );
- Column stateColumn = (Column) classMapping.getProperty( "state"
).getColumnIterator().next();
- assertFalse( stateColumn.getLength() == 3 );
- Column zipColumn = (Column) classMapping.getProperty( "zip"
).getColumnIterator().next();
- assertFalse( zipColumn.getLength() == 5 );
- assertTrue( zipColumn.isNullable() );
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS,
PrefixMessageInterpolator.class.getName() );
- cfg.setProperty( Environment.APPLY_TO_DDL, "false" );
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidatePreUpdateEventListener()} );
- }
-
- protected Class[] getMappings() {
- return new Class[]{
- Address.class,
- };
- }
-
- public NonHibernateAnnotationsIntegrationTest(String x) {
- super( x );
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,14 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test;
-
-import org.hibernate.validator.MessageInterpolator;
-import org.hibernate.validator.Validator;
-
-/**
- * @author Emmanuel Bernard
- */
-public class PrefixMessageInterpolator implements MessageInterpolator {
- public String interpolate(String message, Validator validator, MessageInterpolator
defaultInterpolator) {
- return "prefix_" + defaultInterpolator.interpolate( message, validator,
defaultInterpolator );
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Rock.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,15 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import javax.persistence.Entity;
-
-import org.hibernate.validator.NotNull;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Rock extends Music {
- @NotNull
- public Integer bit;
-}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Tv.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,10 +1,8 @@
//$Id$
package org.hibernate.validator.test;
-import java.util.Date;
import java.math.BigInteger;
-import javax.persistence.Entity;
-import javax.persistence.Id;
+import java.util.Date;
import org.hibernate.validator.Future;
import org.hibernate.validator.Length;
@@ -13,9 +11,7 @@
/**
* @author Emmanuel Bernard
*/
-@Entity
public class Tv {
- @Id
@Length(max = 2)
public String serial;
public int size;
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/TvOwner.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,22 +1,16 @@
//$Id$
package org.hibernate.validator.test;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-
import org.hibernate.validator.NotNull;
+import org.hibernate.validator.Valid;
/**
* @author Emmanuel Bernard
*/
-@Entity
public class TvOwner {
- @Id
- @GeneratedValue
public Integer id;
- @ManyToOne
+
@NotNull
+ @Valid
public Tv tv;
}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,11 +1,11 @@
//$Id$
package org.hibernate.validator.test;
+import java.io.Serializable;
+import java.math.BigInteger;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
-import java.math.BigInteger;
-import java.io.Serializable;
import junit.framework.TestCase;
import org.hibernate.validator.ClassValidator;
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/Venusian.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,38 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-(a)IdClass(VenusianPk.class)
-public class Venusian implements Serializable {
- private String region;
- private String name;
-
- @Id
- @Length(min = 3)
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- @Id
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/VenusianPk.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,47 +0,0 @@
-//$Id$
-package org.hibernate.validator.test;
-
-import java.io.Serializable;
-
-/**
- * @author Emmanuel Bernard
- */
-public class VenusianPk implements Serializable {
- private String region;
- private String name;
-
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public boolean equals(Object o) {
- if ( this == o ) return true;
- if ( o == null || getClass() != o.getClass() ) return false;
-
- final VenusianPk that = (VenusianPk) o;
-
- if ( !name.equals( that.name ) ) return false;
- if ( !region.equals( that.region ) ) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = region.hashCode();
- result = 29 * result + name.hashCode();
- return result;
- }
-}
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/Building.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,38 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test.haintegration;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-
-import org.hibernate.validator.NotNull;
-import org.hibernate.validator.Length;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Building {
- @Id
- @GeneratedValue private Long id;
-
- @Length(min=1, message = "{notpresent.Key} and #{key.notPresent} and
{key.notPresent2} {min}")
- private String address;
-
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/EmbeddedObjectTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -8,10 +8,8 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.validator.ClassValidator;
-import org.hibernate.validator.Environment;
import org.hibernate.validator.event.ValidatePreInsertEventListener;
import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
/**
* @author Emmanuel Bernard
Copied:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
(from rev 11108,
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java)
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,173 @@
+//$Id$
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.validator.InvalidStateException;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.event.ValidateEventListener;
+
+/**
+ * Test the validate framework integration with the Hibernate
+ * metadata binding
+ *
+ * @author Emmanuel Bernard
+ */
+public class HibernateAnnotationIntegrationTest extends TestCase {
+ public void testApply() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
+ //new ClassValidator( Address.class, ResourceBundle.getBundle("messages",
Locale.ENGLISH) ).apply( classMapping );
+ Column stateColumn = (Column) classMapping.getProperty( "state"
).getColumnIterator().next();
+ assertEquals( stateColumn.getLength(), 3 );
+ Column zipColumn = (Column) classMapping.getProperty( "zip"
).getColumnIterator().next();
+ assertEquals( zipColumn.getLength(), 5 );
+ assertFalse( zipColumn.isNullable() );
+ }
+
+ public void testApplyOnIdColumn() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
+ Column serialColumn = (Column)
classMapping.getIdentifierProperty().getColumnIterator().next();
+ assertEquals( "Vaidator annotation not applied on ids", 2,
serialColumn.getLength() );
+ }
+
+ public void testApplyOnManyToOne() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
+ Column serialColumn = (Column) classMapping.getProperty( "tv"
).getColumnIterator().next();
+ assertEquals( "Validator annotations not applied on associations", false,
serialColumn.isNullable() );
+ }
+
+ public void testSingleTableAvoidNotNull() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Rock.class.getName() );
+ Column serialColumn = (Column) classMapping.getProperty( "bit"
).getColumnIterator().next();
+ assertTrue( "Notnull should not be applised on single tables",
serialColumn.isNullable() );
+ }
+
+ public void testEvents() throws Exception {
+ Session s;
+ Transaction tx;
+ Address a = new Address();
+ Address.blacklistedZipCode = "3232";
+ a.setId( 12 );
+ a.setCountry( "Country" );
+ a.setLine1( "Line 1" );
+ a.setZip( "nonnumeric" );
+ a.setState( "NY" );
+ s = openSession();
+ tx = s.beginTransaction();
+ try {
+ s.persist( a );
+ tx.commit();
+ fail( "bean should have been validated" );
+ }
+ catch (InvalidStateException e) {
+ //success
+ assertEquals( 2, e.getInvalidValues().length );
+ assertTrue( "Environment.MESSAGE_INTERPOLATOR_CLASS does not work",
+ e.getInvalidValues()[0].getMessage().startsWith( "prefix_")
+ );
+ }
+ finally {
+ if ( tx != null ) tx.rollback();
+ s.close();
+ }
+ s = openSession();
+ tx = s.beginTransaction();
+ a.setCountry( "Country" );
+ a.setLine1( "Line 1" );
+ a.setZip( "4343" );
+ a.setState( "NY" );
+ s.persist( a );
+ a.setState( "TOOLONG" );
+ try {
+ s.flush();
+ fail( "update should have been checked" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 1, e.getInvalidValues().length );
+ }
+ finally {
+ if ( tx != null ) tx.rollback();
+ s.close();
+ }
+ }
+
+ public void testComponents() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Martian martian = new Martian();
+ MartianPk pk = new MartianPk();
+ pk.setColony( "Liberal" ); //one failure
+ pk.setName( "Biboudie" );
+ MarsAddress address = new MarsAddress();
+ address.setContinent( "cont" ); //one failure
+ address.setCanal( "Plus" ); //one failure
+ martian.setId( pk );
+ martian.setAddress( address );
+ s.persist( martian );
+ try {
+ s.flush();
+ fail( "Components are not validated" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 2, e.getInvalidValues().length );
+ }
+ finally {
+ tx.rollback();
+ s.close();
+ }
+ }
+
+ public void testIdClass() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Venusian venus = new Venusian();
+ venus.setName( "bibi" );
+ venus.setRegion( "ts" );
+ s.persist( venus );
+ try {
+ s.flush();
+ fail( "test on embedded properties should have been done" );
+ }
+ catch (InvalidStateException e) {
+ assertEquals( 1, e.getInvalidValues().length );
+ }
+ finally {
+ tx.rollback();
+ s.close();
+ }
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS,
PrefixMessageInterpolator.class.getName() );
+ cfg.getEventListeners()
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidateEventListener()} );
+ cfg.getEventListeners()
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidateEventListener()} );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Address.class,
+ Martian.class,
+ Venusian.class,
+ Tv.class,
+ TvOwner.class,
+ Music.class,
+ Rock.class
+ };
+ }
+
+ public HibernateAnnotationIntegrationTest(String x) {
+ super( x );
+ }
+}
Property changes on:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/HibernateAnnotationIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Deleted:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/InterpolationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,70 +0,0 @@
-//$Id: $
-package org.hibernate.validator.test.haintegration;
-
-import java.util.MissingResourceException;
-
-import org.hibernate.test.annotations.TestCase;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.event.PreInsertEventListener;
-import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.validator.InvalidStateException;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
-
-/**
- * @author Emmanuel Bernard
- */
-public class InterpolationTest extends TestCase {
- public void testMissingKey() {
- Session s = openSession();
- Transaction tx = s.beginTransaction();
- Building b = new Building();
- b.setAddress( "2323 Younge St");
- try {
- s.persist( b );
- s.flush();
- }
- catch (MissingResourceException e) {
- fail("message should be interpolated lazily in
DefaultMessageInterpolator");
- }
- tx.rollback();
- s.close();
-
- s = openSession();
- tx = s.beginTransaction();
- b = new Building();
- b.setAddress("");
- boolean failure = false;
- try {
- s.persist( b );
- s.flush();
- fail("Insert should fail");
- }
- catch (InvalidStateException e) {
- assertEquals( "Missing key should be left unchanged",
- "{notpresent.Key} and #{key.notPresent} and {key.notPresent2}
1",
- e.getInvalidValues()[0].getMessage() );
- failure = true;
- }
- assertTrue( "No invalid state found", failure );
- tx.rollback();
- s.close();
- }
-
- protected Class[] getMappings() {
- return new Class[] {
- Building.class
- };
- }
-
- protected void configure(Configuration cfg) {
- cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidatePreInsertEventListener()} );
- cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidatePreUpdateEventListener()} );
- }
-}
Copied:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
(from rev 11108,
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/NonHibernateAnnotationsIntegrationTest.java)
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/NonHibernateAnnotationsIntegrationTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,47 @@
+//$Id: $
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Column;
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.event.ValidateEventListener;
+
+/**
+ * Test the ability to disable DDL update
+ *
+ * @author Emmanuel Bernard
+ */
+public class NonHibernateAnnotationsIntegrationTest extends TestCase {
+ public void testNotApply() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
+ //new ClassValidator( Address.class, ResourceBundle.getBundle("messages",
Locale.ENGLISH) ).apply( classMapping );
+ Column stateColumn = (Column) classMapping.getProperty( "state"
).getColumnIterator().next();
+ assertFalse( stateColumn.getLength() == 3 );
+ Column zipColumn = (Column) classMapping.getProperty( "zip"
).getColumnIterator().next();
+ assertFalse( zipColumn.getLength() == 5 );
+ assertTrue( zipColumn.isNullable() );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS,
PrefixMessageInterpolator.class.getName() );
+ cfg.setProperty( Environment.APPLY_TO_DDL, "false" );
+ cfg.getEventListeners()
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidateEventListener()} );
+ cfg.getEventListeners()
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidateEventListener()} );
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Address.class,
+ };
+ }
+
+ public NonHibernateAnnotationsIntegrationTest(String x) {
+ super( x );
+ }
+}
Copied:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java
(from rev 11108,
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java)
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java
(rev 0)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/haintegration/PrefixMessageInterpolator.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -0,0 +1,14 @@
+//$Id: $
+package org.hibernate.validator.test.haintegration;
+
+import org.hibernate.validator.MessageInterpolator;
+import org.hibernate.validator.Validator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class PrefixMessageInterpolator implements MessageInterpolator {
+ public String interpolate(String message, Validator validator, MessageInterpolator
defaultInterpolator) {
+ return "prefix_" + defaultInterpolator.interpolate( message, validator,
defaultInterpolator );
+ }
+}
Copied:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators
(from rev 11108,
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator)
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/Car.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/Car.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import java.math.BigDecimal;
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/CreditCard.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/CreditCard.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import org.hibernate.validator.EAN;
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/DigitsTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/DigitsTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,22 +1,17 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import java.math.BigDecimal;
-import org.hibernate.validator.ClassValidator;
-import org.hibernate.validator.InvalidValue;
-import org.hibernate.validator.Environment;
-import org.hibernate.validator.event.ValidatePreInsertEventListener;
-import org.hibernate.validator.event.ValidatePreUpdateEventListener;
-import org.hibernate.validator.test.Address;
-import org.hibernate.validator.test.PrefixMessageInterpolator;
-import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Column;
+import org.hibernate.mapping.PersistentClass;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.validator.ClassValidator;
+import org.hibernate.validator.InvalidValue;
+import org.hibernate.validator.event.ValidateEventListener;
/**
* @author Emmanuel Bernard
@@ -47,9 +42,9 @@
protected void configure(Configuration cfg) {
cfg.getEventListeners()
- .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidatePreInsertEventListener()} );
+ .setPreInsertEventListeners( new PreInsertEventListener[]{new
ValidateEventListener()} );
cfg.getEventListeners()
- .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidatePreUpdateEventListener()} );
+ .setPreUpdateEventListeners( new PreUpdateEventListener[]{new
ValidateEventListener()} );
}
protected Class[] getMappings() {
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/LuhnTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/LuhnTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,5 +1,5 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
import junit.framework.TestCase;
import org.hibernate.validator.ClassValidator;
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validator/NotEmptyTest.java 2007-01-26
21:21:03 UTC (rev 11108)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/validator/test/validators/NotEmptyTest.java 2007-01-27
02:53:20 UTC (rev 11109)
@@ -1,24 +1,9 @@
//$Id: $
-package org.hibernate.validator.test.validator;
+package org.hibernate.validator.test.validators;
-import java.util.ResourceBundle;
-import java.util.Locale;
-import java.util.Date;
-import java.io.Serializable;
-import java.math.BigInteger;
-
import junit.framework.TestCase;
-import org.hibernate.validator.test.Address;
-import org.hibernate.validator.test.Brother;
-import org.hibernate.validator.test.Tv;
-import org.hibernate.validator.test.Vase;
-import org.hibernate.validator.test.Site;
-import org.hibernate.validator.test.Contact;
-import org.hibernate.validator.test.ValidatorTest;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
-import org.hibernate.validator.MessageInterpolator;
-import org.hibernate.validator.Validator;
/**
* @author Gavin King