use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class DDLWithoutCallbackTest method assertDatabaseConstraintViolationThrown.
private void assertDatabaseConstraintViolationThrown(Object o) {
Session s = openSession();
Transaction tx = s.beginTransaction();
try {
s.persist(o);
s.flush();
fail("expecting SQL constraint violation");
} catch (PersistenceException pe) {
final Throwable cause = pe.getCause();
if (cause instanceof ConstraintViolationException) {
fail("invalid object should not be validated");
} else if (cause instanceof org.hibernate.exception.ConstraintViolationException) {
if (getDialect().supportsColumnCheck()) {
// expected
} else {
org.hibernate.exception.ConstraintViolationException cve = (org.hibernate.exception.ConstraintViolationException) cause;
fail("Unexpected SQL constraint violation [" + cve.getConstraintName() + "] : " + cve.getSQLException());
}
}
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testToOneAssocNotValidated.
@Test
public void testToOneAssocNotValidated() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
PowerSupply ps = new PowerSupply();
ps.setPosition("1");
ps.setPower(new BigDecimal(350));
screen.setPowerSupply(ps);
try {
s.persist(screen);
s.flush();
fail("Associated objects should not be validated");
} catch (ConstraintViolationException e) {
assertEquals(1, e.getConstraintViolations().size());
final ConstraintViolation constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(PowerSupply.class, constraintViolation.getRootBeanClass());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project hibernate-orm by hibernate.
the class HibernateTraversableResolverTest method testAssocInEmbeddedNotValidated.
@Test
public void testAssocInEmbeddedNotValidated() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Screen screen = new Screen();
screen.setStopButton(new Button());
screen.getStopButton().setName("STOOOOOP");
PowerSupply ps = new PowerSupply();
screen.setPowerSupply(ps);
DisplayConnector conn = new DisplayConnector();
conn.setNumber(1);
screen.getConnectors().add(conn);
final Display display = new Display();
display.setBrand("dell");
conn.setDisplay(display);
s.persist(display);
s.flush();
try {
display.setBrand(null);
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(Display.class, constraintViolation.getRootBeanClass());
}
tx.rollback();
s.close();
}
use of javax.validation.ConstraintViolationException in project apex-core by apache.
the class ApplicationTest method testApplication.
@Test
public void testApplication() throws IOException, Exception {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
lma.prepareDAG(new Application(), conf);
LocalMode.Controller lc = lma.getController();
// runs for 10 seconds and quits
lc.run(10000);
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
use of javax.validation.ConstraintViolationException in project apex-core by apache.
the class OiOStreamTest method validatePositiveOiOiOExtendeddiamond.
@Test
public void validatePositiveOiOiOExtendeddiamond() {
logger.info("Checking the logic for sanity checking of OiO");
LogicalPlan plan = new LogicalPlan();
ThreadIdValidatingInputOperator inputOperator = plan.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = plan.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = plan.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator3 = plan.addOperator("intermediateOperator3", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator4 = plan.addOperator("intermediateOperator4", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = plan.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
plan.addStream("OiOin", inputOperator.output, intermediateOperator1.input, intermediateOperator3.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOIntermediate1", intermediateOperator1.output, intermediateOperator2.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOIntermediate2", intermediateOperator3.output, intermediateOperator4.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOout1", intermediateOperator2.output, outputOperator.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOout2", intermediateOperator4.output, outputOperator.input2).setLocality(Locality.THREAD_LOCAL);
try {
plan.validate();
Assert.assertTrue("OiOiO extended diamond validation", true);
} catch (ConstraintViolationException ex) {
Assert.fail("OIOIO extended diamond validation");
}
}
Aggregations