can load accounts
parent
3dd6faea6c
commit
095acd24e4
|
|
@ -24,3 +24,11 @@ testing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
|
||||||
|
testImplementation("com.willowtreeapps.assertk:assertk:0.28.1")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,4 @@ dependencies {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.bundles.hoplite)
|
implementation(libs.bundles.hoplite)
|
||||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package de.itkl.modConfiguration.loaders
|
package de.itkl.modConfiguration.loaders
|
||||||
|
|
||||||
import com.sksamuel.hoplite.ConfigLoaderBuilder
|
import com.sksamuel.hoplite.ConfigLoaderBuilder
|
||||||
import de.itkl.modConfiguration.types.Account
|
import com.sksamuel.hoplite.addPathSource
|
||||||
|
import de.itkl.modConfiguration.types.Accounts
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
fun loadAccounts(path: Path): Map<String, Account> {
|
fun loadAccounts(path: Path): Accounts {
|
||||||
return ConfigLoaderBuilder.default()
|
return ConfigLoaderBuilder.default()
|
||||||
|
.addPathSource(path)
|
||||||
.build()
|
.build()
|
||||||
.loadConfigOrThrow()
|
.loadConfigOrThrow()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
package de.itkl.modConfiguration.types
|
package de.itkl.modConfiguration.types
|
||||||
|
|
||||||
|
data class Accounts(
|
||||||
|
val account: Map<String, AccountDef>,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
package de.itkl.modConfiguration.loaders
|
package de.itkl.modConfiguration.loaders
|
||||||
|
|
||||||
|
import de.itkl.moduleCore.support.requiredResourcePath
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class AccountLoaderTests {
|
class AccountLoaderTests {
|
||||||
@Test
|
@Test
|
||||||
fun testAccountLoad() {}
|
fun testAccountLoad() {
|
||||||
|
val accountsToml = requiredResourcePath("testAccounts.toml")
|
||||||
|
val accounts = loadAccounts(accountsToml)
|
||||||
|
println(accounts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
[account."test user"]
|
||||||
|
name = "Sir Test"
|
||||||
|
password = "testitest"
|
||||||
|
|
||||||
|
[account."test users wife"]
|
||||||
|
name = "Madam Test"
|
||||||
|
password = "testitest"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package de.itkl.moduleCore.support
|
||||||
|
|
||||||
|
fun <T : Any> T?.expect(message: () -> String): T {
|
||||||
|
return checkNotNull(this, message)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package de.itkl.moduleCore.support
|
||||||
|
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
fun requiredResourcePath(resourceName: String): Path {
|
||||||
|
return ClassLoader.getSystemResource(resourceName)
|
||||||
|
?.toURI()
|
||||||
|
?.let { Paths.get(it) }
|
||||||
|
.expect { "Resource not found $resourceName" }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue