Package org.mongojack.mock

Examples of org.mongojack.mock.MockObject


        coll = getCollection(MockObject.class, String.class);
    }

    @Test
    public void testIncludes() {
        MockObject o = new MockObject("string", 10);
        o.longs = 20l;
        coll.save(o);
        MockObject result = coll.findOne(DBQuery.empty(),
                DBProjection.include("string", "integer"));
        assertThat(result.string, equalTo("string"));
        assertThat(result.integer, equalTo(10));
        assertNull(result.longs);
    }
View Full Code Here


        assertNull(result.longs);
    }

    @Test
    public void testExcludes() {
        MockObject o = new MockObject("string", 10);
        o.longs = 20l;
        coll.save(o);
        MockObject result = coll.findOne(DBQuery.empty(),
                DBProjection.exclude("string", "integer"));
        assertNull(result.string);
        assertNull(result.integer);
        assertThat(result.longs, equalTo(20l));
    }
View Full Code Here

        coll = getCollection(MockObject.class, String.class);
    }

    @Test
    public void testQuery() {
        MockObject o1 = new MockObject("1", "ten", 10);
        MockObject o2 = new MockObject("2", "ten", 10);
        coll.insert(o1, o2, new MockObject("twenty", 20));

        List<MockObject> results = coll
                .find(new BasicDBObject("string", "ten")).toArray();
        assertThat(results, hasSize(2));
        assertThat(results, contains(o1, o2));
View Full Code Here

        assertThat(results, contains(o1, o2));
    }

    @Test
    public void testQueryWithLimitedKeys() {
        coll.insert(new MockObject("ten", 10));
        coll.insert(new MockObject("ten", 100));
        coll.insert(new MockObject("twenty", 20));

        List<MockObject> results = coll.find(
                new BasicDBObject("string", "ten"),
                new BasicDBObject("string", "something not null")).toArray();
        assertThat(results, hasSize(2));
View Full Code Here

        assertThat(results.get(1).string, equalTo("ten"));
    }

    @Test
    public void testRemove() {
        coll.insert(new MockObject("ten", 10));
        coll.insert(new MockObject("ten", 100));
        MockObject object = new MockObject("1", "twenty", 20);
        coll.insert(object);

        coll.remove(new BasicDBObject("string", "ten"));

        List<MockObject> remaining = coll.find().toArray();
View Full Code Here

        assertThat(remaining, contains(object));
    }

    @Test
    public void testRemoveById() {
        coll.insert(new MockObject("id1", "ten", 10));
        coll.insert(new MockObject("id2", "ten", 100));
        MockObject object = new MockObject("id3", "twenty", 20);
        coll.insert(object);

        coll.removeById("id3");

        List<MockObject> remaining = coll.find().toArray();
View Full Code Here

        assertThat(remaining, not(contains(object)));
    }

    @Test
    public void testFindAndModifyWithBuilder() {
        coll.insert(new MockObject("id1", "ten", 10));
        coll.insert(new MockObject("id2", "ten", 10));

        MockObject result1 = coll.findAndModify(DBQuery.is("_id", "id1"), null,
                null, false, DBUpdate.set("integer", 20)
                        .set("string", "twenty"), true, false);
        assertThat(result1.integer, equalTo(20));
        assertThat(result1.string, equalTo("twenty"));

        MockObject result2 = coll.findAndModify(DBQuery.is("_id", "id2"), null,
                null, false, DBUpdate.set("integer", 30)
                        .set("string", "thirty"), true, false);
        assertThat(result2.integer, equalTo(30));
        assertThat(result2.string, equalTo("thirty"));
View Full Code Here

    }

    @Test
    public void testFindAndModifyWithParameterizedType() {
        coll.insert(new MockObject("ten", 10));

        MockObject init = coll.findOne(DBQuery.is("string", "ten").is(
                "integer", 10));

        MockObject result1 = coll.findAndModify(DBQuery.is("_id", init._id),
                null, null, false, new MockObject("twenty", 20), true, true);
        assertThat(result1.integer, equalTo(20));
        assertThat(result1.string, equalTo("twenty"));

        MockObject result2 = coll.findAndModify(DBQuery.is("_id", "id2"), null,
                null, false, new MockObject("id2", "thirty", 30), true, true);
        assertThat(result2._id, equalTo("id2"));
        assertThat(result2.integer, equalTo(30));
        assertThat(result2.string, equalTo("thirty"));

        coll.removeById("id1");
View Full Code Here

    private JacksonDBCollection<MockObject, String> coll;

    @Before
    public void setUp() {
        coll = getCollection(MockObject.class, String.class);
        coll.save(new MockObject("1", "b", 10));
        coll.save(new MockObject("2", "a", 30));
        coll.save(new MockObject("3", "a", 20));
    }
View Full Code Here

        coll = getCollection(MockObject.class, String.class);
    }

    @Test
    public void testGetSavedId() {
        assertThat(coll.insert(new MockObject("blah", "ten", 10)).getSavedId(),
                equalTo("blah"));
    }
View Full Code Here

TOP

Related Classes of org.mongojack.mock.MockObject

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.