make annotation complie again with java 5

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16530 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Hardy Ferentschik 2009-05-11 12:28:36 +00:00
parent 1aed163763
commit 48916f02eb
1 changed files with 27 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package org.hibernate.test.annotations.beanvalidation; package org.hibernate.test.annotations.beanvalidation;
import java.lang.annotation.Annotation;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -8,7 +9,6 @@ import javax.validation.groups.Default;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.test.annotations.TestCase; import org.hibernate.test.annotations.TestCase;
/** /**
@ -18,32 +18,39 @@ public class BeanValidationGroupsTest extends TestCase {
public void testListeners() { public void testListeners() {
CupHolder ch = new CupHolder(); CupHolder ch = new CupHolder();
ch.setRadius( new BigDecimal( "12" ) ); ch.setRadius( new BigDecimal( "12" ) );
Session s = openSession( ); Session s = openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
try { try {
s.persist( ch ); s.persist( ch );
s.flush(); s.flush();
} }
catch ( ConstraintViolationException e ) { catch ( ConstraintViolationException e ) {
fail("invalid object should not be validated"); fail( "invalid object should not be validated" );
} }
try { try {
ch.setRadius( null ); ch.setRadius( null );
s.flush(); s.flush();
} }
catch ( ConstraintViolationException e ) { catch ( ConstraintViolationException e ) {
fail("invalid object should not be validated"); fail( "invalid object should not be validated" );
} }
try { try {
s.delete( ch ); s.delete( ch );
s.flush(); s.flush();
fail("invalid object should not be persisted"); fail( "invalid object should not be persisted" );
} }
catch ( ConstraintViolationException e ) { catch ( ConstraintViolationException e ) {
assertEquals( 1, e.getConstraintViolations().size() ); assertEquals( 1, e.getConstraintViolations().size() );
assertEquals( NotNull.class, // TODO - seems this explicit case is necessary with JDK 5 (at least on Mac). With Java 6 there is no problem
e.getConstraintViolations().iterator().next().getConstraintDescriptor().getAnnotation().annotationType() Annotation annotation = (Annotation) e.getConstraintViolations()
); .iterator()
.next()
.getConstraintDescriptor()
.getAnnotation();
assertEquals(
NotNull.class,
annotation.annotationType()
);
} }
tx.rollback(); tx.rollback();
s.close(); s.close();
@ -52,12 +59,18 @@ public class BeanValidationGroupsTest extends TestCase {
@Override @Override
protected void configure(Configuration cfg) { protected void configure(Configuration cfg) {
super.configure( cfg ); super.configure( cfg );
cfg.setProperty( "javax.persistence.validation.group.pre-persist", cfg.setProperty(
"" ); "javax.persistence.validation.group.pre-persist",
cfg.setProperty( "javax.persistence.validation.group.pre-update", ""
"" ); );
cfg.setProperty( "javax.persistence.validation.group.pre-remove", cfg.setProperty(
Default.class.getName() + ", " + Strict.class.getName() ); "javax.persistence.validation.group.pre-update",
""
);
cfg.setProperty(
"javax.persistence.validation.group.pre-remove",
Default.class.getName() + ", " + Strict.class.getName()
);
} }
protected Class<?>[] getMappings() { protected Class<?>[] getMappings() {