Add more test on ConstraintViolationException and transaction behavior
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18556 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
ae34143257
commit
8146ab3f9e
|
@ -3,6 +3,7 @@ package org.hibernate.ejb.test.beanvalidation;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.RollbackException;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.hibernate.ejb.test.TestCase;
|
||||
|
@ -12,7 +13,7 @@ import org.hibernate.ejb.test.TestCase;
|
|||
*/
|
||||
public class BeanValidationTest extends TestCase {
|
||||
|
||||
public void testBeanValidationIntegration() {
|
||||
public void testBeanValidationIntegrationOnFlush() {
|
||||
CupHolder ch = new CupHolder();
|
||||
ch.setRadius( new BigDecimal( "12" ) );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
@ -33,6 +34,26 @@ public class BeanValidationTest extends TestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
public void testBeanValidationIntegrationOnCommit() {
|
||||
CupHolder ch = new CupHolder();
|
||||
ch.setRadius( new BigDecimal( "9" ) );
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist( ch );
|
||||
em.flush();
|
||||
try {
|
||||
ch.setRadius( new BigDecimal( "12" ) );
|
||||
em.getTransaction().commit();
|
||||
fail("invalid object should not be persisted");
|
||||
}
|
||||
catch ( RollbackException e ) {
|
||||
final Throwable cve = e.getCause();
|
||||
assertTrue( cve instanceof ConstraintViolationException );
|
||||
assertEquals( 1, ( (ConstraintViolationException) cve ).getConstraintViolations().size() );
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
Loading…
Reference in New Issue