Package org.apache.cayenne

Examples of org.apache.cayenne.MockPersistentObject


public class ClientChannelTest extends CayenneCase {

    public void testOnQuerySelect() {

        final MockPersistentObject o1 = new MockPersistentObject();
        ObjectId oid1 = new ObjectId("test_entity");
        o1.setObjectId(oid1);

        ClientConnection connection = mock(ClientConnection.class);
        when(connection.sendMessage((ClientMessage) any())).thenAnswer(
                new Answer<Object>() {

                    public Object answer(InvocationOnMock invocation) {
                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];

                        if (arg instanceof BootstrapMessage) {
                            return new EntityResolver();
                        }
                        else {
                            return new GenericResponse(Arrays.asList(o1));
                        }
                    }
                });

        ClientChannel channel = new ClientChannel(
                connection,
                false,
                new MockEventManager(),
                false);

        CayenneContext context = new CayenneContext(channel);
        ObjEntity entity = new ObjEntity("test_entity");
        entity.setClassName(MockPersistentObject.class.getName());

        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection<DataMap> entities = Collections.singleton(dataMap);
        context.setEntityResolver(new EntityResolver(entities));

        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);
        List<?> list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        Persistent o1_1 = (Persistent) list.get(0);

        assertEquals(o1.getObjectId(), o1_1.getObjectId());

        // ObjectContext must be injected
        assertEquals(context, o1_1.getObjectContext());
        assertSame(o1_1, context.getGraphManager().getNode(oid1));
    }
View Full Code Here


        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(
View Full Code Here

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        o1.setPersistenceState(PersistenceState.MODIFIED);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);
        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(
                connection,
View Full Code Here

import org.apache.cayenne.util.GenericResponse;

public class ClientChannelTest extends CayenneCase {

    public void testOnQuerySelect() {
        final MockPersistentObject o1 = new MockPersistentObject();
        ObjectId oid1 = new ObjectId("test_entity");
        o1.setObjectId(oid1);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o1)));

        ClientChannel channel = new ClientChannel(
                connection,
                false,
                new MockEventManager(),
                false);

        CayenneContext context = new CayenneContext(channel);
        ObjEntity entity = new ObjEntity("test_entity");
        entity.setClassName(MockPersistentObject.class.getName());

        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection<DataMap> entities = Collections.singleton(dataMap);
        context.setEntityResolver(new EntityResolver(entities));

        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);
        List<?> list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        Persistent o1_1 = (Persistent) list.get(0);

        assertEquals(o1.getObjectId(), o1_1.getObjectId());

        // ObjectContext must be injected
        assertEquals(context, o1_1.getObjectContext());
        assertSame(o1_1, context.getGraphManager().getNode(oid1));
    }
View Full Code Here

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(
View Full Code Here

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        o1.setPersistenceState(PersistenceState.MODIFIED);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);
        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(connection,
                false,
View Full Code Here

import org.apache.cayenne.util.GenericResponse;

public class ClientChannelTest extends CayenneCase {

    public void testOnQuerySelect() {
        final MockPersistentObject o1 = new MockPersistentObject();
        ObjectId oid1 = new ObjectId("test_entity");
        o1.setObjectId(oid1);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o1)));

        ClientChannel channel = new ClientChannel(connection);

        CayenneContext context = new CayenneContext(channel);
        ObjEntity entity = new ObjEntity("test_entity");
        entity.setClassName(MockPersistentObject.class.getName());

        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection entities = Collections.singleton(dataMap);
        context.setEntityResolver(new EntityResolver(entities));

        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);
        List list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        Persistent o1_1 = (Persistent) list.get(0);

        assertEquals(o1.getObjectId(), o1_1.getObjectId());

        // ObjectContext must be injected
        assertEquals(context, o1_1.getObjectContext());
        assertSame(o1_1, context.getGraphManager().getNode(oid1));
    }
View Full Code Here

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(connection);
View Full Code Here

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        o1.setPersistenceState(PersistenceState.MODIFIED);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);
        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(connection);
View Full Code Here

        assertNull(q.getGroupKeys());
        assertFalse(q.isRefreshAll());
    }

    public void testObjectConstructor() {
        Persistent p = new MockPersistentObject();

        RefreshQuery q = new RefreshQuery(p);
        assertNotNull(q.getObjects());
        assertEquals(1, q.getObjects().size());
        assertSame(p, q.getObjects().iterator().next());
View Full Code Here

TOP

Related Classes of org.apache.cayenne.MockPersistentObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.