Author: epbernard
Date: 2009-12-11 04:12:10 -0500 (Fri, 11 Dec 2009)
New Revision: 18206
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/CupHolder.java
Modified:
core/trunk/annotations/pom.xml
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java
core/trunk/entitymanager/pom.xml
core/trunk/parent/pom.xml
Log:
add test on Bean Validation in HEM
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2009-12-11 07:47:28 UTC (rev 18205)
+++ core/trunk/annotations/pom.xml 2009-12-11 09:12:10 UTC (rev 18206)
@@ -76,21 +76,6 @@
</dependency>
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>1.0.0.GA</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>4.0.2.GA</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<build>
<testResources>
<testResource>
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java 2009-12-11
07:47:28 UTC (rev 18205)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java 2009-12-11
09:12:10 UTC (rev 18206)
@@ -125,7 +125,7 @@
StringBuilder builder = new StringBuilder();
builder.append( "validation failed for classes " );
builder.append( classNames );
- builder.append( " during" );
+ builder.append( " during " );
builder.append( operation.getName() );
builder.append( " time for groups " );
builder.append( toString( groups ) );
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2009-12-11 07:47:28 UTC (rev 18205)
+++ core/trunk/entitymanager/pom.xml 2009-12-11 09:12:10 UTC (rev 18206)
@@ -40,6 +40,16 @@
<artifactId>jpa-api</artifactId>
</dependency>
<dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<!--
Only really needed for the antrun plugin defined below (which in turn is
only really needed
to work around a missing feature on the compile plugin; lovely no?).
However I have not
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java 2009-12-11
09:12:10 UTC (rev 18206)
@@ -0,0 +1,38 @@
+package org.hibernate.ejb.test.beanvalidation;
+
+import java.math.BigDecimal;
+
+import javax.persistence.EntityManager;
+import javax.validation.ConstraintViolationException;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class BeanValidationTest extends TestCase {
+
+ public void testBeanValidationIntegration() {
+ CupHolder ch = new CupHolder();
+ ch.setRadius( new BigDecimal( "12" ) );
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ try {
+ em.persist( ch );
+ em.flush();
+ fail("invalid object should not be persisted");
+ }
+ catch ( ConstraintViolationException e ) {
+ assertEquals( 1, e.getConstraintViolations().size() );
+ }
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ @Override
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ CupHolder.class
+ };
+ }
+}
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/CupHolder.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/CupHolder.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/CupHolder.java 2009-12-11
09:12:10 UTC (rev 18206)
@@ -0,0 +1,39 @@
+package org.hibernate.ejb.test.beanvalidation;
+
+import java.math.BigDecimal;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class CupHolder {
+ @Id
+ @GeneratedValue
+ //@GeneratedValue(strategy = GenerationType.SEQUENCE)
+ private Integer id;
+ private BigDecimal radius;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @Max( value = 10, message = "Radius way out")
+ @NotNull
+ public BigDecimal getRadius() {
+ return radius;
+ }
+
+ public void setRadius(BigDecimal radius) {
+ this.radius = radius;
+ }
+}
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2009-12-11 07:47:28 UTC (rev 18205)
+++ core/trunk/parent/pom.xml 2009-12-11 09:12:10 UTC (rev 18206)
@@ -472,6 +472,17 @@
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Beta1</version>
</dependency>
+ <!-- set the optional Bean Validation and Hibernate Validator to be used
throughout the project -->
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.2.GA</version>
+ </dependency>
</dependencies>
</dependencyManagement>
Show replies by date