Author: epbernard
Date: 2007-08-11 02:48:08 -0400 (Sat, 11 Aug 2007)
New Revision: 12923
Added:
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/Cat.java
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/HEMAutoWireringTest.java
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/NoOpListener.java
Log:
Remove dependency in tests from em -> validator: move wiring tests into validator
project
Added: trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/Cat.java
===================================================================
--- trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/Cat.java
(rev 0)
+++
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/Cat.java 2007-08-11
06:48:08 UTC (rev 12923)
@@ -0,0 +1,48 @@
+//$Id$
+package org.hibernate.validator.test.jpa;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.validator.Length;
+import org.hibernate.validator.Min;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Cat implements Serializable {
+ private Integer id;
+ private String name;
+ private long length;
+
+ @Id
+ @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ @Length(min = 4)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Min(0)
+ public long getLength() {
+ return length;
+ }
+
+ public void setLength(long length) {
+ this.length = length;
+ }
+}
\ No newline at end of file
Added:
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/HEMAutoWireringTest.java
===================================================================
---
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/HEMAutoWireringTest.java
(rev 0)
+++
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/HEMAutoWireringTest.java 2007-08-11
06:48:08 UTC (rev 12923)
@@ -0,0 +1,54 @@
+//$Id$
+package org.hibernate.validator.test.jpa;
+
+import java.util.Date;
+import java.util.Map;
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.HibernatePersistence;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.validator.InvalidStateException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class HEMAutoWireringTest extends JPATestCase {
+ public void testPropertyValidation() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ Cat cat = new Cat();
+ cat.setName( "iti" );
+ em.getTransaction().begin();
+ try {
+ em.persist( cat );
+ em.flush();
+ fail( "No validation" );
+ }
+ catch (InvalidStateException e) {
+ //success
+ }
+ finally {
+ em.getTransaction().rollback();
+ em.close();
+ }
+ }
+
+ public void testEventPerProperties() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ assertEquals( "Only validator and explicit NoOp should be present", 2,
+ ( (SessionImplementor) em.getDelegate()
).getListeners().getPreInsertEventListeners().length );
+ em.close();
+ }
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ Cat.class
+ };
+ }
+
+
+ public Map getConfig() {
+ Map config = super.getConfig();
+ config.put( HibernatePersistence.EVENT_LISTENER_PREFIX + ".pre-insert",
NoOpListener.class.getName() );
+ return config;
+ }
+}
Added:
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/NoOpListener.java
===================================================================
---
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/NoOpListener.java
(rev 0)
+++
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/jpa/NoOpListener.java 2007-08-11
06:48:08 UTC (rev 12923)
@@ -0,0 +1,14 @@
+//$Id$
+package org.hibernate.validator.test.jpa;
+
+import org.hibernate.event.PreInsertEventListener;
+import org.hibernate.event.PreInsertEvent;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class NoOpListener implements PreInsertEventListener {
+ public boolean onPreInsert(PreInsertEvent event) {
+ return false;
+ }
+}
Show replies by date