[skip ci] cleanup - remove EntryKt & other cleanup

This commit is contained in:
ansgarz 2022-01-22 14:38:48 +01:00
parent 3b29bfd2ce
commit 213541fc3b
4 changed files with 4 additions and 148 deletions

View file

@ -1,38 +0,0 @@
package org.domaindrivenarchitecture.provs.framework.core.entry
/**
* Calls a static method of a class.
* Only methods are supported with either no parameters or with one vararg parameter of type String.
* Methods with a vararg parameter must be called with at least one argument.
*
* @param args specify class and (optionally) method and parameters, in detail:
* @param args[0] fully-qualified class name of the class to be called
* @param args[1] (optional) static method of the class with a vararg parameter of type String; if not specified, the "main" method is used
* @param args[2...] (optional) String parameters that are passed to the method; can be only used if method name (args[1]) is provided
*/
// TODO: jem - 2022.01.21 - do we need this way or can this be removed?
fun main(vararg args: String) {
if (args.isNotEmpty()) {
val className = args[0]
val jClass = Class.forName(className)
val parameterTypeStringArray = arrayOf<Class<*>>(
Array<String>::class.java
)
val method = if (args.size == 1) {
jClass.getMethod("main", *parameterTypeStringArray)
} else {
jClass.getMethod(args[1], *parameterTypeStringArray)
}
if (args.size <= 2) {
method.invoke(null, emptyArray<String>())
} else {
method.invoke(null, args.drop(2).toTypedArray())
}
} else {
println("Usage: <packageName.className> <optional static methodName> <optional parameters ... >")
}
}

View file

@ -1,9 +1,6 @@
package org.domaindrivenarchitecture.provs.server.application
import kotlinx.cli.ArgType
import kotlinx.cli.Subcommand
import kotlinx.cli.default
import org.domaindrivenarchitecture.provs.desktop.application.WorkplaceCliCommand
import org.domaindrivenarchitecture.provs.framework.core.cli.CliTargetParser
import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand
import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
@ -13,7 +10,7 @@ class CliArgumentsParser(
name: String
) : CliTargetParser(name) {
val modules: List<ServerSubcommand> = listOf(K3s(), K3d())
private val modules: List<ServerSubcommand> = listOf(K3s(), K3d())
init {
subcommands(*modules.toTypedArray())
}

View file

@ -1,101 +0,0 @@
package org.domaindrivenarchitecture.provs.framework.core.entry
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@Suppress("unused")
fun testfun(args: Array<String>) {
println("test is fun " + args.joinToString(" "))
}
@Suppress("unused")
fun main(args: Array<String>) {
println("main is fun " + args.joinToString(" "))
}
internal class EntryKtTest {
private var outContent = ByteArrayOutputStream()
private var originalOut = System.out
@BeforeEach
fun redirectSystemOutStream() {
originalOut = System.out
// given
outContent = ByteArrayOutputStream()
System.setOut(PrintStream(outContent))
}
@AfterEach
fun restoreSystemOutStream() {
System.setOut(originalOut)
}
@Test
fun test_without_method_argument() {
// when
org.domaindrivenarchitecture.provs.framework.core.entry.main("org.domaindrivenarchitecture.provs.framework.core.entry.EntryTestKt")
// then
assertEquals("main is fun \n", outContent.toString())
}
@Test
fun test_method_main_without_args() {
// when
org.domaindrivenarchitecture.provs.framework.core.entry.main(
"org.domaindrivenarchitecture.provs.framework.core.entry.EntryTestKt",
"main"
)
// then
assertEquals("main is fun \n", outContent.toString())
}
@Test
fun test_named_method_without_args() {
// when
org.domaindrivenarchitecture.provs.framework.core.entry.main(
"org.domaindrivenarchitecture.provs.framework.core.entry.EntryTestKt",
"testfun"
)
// then
assertEquals("test is fun \n", outContent.toString())
}
@Test
fun test_method_main_with_args() {
// when
org.domaindrivenarchitecture.provs.framework.core.entry.main(
"org.domaindrivenarchitecture.provs.framework.core.entry.EntryTestKt",
"main",
"arg1",
"arg2"
)
// then
assertEquals("main is fun arg1 arg2\n", outContent.toString())
}
@Test
fun test_named_method_with_args() {
// when
org.domaindrivenarchitecture.provs.framework.core.entry.main(
"org.domaindrivenarchitecture.provs.framework.core.entry.EntryTestKt",
"testfun",
"arg1",
"arg2"
)
// then
assertEquals("test is fun arg1 arg2\n", outContent.toString())
}
}

View file

@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test
internal class UbuntuProvTest {
private fun Prov.ping(url: String) = def {
xec("ping", "-c", "4", url)
xec("ping", "-c", "2", url)
}
private fun Prov.outerPing() = def {
@ -87,15 +87,13 @@ internal class UbuntuProvTest {
// when
val res1 = a.xec("/usr/bin/printf", "hi")
val res2 = a.xec("/bin/ping", "-c", "2", "gitlab.com")
val res3 = a.xec("/bin/bash", "-c", "echo echoed")
val res2 = a.xec("/bin/bash", "-c", "echo echoed")
// then
assert(res1.success)
assert(res1.out?.trim() == "hi")
assert(res2.success)
assert(res3.success)
assert(res3.out?.trim() == "echoed")
assert(res2.out?.trim() == "echoed")
}
@Test