Package org.jongo.model

Examples of org.jongo.model.Friend


    @Test
    public void shouldNotAddBsonConfWithCustomMapper() throws Exception {
        Mapping.Builder builder = new Mapping.Builder(new ObjectMapper());
        Mapping mapping = builder.build();
        ObjectId id = ObjectId.get();//serialized using bson serializer
        Friend friend = new Friend(id, "John");

        Writer writer = new StringWriter();
        mapping.getWriter(friend).writeValue(writer, friend);

        assertThat(writer.toString()).contains("John");
View Full Code Here


    @Test
    public void canFindAndMap() throws Exception {
        /* given */
        ResultHandler<DBObject> handler = new RawResultHandler<DBObject>();
        collection.save(new Friend("John", "22 Wall Street Avenue"));
        collection.save(new Friend("Peter", "22 Wall Street Avenue"));

        /* when */
        for (DBObject result : collection.find().map(handler)) {
            /* then */
            assertThat(result.get("name")).isIn("John", "Peter");
View Full Code Here

    @Test
    public void canFindOneAndMap() throws Exception {
        /* given */
        ResultHandler<DBObject> handler = new RawResultHandler<DBObject>();
        Friend john = new Friend("John", "22 Wall Street Avenue");
        collection.save(john);

        /* when */
        DBObject result = collection.findOne().map(handler);

View Full Code Here

        Jongo jongo = new Jongo(getDatabase());

        Mapper mapper = jongo.getMapper();

        assertThat(mapper).isNotNull();
        assertThat(mapper.getMarshaller().marshall(new Friend("test"))).isNotNull();
    }
View Full Code Here

    }

    @Test
    public void canFindAndModifyOne() throws Exception {
        /* given */
        collection.save(new Friend("John", "22 Wall Street Avenue"));

        /* when */
        Friend originalFriend = collection.findAndModify("{name:#}", "John").with("{$set: {address: #}}", "A better place").as(Friend.class);

        /* then */
        assertThat(originalFriend.getAddress()).isEqualTo("22 Wall Street Avenue");

        Friend updatedFriend = collection.findOne().as(Friend.class);
        assertThat(updatedFriend.getAddress()).isEqualTo("A better place");
        assertThat(updatedFriend.getName()).isEqualTo("John");
    }
View Full Code Here

    }

    @Test
    public void canFindAndModifyWithResultHandler() throws Exception {
        /* given */
        collection.save(new Friend("John", "22 Wall Street Avenue"));

        /* when */
        DBObject dbo = collection.findAndModify("{name:#}", "John").with("{$set: {address: #}}", "A better place").map(new RawResultHandler<DBObject>());

        /* then */
 
View Full Code Here

    }

    @Test
    public void canReturnNew() throws Exception {
        /* given */
        collection.save(new Friend("John", "22 Wall Street Avenue"));

        /* when */
        Friend updatedFriend = collection.findAndModify().with("{$set: {address: 'A better place'}}").returnNew().as(Friend.class);

        /* then */
        assertThat(updatedFriend.getAddress()).isEqualTo("A better place");
    }
View Full Code Here

    }

    @Test
    public void canRemove() {
        /* given */
        collection.save(new Friend("John", "22 Wall Street Avenue"));

        /* when */
        Friend deletedFriend = collection.findAndModify().remove().as(Friend.class);

        /* then */
        assertThat(deletedFriend.getName()).isEqualTo("John");
        assertThat(collection.count()).isEqualTo(0);
    }
View Full Code Here

    }

    @Test
    public void canSort() {
        /* given */
        collection.save(new Friend("John", "22 Wall Streem Avenue"));
        collection.save(new Friend("Wally", "22 Wall Streem Avenue"));

        /* when */
        Friend friend = collection.findAndModify()
                .sort("{name: -1}")
                .with("{$set: {address:'Sesame Street'}}")
                .as(Friend.class);

        /* then */
        assertThat(friend.getName()).isEqualTo("Wally");
    }
View Full Code Here

    }

    @Test
    public void canFindWithProjection() throws Exception {

        collection.save(new Friend("John", "Jermin Street"));

        collection.findAndModify("{name:'John'}").with("{$set: {name:'Robert'}}").projection("{name:1}").map(new ResultHandler<Boolean>() {
            public Boolean map(DBObject result) {
                assertThat(result.containsField("name")).isTrue();
                assertThat(result.containsField("address")).isFalse();
View Full Code Here

TOP

Related Classes of org.jongo.model.Friend

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.