Skip to content

Commit

Permalink
* better reading of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
benedeki committed Oct 22, 2024
1 parent 6738827 commit e492ac6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
10 changes: 8 additions & 2 deletions balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,15 @@ abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) exte
}

// private functions
protected def readConnectionInfoFromConfig: ConnectionInfo = {
private def readConnectionInfoFromConfig: ConnectionInfo = {
DBTestSuite.connectionInfoFromResourceConfig("/database.properties")
}
}

object DBTestSuite {
def connectionInfoFromResourceConfig(resourceName: String): ConnectionInfo = {
val properties = new Properties()
properties.load(getClass.getResourceAsStream("/database.properties"))
properties.load(getClass.getResourceAsStream(resourceName))

ConnectionInfo(
dbUrl = properties.getProperty("test.jdbc.url"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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

import org.scalatest.funsuite.AnyFunSuiteLike

class DBTestSuiteUnitTests extends AnyFunSuiteLike {
test("connectionInfoFromResourceConfig reads local resource file correctly") {
val connectionInfo = DBTestSuite.connectionInfoFromResourceConfig("/database.properties")
assert(connectionInfo.dbUrl == "jdbc:postgresql://localhost:5432/mag_db")
assert(connectionInfo.username == "mag_owner")
assert(connectionInfo.password == "changeme")
assert(!connectionInfo.persistData)
}
}

0 comments on commit e492ac6

Please sign in to comment.