-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce QueryTestOptions and simplify calls
- Loading branch information
1 parent
2c5f0ac
commit 5bd48de
Showing
35 changed files
with
161 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
core/src/test/java/dev/morphia/test/query/filters/QueryTestOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.morphia.test.query.filters; | ||
|
||
import dev.morphia.test.ServerVersion; | ||
|
||
import static dev.morphia.test.ServerVersion.ANY; | ||
|
||
public class QueryTestOptions { | ||
private ServerVersion serverVersion = ANY; | ||
private boolean removeIds = false; | ||
private boolean orderMatters = true; | ||
|
||
public QueryTestOptions() { | ||
serverVersion = ANY; | ||
} | ||
|
||
public ServerVersion serverVersion() { | ||
return serverVersion; | ||
} | ||
|
||
public QueryTestOptions serverVersion(ServerVersion serverVersion) { | ||
this.serverVersion = serverVersion; | ||
return this; | ||
} | ||
|
||
public boolean removeIds() { | ||
return removeIds; | ||
} | ||
|
||
public QueryTestOptions removeIds(boolean removeIds) { | ||
this.removeIds = removeIds; | ||
return this; | ||
} | ||
|
||
public boolean orderMatters() { | ||
return orderMatters; | ||
} | ||
|
||
public QueryTestOptions orderMatters(boolean orderMatters) { | ||
this.orderMatters = orderMatters; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
core/src/test/java/dev/morphia/test/query/filters/TestBitsAllClear.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
core/src/test/java/dev/morphia/test/query/filters/TestBitsAllSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
core/src/test/java/dev/morphia/test/query/filters/TestBitsAnyClear.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
core/src/test/java/dev/morphia/test/query/filters/TestBitsAnySet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/src/test/java/dev/morphia/test/query/filters/TestEq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dev.morphia.test.query.filters; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static dev.morphia.query.filters.Filters.eq; | ||
|
||
public class TestEq extends FilterTest { | ||
@Test(testName = "Equals a Specified Value") | ||
public void testExample1() { | ||
testQuery((query) -> query.filter( | ||
eq("qty", 20))); | ||
} | ||
|
||
@Test(testName = "Field in Embedded Document Equals a Value") | ||
public void testExample2() { | ||
testQuery((query) -> query.filter( | ||
eq("item.name", "ab"))); | ||
} | ||
|
||
@Test(testName = "Array Element Equals a Value") | ||
public void testExample3() { | ||
testQuery((query) -> query.filter( | ||
eq("tags", "B"))); | ||
} | ||
|
||
@Test(testName = "Equals an Array Value") | ||
public void testExample4() { | ||
testQuery((query) -> query.filter( | ||
eq("tags", List.of("A", "B")) | ||
|
||
)); | ||
} | ||
|
||
@Test(testName = "Regex Match Behaviour") | ||
public void testExample5() { | ||
testQuery(new QueryTestOptions().removeIds(true), (query) -> query.filter( | ||
eq("company", Pattern.compile("MongoDB")))); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example1/action.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
db.inventory.find( { qty: 20 } ) |
5 changes: 5 additions & 0 deletions
5
core/src/test/resources/dev/morphia/test/query/filters/eq/example1/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] }, | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 4, item: { name: "xy", code: "456" }, qty: 30, tags: [ "B", "A" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
2 changes: 2 additions & 0 deletions
2
core/src/test/resources/dev/morphia/test/query/filters/eq/example1/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example1/lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
update action to use shortened version of $eq |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example1/name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Equals a Specified Value |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example2/action.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
db.inventory.find( { "item.name": "ab" } ) |
5 changes: 5 additions & 0 deletions
5
core/src/test/resources/dev/morphia/test/query/filters/eq/example2/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] }, | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 4, item: { name: "xy", code: "456" }, qty: 30, tags: [ "B", "A" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example2/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[ { _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] } ] |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example2/lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
update action to use shortened version of $eq |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example2/name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Field in Embedded Document Equals a Value |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example3/action.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
db.inventory.find( { tags: "B" } ) |
5 changes: 5 additions & 0 deletions
5
core/src/test/resources/dev/morphia/test/query/filters/eq/example3/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] }, | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 4, item: { name: "xy", code: "456" }, qty: 30, tags: [ "B", "A" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
4 changes: 4 additions & 0 deletions
4
core/src/test/resources/dev/morphia/test/query/filters/eq/example3/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] }, | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 4, item: { name: "xy", code: "456" }, qty: 30, tags: [ "B", "A" ] } |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example3/lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
update action to use shortened version of $eq |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example3/name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Array Element Equals a Value |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example4/action.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
db.inventory.find( { tags: [ "A", "B" ] } ) |
5 changes: 5 additions & 0 deletions
5
core/src/test/resources/dev/morphia/test/query/filters/eq/example4/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ _id: 1, item: { name: "ab", code: "123" }, qty: 15, tags: [ "A", "B", "C" ] }, | ||
{ _id: 2, item: { name: "cd", code: "123" }, qty: 20, tags: [ "B" ] }, | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 4, item: { name: "xy", code: "456" }, qty: 30, tags: [ "B", "A" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
2 changes: 2 additions & 0 deletions
2
core/src/test/resources/dev/morphia/test/query/filters/eq/example4/expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ _id: 3, item: { name: "ij", code: "456" }, qty: 25, tags: [ "A", "B" ] }, | ||
{ _id: 5, item: { name: "mn", code: "000" }, qty: 20, tags: [ [ "A", "B" ], "C" ] } |
1 change: 1 addition & 0 deletions
1
core/src/test/resources/dev/morphia/test/query/filters/eq/example4/lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
update action to use shortened version of $eq |
Oops, something went wrong.