use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextRefreshingIT method testInvalidateThenModify.
@Test
public void testInvalidateThenModify() throws Exception {
createSingleArtistDataSet();
final Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(0);
assertNotNull(artist);
context.invalidateObjects(artist);
assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
// this must trigger a fetch
artist.setArtistName("new name");
}
});
assertEquals(1, queries);
assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextRefreshingIT method testModifyHollow.
@Test
public void testModifyHollow() throws Exception {
createSingleArtistAndPaintingDataSet();
Painting painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
final Artist artist = painting.getToArtist();
assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
assertNull(artist.readPropertyDirectly("artistName"));
int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
// this must trigger a fetch
artist.setDateOfBirth(new Date());
}
});
assertEquals(1, queries);
assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
assertNotNull(artist.readPropertyDirectly("artistName"));
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneDataObjectFlattenedRelIT method testAddRemoveFlattenedRelationship1.
@Test
public void testAddRemoveFlattenedRelationship1() throws Exception {
create1Artist1ArtGroupDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ArtGroup group = (ArtGroup) results.get(0);
a1.addToGroupArray(group);
group.removeFromArtistArray(a1);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Higher.
@Test
public void testIncrementalFaultList_Higher() throws Exception {
insertData_OneBag_100Boxes();
runtime.getDataDomain().setMaxIdQualifierSize(101);
final SelectQuery query = new SelectQuery(Painting.class);
query.setPageSize(10);
int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
final List<Painting> boxes = context.performQuery(query);
for (Painting box : boxes) {
box.getToArtist();
}
}
});
assertEquals(11, queriesCount);
queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
final List<Painting> boxes = context.performQuery(query);
List<Painting> tempList = new ArrayList<Painting>();
tempList.addAll(boxes);
}
});
assertEquals(2, queriesCount);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch_Negative.
@Test
public void testDisjointByIdPrefetch_Negative() throws Exception {
insertData();
runtime.getDataDomain().setMaxIdQualifierSize(-1);
final SelectQuery query = new SelectQuery(Artist.class);
query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
context.performQuery(query);
}
});
assertEquals(2, queriesCount);
}
Aggregations