-
Notifications
You must be signed in to change notification settings - Fork 88
/
RealMongoBackendTest.java
155 lines (128 loc) · 4.47 KB
/
RealMongoBackendTest.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package de.bwaldvogel.mongo;
import static de.bwaldvogel.mongo.backend.TestUtils.json;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.Date;
import org.bson.Document;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import com.mongodb.MongoCommandException;
import de.bwaldvogel.mongo.backend.AbstractBackendTest;
public class RealMongoBackendTest extends AbstractBackendTest {
@RegisterExtension
static RealMongoContainer realMongoContainer = new RealMongoContainer();
@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
dropAllDatabases();
}
@Override
protected void setUpBackend() throws Exception {
connectionString = realMongoContainer.getConnectionString();
}
@Override
protected void restart() throws Exception {
tearDown();
realMongoContainer.restart();
setUp();
}
@Override
protected MongoBackend createBackend() throws Exception {
throw new UnsupportedOperationException();
}
private void assumeStrictMode() {
Assumptions.assumeTrue(Boolean.getBoolean(getClass().getSimpleName() + ".strict"));
}
@Test
@Override
public void testListDatabaseNames() throws Exception {
assumeStrictMode();
super.testListDatabaseNames();
}
@Test
@Override
public void testCurrentOperations() throws Exception {
assumeStrictMode();
super.testCurrentOperations();
}
@Test
@Override
public void testInsertInSystemNamespace() throws Exception {
assumeStrictMode();
super.testInsertInSystemNamespace();
}
@Test
@Override
public void testQuerySystemNamespace() throws Exception {
assumeStrictMode();
super.testQuerySystemNamespace();
}
@Test
@Override
public void testSystemNamespaces() throws Exception {
assumeStrictMode();
super.testSystemNamespaces();
}
@Test
@Override
public void testUpdateInSystemNamespace() throws Exception {
assumeStrictMode();
super.testUpdateInSystemNamespace();
}
@Test
@Override
public void testGetLogStartupWarnings() throws Exception {
assumeStrictMode();
super.testGetLogStartupWarnings();
}
@Test
@Override
public void testReservedCollectionNames() throws Exception {
assumeStrictMode();
super.testReservedCollectionNames();
}
@Test
@Override
public void testQueryWithSubdocumentIndex() throws Exception {
assumeStrictMode();
super.testQueryWithSubdocumentIndex();
}
@Test
@Override
public void testServerStatus() throws Exception {
verifyServerStatus(runCommand("serverStatus"));
verifyServerStatus(db.runCommand(json("serverStatus:1")));
}
private void verifyServerStatus(Document serverStatus) {
assertThat(serverStatus.getDouble("ok")).isEqualTo(1);
assertThat(serverStatus.get("uptime")).isInstanceOf(Number.class);
assertThat(serverStatus.get("uptimeMillis")).isInstanceOf(Long.class);
assertThat(serverStatus.get("localTime")).isInstanceOf(Date.class);
Document connections = (Document) serverStatus.get("connections");
assertThat(connections.get("current")).isNotNull();
}
@Test
@Disabled
@Override
public void testCursor_iteratingACursorThatNoLongerExists() {
// disabled on real MongoDB
}
@Test
@Override
public void testResetError() throws Exception {
// Note: No longer implemented since MongoDB 5: "Command failed with error 59 (CommandNotFound): 'no such command: 'reseterror'"
assertThatExceptionOfType(MongoCommandException.class)
.isThrownBy(() -> db.runCommand(json("reseterror: 1")))
.withMessageStartingWith("Command failed with error 59 (CommandNotFound): 'no such command: 'reseterror'");
}
@Test
@Override
public void testCommandThatTriggersAnInternalException() throws Exception {
assertThatExceptionOfType(MongoCommandException.class)
.isThrownBy(() -> db.runCommand(json("triggerInternalException: 1")))
.withMessageStartingWith("Command failed with error 59 (CommandNotFound): 'no such command: 'triggerInternalException'");
}
}