When I using Arquillian to test my entities (JPA) with integration test, everything seems to work perfectly instead of testing for ConstraintViolation, i.e. entity can not be persisted in test cause there are not set some nullable fields and I'm using Bean Validation to validate this fields like (@NotNull). So Instead of having thrown ConstrainViolationException i got ArquillianProxyExcepeption like below:
Unexpected exception, expected<javax.validation.ConstraintViolationException> but was<org.jboss.arquillian.test.spi.ArquillianProxyException>
This is my simple test:
@Test(expected = ConstraintViolationException.class) // not set required fields
public void shouldNotCreateNewFirm() {
// Create instance of firm entity
Firm firm = new Firm("firma@allegro.pl", "allegro", "aAle2@", "Allegro Ltd.");
// persist the firm to the database
transaction.begin();
em.persist(firm);
em.remove(firm);
transaction.commit();
}
and error details:
Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: javax.validation.ConstraintViolationException : Validation failed for classes [pl.salonea.entities.Firm] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=companyNumber, rootBeanClass=class pl.salonea.entities.Firm, messageTemplate='{javax.validation.constraints.NotNull.message}'}
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=address, rootBeanClass=class pl.salonea.entities.Firm, messageTemplate='{javax.validation.constraints.NotNull.message}'}
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=vatin, rootBeanClass=class pl.salonea.entities.Firm, messageTemplate='{javax.validation.constraints.NotNull.message}'}
] [Proxied because : Original exception not deserilizable, ClassNotFoundException]
Aucun commentaire:
Enregistrer un commentaire