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