-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use interface for interactive parsers + implement in ValidatorTool (#…
…2822) * chore: fix editorconfig for gradle files * refactor: use interface for interactive parsers this allows us to automatically detect them from the subcommands, and makes a separate map unnecessary * feat: implement InteractiveParser in ValidationTool * fix: use same testing framework (Spek) as in the rest of the app * fix: switch back to JUnit * fix: interactive dialog inserted unwanted space char at beginning of output file name * refactor: clean up ParserServiceTest * fix: use this for CommandLine * rename callInteractive to executeWithInteractive #2341 * refactor: move executeWithInteractive into ParserService * add changelog entry #2341 * add parametrized tests #2341 Co-authored-by: Mira Weller <mira.weller@maibornwolff.de> Co-authored-by: IhsenBouallegue <bouallegueihsen@gmail.com>
- Loading branch information
1 parent
a6a46b3
commit 5acb19e
Showing
16 changed files
with
205 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ quote_type = unset | |
|
||
[*.md] | ||
indent_size = 4 | ||
|
||
[*.gradle] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...r/src/main/kotlin/de/maibornwolff/codecharta/tools/interactiveparser/InteractiveParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.maibornwolff.codecharta.tools.interactiveparser | ||
|
||
interface InteractiveParser { | ||
fun getDialog(): ParserDialogInterface | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...alidationTool/src/main/kotlin/de/maibornwolff/codecharta/tools/validation/ParserDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.maibornwolff.codecharta.tools.validation | ||
|
||
import com.github.kinquirer.KInquirer | ||
import com.github.kinquirer.components.promptInput | ||
import de.maibornwolff.codecharta.tools.interactiveparser.ParserDialogInterface | ||
import mu.KotlinLogging | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
class ParserDialog { | ||
companion object : ParserDialogInterface { | ||
private const val EXTENSION = "cc.json" | ||
|
||
override fun collectParserArgs(): List<String> { | ||
val inputFileName = KInquirer.promptInput(message = "Which $EXTENSION file do you want to validate?") | ||
logger.info { "File path: $inputFileName" } | ||
|
||
return listOf(inputFileName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 23 additions & 22 deletions
45
...onTool/src/test/kotlin/de/maibornwolff/codecharta/tools/validation/EveritValidatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
package de.maibornwolff.codecharta.tools.validation | ||
|
||
import de.maibornwolff.codecharta.tools.validation.ValidationTool.Companion.SCHEMA_PATH | ||
import org.everit.json.schema.ValidationException | ||
import org.json.JSONException | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class EveritValidatorTest : Spek({ | ||
describe("a validator") { | ||
val validator = EveritValidator(SCHEMA_PATH) | ||
class EveritValidatorTest { | ||
|
||
it("should validate valid File") { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("validFile.json")) | ||
} | ||
private val validator = EveritValidator(ValidationTool.SCHEMA_PATH) | ||
|
||
@Test | ||
fun `should validate valid File`() { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("validFile.json")) | ||
} | ||
|
||
it("should throw exception on missing node name") { | ||
assertFailsWith(ValidationException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("missingNodeNameFile.json")) | ||
} | ||
@Test | ||
fun `should throw exception on missing node name`() { | ||
assertFailsWith(ValidationException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("missingNodeNameFile.json")) | ||
} | ||
} | ||
|
||
it("should throw exception on missing project") { | ||
assertFailsWith(ValidationException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("invalidFile.json")) | ||
} | ||
@Test | ||
fun `should throw exception on missing project`() { | ||
assertFailsWith(ValidationException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("invalidFile.json")) | ||
} | ||
} | ||
|
||
it("should throw exception if no json file") { | ||
assertFailsWith(JSONException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("invalidJson.json")) | ||
} | ||
@Test | ||
fun `should throw exception if no json file`() { | ||
assertFailsWith(JSONException::class) { | ||
validator.validate(this.javaClass.classLoader.getResourceAsStream("invalidJson.json")) | ||
} | ||
} | ||
}) | ||
} |
32 changes: 32 additions & 0 deletions
32
...ationTool/src/test/kotlin/de/maibornwolff/codecharta/tools/validation/ParserDialogTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.maibornwolff.codecharta.tools.validation | ||
|
||
import com.github.kinquirer.KInquirer | ||
import com.github.kinquirer.components.promptInput | ||
import io.mockk.every | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.AfterAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class ParserDialogTest { | ||
|
||
@AfterAll | ||
fun afterTest() { | ||
unmockkAll() | ||
} | ||
|
||
@Test | ||
fun `should output correct arguments`() { | ||
mockkStatic("com.github.kinquirer.components.InputKt") | ||
every { | ||
KInquirer.promptInput(any(), any(), any()) | ||
} returns "sampleFile.cc.json" | ||
|
||
val parserArguments = ParserDialog.collectParserArgs() | ||
|
||
Assertions.assertThat(parserArguments).isEqualTo(listOf("sampleFile.cc.json")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.