Search in sources :

Example 1 with SFSB1

use of org.jboss.as.test.integration.jpa.beanvalidation.SFSB1 in project wildfly by wildfly.

the class JPABeanValidationTestCase method testSuccessfulBeanValidation.

/**
     * Test that a bean validation error is not thrown
     *
     * @throws Exception
     */
@Test
public void testSuccessfulBeanValidation() throws Exception {
    SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
    sfsb1.createEmployee("name", "address", 1);
}
Also used : SFSB1(org.jboss.as.test.integration.jpa.beanvalidation.SFSB1) Test(org.junit.Test)

Example 2 with SFSB1

use of org.jboss.as.test.integration.jpa.beanvalidation.SFSB1 in project wildfly by wildfly.

the class JPABeanValidationTestCase method testFailingBeanValidationNullAddress.

/**
     * Test that a bean validation error is thrown
     *
     * @throws Exception
     */
@Test
public void testFailingBeanValidationNullAddress() throws Exception {
    SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
    try {
        sfsb1.createEmployee("name", null, 2);
        fail("should of thrown validation error for null address in Employee entity");
    } catch (Throwable throwable) {
        ConstraintViolationException constraintViolationException = null;
        // find the ConstraintViolationException
        while (throwable != null && !(throwable instanceof ConstraintViolationException)) {
            throwable = throwable.getCause();
        }
        // should be null or instanceof ConstraintViolationException
        constraintViolationException = (ConstraintViolationException) throwable;
        assertTrue("expected ConstraintViolationException but got " + constraintViolationException, constraintViolationException instanceof ConstraintViolationException);
    }
}
Also used : ConstraintViolationException(javax.validation.ConstraintViolationException) SFSB1(org.jboss.as.test.integration.jpa.beanvalidation.SFSB1) Test(org.junit.Test)

Aggregations

SFSB1 (org.jboss.as.test.integration.jpa.beanvalidation.SFSB1)2 Test (org.junit.Test)2 ConstraintViolationException (javax.validation.ConstraintViolationException)1