Search in sources :

Example 66 with ConstraintViolationException

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();
}
Also used : Transaction(org.hibernate.Transaction) PersistenceException(javax.persistence.PersistenceException) ConstraintViolationException(javax.validation.ConstraintViolationException) Session(org.hibernate.Session)

Example 67 with ConstraintViolationException

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();
}
Also used : Transaction(org.hibernate.Transaction) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) Test(org.junit.Test)

Example 68 with ConstraintViolationException

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();
}
Also used : Transaction(org.hibernate.Transaction) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) Session(org.hibernate.Session) Test(org.junit.Test)

Example 69 with ConstraintViolationException

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());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) Application(com.example.mydtapp.Application) Test(org.junit.Test)

Example 70 with ConstraintViolationException

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");
    }
}
Also used : ConstraintViolationException(javax.validation.ConstraintViolationException) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) Test(org.junit.Test)

Aggregations

ConstraintViolationException (javax.validation.ConstraintViolationException)87 Test (org.junit.Test)67 LocalMode (com.datatorrent.api.LocalMode)35 Configuration (org.apache.hadoop.conf.Configuration)34 File (java.io.File)16 ConstraintViolation (javax.validation.ConstraintViolation)15 Session (org.hibernate.Session)11 Transaction (org.hibernate.Transaction)11 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)9 Map (java.util.Map)9 BigDecimal (java.math.BigDecimal)7 HashMap (java.util.HashMap)7 Set (java.util.Set)6 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 HashSet (java.util.HashSet)5 ValidationException (javax.validation.ValidationException)5 Validator (javax.validation.Validator)5 Response (javax.ws.rs.core.Response)5 Path (org.apache.hadoop.fs.Path)5