Search in sources :

Example 61 with UnitTestClosure

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

the class DataContextLocalObjectIT method testLocalObject_TempId.

@Test
public void testLocalObject_TempId() throws Exception {
    final Artist a1 = context1.newObject(Artist.class);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a = context2.localObject(a1);
            assertNotNull(a);
            assertEquals(a1.getObjectId(), a.getObjectId());
            // FFE mist be thrown on attempt to read non-existing temp ID
            try {
                a.getArtistName();
                fail("FaultFailureException wasn't thrown on attempt to " + "resolve HOLLOW object with temp id");
            } catch (FaultFailureException e) {
            // expected
            }
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) FaultFailureException(org.apache.cayenne.FaultFailureException) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 62 with UnitTestClosure

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

the class DataContextLocalObjectIT method testLocalObject_InCache.

@Test
public void testLocalObject_InCache() throws Exception {
    tArtist.insert(456, "Bla");
    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
    final Artist a2 = Cayenne.objectForPK(context2, Artist.class, 456);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a3 = context2.localObject(a1);
            assertSame(a3, a2);
            assertSame(context2, a3.getObjectContext());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 63 with UnitTestClosure

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

the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache_AfterCayenneInsert.

@Test
public void testPolymorphicSharedCache_AfterCayenneInsert() throws SQLException {
    // see CAY-2101... we are trying to get a snapshot from a new object in the shared cache, and then read this
    // object via a relationship, so that shared cache is consulted
    Employee e = context1.newObject(Employee.class);
    e.setName("E1");
    e.setSalary(1234.01f);
    context1.commitChanges();
    final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", Cayenne.intPKForObject(e)), false, ObjectIdQuery.CACHE);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            // use different context to ensure we hit shared cache
            AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
            assertTrue(ap1 instanceof Employee);
        }
    });
}
Also used : Employee(org.apache.cayenne.testdo.inheritance_people.Employee) ObjectId(org.apache.cayenne.ObjectId) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 64 with UnitTestClosure

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

the class DataContextPerformQueryAPIIT method testObjectQueryWithSharedCache.

@Test
public void testObjectQueryWithSharedCache() throws Exception {
    createTwoArtists();
    List<?> artists = context.performQuery("QueryWithSharedCache", true);
    assertEquals(2, artists.size());
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> artists1 = context2.performQuery("QueryWithSharedCache", false);
            assertEquals(2, artists1.size());
        }
    });
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) Test(org.junit.Test)

Example 65 with UnitTestClosure

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

the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship_Joint.

@Test
public void testPrefetchToOneWithBackRelationship_Joint() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
    query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
    query.addPrefetch(Painting.TO_PAINTING_INFO.joint());
    query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).joint());
    final List<Painting> results = context.select(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting p0 = results.get(0);
            PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertNotNull(pi0);
            assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) 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