use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testEmbeddedCollection.
@Test
public void testEmbeddedCollection() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
PowerSupply ps = new PowerSupply();
screen.setPowerSupply(ps);
DisplayConnector conn = new DisplayConnector();
conn.setNumber(0);
screen.getConnectors().add(conn);
try {
s.persist(screen);
s.flush();
fail("Collection of embedded objects should be validated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
final ConstraintViolation constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(Screen.class, constraintViolation.getRootBeanClass());
// toString works since hibernate validator's Path implementation works accordingly. Should do a Path comparison though
assertEquals("connectors[].number", constraintViolation.getPropertyPath().toString());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class BeanValidationAutoTest method testListeners.
@Test
public void testListeners() {
CupHolder ch = new CupHolder();
ch.setRadius(new BigDecimal("12"));
Session s = openSession();
Transaction tx = s.beginTransaction();
try {
s.persist(ch);
s.flush();
fail("invalid object should not be persisted");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class BeanValidationGroupsTest method testListeners.
@Test
public void testListeners() {
CupHolder ch = new CupHolder();
ch.setRadius(new BigDecimal("12"));
Session s = openSession();
Transaction tx = s.beginTransaction();
try {
s.persist(ch);
s.flush();
} catch (ConstraintViolationException e) {
fail("invalid object should not be validated");
}
try {
ch.setRadius(null);
s.flush();
} catch (ConstraintViolationException e) {
fail("invalid object should not be validated");
}
try {
s.delete(ch);
s.flush();
fail("invalid object should not be persisted");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
// TODO - seems this explicit case is necessary with JDK 5 (at least on Mac). With Java 6 there is no problem
Annotation annotation = e.getConstraintViolations().iterator().next().getConstraintDescriptor().getAnnotation();
assertEquals(NotNull.class, annotation.annotationType());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testNonLazyAssocFieldWithConstraintsFailureExpected.
@Test
public void testNonLazyAssocFieldWithConstraintsFailureExpected() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
screen.setPowerSupply(null);
try {
s.persist(screen);
s.flush();
fail("@NotNull on a non lazy association is not evaluated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project apex-core by apache.
the class CustomControlTupleTest method testApp.
public void testApp(StreamingApplication app) throws Exception {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
lma.prepareDAG(app, conf);
LocalMode.Controller lc = lma.getController();
((StramLocalCluster) lc).setExitCondition(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return endApp;
}
});
// runs for 20 seconds and quits if terminating condition not reached
lc.run(200000);
LOG.info("Control Tuples received {} expected {}", numControlTuples, controlIndex);
Assert.assertTrue("Incorrect Control Tuples", numControlTuples == controlIndex);
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
Aggregations