diff --git a/driver-core/src/test/resources/unified-test-format/crud/findOne.json b/driver-core/src/test/resources/unified-test-format/crud/findOne.json new file mode 100644 index 00000000000..826c0f5dfdb --- /dev/null +++ b/driver-core/src/test/resources/unified-test-format/crud/findOne.json @@ -0,0 +1,158 @@ +{ + "description": "findOne", + "schemaVersion": "1.0", + "createEntities": [ + { + "client": { + "id": "client0", + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "find-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "coll0" + } + } + ], + "initialData": [ + { + "collectionName": "coll0", + "databaseName": "find-tests", + "documents": [ + { + "_id": 1, + "x": 11 + }, + { + "_id": 2, + "x": 22 + }, + { + "_id": 3, + "x": 33 + }, + { + "_id": 4, + "x": 44 + }, + { + "_id": 5, + "x": 55 + }, + { + "_id": 6, + "x": 66 + } + ] + } + ], + "tests": [ + { + "description": "FindOne with filter", + "operations": [ + { + "object": "collection0", + "name": "findOne", + "arguments": { + "filter": { + "_id": 1 + } + }, + "expectResult": { + "_id": 1, + "x": 11 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "coll0", + "filter": { + "_id": 1 + }, + "batchSize": { + "$$exists": false + }, + "limit": 1, + "singleBatch": true + }, + "commandName": "find", + "databaseName": "find-tests" + } + } + ] + } + ] + }, + { + "description": "FindOne with filter, sort, and skip", + "operations": [ + { + "object": "collection0", + "name": "findOne", + "arguments": { + "filter": { + "_id": { + "$gt": 2 + } + }, + "sort": { + "_id": 1 + }, + "skip": 2 + }, + "expectResult": { + "_id": 5, + "x": 55 + } + } + ], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandStartedEvent": { + "command": { + "find": "coll0", + "filter": { + "_id": { + "$gt": 2 + } + }, + "sort": { + "_id": 1 + }, + "skip": 2, + "batchSize": { + "$$exists": false + }, + "limit": 1, + "singleBatch": true + }, + "commandName": "find", + "databaseName": "find-tests" + } + } + ] + } + ] + } + ] +} diff --git a/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedCrudTest.kt b/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedCrudTest.kt index 5091058573e..b2836ed9f9c 100644 --- a/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedCrudTest.kt +++ b/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedCrudTest.kt @@ -24,7 +24,7 @@ internal class UnifiedCrudTest() : UnifiedTest() { @JvmStatic @Throws(URISyntaxException::class, IOException::class) fun data(): Collection? { - return getTestData("unified-test-format/crud", true) + return getTestData("unified-test-format/crud", true, Language.KOTLIN) } } } diff --git a/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedTest.kt b/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedTest.kt index b027b3946c5..f676f93956f 100644 --- a/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedTest.kt +++ b/driver-kotlin-coroutine/src/integrationTest/kotlin/com/mongodb/kotlin/client/coroutine/UnifiedTest.kt @@ -39,4 +39,8 @@ internal abstract class UnifiedTest() : JUnifiedTest() { ): ClientEncryption { TODO("Not yet implemented - JAVA-4896") } + + override fun isReactive(): Boolean = true + + override fun getLanguage(): Language = Language.KOTLIN } diff --git a/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedCrudTest.kt b/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedCrudTest.kt index f030cb54645..d2c86354b17 100644 --- a/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedCrudTest.kt +++ b/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedCrudTest.kt @@ -24,7 +24,7 @@ internal class UnifiedCrudTest() : UnifiedTest() { @JvmStatic @Throws(URISyntaxException::class, IOException::class) fun data(): Collection? { - return getTestData("unified-test-format/crud", false) + return getTestData("unified-test-format/crud", false, Language.KOTLIN) } } } diff --git a/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedTest.kt b/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedTest.kt index 4f4726bbb6f..7c115efc6f8 100644 --- a/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedTest.kt +++ b/driver-kotlin-sync/src/integrationTest/kotlin/com/mongodb/kotlin/client/UnifiedTest.kt @@ -39,4 +39,6 @@ internal abstract class UnifiedTest() : JUnifiedTest() { ): ClientEncryption { TODO("Not yet implemented - JAVA-4896") } + + override fun getLanguage(): Language = Language.KOTLIN } diff --git a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedReactiveStreamsTest.java b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedReactiveStreamsTest.java index 716d04a2890..640d88964ce 100644 --- a/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedReactiveStreamsTest.java +++ b/driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedReactiveStreamsTest.java @@ -101,6 +101,6 @@ protected void postCleanUp(final TestDef testDef) { @NonNull protected static Collection getTestData(final String directory) { - return getTestData(directory, true); + return getTestData(directory, true, Language.JAVA); } } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java index 735c35dc9ed..0c91057aeeb 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java @@ -408,6 +408,11 @@ OperationResult executeFind(final BsonDocument operation) { }); } + /** + * There is no explicit {@code findOne()} method in {@link MongoCollection} class. + * Its feature was emulated by {@link FindIterable#first()}, which would close cursor on server + * by setting {@code batchSize} and {@code limit} appropriately. + */ OperationResult executeFindOne(final BsonDocument operation) { return resultOf(() -> createFindIterable(operation).first()); } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedSyncTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedSyncTest.java index e206dcc138a..9fc9ef5617f 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedSyncTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedSyncTest.java @@ -51,6 +51,6 @@ protected ClientEncryption createClientEncryption(final MongoClient keyVaultClie @NonNull protected static Collection getTestData(final String directory) { - return getTestData(directory, false); + return getTestData(directory, false, Language.JAVA); } } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java index 6f20c0b22a8..6453f67cf26 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java @@ -161,7 +161,7 @@ public Entities getEntities() { } @NonNull - protected static Collection getTestData(final String directory, final boolean isReactive) { + protected static Collection getTestData(final String directory, final boolean isReactive, final Language language) { List data = new ArrayList<>(); for (BsonDocument fileDocument : getTestDocuments("/" + directory + "/")) { for (BsonValue cur : fileDocument.getArray("tests")) { @@ -169,7 +169,7 @@ protected static Collection getTestData(final String directory, final final BsonDocument testDocument = cur.asDocument(); String testDescription = testDocument.getString("description").getValue(); String fileDescription = fileDocument.getString("description").getValue(); - TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive); + TestDef testDef = testDef(directory, fileDescription, testDescription, isReactive, language); applyCustomizations(testDef); boolean forceFlaky = testDef.wasAssignedModifier(Modifier.FORCE_FLAKY); @@ -240,7 +240,7 @@ public void setUp( rootContext.getAssertionContext().push(ContextElement.ofTest(definition)); ignoreExtraEvents = false; if (directoryName != null && fileDescription != null && testDescription != null) { - testDef = testDef(directoryName, fileDescription, testDescription, isReactive()); + testDef = testDef(directoryName, fileDescription, testDescription, isReactive(), getLanguage()); applyCustomizations(testDef); boolean skip = testDef.wasAssignedModifier(Modifier.SKIP); @@ -329,6 +329,10 @@ protected boolean isReactive() { return false; } + protected Language getLanguage() { + return Language.JAVA; + } + @ParameterizedTest(name = "{0}") @MethodSource("data") public void shouldPassAllOutcomes( @@ -1112,4 +1116,8 @@ protected void ignoreExtraCommandEvents(final boolean ignoreExtraEvents) { protected void ignoreExtraEvents() { this.ignoreExtraEvents = true; } + + public enum Language { + JAVA, KOTLIN + } } diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java index 31b8ebb3bdf..f908e81937b 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTestModifications.java @@ -143,6 +143,10 @@ public static void applyCustomizations(final TestDef def) { .test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint string on 4.4+ server") .test("crud", "findOneAndDelete-hint-unacknowledged", "Unacknowledged findOneAndDelete with hint document on 4.4+ server"); + def.skipNoncompliant("https://jira.mongodb.org/browse/JAVA-5838") + .when(() -> def.isReactive() && UnifiedTest.Language.KOTLIN.equals(def.getLanguage())) + .file("crud", "findOne"); + // gridfs def.skipDeprecated("contentType is deprecated in GridFS spec, and 4.x Java driver no longer supports it") @@ -256,24 +260,28 @@ public static void applyCustomizations(final TestDef def) { private UnifiedTestModifications() {} - public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive) { - return new TestDef(dir, file, test, reactive); + public static TestDef testDef(final String dir, final String file, final String test, final boolean reactive, + final UnifiedTest.Language language) { + return new TestDef(dir, file, test, reactive, language); } public static final class TestDef { + private final String dir; private final String file; private final String test; private final boolean reactive; + private final UnifiedTest.Language language; private final List modifiers = new ArrayList<>(); private Function matchesThrowable; - private TestDef(final String dir, final String file, final String test, final boolean reactive) { + private TestDef(final String dir, final String file, final String test, final boolean reactive, final UnifiedTest.Language language) { this.dir = assertNotNull(dir); this.file = assertNotNull(file); this.test = assertNotNull(test); this.reactive = reactive; + this.language = assertNotNull(language); } /** @@ -354,6 +362,10 @@ public boolean isReactive() { return reactive; } + public UnifiedTest.Language getLanguage() { + return language; + } + public boolean wasAssignedModifier(final Modifier modifier) { return this.modifiers.contains(modifier); }