add util function getResourceAsText

merge-requests/1/merge
az 3 years ago
parent 39db40cd5e
commit 3653620369

@ -16,7 +16,7 @@ import java.net.InetAddress
*/
fun getCallingMethodName(): String? {
val offsetVal = 1
val exclude = arrayOf("def", "record", "invoke", "invoke0", "handle", "def\$default", "addResultToEval")
val exclude = arrayOf("def", "record", "invoke", "invoke0", "handle", "def\$default", "addResultToEval", "handle\$default")
// suffixes are also ignored as method names but will be added as suffix in the evaluation results
val suffixes = arrayOf("optional", "requireAll", "requireLast", "inContainer")
@ -57,6 +57,12 @@ fun hostUserHome(): String = System.getProperty("user.home") + fileSeparator()
fun newline(): String = System.getProperty("line.separator")
fun fileSeparator(): String = File.separator
fun getResourceAsText(path: String): String {
val resource = Thread.currentThread().contextClassLoader.getResource(path)
requireNotNull(resource) { "Resource $path not found" }
return resource.readText()
}
/**
* Returns default local Prov instance.

@ -5,6 +5,7 @@ import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.net.UnknownHostException
internal class UtilsKtTest {
@ -41,6 +42,18 @@ internal class UtilsKtTest {
{ remote("invalid_host", "user") })
}
@Test
fun getResourceAsText_successful() {
assertEquals("resource text\n", getResourceAsText("resource-test"))
}
@Test
fun getResourceAsText_throws_exception_for_missing_file() {
assertThrows<IllegalArgumentException> {
getResourceAsText("not existing resource")
}
}
@Test
@Disabled // run manually after having updated user
fun test_remote() {

Loading…
Cancel
Save