diff --git a/.gitignore b/.gitignore index 2376c4e7e..b618c21e6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ build/ bin/ gen/ out/ -/src/test/resources/config.properties +test.properties *.DS_STORE # GitHub Actions # diff --git a/build.gradle b/build.gradle index 17c98ae8c..9f6b0732a 100644 --- a/build.gradle +++ b/build.gradle @@ -67,7 +67,7 @@ dependencies { allTest "ch.qos.logback:logback-classic:1.2.3" allTest "ch.qos.logback:logback-core:1.2.3" allTest "org.json:json:20210307" - allTest "dev.nohus:AutoKonfig:1.0.0" + allTest 'org.aeonbits.owner:owner:1.0.12' testImplementation "io.mockk:mockk:1.11.0" testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '6.10.4' diff --git a/src/test/kotlin/com/pubnub/api/Keys.kt b/src/test/kotlin/com/pubnub/api/Keys.kt index c225c9bd5..ed0a6e30b 100644 --- a/src/test/kotlin/com/pubnub/api/Keys.kt +++ b/src/test/kotlin/com/pubnub/api/Keys.kt @@ -1,25 +1,24 @@ package com.pubnub.api -import dev.nohus.autokonfig.AutoKonfig -import dev.nohus.autokonfig.types.StringSetting -import dev.nohus.autokonfig.withEnvironmentVariables -import dev.nohus.autokonfig.withResourceConfig +import org.aeonbits.owner.Config +import org.aeonbits.owner.ConfigFactory -object Keys { - private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply { - try { - withResourceConfig(resource) - } catch (e: Exception) { - } - } +@Config.Sources("file:test.properties") +interface KeysConfig : Config { + @get:Config.Key("subKey") + val subscribeKey: String - private val config = AutoKonfig() - .withSafeResourceConfig("config.properties") - .withEnvironmentVariables() + @get:Config.Key("pubKey") + val publishKey: String - val pubKey by config.StringSetting() - val subKey by config.StringSetting() - val pamPubKey by config.StringSetting() - val pamSubKey by config.StringSetting() - val pamSecKey by config.StringSetting() + @get:Config.Key("pamSubKey") + val pamSubKey: String + + @get:Config.Key("pamPubKey") + val pamPubKey: String + + @get:Config.Key("pamSecKey") + val pamSecKey: String } + +val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv()) diff --git a/src/test/kotlin/com/pubnub/contract/ContractTestConfig.kt b/src/test/kotlin/com/pubnub/contract/ContractTestConfig.kt index 769063647..7c6f5b80c 100644 --- a/src/test/kotlin/com/pubnub/contract/ContractTestConfig.kt +++ b/src/test/kotlin/com/pubnub/contract/ContractTestConfig.kt @@ -1,28 +1,31 @@ package com.pubnub.contract -import dev.nohus.autokonfig.AutoKonfig -import dev.nohus.autokonfig.types.BooleanSetting -import dev.nohus.autokonfig.types.StringSetting -import dev.nohus.autokonfig.withEnvironmentVariables -import dev.nohus.autokonfig.withResourceConfig - -object ContractTestConfig { - private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply { - try { - withResourceConfig(resource) - } catch (e: Exception) { - } - } - - private val config = AutoKonfig() - .withSafeResourceConfig("config.properties") - .withEnvironmentVariables() - - val pamSubKey by config.StringSetting() - val pamPubKey by config.StringSetting() - val pamSecKey by config.StringSetting() - val pubKey by config.StringSetting() - val subKey by config.StringSetting() - val serverHostPort by config.StringSetting() - val serverMock by config.BooleanSetting(true) +import org.aeonbits.owner.Config +import org.aeonbits.owner.ConfigFactory + +@Config.Sources("file:test.properties") +interface ContractTestKeysConfig : Config { + @get:Config.Key("subKey") + val subKey: String + + @get:Config.Key("pubKey") + val pubKey: String + + @get:Config.Key("pamSubKey") + val pamSubKey: String + + @get:Config.Key("pamPubKey") + val pamPubKey: String + + @get:Config.Key("pamSecKey") + val pamSecKey: String + + @get:Config.Key("serverHostPort") + val serverHostPort: String + + @get:Config.Key("serverMock") + @get:Config.DefaultValue("true") + val serverMock: Boolean } + +val ContractTestConfig: ContractTestKeysConfig = ConfigFactory.create(ContractTestKeysConfig::class.java, System.getenv()) diff --git a/src/testFixtures/kotlin/com/pubnub/api/Keys.kt b/src/testFixtures/kotlin/com/pubnub/api/Keys.kt index c225c9bd5..7f0e8bfde 100644 --- a/src/testFixtures/kotlin/com/pubnub/api/Keys.kt +++ b/src/testFixtures/kotlin/com/pubnub/api/Keys.kt @@ -1,25 +1,24 @@ package com.pubnub.api -import dev.nohus.autokonfig.AutoKonfig -import dev.nohus.autokonfig.types.StringSetting -import dev.nohus.autokonfig.withEnvironmentVariables -import dev.nohus.autokonfig.withResourceConfig +import org.aeonbits.owner.Config +import org.aeonbits.owner.ConfigFactory -object Keys { - private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply { - try { - withResourceConfig(resource) - } catch (e: Exception) { - } - } +@Config.Sources("file:test.properties") +interface KeysConfig : Config { + @get:Config.Key("subKey") + val subKey: String - private val config = AutoKonfig() - .withSafeResourceConfig("config.properties") - .withEnvironmentVariables() + @get:Config.Key("pubKey") + val pubKey: String - val pubKey by config.StringSetting() - val subKey by config.StringSetting() - val pamPubKey by config.StringSetting() - val pamSubKey by config.StringSetting() - val pamSecKey by config.StringSetting() + @get:Config.Key("pamSubKey") + val pamSubKey: String + + @get:Config.Key("pamPubKey") + val pamPubKey: String + + @get:Config.Key("pamSecKey") + val pamSecKey: String } + +val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv()) diff --git a/src/testFixtures/resources/config-example.properties b/src/testFixtures/resources/config-example.properties deleted file mode 100644 index 1b919b500..000000000 --- a/src/testFixtures/resources/config-example.properties +++ /dev/null @@ -1,8 +0,0 @@ -#copy this file to `config.properties` and put real pubnub keys to run integration tests. -#other way is to provide an environmental variables: PUB_KEY, SUB_KEY, etc. - -pubKey=somePubKey -subKey=someSubKey -pamPubKey=somePamPubKey -pamSubKey=somePamSubKey -pamSecKey=somePamSecKey diff --git a/src/test/resources/config-example.properties b/test-example.properties similarity index 78% rename from src/test/resources/config-example.properties rename to test-example.properties index c44147f9c..091b14e36 100644 --- a/src/test/resources/config-example.properties +++ b/test-example.properties @@ -1,4 +1,4 @@ -#copy this file to `config.properties` and put real pubnub keys to run integration tests. +#copy this file to `test.properties` and put real pubnub keys to run integration tests. #other way is to provide an environmental variables: PUB_KEY, SUB_KEY, etc. pubKey=somePubKey