Search in sources :

Example 51 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesAndScalarFetchInnerJoins.

@Test
public void testSeveralEntitiesAndScalarFetchInnerJoins() throws Exception {
    createMultipleFetchJoinsDataSet();
    String ejbql = "SELECT DISTINCT a, a.artistName , g " + "FROM Artist a JOIN FETCH a.paintingArray, Gallery g JOIN FETCH g.exhibitArray " + "ORDER BY a.artistName";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    final List<?> objects = context.performQuery(query);
    queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, objects.size());
            Object[] firstRow = (Object[]) objects.get(0);
            Artist a = (Artist) firstRow[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()));
            }
            String artistName = (String) firstRow[1];
            assertEquals("A1", artistName);
            Gallery g1 = (Gallery) firstRow[2];
            assertEquals("gallery1", g1.getGalleryName());
            List<Exhibit> exibits = g1.getExhibitArray();
            assertNotNull(exibits);
            assertFalse(((ValueHolder) exibits).isFault());
            assertEquals(2, exibits.size());
            Object[] secondRow = (Object[]) objects.get(1);
            a = (Artist) secondRow[0];
            assertEquals("A2", a.getArtistName());
            paintings = a.getPaintingArray();
            assertNotNull(paintings);
            assertFalse(((ValueHolder) paintings).isFault());
            assertEquals(1, paintings.size());
            expectedPaintingsNames = new ArrayList<String>();
            expectedPaintingsNames.add("P2");
            paintingsIterator = paintings.iterator();
            while (paintingsIterator.hasNext()) {
                Painting p = paintingsIterator.next();
                assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
                assertNotNull(p.getPaintingTitle());
                assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
            }
            artistName = (String) secondRow[1];
            assertEquals("A2", artistName);
            Gallery g2 = (Gallery) secondRow[2];
            assertEquals(g1, g2);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) ValueHolder(org.apache.cayenne.ValueHolder) Painting(org.apache.cayenne.testdo.testmap.Painting) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 52 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextEJBQLFetchJoinIT method testFetchJoinForOneEntity.

@Test
public void testFetchJoinForOneEntity() throws Exception {
    createOneFetchJoinDataSet();
    String ejbql = "SELECT a FROM Artist a JOIN FETCH a.paintingArray ";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    final List<?> objects = context.performQuery(query);
    queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, objects.size());
            Iterator<?> it = objects.iterator();
            while (it.hasNext()) {
                Artist a = (Artist) it.next();
                List<Painting> list = a.getPaintingArray();
                assertNotNull(list);
                assertFalse(((ValueHolder) list).isFault());
                for (Painting p : list) {
                    assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
                    // make sure properties are not null..
                    assertNotNull(p.getPaintingTitle());
                }
            }
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 53 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Lower.

@Test
public void testIncrementalFaultList_Lower() throws Exception {
    insertData_OneBag_100Boxes();
    runtime.getDataDomain().setMaxIdQualifierSize(5);
    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(21, 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(21, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 54 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Zero.

@Test
public void testIncrementalFaultList_Zero() throws Exception {
    insertData_OneBag_100Boxes();
    runtime.getDataDomain().setMaxIdQualifierSize(0);
    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);
            List<Painting> tempList = new ArrayList<Painting>();
            tempList.addAll(boxes);
        }
    });
    assertEquals(2, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 55 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Negative.

@Test
public void testIncrementalFaultList_Negative() throws Exception {
    insertData_OneBag_100Boxes();
    runtime.getDataDomain().setMaxIdQualifierSize(-1);
    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);
            List<Painting> tempList = new ArrayList<Painting>();
            tempList.addAll(boxes);
        }
    });
    assertEquals(2, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)107 Test (org.junit.Test)107 SelectQuery (org.apache.cayenne.query.SelectQuery)64 List (java.util.List)48 Artist (org.apache.cayenne.testdo.testmap.Artist)47 Painting (org.apache.cayenne.testdo.testmap.Painting)35 ValueHolder (org.apache.cayenne.ValueHolder)23 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)19 ArrayList (java.util.ArrayList)15 ObjectContext (org.apache.cayenne.ObjectContext)14 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)9 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)8 Iterator (java.util.Iterator)7 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)7 Expression (org.apache.cayenne.exp.Expression)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)5 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5