-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/82 increase unit test coverage #83
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
Changes from all commits
a4ef7a9
3c552dc
8ca8285
0c236f7
3f25600
992f929
352188e
e6087b4
ddf5af6
0cca7e7
f2fbc3c
f213797
7aea462
e4b3f5d
1330c03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,10 +45,12 @@ class QueryResultRow private[classes](val rowNumber: Int, | |
|
|
||
| /** | ||
| * Extracts a value from the row by column number. | ||
| * @param column - the number of the column, 1 based | ||
| * @param column - the 1-based column number (JDBC convention); note: prior to this fix the parameter was | ||
| * incorrectly treated as 0-based (direct vector index), causing column 1 to silently return | ||
| * the value of the second column | ||
| * @return - the value stored in the column, type `Any` is for warningless comparison with any type | ||
| */ | ||
| def apply(column: Int): Option[Any] = getObject(column - 1) | ||
| def apply(column: Int): Option[Any] = getObject(column) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that previously there was a bug in the codebase, but please document it. On the parameter level ideally, instead of this:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc improved in commit - 1330c03. |
||
| /** | ||
| * Extracts a value from the row by column name. | ||
| * @param columnLabel - the name of the column | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # jdbc settings — test fixture with persist=true | ||
| test.jdbc.url=jdbc:postgresql://localhost:5432/mag_db | ||
|
|
||
| test.jdbc.username=mag_owner | ||
| test.jdbc.password=changeme | ||
|
|
||
| test.persist.db=true | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really persist to true?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is used only in unit test fixture - explicity name is there.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I still don't get why is it needed?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah the only usecase for this setting to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, It is here from the begin to allow to keep state after test for manual review. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Copyright 2023 ABSA Group Limited | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package za.co.absa.db.balta.classes | ||
|
|
||
| import org.scalatest.funsuite.AnyFunSuiteLike | ||
| import za.co.absa.db.balta.classes.DBFunction.{DBFunctionWithNamedParamsToo, DBFunctionWithPositionedParamsOnly} | ||
|
|
||
| class DBFunctionUnitTests extends AnyFunSuiteLike { | ||
|
|
||
| test("DBFunction.apply creates a positioned-params instance with no params") { | ||
| val fn = DBFunction("my_schema.my_function") | ||
| assert(fn.isInstanceOf[DBFunctionWithPositionedParamsOnly]) | ||
| assert(fn.params.isEmpty) | ||
| assert(fn.functionName == "my_schema.my_function") | ||
| } | ||
|
|
||
| test("setParam by position auto-increments the key") { | ||
| val fn = DBFunction("fn") | ||
| .setParam(10) | ||
| .setParam("hello") | ||
| .setParam(true) | ||
| assert(fn.params.size == 3) | ||
| assert(fn.params.keys.toList == List(Left(1), Left(2), Left(3))) | ||
| } | ||
|
|
||
| test("setParam by position returns DBFunctionWithPositionedParamsOnly") { | ||
| val fn = DBFunction("fn").setParam(42) | ||
| assert(fn.isInstanceOf[DBFunctionWithPositionedParamsOnly]) | ||
| } | ||
|
|
||
| test("setParam by name creates a named-params instance") { | ||
| val fn = DBFunction("fn").setParam("p_name", "value") | ||
| assert(fn.isInstanceOf[DBFunctionWithNamedParamsToo]) | ||
| assert(fn.params.size == 1) | ||
| assert(fn.params.keys.head == Right("p_name")) | ||
| } | ||
|
|
||
| test("mixing positioned and named params preserves order") { | ||
| val fn = DBFunction("fn") | ||
| .setParam(1) | ||
| .setParam(2) | ||
| .setParam("named", "val") | ||
| assert(fn.params.size == 3) | ||
| assert(fn.params.keys.toList == List(Left(1), Left(2), Right("named"))) | ||
| } | ||
|
|
||
| test("clear resets params to empty") { | ||
| val fn = DBFunction("fn").setParam(1).setParam(2).clear() | ||
| assert(fn.params.isEmpty) | ||
| assert(fn.functionName == "fn") | ||
| } | ||
|
|
||
| test("clear returns DBFunctionWithPositionedParamsOnly") { | ||
| val fn = DBFunction("fn").setParam("p", "v").clear() | ||
| assert(fn.isInstanceOf[DBFunctionWithPositionedParamsOnly]) | ||
| } | ||
|
|
||
| test("setParamNull by name adds NULL param with named key") { | ||
| val fn = DBFunction("fn").setParamNull("p_null") | ||
| assert(fn.params.size == 1) | ||
| assert(fn.params.keys.head == Right("p_null")) | ||
| assert(fn.params.values.head.sqlEntry == "NULL") | ||
| assert(fn.params.values.head.equalityOperator == "IS") | ||
| } | ||
|
|
||
| test("setParamNull by position appends NULL as next index") { | ||
| val fn = DBFunction("fn").setParam(10).setParamNull() | ||
| assert(fn.params.size == 2) | ||
| assert(fn.params.keys.toList == List(Left(1), Left(2))) | ||
| assert(fn.params.values.toList.last.sqlEntry == "NULL") | ||
| assert(fn.params.values.toList.last.equalityOperator == "IS") | ||
| } | ||
| } |
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.
Why this change?
It might be breaking, AFAIK, JDBC has 0-based indexing of columns, which is counterintuitive.
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.
Pls confirm if it is or is not a bug, I have found it during review using copilot. I have read a lot about it, and the bug looks legit. I am not deep familiar with this.
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.
You are right, it's 1 based. So it's a bug.
Would mention it in the release notes, and mark it as breaking change.
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.
Done.