Search in sources :

Example 36 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataDomainFiltersIT method testOnQuery_Blocking.

@Test
public void testOnQuery_Blocking() {
    DataDomain domain = runtime.getDataDomain();
    final QueryResponse r1 = new ListResponse();
    final QueryResponse r2 = new ListResponse();
    DataChannelFilter f1 = new MockDataChannelFilter() {

        @Override
        public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
            return r1;
        }
    };
    DataChannelFilter f2 = new MockDataChannelFilter() {

        @Override
        public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
            return r2;
        }
    };
    domain.filters.add(f1);
    domain.filters.add(f2);
    SelectQuery query = new SelectQuery(Artist.class);
    QueryResponse response = domain.onQuery(context, query);
    assertSame(r2, response);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) ListResponse(org.apache.cayenne.util.ListResponse) SelectQuery(org.apache.cayenne.query.SelectQuery) Query(org.apache.cayenne.query.Query) QueryResponse(org.apache.cayenne.QueryResponse) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilterChain(org.apache.cayenne.DataChannelFilterChain) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 37 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataDomainIT method testAddListener.

@Test
public void testAddListener() {
    DataDomain domain = runtime.getDataDomain();
    PostAddListener listener = new PostAddListener();
    domain.addListener(listener);
    ObjectContext context = runtime.newContext();
    context.newObject(Gallery.class);
    assertEquals("e:Gallery;", listener.getAndReset());
    context.newObject(Artist.class);
    assertEquals("a:Artist;", listener.getAndReset());
    context.newObject(Exhibit.class);
    assertEquals("", listener.getAndReset());
    context.newObject(Painting.class);
    assertEquals("e:Painting;", listener.getAndReset());
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 38 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class ColumnSelectIT method testNestedContextObjectResult.

@Test
public void testNestedContextObjectResult() {
    ObjectContext childContext = runtime.newContext(context);
    Property<Artist> artistProperty = Property.createSelf(Artist.class);
    List<Artist> artists = ObjectSelect.columnQuery(Artist.class, artistProperty).select(childContext);
    assertEquals(20, artists.size());
    for (Artist artist : artists) {
        assertNotNull(artist);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 39 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class ColumnSelectIT method testNestedContextScalarArrayResult.

@Test
public void testNestedContextScalarArrayResult() {
    ObjectContext childContext = runtime.newContext(context);
    List<Object[]> data = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH).select(childContext);
    assertEquals(20, data.size());
    for (Object[] next : data) {
        assertTrue(next[0] instanceof String);
        assertTrue(next[1] instanceof Date);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) Date(java.util.Date) Test(org.junit.Test)

Example 40 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class ColumnSelectIT method testNestedContextScalarResult.

/*
     * Test selection from nested context
     */
@Test
public void testNestedContextScalarResult() {
    ObjectContext childContext = runtime.newContext(context);
    List<String> names = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME).select(childContext);
    assertEquals(20, names.size());
    for (String name : names) {
        assertNotNull(name);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)108 Test (org.junit.Test)99 Artist (org.apache.cayenne.testdo.testmap.Artist)32 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)14 SelectQuery (org.apache.cayenne.query.SelectQuery)13 Painting (org.apache.cayenne.testdo.testmap.Painting)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)10 GraphDiff (org.apache.cayenne.graph.GraphDiff)9 ObjectId (org.apache.cayenne.ObjectId)8 Table2 (org.apache.cayenne.crypto.db.Table2)7 HashMap (java.util.HashMap)6 Persistent (org.apache.cayenne.Persistent)6 QueryResponse (org.apache.cayenne.QueryResponse)6 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 Query (org.apache.cayenne.query.Query)5 CayenneContext (org.apache.cayenne.CayenneContext)4 DataChannel (org.apache.cayenne.DataChannel)4 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)4 EntityResolver (org.apache.cayenne.map.EntityResolver)4