Skip to content

Commit 0190996

Browse files
committed
Added mongodb/specifications as a git submodule
Set the specifications submodule to last schemaVersion 1.21 commit Deleted old copied json tests. Updated test runners to use the new submodule locations Added skips for any tests that haven't been implemented JAVA-5821
1 parent 3e95e0d commit 0190996

File tree

1,111 files changed

+280
-333637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,111 files changed

+280
-333637
lines changed

.evergreen/.evg.yml

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ functions:
3131
# Applies the subitted patch, if any
3232
# Deprecated. Should be removed. But still needed for certain agents (ZAP)
3333
- command: git.apply_patch
34+
# Fetch the specifications submodule
35+
- command: shell.exec
36+
params:
37+
working_dir: "src"
38+
script: |
39+
git submodule update --init
3440
# Make an evergreen expansion file with dynamic values
3541
- command: shell.exec
3642
params:

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "specifications"]
2+
path = driver-core/src/test/resources/specifications
3+
url = https://github.com/mongodb/specifications

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Example for Maven:
113113
Java 17+ and git is required to build and compile the source. To build and test the driver:
114114

115115
```
116-
$ git clone https://github.com/mongodb/mongo-java-driver.git
116+
$ git clone --recurse-submodules https://github.com/mongodb/mongo-java-driver.git
117117
$ cd mongo-java-driver
118118
$ ./gradlew check
119119
```

bson/src/test/unit/util/JsonPoweredTestHelper.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
import org.bson.BsonDocument;
2020
import org.bson.BsonString;
2121
import org.bson.BsonValue;
22-
import org.bson.codecs.BsonDocumentCodec;
23-
import org.bson.codecs.DecoderContext;
24-
import org.bson.json.JsonReader;
2522

2623
import java.io.BufferedReader;
2724
import java.io.IOException;
2825
import java.io.InputStream;
2926
import java.io.InputStreamReader;
3027
import java.net.URI;
28+
import java.net.URL;
3129
import java.nio.charset.StandardCharsets;
3230
import java.nio.file.FileSystem;
3331
import java.nio.file.FileSystems;
@@ -42,21 +40,22 @@
4240
import java.util.Collections;
4341
import java.util.List;
4442

45-
import static org.bson.assertions.Assertions.assertNotNull;
4643
import static org.junit.jupiter.api.Assertions.fail;
4744

4845
public final class JsonPoweredTestHelper {
4946

47+
private static final String SPECIFICATIONS_PREFIX = "/specifications/source/";
48+
5049
public static BsonDocument getTestDocument(final String resourcePath) {
51-
BsonDocument testDocument = getTestDocumentWithMetaData(resourcePath);
50+
BsonDocument testDocument = getTestDocumentWithMetaData(SPECIFICATIONS_PREFIX + resourcePath);
5251
testDocument.remove("resourcePath");
5352
testDocument.remove("fileName");
5453
return testDocument;
5554
}
5655

57-
public static Collection<Object[]> getTestData(final String resourcePath) {
56+
public static Collection<Object[]> getLegacyTestData(final String resourcePath) {
5857
List<Object[]> data = new ArrayList<>();
59-
for (BsonDocument document : getTestDocuments(resourcePath)) {
58+
for (BsonDocument document : getSpecTestDocuments(resourcePath)) {
6059
for (BsonValue test : document.getArray("tests")) {
6160
BsonDocument testDocument = test.asDocument();
6261
data.add(new Object[]{document.getString("fileName").getValue(),
@@ -68,10 +67,19 @@ public static Collection<Object[]> getTestData(final String resourcePath) {
6867
return data;
6968
}
7069

70+
public static List<BsonDocument> getSpecTestDocuments(final String resourcePath) {
71+
return getTestDocuments(SPECIFICATIONS_PREFIX + resourcePath);
72+
}
73+
7174
public static List<BsonDocument> getTestDocuments(final String resourcePath) {
7275
List<BsonDocument> files = new ArrayList<>();
7376
try {
74-
URI resource = assertNotNull(JsonPoweredTestHelper.class.getResource(resourcePath)).toURI();
77+
URL urlResource = JsonPoweredTestHelper.class.getResource(resourcePath);
78+
if (urlResource == null) {
79+
fail("No such resource: " + resourcePath);
80+
}
81+
82+
URI resource = urlResource.toURI();
7583
try (FileSystem fileSystem = (resource.getScheme().equals("jar") ? FileSystems.newFileSystem(resource, Collections.emptyMap()) : null)) {
7684
Path myPath = Paths.get(resource);
7785
Files.walkFileTree(myPath, new SimpleFileVisitor<Path>() {
@@ -89,14 +97,13 @@ public FileVisitResult visitFile(final Path filePath, final BasicFileAttributes
8997
});
9098
}
9199
} catch (Exception e) {
92-
fail("Unable to load resource", e);
100+
fail("Unable to load resource: " + resourcePath, e);
93101
}
94102
return files;
95103
}
96104

97105
private static BsonDocument getTestDocumentWithMetaData(final String resourcePath) {
98-
JsonReader jsonReader = new JsonReader(resourcePathToString(resourcePath));
99-
BsonDocument testDocument = new BsonDocumentCodec().decode(jsonReader, DecoderContext.builder().build());
106+
BsonDocument testDocument = BsonDocument.parse(resourcePathToString(resourcePath));
100107
testDocument.append("resourcePath", new BsonString(resourcePath))
101108
.append("fileName", new BsonString(resourcePath.substring(resourcePath.lastIndexOf('/') + 1)));
102109
return testDocument;
@@ -107,7 +114,9 @@ private static String resourcePathToString(final String resourcePath) {
107114
String line;
108115
String ls = System.lineSeparator();
109116
try (InputStream inputStream = JsonPoweredTestHelper.class.getResourceAsStream(resourcePath)) {
110-
assertNotNull(inputStream);
117+
if (inputStream == null) {
118+
fail("Unable to load resource: " + resourcePath);
119+
}
111120
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
112121
while ((line = reader.readLine()) != null) {
113122
stringBuilder.append(line);

0 commit comments

Comments
 (0)