From 0a1cb6c99438a8c265c9caebd1f150b84b9ac07a Mon Sep 17 00:00:00 2001 From: Oleksandr Mordyk Date: Thu, 31 Oct 2024 04:49:04 -0700 Subject: [PATCH 1/3] issue 597: Rework unit-test for ExchangeConfig - Increased the number of test cases to cover corner cases. Signed-off-by: Oleksandr Mordyk --- .../exchangeapi/ExchConfigSuite.scala | 25 ------- .../TestExchConfiguration.scala | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 25 deletions(-) delete mode 100644 src/test/scala/org/openhorizon/exchangeapi/ExchConfigSuite.scala create mode 100644 src/test/scala/org/openhorizon/exchangeapi/utility/exchconfiguration/TestExchConfiguration.scala diff --git a/src/test/scala/org/openhorizon/exchangeapi/ExchConfigSuite.scala b/src/test/scala/org/openhorizon/exchangeapi/ExchConfigSuite.scala deleted file mode 100644 index cdc7da1f..00000000 --- a/src/test/scala/org/openhorizon/exchangeapi/ExchConfigSuite.scala +++ /dev/null @@ -1,25 +0,0 @@ -package org.openhorizon.exchangeapi - -import org.scalatest.funsuite.AnyFunSuite -import org.junit.runner.RunWith -import org.scalatestplus.junit.JUnitRunner -import org.openhorizon.exchangeapi._ -import org.openhorizon.exchangeapi.utility.Configuration - -/** - * Tests for the Version and VersionRange case classes - */ -@RunWith(classOf[JUnitRunner]) -class ExchConfigSuite extends AnyFunSuite { - test("ExchConfig tests") { - Configuration.reload() - // Note: this test needs to work with the default version of config.json that is in src/main/resources (so that 'make test' in travis works) - assert(Configuration.getConfig.getInt("api.limits.maxNodes") === 45000) - assert(Configuration.getConfig.getInt("api.limits.maxAgreements") === 0) - assert(Configuration.getConfig.getInt("api.limits.maxMessagesInMailbox") === 0) - assert(Configuration.getConfig.getString("exchange-db-connection.dataSourceClass") === "org.postgresql.ds.PGSimpleDataSource") - // assert(Configuration.getConfig.getInt("api.db.minPoolSize") === 1) - // assert(Configuration.getConfig.getInt("api.db.acquireIncrement") === 1) - // assert(Configuration.getConfig.getInt("api.db.maxPoolSize") === 50) - } -} \ No newline at end of file diff --git a/src/test/scala/org/openhorizon/exchangeapi/utility/exchconfiguration/TestExchConfiguration.scala b/src/test/scala/org/openhorizon/exchangeapi/utility/exchconfiguration/TestExchConfiguration.scala new file mode 100644 index 00000000..ac85131c --- /dev/null +++ b/src/test/scala/org/openhorizon/exchangeapi/utility/exchconfiguration/TestExchConfiguration.scala @@ -0,0 +1,73 @@ +package org.openhorizon.exchangeapi + +import org.scalatest.funsuite.AnyFunSuite +import org.openhorizon.exchangeapi._ +import org.openhorizon.exchangeapi.utility.Configuration + +import com.typesafe.config.{Config, ConfigFactory} +import org.scalatest.BeforeAndAfterEach + +class TestConfiguration extends AnyFunSuite with BeforeAndAfterEach { + + override def beforeEach(): Unit = { + Configuration.reload() + } + + test("Should load the configuration successfully") { + val config: Config = Configuration.getConfig + assert(config != null) + } + + test("Should validate necessary configuration keys") { + val config: Config = Configuration.getConfig + assert(config.hasPath("api")) + assert(config.hasPath("exchange-db-connection")) + } + + test ("Should set logback properties correctly") { + val config: Config = Configuration.getConfig + // Extract expected values from the config + val logbackConfigValues = Map( + "log.logback.appenderrefmodelhandler" -> config.getString("logback.core.model.processor.AppenderRefModelHandler"), + "log.logback.loggermodelhandler" -> config.getString("logback.classic.model.processor.LoggerModelHandler"), + "log.hikari.config" -> config.getString("logback.hikari.HikariConfig"), + "log.hikari.datasource" -> config.getString("logback.hikari.HikariDataSource"), + "log.hikari.pool" -> config.getString("logback.hikari.pool.HikariPool"), + "log.hikari.pool.base" -> config.getString("logback.hikari.pool.PoolBase"), + "log.guavacache" -> config.getString("logback.scalacache.guava.GuavaCache"), + "log.action" -> config.getString("logback.slick.basic.BasicBackend.action"), + "log.stream" -> config.getString("logback.slick.basic.BasicBackend.stream"), + "log.qcomp" -> config.getString("logback.slick.compiler-log"), + "log.jdbc.driver" -> config.getString("logback.slick.jdbc.DriverDataSource"), + "log.jdbc.bench" -> config.getString("logback.slick.jdbc.JdbcBackend.benchmark"), + ) + + logbackConfigValues.foreach { case (key, expectedValue) => + assert(System.getProperty(key) == expectedValue, "Expected $key to be $expectedValue, but was ${System.getProperty(key)}") + } + } + + test ("Allow reloading of configuration") { + val initialConfig: Config = Configuration.getConfig + + // Simulate a reload + Configuration.reload() + val reloadedConfig: Config = Configuration.getConfig + + // Verify that the config remains the same (or check for specific changes) + assert(initialConfig == reloadedConfig, "Reloaded config should be the same as initial") + } + + test ("Should have correct ExchConfig values") { + // Assertions based on the expected values in your config.json + assert(Configuration.getConfig.getInt("api.limits.maxNodes") === 45000) + assert(Configuration.getConfig.getInt("api.limits.maxAgreements") === 0) + assert(Configuration.getConfig.getInt("api.limits.maxMessagesInMailbox") === 0) + assert(Configuration.getConfig.getString("exchange-db-connection.dataSourceClass") === "org.postgresql.ds.PGSimpleDataSource") + + // Uncomment if you want to test these as well + // assert(Configuration.getConfig.getInt("api.db.minPoolSize") === 1) + // assert(Configuration.getConfig.getInt("api.db.acquireIncrement") === 1) + // assert(Configuration.getConfig.getInt("api.db.maxPoolSize") === 50) + } +} From aa769f6008e003048a669df2ac8d8baae16d07e6 Mon Sep 17 00:00:00 2001 From: Oleksandr Mordyk Date: Thu, 31 Oct 2024 06:16:19 -0700 Subject: [PATCH 2/3] issue 597: Update exchange-api version Signed-off-by: Oleksandr Mordyk --- CHANGELOG.md | 4 ++++ docs/openapi-3-developer.json | 2 +- docs/openapi-3-user.json | 2 +- src/main/resources/version.txt | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c2916b8..5b5dd416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [2.125.3](https://github.com/open-horizon/exchange-api/pull/727) - 2024-10-31 +- issue 597: Rework unit-test for ExchangeConfigSuite. +- Increased the number of test cases to cover corner cases for ExchangeConfig. + ## [2.125.2](https://github.com/open-horizon/exchange-api/pull/726) - 2024-10-31 - issue 607: Rework unit-test for version. - Increased the number of test cases to cover corner cases for Version. diff --git a/docs/openapi-3-developer.json b/docs/openapi-3-developer.json index 0b97b0dc..0a4fd53d 100644 --- a/docs/openapi-3-developer.json +++ b/docs/openapi-3-developer.json @@ -8,7 +8,7 @@ "name" : "Apache License Version 2.0", "url" : "https://www.apache.org/licenses/LICENSE-2.0" }, - "version" : "2.125.2" + "version" : "2.125.3" }, "externalDocs" : { "description" : "Open-horizon ExchangeAPI", diff --git a/docs/openapi-3-user.json b/docs/openapi-3-user.json index 01b27f4c..ca8e4082 100644 --- a/docs/openapi-3-user.json +++ b/docs/openapi-3-user.json @@ -8,7 +8,7 @@ "name" : "Apache License Version 2.0", "url" : "https://www.apache.org/licenses/LICENSE-2.0" }, - "version" : "2.125.2" + "version" : "2.125.3" }, "externalDocs" : { "description" : "Open-horizon ExchangeAPI", diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 394b36fa..01a32c8b 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -2.125.2 +2.125.3 From e701bb18c729a625914d2b0724c40eaaec424ee3 Mon Sep 17 00:00:00 2001 From: Oleksandr Mordyk Date: Mon, 4 Nov 2024 00:25:36 -0800 Subject: [PATCH 3/3] Revert "issue 597: Update exchange-api version" This reverts commit aa769f6008e003048a669df2ac8d8baae16d07e6. Signed-off-by: Oleksandr Mordyk --- CHANGELOG.md | 4 ---- docs/openapi-3-developer.json | 2 +- docs/openapi-3-user.json | 2 +- src/main/resources/version.txt | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5dd416..8c2916b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). -## [2.125.3](https://github.com/open-horizon/exchange-api/pull/727) - 2024-10-31 -- issue 597: Rework unit-test for ExchangeConfigSuite. -- Increased the number of test cases to cover corner cases for ExchangeConfig. - ## [2.125.2](https://github.com/open-horizon/exchange-api/pull/726) - 2024-10-31 - issue 607: Rework unit-test for version. - Increased the number of test cases to cover corner cases for Version. diff --git a/docs/openapi-3-developer.json b/docs/openapi-3-developer.json index 0a4fd53d..0b97b0dc 100644 --- a/docs/openapi-3-developer.json +++ b/docs/openapi-3-developer.json @@ -8,7 +8,7 @@ "name" : "Apache License Version 2.0", "url" : "https://www.apache.org/licenses/LICENSE-2.0" }, - "version" : "2.125.3" + "version" : "2.125.2" }, "externalDocs" : { "description" : "Open-horizon ExchangeAPI", diff --git a/docs/openapi-3-user.json b/docs/openapi-3-user.json index ca8e4082..01b27f4c 100644 --- a/docs/openapi-3-user.json +++ b/docs/openapi-3-user.json @@ -8,7 +8,7 @@ "name" : "Apache License Version 2.0", "url" : "https://www.apache.org/licenses/LICENSE-2.0" }, - "version" : "2.125.3" + "version" : "2.125.2" }, "externalDocs" : { "description" : "Open-horizon ExchangeAPI", diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 01a32c8b..394b36fa 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -2.125.3 +2.125.2