use of org.apache.cayenne.unit.util.ValidationDelegate in project cayenne by apache.
the class DataContextValidationIT method testValidationModifyingContext.
@Test
public void testValidationModifyingContext() throws Exception {
ValidationDelegate delegate = new ValidationDelegate() {
public void validateForSave(Object object, ValidationResult validationResult) {
Artist a = (Artist) object;
Painting p = a.getObjectContext().newObject(Painting.class);
p.setPaintingTitle("XXX");
p.setToArtist(a);
}
};
context.setValidatingObjectsOnCommit(true);
Artist a1 = context.newObject(Artist.class);
a1.setValidationDelegate(delegate);
a1.setArtistName("a1");
// add another artist to ensure that modifying context works when more than one
// object is committed
Artist a2 = context.newObject(Artist.class);
a2.setValidationDelegate(delegate);
a2.setArtistName("a2");
context.commitChanges();
assertEquals(2, context.performQuery(new SelectQuery(Painting.class)).size());
}
Aggregations