use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testFlattenedRelationship.
@Test
public void testFlattenedRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Bag.class);
query.addPrefetch(Bag.BALLS.disjointById());
final List<Bag> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Bag b1 = result.get(0);
List<Ball> balls = (List<Ball>) b1.readPropertyDirectly(Bag.BALLS.getName());
assertNotNull(balls);
assertFalse(((ValueHolder) balls).isFault());
assertEquals(6, balls.size());
List<Integer> volumes = new ArrayList<Integer>();
for (Ball b : balls) {
assertEquals(PersistenceState.COMMITTED, b.getPersistenceState());
volumes.add(b.getThingVolume());
}
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 30, 40, 20, 40)));
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testFlattenedMultiColumnRelationship.
@Test
public void testFlattenedMultiColumnRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Box.class);
query.addPrefetch(Box.THINGS.disjointById());
final List<Box> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
List<Integer> volumes = new ArrayList<Integer>();
for (Box box : result) {
List<Thing> things = (List<Thing>) box.readPropertyDirectly(Box.THINGS.getName());
assertNotNull(things);
assertFalse(((ValueHolder) things).isFault());
for (Thing t : things) {
assertEquals(PersistenceState.COMMITTED, t.getPersistenceState());
volumes.add(t.getVolume());
}
}
assertEquals(6, volumes.size());
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 30, 40)));
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testLongFlattenedRelationship.
@Test
public void testLongFlattenedRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Bag.class);
query.addPrefetch(Bag.THINGS.disjointById());
final List<Bag> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Bag b1 = result.get(0);
List<Thing> things = (List<Thing>) b1.readPropertyDirectly(Bag.THINGS.getName());
assertNotNull(things);
assertFalse(((ValueHolder) things).isFault());
assertEquals(6, things.size());
List<Integer> volumes = new ArrayList<Integer>();
for (Thing t : things) {
assertEquals(PersistenceState.COMMITTED, t.getPersistenceState());
volumes.add(t.getVolume());
}
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 20, 30, 40, 40)));
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralFetchJoins.
@Test
public void testSeveralFetchJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT a " + "FROM Artist a JOIN FETCH a.paintingArray JOIN FETCH a.artistExhibitArray " + "WHERE a.artistName = 'A1'";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, objects.size());
Artist a = (Artist) objects.get(0);
assertEquals("A1", a.getArtistName());
List<Painting> paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(2, paintings.size());
List<String> expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P11");
expectedPaintingsNames.add("P12");
Iterator<Painting> paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
List<ArtistExhibit> exibits = a.getArtistExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
Iterator<ArtistExhibit> exibitsIterator = exibits.iterator();
while (exibitsIterator.hasNext()) {
ArtistExhibit ae = exibitsIterator.next();
assertEquals(PersistenceState.COMMITTED, ae.getPersistenceState());
assertNotNull(ae.getObjectId());
}
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesAndScalarFetchOuterJoins.
@Test
public void testSeveralEntitiesAndScalarFetchOuterJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT DISTINCT a, a.artistName , g " + "FROM Artist a LEFT JOIN FETCH a.paintingArray, Gallery g LEFT JOIN FETCH g.exhibitArray " + "ORDER BY a.artistName, g.galleryName";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(6, objects.size());
Object[] row = (Object[]) objects.get(0);
Artist a1 = (Artist) row[0];
assertEquals("A1", a1.getArtistName());
List<Painting> paintings = a1.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(2, paintings.size());
List<String> expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P11");
expectedPaintingsNames.add("P12");
Iterator<Painting> paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
String artistName1 = (String) row[1];
assertEquals("A1", artistName1);
Gallery g1 = (Gallery) row[2];
assertEquals("gallery1", g1.getGalleryName());
List<?> exibits = g1.getExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
row = (Object[]) objects.get(1);
assertEquals(a1, row[0]);
assertEquals(artistName1, row[1]);
Gallery g2 = (Gallery) row[2];
assertEquals("gallery2", g2.getGalleryName());
exibits = g2.getExhibitArray();
assertTrue(exibits.isEmpty());
row = (Object[]) objects.get(2);
Artist a2 = (Artist) row[0];
assertEquals("A2", a2.getArtistName());
paintings = a2.getPaintingArray();
assertNotNull(paintings);
assertEquals(1, paintings.size());
Painting p = paintings.get(0);
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertEquals("P2", p.getPaintingTitle());
String artistName2 = (String) row[1];
assertEquals("A2", artistName2);
assertEquals(g1, row[2]);
row = (Object[]) objects.get(3);
assertEquals(a2, row[0]);
assertEquals(artistName2, row[1]);
assertEquals(g2, row[2]);
row = (Object[]) objects.get(4);
Artist a3 = (Artist) row[0];
assertEquals("A3", a3.getArtistName());
paintings = a3.getPaintingArray();
assertTrue(paintings.isEmpty());
String artistName3 = (String) row[1];
assertEquals("A3", artistName3);
assertEquals(g1, row[2]);
row = (Object[]) objects.get(5);
assertEquals(a3, row[0]);
assertEquals(artistName3, row[1]);
assertEquals(g2, row[2]);
}
});
}
Aggregations