Skip to content
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

issue 597: Rework unit-test for ExchangeConfigSuite #727

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-3-developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-3-user.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.125.2
2.125.3
25 changes: 0 additions & 25 deletions src/test/scala/org/openhorizon/exchangeapi/ExchConfigSuite.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading