forked from bwaldvogel/mongo-java-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleTest.java
More file actions
52 lines (38 loc) · 1.35 KB
/
SimpleTest.java
File metadata and controls
52 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import static org.junit.Assert.assertEquals;
import java.net.InetSocketAddress;
import org.bson.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import de.bwaldvogel.mongo.MongoServer;
import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
public class SimpleTest {
private MongoCollection<Document> collection;
private MongoClient client;
private MongoServer server;
@Before
public void setUp() {
server = new MongoServer(new MemoryBackend());
// bind on a random local port
InetSocketAddress serverAddress = server.bind();
client = new MongoClient(new ServerAddress(serverAddress));
collection = client.getDatabase("testdb").getCollection("testcollection");
}
@After
public void tearDown() {
client.close();
server.shutdown();
}
@Test
public void testSimpleInsertQuery() throws Exception {
assertEquals(0, collection.count());
// creates the database and collection in memory and insert the object
Document obj = new Document("_id", 1).append("key", "value");
collection.insertOne(obj);
assertEquals(1, collection.count());
assertEquals(obj, collection.find().first());
}
}