Created
February 25, 2014 11:22
-
-
Save dgageot/9207145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jongo.Jongo; | |
import org.jongo.MongoCollection; | |
import org.junit.Test; | |
import com.fasterxml.jackson.annotation.JsonCreator; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.github.fakemongo.Fongo; | |
import com.mongodb.DB; | |
import static org.assertj.core.api.Assertions.assertThat; | |
public class MongoJongoFongoTest { | |
@Test | |
public void test_in_memory_mongodb() { | |
DB db = new Fongo("Test").getDB("Database"); | |
Jongo jongo = new Jongo(db); | |
MongoCollection friends = jongo.getCollection("friends"); | |
friends.insert( | |
new Friend("Sheldon"), | |
new Friend("Leonard"), | |
new Friend("Penny"), | |
new Friend("Howard"), | |
new Friend("Rajesh"), | |
new Friend("Bernadette"), | |
new Friend("Amy")); | |
assertThat(friends.count()).isEqualTo(7); | |
assertThat(friends.findOne("{name: #}", "Sheldon").as(Friend.class)).isNotNull(); | |
assertThat(friends.findOne("{name: #}", "Ross").as(Friend.class)).isNull(); | |
} | |
static class Friend { | |
String name; | |
@JsonCreator | |
Friend(@JsonProperty("name") String name) { | |
this.name = name; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.mongodb</groupId> | |
<artifactId>mongo-java-driver</artifactId> | |
<version>2.11.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.jongo</groupId> | |
<artifactId>jongo</artifactId> | |
<version>1.0</version> | |
</dependency> | |
<dependency> | |
<groupId>com.github.fakemongo</groupId> | |
<artifactId>fongo</artifactId> | |
<version>1.3.6</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment