Skip to content

Commit b966e7f

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 b966e7f

File tree

1,112 files changed

+291
-333640
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,112 files changed

+291
-333640
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/main/org/bson/assertions/Assertions.java

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ public static AssertionError fail(final String msg) throws AssertionError {
103103
throw new AssertionError(assertNotNull(msg));
104104
}
105105

106+
/**
107+
* @param msg The failure message.
108+
* @param cause The underlying cause
109+
* @return Never completes normally. The return type is {@link AssertionError} to allow writing
110+
* {@code throw fail("failure message", throwable)}.
111+
* This may be helpful in non-{@code void} methods.
112+
* @throws AssertionError Always
113+
*/
114+
public static AssertionError fail(final String msg, final Throwable cause) throws AssertionError {
115+
throw new AssertionError(assertNotNull(msg), assertNotNull(cause));
116+
}
117+
106118
/**
107119
* @param value A value to check.
108120
* @param <T> The type of {@code value}.

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

+23-15
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
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;
22+
import org.bson.assertions.Assertions;
2523

2624
import java.io.BufferedReader;
2725
import java.io.IOException;
2826
import java.io.InputStream;
2927
import java.io.InputStreamReader;
3028
import java.net.URI;
29+
import java.net.URL;
3130
import java.nio.charset.StandardCharsets;
3231
import java.nio.file.FileSystem;
3332
import java.nio.file.FileSystems;
@@ -42,21 +41,20 @@
4241
import java.util.Collections;
4342
import java.util.List;
4443

45-
import static org.bson.assertions.Assertions.assertNotNull;
46-
import static org.junit.jupiter.api.Assertions.fail;
47-
4844
public final class JsonPoweredTestHelper {
4945

46+
private static final String SPECIFICATIONS_PREFIX = "/specifications/source/";
47+
5048
public static BsonDocument getTestDocument(final String resourcePath) {
51-
BsonDocument testDocument = getTestDocumentWithMetaData(resourcePath);
49+
BsonDocument testDocument = getTestDocumentWithMetaData(SPECIFICATIONS_PREFIX + resourcePath);
5250
testDocument.remove("resourcePath");
5351
testDocument.remove("fileName");
5452
return testDocument;
5553
}
5654

57-
public static Collection<Object[]> getTestData(final String resourcePath) {
55+
public static Collection<Object[]> getLegacyTestData(final String resourcePath) {
5856
List<Object[]> data = new ArrayList<>();
59-
for (BsonDocument document : getTestDocuments(resourcePath)) {
57+
for (BsonDocument document : getSpecTestDocuments(resourcePath)) {
6058
for (BsonValue test : document.getArray("tests")) {
6159
BsonDocument testDocument = test.asDocument();
6260
data.add(new Object[]{document.getString("fileName").getValue(),
@@ -68,10 +66,19 @@ public static Collection<Object[]> getTestData(final String resourcePath) {
6866
return data;
6967
}
7068

69+
public static List<BsonDocument> getSpecTestDocuments(final String resourcePath) {
70+
return getTestDocuments(SPECIFICATIONS_PREFIX + resourcePath);
71+
}
72+
7173
public static List<BsonDocument> getTestDocuments(final String resourcePath) {
7274
List<BsonDocument> files = new ArrayList<>();
7375
try {
74-
URI resource = assertNotNull(JsonPoweredTestHelper.class.getResource(resourcePath)).toURI();
76+
URL urlResource = JsonPoweredTestHelper.class.getResource(resourcePath);
77+
if (urlResource == null) {
78+
Assertions.fail("No such resource: " + resourcePath);
79+
}
80+
81+
URI resource = urlResource.toURI();
7582
try (FileSystem fileSystem = (resource.getScheme().equals("jar") ? FileSystems.newFileSystem(resource, Collections.emptyMap()) : null)) {
7683
Path myPath = Paths.get(resource);
7784
Files.walkFileTree(myPath, new SimpleFileVisitor<Path>() {
@@ -89,14 +96,13 @@ public FileVisitResult visitFile(final Path filePath, final BasicFileAttributes
8996
});
9097
}
9198
} catch (Exception e) {
92-
fail("Unable to load resource", e);
99+
Assertions.fail("Unable to load resource: " + resourcePath, e);
93100
}
94101
return files;
95102
}
96103

97104
private static BsonDocument getTestDocumentWithMetaData(final String resourcePath) {
98-
JsonReader jsonReader = new JsonReader(resourcePathToString(resourcePath));
99-
BsonDocument testDocument = new BsonDocumentCodec().decode(jsonReader, DecoderContext.builder().build());
105+
BsonDocument testDocument = BsonDocument.parse(resourcePathToString(resourcePath));
100106
testDocument.append("resourcePath", new BsonString(resourcePath))
101107
.append("fileName", new BsonString(resourcePath.substring(resourcePath.lastIndexOf('/') + 1)));
102108
return testDocument;
@@ -107,15 +113,17 @@ private static String resourcePathToString(final String resourcePath) {
107113
String line;
108114
String ls = System.lineSeparator();
109115
try (InputStream inputStream = JsonPoweredTestHelper.class.getResourceAsStream(resourcePath)) {
110-
assertNotNull(inputStream);
116+
if (inputStream == null) {
117+
Assertions.fail("Unable to load resource: " + resourcePath);
118+
}
111119
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
112120
while ((line = reader.readLine()) != null) {
113121
stringBuilder.append(line);
114122
stringBuilder.append(ls);
115123
}
116124
}
117125
} catch (Exception e) {
118-
fail("Unable to load resource", e);
126+
Assertions.fail("Unable to load resource", e);
119127
}
120128
return stringBuilder.toString();
121129
}

0 commit comments

Comments
 (0)