Skip to content

Commit de0b421

Browse files
authored
Use the same configuration library for tests as Java SDK (#14)
1 parent e359340 commit de0b421

File tree

7 files changed

+67
-74
lines changed

7 files changed

+67
-74
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build/
88
bin/
99
gen/
1010
out/
11-
/src/test/resources/config.properties
11+
test.properties
1212
*.DS_STORE
1313

1414
# GitHub Actions #

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ dependencies {
6767
allTest "ch.qos.logback:logback-classic:1.2.3"
6868
allTest "ch.qos.logback:logback-core:1.2.3"
6969
allTest "org.json:json:20210307"
70-
allTest "dev.nohus:AutoKonfig:1.0.0"
70+
allTest 'org.aeonbits.owner:owner:1.0.12'
7171

7272
testImplementation "io.mockk:mockk:1.11.0"
7373
testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '6.10.4'
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package com.pubnub.api
22

3-
import dev.nohus.autokonfig.AutoKonfig
4-
import dev.nohus.autokonfig.types.StringSetting
5-
import dev.nohus.autokonfig.withEnvironmentVariables
6-
import dev.nohus.autokonfig.withResourceConfig
3+
import org.aeonbits.owner.Config
4+
import org.aeonbits.owner.ConfigFactory
75

8-
object Keys {
9-
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
10-
try {
11-
withResourceConfig(resource)
12-
} catch (e: Exception) {
13-
}
14-
}
6+
@Config.Sources("file:test.properties")
7+
interface KeysConfig : Config {
8+
@get:Config.Key("subKey")
9+
val subscribeKey: String
1510

16-
private val config = AutoKonfig()
17-
.withSafeResourceConfig("config.properties")
18-
.withEnvironmentVariables()
11+
@get:Config.Key("pubKey")
12+
val publishKey: String
1913

20-
val pubKey by config.StringSetting()
21-
val subKey by config.StringSetting()
22-
val pamPubKey by config.StringSetting()
23-
val pamSubKey by config.StringSetting()
24-
val pamSecKey by config.StringSetting()
14+
@get:Config.Key("pamSubKey")
15+
val pamSubKey: String
16+
17+
@get:Config.Key("pamPubKey")
18+
val pamPubKey: String
19+
20+
@get:Config.Key("pamSecKey")
21+
val pamSecKey: String
2522
}
23+
24+
val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv())
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
package com.pubnub.contract
22

3-
import dev.nohus.autokonfig.AutoKonfig
4-
import dev.nohus.autokonfig.types.BooleanSetting
5-
import dev.nohus.autokonfig.types.StringSetting
6-
import dev.nohus.autokonfig.withEnvironmentVariables
7-
import dev.nohus.autokonfig.withResourceConfig
8-
9-
object ContractTestConfig {
10-
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
11-
try {
12-
withResourceConfig(resource)
13-
} catch (e: Exception) {
14-
}
15-
}
16-
17-
private val config = AutoKonfig()
18-
.withSafeResourceConfig("config.properties")
19-
.withEnvironmentVariables()
20-
21-
val pamSubKey by config.StringSetting()
22-
val pamPubKey by config.StringSetting()
23-
val pamSecKey by config.StringSetting()
24-
val pubKey by config.StringSetting()
25-
val subKey by config.StringSetting()
26-
val serverHostPort by config.StringSetting()
27-
val serverMock by config.BooleanSetting(true)
3+
import org.aeonbits.owner.Config
4+
import org.aeonbits.owner.ConfigFactory
5+
6+
@Config.Sources("file:test.properties")
7+
interface ContractTestKeysConfig : Config {
8+
@get:Config.Key("subKey")
9+
val subKey: String
10+
11+
@get:Config.Key("pubKey")
12+
val pubKey: String
13+
14+
@get:Config.Key("pamSubKey")
15+
val pamSubKey: String
16+
17+
@get:Config.Key("pamPubKey")
18+
val pamPubKey: String
19+
20+
@get:Config.Key("pamSecKey")
21+
val pamSecKey: String
22+
23+
@get:Config.Key("serverHostPort")
24+
val serverHostPort: String
25+
26+
@get:Config.Key("serverMock")
27+
@get:Config.DefaultValue("true")
28+
val serverMock: Boolean
2829
}
30+
31+
val ContractTestConfig: ContractTestKeysConfig = ConfigFactory.create(ContractTestKeysConfig::class.java, System.getenv())
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package com.pubnub.api
22

3-
import dev.nohus.autokonfig.AutoKonfig
4-
import dev.nohus.autokonfig.types.StringSetting
5-
import dev.nohus.autokonfig.withEnvironmentVariables
6-
import dev.nohus.autokonfig.withResourceConfig
3+
import org.aeonbits.owner.Config
4+
import org.aeonbits.owner.ConfigFactory
75

8-
object Keys {
9-
private fun AutoKonfig.withSafeResourceConfig(resource: String) = apply {
10-
try {
11-
withResourceConfig(resource)
12-
} catch (e: Exception) {
13-
}
14-
}
6+
@Config.Sources("file:test.properties")
7+
interface KeysConfig : Config {
8+
@get:Config.Key("subKey")
9+
val subKey: String
1510

16-
private val config = AutoKonfig()
17-
.withSafeResourceConfig("config.properties")
18-
.withEnvironmentVariables()
11+
@get:Config.Key("pubKey")
12+
val pubKey: String
1913

20-
val pubKey by config.StringSetting()
21-
val subKey by config.StringSetting()
22-
val pamPubKey by config.StringSetting()
23-
val pamSubKey by config.StringSetting()
24-
val pamSecKey by config.StringSetting()
14+
@get:Config.Key("pamSubKey")
15+
val pamSubKey: String
16+
17+
@get:Config.Key("pamPubKey")
18+
val pamPubKey: String
19+
20+
@get:Config.Key("pamSecKey")
21+
val pamSecKey: String
2522
}
23+
24+
val Keys: KeysConfig = ConfigFactory.create(KeysConfig::class.java, System.getenv())

src/testFixtures/resources/config-example.properties

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/resources/config-example.properties renamed to test-example.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#copy this file to `config.properties` and put real pubnub keys to run integration tests.
1+
#copy this file to `test.properties` and put real pubnub keys to run integration tests.
22
#other way is to provide an environmental variables: PUB_KEY, SUB_KEY, etc.
33

44
pubKey=somePubKey

0 commit comments

Comments
 (0)