From 55ec68fca71b9a3754eaef807eeef6415ec83a49 Mon Sep 17 00:00:00 2001 From: David Benedeki Date: Wed, 16 Oct 2024 14:04:59 +0200 Subject: [PATCH 1/2] #43: DBTestSuite: parametrize persist_data into constructor * make it easy to override data persitence in the `DBTestSuite` class, without the need to override functions. --- .../main/scala/za/co/absa/db/balta/DBTestSuite.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala index ba310ed..d28334c 100644 --- a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala +++ b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala @@ -35,7 +35,11 @@ import java.util.Properties * * easy access to DB tables and functions * * the now() function that returns the current transaction time in the DB */ -abstract class DBTestSuite extends AnyFunSuite { +abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) extends AnyFunSuite { + + def this(persistDataOverride: Boolean) { + this(Some(persistDataOverride)); + } /* the DB connection is ``lazy`, so it actually can be created only when needed and therefore the credentials overridden in the successor */ @@ -44,7 +48,9 @@ abstract class DBTestSuite extends AnyFunSuite { /** * This is the connection info for the DB. It can be overridden in the derived classes to provide specific credentials */ - protected lazy val connectionInfo: ConnectionInfo = readConnectionInfoFromConfig + protected lazy val connectionInfo: ConnectionInfo = { + persistDataOverride.map(overrideValue => connectionInfo.copy(persistData = overrideValue)).getOrElse(connectionInfo) + } /** * This is an enhanced test function that automatically rolls back the transaction after the test is finished From 8e2fb9b2f2e387684143ed4ab1582843b115331a Mon Sep 17 00:00:00 2001 From: David Benedeki Date: Fri, 18 Oct 2024 08:22:30 +0200 Subject: [PATCH 2/2] * fix --- balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala index d28334c..1731135 100644 --- a/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala +++ b/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala @@ -49,7 +49,9 @@ abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) exte * This is the connection info for the DB. It can be overridden in the derived classes to provide specific credentials */ protected lazy val connectionInfo: ConnectionInfo = { - persistDataOverride.map(overrideValue => connectionInfo.copy(persistData = overrideValue)).getOrElse(connectionInfo) + val connectionInfoFromConfig = readConnectionInfoFromConfig + persistDataOverride.map(overrideValue => connectionInfoFromConfig.copy(persistData = overrideValue)) + .getOrElse(connectionInfoFromConfig) } /** @@ -152,7 +154,7 @@ abstract class DBTestSuite(val persistDataOverride: Option[Boolean] = None) exte } // private functions - private def readConnectionInfoFromConfig: ConnectionInfo = { + protected def readConnectionInfoFromConfig: ConnectionInfo = { val properties = new Properties() properties.load(getClass.getResourceAsStream("/database.properties"))