From 213541fc3bc30c85cfed955147e0154150524306 Mon Sep 17 00:00:00 2001 From: ansgarz Date: Sat, 22 Jan 2022 14:38:48 +0100 Subject: [PATCH] [skip ci] cleanup - remove EntryKt & other cleanup --- .../provs/framework/core/entry/Entry.kt | 38 ------- .../server/application/CliArgumentsParser.kt | 5 +- .../provs/framework/core/entry/EntryTest.kt | 101 ------------------ .../core/platformTest/UbuntuProvTest.kt | 8 +- 4 files changed, 4 insertions(+), 148 deletions(-) delete mode 100644 src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/Entry.kt delete mode 100644 src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/EntryTest.kt diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/Entry.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/Entry.kt deleted file mode 100644 index 3c44450..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/Entry.kt +++ /dev/null @@ -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>( - Array::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()) - } else { - method.invoke(null, args.drop(2).toTypedArray()) - } - } else { - println("Usage: ") - } -} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt index 3d743be..f8a0917 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt @@ -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 = listOf(K3s(), K3d()) + private val modules: List = listOf(K3s(), K3d()) init { subcommands(*modules.toTypedArray()) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/EntryTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/EntryTest.kt deleted file mode 100644 index 387a4ec..0000000 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/entry/EntryTest.kt +++ /dev/null @@ -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) { - println("test is fun " + args.joinToString(" ")) -} - -@Suppress("unused") -fun main(args: Array) { - 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()) - } -} diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/platformTest/UbuntuProvTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/platformTest/UbuntuProvTest.kt index 5272d14..8020adc 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/platformTest/UbuntuProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/platformTest/UbuntuProvTest.kt @@ -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