Examples of Friend


Examples of org.jongo.model.Friend

    }

    @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

Examples of org.jongo.model.Friend

    }

    @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

Examples of org.jongo.model.Friend

    }

    @Test
    public void canFindWithProjectionParams() 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

Examples of org.jongo.model.Friend

    @Test
    // https://groups.google.com/forum/?hl=fr&fromgroups#!topic/jongo-user/ga3n5_ybYm4
    public void pushANonBSONObject() throws Exception {
        Party party = new Party();
        party.with(new Friend("john"));
        party.with(new Friend("peter"));
        collection.save(party);

        DBObject robert = new JacksonEngine(Mapping.defaultMapping()).marshall(new Friend("Robert")).toDBObject();
        collection.update("{}").with("{$push:{friends:" + robert.toString() + "}}");

        assertThat(collection.count("{ 'friends.name' : 'Robert'}")).isEqualTo(1);
    }
View Full Code Here

Examples of org.jongo.model.Friend

    }

    @Test
    public void canUpdateMulti() throws Exception {
        /* given */
        collection.save(new Friend("John"));
        collection.save(new Friend("John"));

        /* when */
        WriteResult writeResult = collection.update("{name:'John'}").multi().with("{$unset:{name:1}}");

        /* then */
 
View Full Code Here

Examples of org.jongo.model.Friend

    //https://groups.google.com/forum/?fromgroups#!topic/jongo-user/Nu4J1tK0kAM
    public void canSelectOnlyAField() throws Exception {

        final Unmarshaller unmarshaller = getMapper().getUnmarshaller();
        Party party = new Party();
        party.with(new Friend("John"));
        party.with(new Friend("Peter"));
        party.with(new Friend("Robert"));
        collection.save(party);

        Friend friend = collection.findOne("{friends.name:'Peter'}").projection("{friends.$:1}").map(new ResultHandler<Friend>() {
            public Friend map(DBObject dbo) {
                Party result = unmarshaller.unmarshall((BsonDocument) dbo, Party.class);
                return result.friends.get(0);
            }
        });

        assertThat(friend.getName()).isEqualTo("Peter");
    }
View Full Code Here

Examples of org.jongo.model.Friend

    }

    @Test
    public void canUpdateMultiWithWriteConcern() throws Exception {
        /* given */
        collection.save(new Friend("John"));
        collection.save(new Friend("John"));

        /* when */
        WriteResult writeResult = collection.withWriteConcern(WriteConcern.SAFE).update("{name:'John'}").multi().with("{$unset:{name:1}}");

        /* then */
 
View Full Code Here

Examples of org.jongo.model.Friend

    }

    @Test
    public void canUpdateByObjectId() throws Exception {

        Friend friend = new Friend();
        collection.save(friend);

        /* when */
        collection.update(friend.getId()).with("{$set:{name:'John'}}");

        /* then */
        Friend john = collection.findOne("{name:'John'}").as(Friend.class);
        assertThat(john.getName()).isEqualTo("John");
        assertThat(friend.getId()).isEqualTo(john.getId());
    }
View Full Code Here

Examples of org.jongo.model.Friend

    //https://groups.google.com/forum/?fromgroups#!topic/jongo-user/p9CEKnkKX9Q
    public void canUpdateIntoAnArray() throws Exception {

        collection.insert("{friends:[{name:'Robert'},{name:'Peter'}]}");

        collection.update("{ 'friends.name' : 'Peter' }").with("{ $set : { 'friends.$' : #} }", new Friend("John"));

        Party party = collection.findOne().as(Party.class);

        assertThat(party.friends).extracting("name").containsExactly("Robert", "John");
    }
View Full Code Here

Examples of org.jongo.model.Friend

                mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
            }
        }).build();
        Jongo jongo = new Jongo(getDatabase(), mapper);
        MongoCollection friends = jongo.getCollection("friends");
        Friend friend = new Friend("Peter", "31 rue des Lilas");
        friends.save(friend);

        friends.update(friend.getId()).with(new Friend("John"));

        Friend updated = friends.findOne().as(Friend.class);
        assertThat(updated.getName()).isEqualTo("John");
        assertThat(updated.getAddress()).isNull();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.