Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions audits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ These remain because coverage has not fully moved off them yet. Each one goes wh
its users does.

- **Core's legacy fixture loader** (`data.json`, `action.json`, `expected.json` through
`TemplatedTestBase`). It runs 186 legacy fixture directories; 370 cases have moved to the runner.
Of the 186:
`TemplatedTestBase`). It runs 183 legacy fixture directories; 373 cases have moved to the runner.
Of the 183:
- 98 are still locked: 96 have no documented source that reproduces them, and are listed under
`unresolved` in `form-review.json`;
- 16 are tracked as legacy-only in `cutover.json`;
- 15 are tracked as legacy-only in `cutover.json`;
- 69 never-locked fixtures have no pinned reference.
- **The legacy RST extractor** (`rst/`, `model/CodeBlock`). Cutover and the example inventory
read pages through it, with tested snippets spliced in and only the mongosh content of each
Expand Down
8 changes: 7 additions & 1 deletion audits/catalog/curated-repairs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6399,6 +6399,9 @@
"markers" : [ ],
"method" : "testUseTheInOperatorToMatchValues",
"options" : [ {
"argument" : "new FindOptions().projection().exclude(\"_id\")",
"name" : "findOptions"
}, {
"argument" : "true",
"name" : "removeIds"
} ],
Expand Down Expand Up @@ -6733,6 +6736,9 @@
"markers" : [ ],
"method" : "testSelectOnUnmatchingDocuments",
"options" : [ {
"argument" : "new FindOptions().projection().exclude(\"_id\")",
"name" : "findOptions"
}, {
"argument" : "true",
"name" : "removeIds"
} ],
Expand Down Expand Up @@ -7985,7 +7991,7 @@
"exclusion.TESTED_ELSEWHERE" : 1,
"markers.lock" : 97,
"markers.lockd" : 1,
"option.findOptions" : 6,
"option.findOptions" : 8,
"option.orderMatters" : 107,
"option.removeIds" : 61,
"option.serverVersion" : 18,
Expand Down
10 changes: 3 additions & 7 deletions audits/catalog/cutover.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@
"detail" : "the shell normalizer cannot read the documented results (expected syntax)",
"fixture" : "aggregation/stages/graphLookup/acrossMultipleCollections"
}, {
"check" : "SOURCE",
"detail" : "the page documents a projection, which needs the unmapped findOptions",
"fixture" : "query/filters/in/useTheInOperatorToMatchValues"
}, {
"check" : "SOURCE",
"detail" : "the page documents a projection, which needs the unmapped findOptions",
"fixture" : "query/filters/nin/selectOnUnmatchingDocuments"
"check" : "SERIALIZATION",
"detail" : "the page's projection is {_id: 0, name: 1, registered: 1}; the test includes name and registered and drops _id with removeIds, so Morphia's projection lacks the _id exclusion",
"fixture" : "query/filters/rand/selectRandomItemsFromACollection"
} ],
"schemaVersion" : 1
}
270 changes: 270 additions & 0 deletions audits/catalog/fixture-migration.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ object FixtureMigration {
* comparison, `serverVersion` becomes the minimum server, and `skipActionCheck` and
* `skipDataCheck` become skipped checks that name their reason.
*/
val mappedOptions = setOf("removeIds", "serverVersion", "skipActionCheck", "skipDataCheck")
/**
* The legacy options a converted case may keep. `findOptions` carries the projection the page
* documents, which the runner compares with the page's; it changes nothing in the scenario.
*/
val mappedOptions =
setOf("removeIds", "serverVersion", "skipActionCheck", "skipDataCheck", "findOptions")

/**
* [documented] with [override]'s retypes and corrections applied as it pins them: to the rows
Expand Down Expand Up @@ -293,11 +298,9 @@ object FixtureMigration {
when (documented.shape) {
ActionShape.PIPELINE -> action["pipeline"] = BsonArray(documented.action)
ActionShape.FIND -> {
// A projection needs the legacy findOptions, which the adapter does not map yet.
require(documented.action.size == 1) {
"${override.fixture}: a documented projection is not supported yet"
}
action["filter"] = documented.action[0]
// The page's projection, when it documents one.
documented.action.getOrNull(1)?.let { action["projection"] = it }
}
ActionShape.UPDATE -> {
require(documented.action.size == 2 && documented.action[1].isDocument) {
Expand Down
38 changes: 30 additions & 8 deletions core/src/test/java/dev/morphia/test/OperatorCaseRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,36 @@ public void aggregate(OperatorCase operatorCase, Function<Aggregation<Document>,
*/
public void find(OperatorCase operatorCase, ActionTestOptions options, Function<Query<Document>, Query<Document>> dsl) {
options(operatorCase, options);
find(operatorCase, dsl);
find(operatorCase, dsl, options.findOptions());
}

/**
* Runs a query case: the documented filter runs through the driver, and Morphia's query as {@code dsl} builds it.
*/
public void find(OperatorCase operatorCase, Function<Query<Document>, Query<Document>> dsl) {
find(operatorCase, dsl, new FindOptions());
}

/**
* Runs a query case whose page documents a projection: Morphia's is {@code options}', compared with the page's
* after the filter. Any other option would change the results, which the behavior check compares with the
* documented query's.
*/
public void find(OperatorCase operatorCase, Function<Query<Document>, Query<Document>> dsl, FindOptions options) {
run(operatorCase, "find", Shape.FIND, (action, collection) -> {
Query<Document> query = dsl.apply(test.getDs().find(Document.class, new FindOptions().collection(collection))
.disableValidation());
FindOptions found = new FindOptions().copy(options).collection(collection);
Query<Document> query = dsl.apply(test.getDs().find(Document.class, found).disableValidation());
BsonDocument filter = action.getDocument("filter");
return new Execution(bson(List.of(((MorphiaQuery<Document>) query).toDocument())),
BsonDocument projection = action.getDocument("projection", null);
List<Document> emitted = new ArrayList<>(List.of(((MorphiaQuery<Document>) query).toDocument()));
found.projection().disableValidation(true);
Document mapped = found.projection().map(test.getMapper(), Document.class);
if (mapped != null || projection != null) {
emitted.add(mapped != null ? mapped : new Document());
}
return new Execution(bson(emitted),
reference -> new ArrayList<>(reference.getCollection(collection, BsonDocument.class).find(filter)
.into(new ArrayList<>())),
.projection(projection).into(new ArrayList<>())),
() -> {
try (var cursor = query.iterator()) {
return bson(cursor.toList()).getValues();
Expand Down Expand Up @@ -165,7 +181,9 @@ private record Execution(BsonArray emitted, Function<MongoDatabase, List<BsonVal
private static BsonArray documented(BsonDocument action) {
return switch (action.getString("kind").getValue()) {
case "aggregate" -> action.getArray("pipeline");
case "find" -> new BsonArray(List.of(action.getDocument("filter")));
case "find" -> action.containsKey("projection")
? new BsonArray(List.of(action.getDocument("filter"), action.getDocument("projection")))
: new BsonArray(List.of(action.getDocument("filter")));
default -> new BsonArray(List.of(action.getDocument("filter"), action.getDocument("update")));
};
}
Expand Down Expand Up @@ -197,7 +215,10 @@ private void options(OperatorCase operatorCase, ActionTestOptions options) {
}
// The runner builds its own find and update options, so a test's own would be silently dropped.
// FindOptions.equals leaves out timeoutMode, so it is checked on its own.
if (!options.findOptions().equals(new FindOptions()) || options.findOptions().timeoutMode() != null
// A documented projection is Morphia's findOptions; any other find option changes the results, which the behavior
// check compares.
boolean projected = scenario.getDocument("action").containsKey("projection");
if (!projected && (!options.findOptions().equals(new FindOptions()) || options.findOptions().timeoutMode() != null)
|| options.hasUpdateOptions()) {
differences.add("findOptions/updateOptions");
}
Expand Down Expand Up @@ -371,7 +392,8 @@ private static void supported(OperatorCase operatorCase, BsonDocument scenario)
BsonDocument action = scenario.getDocument("action");
Set<String> fields = switch (action.getString("kind", new BsonString("")).getValue()) {
case "aggregate" -> Set.of("kind", "collection", "pipeline");
case "find" -> Set.of("kind", "collection", "filter");
case "find" -> action.containsKey("projection") ? Set.of("kind", "collection", "filter", "projection")
: Set.of("kind", "collection", "filter");
case "update" -> Set.of("kind", "collection", "filter", "update", "multi");
default -> Set.of();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.regex.Pattern;

import dev.morphia.query.FindOptions;
import dev.morphia.test.TemplatedTestBase;
import dev.morphia.test.util.ActionTestOptions;

Expand All @@ -20,7 +21,8 @@ public class TestIn extends TemplatedTestBase {
@Test
@DisplayName("Use the ``$in`` Operator to Match Values")
public void testUseTheInOperatorToMatchValues() {
testQuery(new ActionTestOptions().removeIds(true), (query) -> query.filter(in("quantity", List.of(5, 15))));
testQuery(new ActionTestOptions().removeIds(true).findOptions(new FindOptions().projection().exclude("_id")),
(query) -> query.filter(in("quantity", List.of(5, 15))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import dev.morphia.query.FindOptions;
import dev.morphia.test.TemplatedTestBase;
import dev.morphia.test.util.ActionTestOptions;

Expand All @@ -19,7 +20,8 @@ public class TestNin extends TemplatedTestBase {
@Test
@DisplayName("Select on Unmatching Documents")
public void testSelectOnUnmatchingDocuments() {
testQuery(new ActionTestOptions().removeIds(true), (query) -> query.filter(nin("quantity", List.of(5, 15))));
testQuery(new ActionTestOptions().removeIds(true).findOptions(new FindOptions().projection().exclude("_id")),
(query) -> query.filter(nin("quantity", List.of(5, 15))));
}

/**
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/resources/dev/morphia/test/generated/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,11 @@
"name" : "query/filters/in/matchValuesInAnArray",
"scenario" : "/dev/morphia/test/generated/fixtures/filters/in/matchValuesInAnArray/scenario.json",
"test" : "dev.morphia.test.generated.filters.TestIn#matchValuesInAnArray"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/in/useTheInOperatorToMatchValues",
"scenario" : "/dev/morphia/test/query/filters/in/useTheInOperatorToMatchValues/scenario.json",
"test" : "dev.morphia.test.query.filters.TestIn#testUseTheInOperatorToMatchValues"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/in/useTheInOperatorToMatchValuesInAnArray",
Expand Down Expand Up @@ -1679,6 +1684,11 @@
"name" : "query/filters/nearSphere/specifyCenterPointUsingGeoJson",
"scenario" : "/dev/morphia/test/query/filters/nearSphere/specifyCenterPointUsingGeoJson/scenario.json",
"test" : "dev.morphia.test.query.filters.TestNearSphere#testSpecifyCenterPointUsingGeoJson"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/nin/selectOnUnmatchingDocuments",
"scenario" : "/dev/morphia/test/query/filters/nin/selectOnUnmatchingDocuments/scenario.json",
"test" : "dev.morphia.test.query.filters.TestNin#testSelectOnUnmatchingDocuments"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/nor/norAndAdditionalComparisons",
Expand Down Expand Up @@ -1729,6 +1739,11 @@
"name" : "query/filters/text/queryADifferentLanguage",
"scenario" : "/dev/morphia/test/query/filters/text/queryADifferentLanguage/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testQueryADifferentLanguage"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/relevanceScoreExamples",
"scenario" : "/dev/morphia/test/query/filters/text/relevanceScoreExamples/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testRelevanceScoreExamples"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/textWithASingleWord",
Expand Down Expand Up @@ -3292,6 +3307,10 @@
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/gte/performAnUpdateBasedOnEmbeddedDocumentFields/scenario.json",
"sha256" : "240da48253c0ae273da07a1c1fac1d18b5460f3d4cbf47af47b25613585f1b39"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/in/useTheInOperatorToMatchValues/scenario.json",
"sha256" : "e93beb956188ae149c0c02e7c87191fc700d0752c86ffcd155809cffc8e84815"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/in/useTheInOperatorToMatchValuesInAnArray/scenario.json",
Expand Down Expand Up @@ -3336,6 +3355,10 @@
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/nearSphere/specifyCenterPointUsingGeoJson/scenario.json",
"sha256" : "e542a4a0092203869ffeaf3f39db98c1408fd3e1f9eeb735c45de12dd513531e"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/nin/selectOnUnmatchingDocuments/scenario.json",
"sha256" : "0220aaeb04b41124da9e4d0e06fae054509b54df0e18cc61b0797fe267f870c1"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/nor/norAndAdditionalComparisons/scenario.json",
Expand Down Expand Up @@ -3376,6 +3399,10 @@
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/queryADifferentLanguage/scenario.json",
"sha256" : "f96a5fc66dd8a48fa6ffcaa220857295d31e777347cf7c8f0d3adadffa7506e5"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/relevanceScoreExamples/scenario.json",
"sha256" : "902c67ea095d9a5b77d9c5aaac3244c3b43835b707220f86697b800de9970275"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/textWithASingleWord/scenario.json",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading