Package org.mongojack.mock

Examples of org.mongojack.mock.MockObject


        assertThat(updated.simpleList, hasItem("!"));
    }

    @Test
    public void testAddToSetSingle() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.addToSet("simpleList", "world"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(2));
        assertThat(updated.simpleList, hasItem("world"));
        // Try again, this time should not be updated
        coll.updateById("blah", DBUpdate.addToSet("simpleList", "world"));
        updated = coll.findOneById("blah");
View Full Code Here


        assertThat(updated.simpleList, hasItem("world"));
    }

    @Test
    public void testAddToSetList() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById("blah",
                DBUpdate.addToSet("simpleList", Arrays.asList("world", "!")));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(3));
        assertThat(updated.simpleList, hasItem("!"));
    }
View Full Code Here

    @Test
    public void testAddToSetListWithUpsert() throws Exception {
        coll.update(DBQuery.is("_id", "blah"), DBUpdate.addToSet("simpleList",
                Arrays.asList("hello", "world")), true, false);
        MockObject inserted = coll.findOneById("blah");
        assertThat(inserted.simpleList, hasSize(2));
        assertThat(inserted.simpleList, hasItem("hello"));
        assertThat(inserted.simpleList, hasItem("world"));
    }
View Full Code Here

        assertThat(inserted.simpleList, hasItem("world"));
    }

    @Test
    public void testAddToSetVarArgs() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.addToSet("simpleList", "world", "!"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(3));
        assertThat(updated.simpleList, hasItem("!"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("!"));
    }

    @Test
    public void testPopFirst() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.popFirst("simpleList"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("world"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("world"));
    }

    @Test
    public void testPopLast() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.popLast("simpleList"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("hello"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("hello"));
    }

    @Test
    public void testPull() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.pull("simpleList", "world"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("hello"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("hello"));
    }

    @Test
    public void testPullWithQuery() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world");
        coll.insert(toSave);
        coll.updateById(
                "blah",
                DBUpdate.pull("simpleList",
                        new BasicDBObject("$regex", Pattern.compile("w??ld"))));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("hello"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("hello"));
    }

    @Test
    public void testPullAllList() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world", "!");
        coll.insert(toSave);
        coll.updateById("blah",
                DBUpdate.pullAll("simpleList", Arrays.asList("hello", "!")));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("world"));
    }
View Full Code Here

        assertThat(updated.simpleList, hasItem("world"));
    }

    @Test
    public void testPullAllVarArgs() throws Exception {
        MockObject toSave = new MockObject("blah", "string", 10);
        toSave.simpleList = Arrays.asList("hello", "world", "!");
        coll.insert(toSave);
        coll.updateById("blah", DBUpdate.pullAll("simpleList", "hello", "!"));
        MockObject updated = coll.findOneById("blah");
        assertThat(updated.simpleList, hasSize(1));
        assertThat(updated.simpleList, hasItem("world"));
    }
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.