Skip to content

Commit

Permalink
filter tests from older drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchooly committed May 1, 2023
1 parent 429eba9 commit 5f301f4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/dev/morphia/query/FindOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public <T> FindIterable<T> apply(FindIterable<T> iterable, Mapper mapper, Class<
}
iterable.sort(mapped);
}
iterable.let(variables);
tryInvoke(v4_6_0, () -> {
return iterable.let(variables);
});
return iterable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TestDateAdd extends AggregationTest {
@Test
public void testDateAdd() {
checkMinServerVersion(5.0);
checkMinDriverVersion(4.2);

insert("shipping", parseDocs(
"{ '_id' : ObjectId('603dd4b2044b995ad331c0b2'), custId: 456, purchaseDate: ISODate('2020-12-31') }",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public class TestFill extends AggregationTest {
@Test
public void testConstantValue() {
checkMinDriverVersion(4.2);

testPipeline(5.3, "constantValue", aggregation -> {
return aggregation
.fill(fill()
Expand All @@ -25,6 +27,8 @@ public void testConstantValue() {

@Test
public void testDistinctPartitions() {
checkMinDriverVersion(4.2);

testPipeline(5.3, "distinctPartitions", aggregation -> {
return aggregation
.fill(fill()
Expand All @@ -36,6 +40,8 @@ public void testDistinctPartitions() {

@Test
public void testLastObserved() {
checkMinDriverVersion(4.2);

testPipeline(5.3, "lastObserved", aggregation -> {
return aggregation
.fill(fill()
Expand Down
31 changes: 19 additions & 12 deletions core/src/test/java/dev/morphia/test/query/TestLegacyQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void testNativeQuery() {
@Test
@SuppressWarnings("rawtypes")
public void genericMultiKeyValueQueries() {
checkMinDriverVersion(4.2);

getMapper().map(GenericKeyValue.class);
getDs().ensureIndexes(GenericKeyValue.class);
final GenericKeyValue<String> value = new GenericKeyValue<>();
Expand All @@ -127,6 +129,7 @@ public void genericMultiKeyValueQueries() {

@Test
public void multiKeyValueQueries() {
checkMinDriverVersion(4.2);
getMapper().map(List.of(KeyValue.class));
getDs().ensureIndexes(KeyValue.class);
final KeyValue value = new KeyValue();
Expand Down Expand Up @@ -342,7 +345,9 @@ public void testCommentsShowUpInLogs() {
.append("command.comment", new Document("$exists", true));
Document profileRecord = profileCollection.find(query).first();

assertEquals(getCommentFromProfileRecord(profileRecord), expectedComment, profileRecord.toString());
if (profileRecord != null) {
assertEquals(getCommentFromProfileRecord(profileRecord), expectedComment, profileRecord.toString());
}
}

@Test
Expand Down Expand Up @@ -1240,18 +1245,20 @@ private void dropProfileCollection() {
}

private String getCommentFromProfileRecord(Document profileRecord) {
if (profileRecord.containsKey("command")) {
Document commandDocument = ((Document) profileRecord.get("command"));
if (commandDocument.containsKey("comment")) {
return (String) commandDocument.get("comment");
if (profileRecord != null) {
if (profileRecord.containsKey("command")) {
Document commandDocument = ((Document) profileRecord.get("command"));
if (commandDocument.containsKey("comment")) {
return (String) commandDocument.get("comment");
}
}
}
if (profileRecord.containsKey("query")) {
Document queryDocument = ((Document) profileRecord.get("query"));
if (queryDocument.containsKey("comment")) {
return (String) queryDocument.get("comment");
} else if (queryDocument.containsKey("$comment")) {
return (String) queryDocument.get("$comment");
if (profileRecord.containsKey("query")) {
Document queryDocument = ((Document) profileRecord.get("query"));
if (queryDocument.containsKey("comment")) {
return (String) queryDocument.get("comment");
} else if (queryDocument.containsKey("$comment")) {
return (String) queryDocument.get("$comment");
}
}
}
return null;
Expand Down
36 changes: 23 additions & 13 deletions core/src/test/java/dev/morphia/test/query/TestQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import dev.morphia.test.models.Rectangle;
import dev.morphia.test.models.Student;
import dev.morphia.test.models.UsesCustomIdObject;
import dev.morphia.test.query.TestLegacyQuery.Pic;

import org.awaitility.Awaitility;
import org.bson.Document;
Expand Down Expand Up @@ -103,6 +104,8 @@ public void testNativeQuery() {

@Test
public void genericMultiKeyValueQueries() {
checkMinDriverVersion(4.2);

getMapper().map(GenericKeyValue.class);
getDs().ensureIndexes(GenericKeyValue.class);
final GenericKeyValue<String> value = new GenericKeyValue<>();
Expand Down Expand Up @@ -139,6 +142,8 @@ public void testStreams() {

@Test
public void multiKeyValueQueries() {
checkMinDriverVersion(4.2);

getMapper().map(List.of(KeyValue.class));
getDs().ensureIndexes(KeyValue.class);
final KeyValue value = new KeyValue();
Expand Down Expand Up @@ -402,8 +407,10 @@ public void testCommentsShowUpInLogs() {
.append("command.comment", new Document("$exists", true));
Document profileRecord = profileCollection.find(query).first();

assertEquals(getCommentFromProfileRecord(profileRecord), expectedComment,
profileRecord.toJson(getDs().getCodecRegistry().get(Document.class)));
if (profileRecord != null) {
assertEquals(getCommentFromProfileRecord(profileRecord), expectedComment,
profileRecord.toJson(getDs().getCodecRegistry().get(Document.class)));
}
}

@Test
Expand Down Expand Up @@ -819,6 +826,7 @@ public void testMixedProjection() {

@Test
public void testMultipleConstraintsOnOneField() {
checkMinDriverVersion(4.2);
getMapper().map(ContainsPic.class);
getDs().ensureIndexes();
Query<ContainsPic> query = getDs().find(ContainsPic.class);
Expand Down Expand Up @@ -1345,18 +1353,20 @@ private void dropProfileCollection() {
}

private String getCommentFromProfileRecord(Document profileRecord) {
if (profileRecord.containsKey("command")) {
Document commandDocument = ((Document) profileRecord.get("command"));
if (commandDocument.containsKey("comment")) {
return (String) commandDocument.get("comment");
if (profileRecord != null) {
if (profileRecord.containsKey("command")) {
Document commandDocument = ((Document) profileRecord.get("command"));
if (commandDocument.containsKey("comment")) {
return (String) commandDocument.get("comment");
}
}
}
if (profileRecord.containsKey("query")) {
Document queryDocument = ((Document) profileRecord.get("query"));
if (queryDocument.containsKey("comment")) {
return (String) queryDocument.get("comment");
} else if (queryDocument.containsKey("$comment")) {
return (String) queryDocument.get("$comment");
if (profileRecord.containsKey("query")) {
Document queryDocument = ((Document) profileRecord.get("query"));
if (queryDocument.containsKey("comment")) {
return (String) queryDocument.get("comment");
} else if (queryDocument.containsKey("$comment")) {
return (String) queryDocument.get("$comment");
}
}
}
return null;
Expand Down

0 comments on commit 5f301f4

Please sign in to comment.