-
Notifications
You must be signed in to change notification settings - Fork 13
Follow-up to PR 136 #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Follow-up to PR 136 #151
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0343f8d
Follow-up to PR 136
stIncMale c8a7a95
Move unite tests out of integration tests
stIncMale f8438af
Remove the unnecessary method `toExtendedJson`
stIncMale 9205f0e
Group invalid/unsupported MQL unit tests together, remove unnecessary…
stIncMale f57561c
Merge branch 'main' into pr136_followup
stIncMale ff34cbd
Apply suggestion from @vbabanin
stIncMale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ | |
| import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doAndTerminateTransaction; | ||
| import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWithSpecifiedAutoCommit; | ||
| import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.insertTestData; | ||
| import static java.lang.String.format; | ||
| import static java.sql.Statement.SUCCESS_NO_INFO; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
@@ -308,14 +307,13 @@ void testNoCollectionNameProvidedExecuteBatch() { | |
| } | ||
|
|
||
| @Test | ||
| void testAbsentRequiredAggregateCommandField() { | ||
| void testMissingRequiredAggregateCommandField() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| """ | ||
| var mql = """ | ||
| { | ||
| aggregate: "books" | ||
| }"""; | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeQuery) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
|
|
@@ -327,15 +325,15 @@ void testAbsentRequiredAggregateCommandField() { | |
| } | ||
|
|
||
| @Test | ||
| void testAbsentRequiredProjectAggregationPipelineStage() { | ||
| void testMissingRequiredProjectAggregationPipelineStage() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mql = | ||
| """ | ||
| { | ||
| aggregate: "books", | ||
| "pipeline": [] | ||
| }"""; | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeQuery) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL. $project stage is missing [%s]".formatted(toExtendedJson(mql))); | ||
|
|
@@ -393,8 +391,7 @@ void testQueriesReturningResult() { | |
| void testEmptyBatch() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (var pstmt = connection.prepareStatement(INSERT_MQL)) { | ||
| var updateCounts = pstmt.executeBatch(); | ||
| assertEquals(0, updateCounts.length); | ||
| assertExecuteBatch(pstmt, 0); | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -403,7 +400,7 @@ void testEmptyBatch() { | |
|
|
||
| @Test | ||
| @DisplayName("Test statement’s batch of commands is reset once executeBatch returns") | ||
| void testBatchQueueIsResetAfterExecute() { | ||
| void testBatchOfCommandsIsResetAfterExecute() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (var pstmt = connection.prepareStatement( | ||
| """ | ||
|
|
@@ -493,7 +490,7 @@ void testBatchInsert() { | |
| }] | ||
| }""")) { | ||
|
|
||
| for (int i = 1; i <= batchSize; i++) { | ||
| for (var i = 1; i <= batchSize; i++) { | ||
| pstmt.setInt(1, i); | ||
| pstmt.setString(2, "Book " + i); | ||
| pstmt.addBatch(); | ||
|
|
@@ -503,14 +500,14 @@ void testBatchInsert() { | |
| }); | ||
|
|
||
| var expectedDocs = new ArrayList<BsonDocument>(); | ||
| for (int i = 1; i <= batchSize; i++) { | ||
| expectedDocs.add(BsonDocument.parse(format( | ||
| for (var i = 1; i <= batchSize; i++) { | ||
| expectedDocs.add(BsonDocument.parse( | ||
| """ | ||
| { | ||
| "_id": %d, | ||
| "title": "Book %d" | ||
| }""", | ||
| i, i))); | ||
| }""" | ||
| .formatted(i, i))); | ||
| } | ||
| assertThat(mongoCollection.find()).containsExactlyElementsOf(expectedDocs); | ||
| } | ||
|
|
@@ -530,7 +527,7 @@ void testBatchUpdate() { | |
| multi: true | ||
| }] | ||
| }""")) { | ||
| for (int i = 1; i <= batchSize; i++) { | ||
| for (var i = 1; i <= batchSize; i++) { | ||
| pstmt.setInt(1, i); | ||
| pstmt.setString(2, "Book " + i); | ||
| pstmt.addBatch(); | ||
|
|
@@ -540,14 +537,14 @@ void testBatchUpdate() { | |
| }); | ||
|
|
||
| var expectedDocs = new ArrayList<BsonDocument>(); | ||
| for (int i = 1; i <= batchSize; i++) { | ||
| expectedDocs.add(BsonDocument.parse(format( | ||
| for (var i = 1; i <= batchSize; i++) { | ||
| expectedDocs.add(BsonDocument.parse( | ||
| """ | ||
| { | ||
| "_id": %d, | ||
| "title": "Book %d" | ||
| }""", | ||
| i, i))); | ||
| }""" | ||
| .formatted(i, i))); | ||
| } | ||
| assertThat(mongoCollection.find()).containsExactlyElementsOf(expectedDocs); | ||
| } | ||
|
|
@@ -566,7 +563,7 @@ void testBatchDelete() { | |
| limit: 0 | ||
| }] | ||
| }""")) { | ||
| for (int i = 1; i <= batchSize; i++) { | ||
| for (var i = 1; i <= batchSize; i++) { | ||
| pstmt.setInt(1, i); | ||
| pstmt.addBatch(); | ||
| } | ||
|
|
@@ -579,9 +576,9 @@ void testBatchDelete() { | |
|
|
||
| private static void assertExecuteBatch(PreparedStatement pstmt, int expectedUpdateCountsSize) | ||
| throws SQLException { | ||
| int[] updateCounts = pstmt.executeBatch(); | ||
| var updateCounts = pstmt.executeBatch(); | ||
| assertEquals(expectedUpdateCountsSize, updateCounts.length); | ||
| for (int updateCount : updateCounts) { | ||
| for (var updateCount : updateCounts) { | ||
| assertEquals(SUCCESS_NO_INFO, updateCount); | ||
| } | ||
| } | ||
|
|
@@ -761,11 +758,11 @@ void testDelete() { | |
| }"""))); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported commands. Parameters: {0}") | ||
| @ParameterizedTest(name = "test not supported command {0}") | ||
| @ValueSource(strings = {"findAndModify", "aggregate", "bulkWrite"}) | ||
| void testNotSupportedCommands(String commandName) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| %s: "books" | ||
|
|
@@ -778,7 +775,7 @@ void testNotSupportedCommands(String commandName) { | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported update command field. Parameters: option={0}") | ||
| @ParameterizedTest(name = "test not supported update command field {0}") | ||
| @ValueSource( | ||
| strings = { | ||
| "maxTimeMS: 1", | ||
|
|
@@ -790,7 +787,7 @@ void testNotSupportedCommands(String commandName) { | |
| }) | ||
| void testNotSupportedUpdateCommandField(String unsupportedField) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| update: "books", | ||
|
|
@@ -813,14 +810,14 @@ void testNotSupportedUpdateCommandField(String unsupportedField) { | |
| } | ||
|
|
||
| @Test | ||
| void testAbsentRequiredUpdateCommandField() { | ||
| void testMissingRequiredUpdateCommandField() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mql = | ||
| """ | ||
| { | ||
| update: "books" | ||
| }"""; | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeUpdate) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
|
|
@@ -830,11 +827,11 @@ void testAbsentRequiredUpdateCommandField() { | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported delete command field. Parameters: option={0}") | ||
| @ParameterizedTest(name = "test not supported delete command field {0}") | ||
| @ValueSource(strings = {"maxTimeMS: 1", "writeConcern: {}", "comment: {}", "ordered: true", "let: {}"}) | ||
| void testNotSupportedDeleteCommandField(String unsupportedField) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| delete: "books", | ||
|
|
@@ -856,14 +853,14 @@ void testNotSupportedDeleteCommandField(String unsupportedField) { | |
| } | ||
|
|
||
| @Test | ||
| void testAbsentRequiredDeleteCommandField() { | ||
| void testMissingRequiredDeleteCommandField() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mql = | ||
| """ | ||
| { | ||
| delete: "books" | ||
| }"""; | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeUpdate) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
|
|
@@ -873,7 +870,7 @@ void testAbsentRequiredDeleteCommandField() { | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported insert command field. Parameters: option={0}") | ||
| @ParameterizedTest(name = "test not supported insert command field {0}") | ||
| @ValueSource( | ||
| strings = { | ||
| "maxTimeMS: 1", | ||
|
|
@@ -885,7 +882,7 @@ void testAbsentRequiredDeleteCommandField() { | |
| }) | ||
| void testNotSupportedInsertCommandField(String unsupportedField) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| insert: "books", | ||
|
|
@@ -906,14 +903,14 @@ void testNotSupportedInsertCommandField(String unsupportedField) { | |
| } | ||
|
|
||
| @Test | ||
| void testAbsentRequiredInsertCommandField() { | ||
| void testMissingRequiredInsertCommandField() { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mql = | ||
| """ | ||
| { | ||
| insert: "books" | ||
| }"""; | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeUpdate) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
|
|
@@ -923,7 +920,7 @@ void testAbsentRequiredInsertCommandField() { | |
| }); | ||
| } | ||
|
|
||
| private static Stream<Arguments> unsupportedUpdateStatementFields() { | ||
| private static Stream<Arguments> testNotSupportedUpdateStatemenField() { | ||
| return Stream.of( | ||
| of("hint: {}", "Unsupported field in [update] statement: [hint]"), | ||
| of("hint: \"a\"", "Unsupported field in [update] statement: [hint]"), | ||
|
|
@@ -935,11 +932,11 @@ private static Stream<Arguments> unsupportedUpdateStatementFields() { | |
| of("c: {}", "Unsupported field in [update] statement: [c]")); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported update statement field. Parameters: option={0}") | ||
| @MethodSource("unsupportedUpdateStatementFields") | ||
| @ParameterizedTest(name = "test not supported update statement field {0}") | ||
| @MethodSource | ||
| void testNotSupportedUpdateStatemenField(String unsupportedField, String expectedMessage) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| update: "books", | ||
|
|
@@ -960,11 +957,11 @@ void testNotSupportedUpdateStatemenField(String unsupportedField, String expecte | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test absent required update statement field. Parameters: fieldToRemove={0}") | ||
| @ValueSource(strings = {"q: {}", "u: {}"}) | ||
| void testAbsentRequiredUpdateStatementField(String fieldToRemove) { | ||
| @ParameterizedTest(name = "test missing required update statement field {0}") | ||
| @ValueSource(strings = {"q", "u"}) | ||
| void testMissingRequiredUpdateStatementField(String missingFieldName) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mqlDocument = BsonDocument.parse( | ||
| """ | ||
| { | ||
| update: "books", | ||
|
|
@@ -974,23 +971,24 @@ void testAbsentRequiredUpdateStatementField(String fieldToRemove) { | |
| u: {}, | ||
| } | ||
| ] | ||
| }""" | ||
| .replace(fieldToRemove + ",", ""); | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| }"""); | ||
| mqlDocument.getArray("updates").get(0).asDocument().remove(missingFieldName); | ||
| var mql = mqlDocument.toJson(); | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeUpdate) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
| .cause() | ||
| .hasMessage("Document does not contain key %s".formatted(getFieldName(fieldToRemove))); | ||
| .hasMessage("Document does not contain key %s".formatted(missingFieldName)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test not supported delete statement field. Parameters: option={0}") | ||
| @ParameterizedTest(name = "test not supported delete statement field {0}") | ||
| @ValueSource(strings = {"hint: {}", "hint: \"a\"", "collation: {}"}) | ||
| void testNotSupportedDeleteStatementField(String unsupportedField) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement( | ||
| try (var pstm = connection.prepareStatement( | ||
| """ | ||
| { | ||
| delete: "books", | ||
|
|
@@ -1011,28 +1009,29 @@ void testNotSupportedDeleteStatementField(String unsupportedField) { | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "test absent required update statement field. Parameters: fieldToRemove={0}") | ||
| @ValueSource(strings = {"q: {}", "limit: 0"}) | ||
| void testAbsentRequiredDeleteStatementField(String fieldToRemove) { | ||
| @ParameterizedTest(name = "test missing required update statement field {0}") | ||
| @ValueSource(strings = {"q", "limit"}) | ||
| void testMissingRequiredDeleteStatementField(String missingFieldName) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| String mql = | ||
| var mqlDocument = BsonDocument.parse( | ||
| """ | ||
| { | ||
| delete: "books", | ||
| deletes: [ | ||
| { | ||
| q: {}, | ||
| limit: 0, | ||
| } | ||
| ] | ||
| }""" | ||
| .replace(fieldToRemove + ",", ""); | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| { | ||
| delete: "books", | ||
| deletes: [ | ||
| { | ||
| q: {}, | ||
| limit: 0, | ||
| } | ||
| ] | ||
| }"""); | ||
| mqlDocument.getArray("deletes").get(0).asDocument().remove(missingFieldName); | ||
| var mql = mqlDocument.toJson(); | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(pstm::executeUpdate) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage("Invalid MQL: [%s]".formatted(toExtendedJson(mql))) | ||
| .cause() | ||
| .hasMessage("Document does not contain key %s".formatted(getFieldName(fieldToRemove))); | ||
| .hasMessage("Document does not contain key %s".formatted(missingFieldName)); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -1054,7 +1053,7 @@ private void assertExecuteUpdate( | |
| private void assertInvalidMql( | ||
| String mql, SqlConsumer<PreparedStatement> executor, String expectedExceptionMessage) { | ||
| doWorkAwareOfAutoCommit(connection -> { | ||
| try (PreparedStatement pstm = connection.prepareStatement(mql)) { | ||
| try (var pstm = connection.prepareStatement(mql)) { | ||
| assertThatThrownBy(() -> executor.accept(pstm)) | ||
| .isInstanceOf(SQLSyntaxErrorException.class) | ||
| .hasMessage(expectedExceptionMessage); | ||
|
|
@@ -1070,11 +1069,11 @@ void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLEx | |
| doWithSpecifiedAutoCommit(false, connection, () -> doAndTerminateTransaction(connection, work)); | ||
| } | ||
|
|
||
| private static String getFieldName(String unsupportedField) { | ||
| return BsonDocument.parse("{" + unsupportedField + "}").getFirstKey(); | ||
| private static String getFieldName(String field) { | ||
|
||
| return BsonDocument.parse("{" + field + "}").getFirstKey(); | ||
| } | ||
|
|
||
| private String toExtendedJson(String mql) { | ||
| private static String toExtendedJson(String mql) { | ||
| return BsonDocument.parse(mql).toJson(EXTENDED_JSON_WRITER_SETTINGS); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced "absent" with "missing", as that's what the rest of the codebase uses:
$project stage is missingCommand name is missingCollection name is missingStructAggregateEmbeddableIntegrationTests/EmbeddableIntegrationTests.testReadNestedValuesMissingFields