I have an entity with UUID primary key {code} @Id @Type(type = "pg-uuid") @Column(name = "gid") @GeneratedValue(generator = "hibernate-uuid") @GenericGenerator(name = "hibernate-uuid", strategy = "uuid2") private UUID id;
@NotBlank @Column(name = "full_name") private String fullName; {code}
When I save an object with null or empty fullName via org.springframework.data.repository.CrudRepository in production or debug mode of application all is OK. But I have a Junit-test {code} @RunWith(SpringJUnit4ClassRunner.class) @SpringWebApplicationTestCase public class OrganizationTest extends AbstractTestConfig {
@Autowired OrganizationRepository organizationRepository;
private Organization organization;
@Before public void setUp() throws Exception { organization = new Organization(); }
@Test(expected = ConstraintViolationException.class) public void createOrganizationValidation() throws Exception { organizationRepository.save(organization); } } {code} It fails because validation not fired. I found that there is a method "execute" in EntityInsertAction which not fired. {code} Expected exception: javax.validation.ConstraintViolationException java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) {code}
{noformat} ext.junitVersion = '4.12' ext.springVersion = '4.2.0.RELEASE' ext.springDataJpaVersion = '1.8.2.RELEASE' ext.hibernateVersion = '4.3.10.Final' ext.hibernateValidatorVersion = '5.2.1.Final' {noformat} |
|