From 168cea95a66ba05efcb08185e1d34088a60c3321 Mon Sep 17 00:00:00 2001 From: Alexey Zverev Date: Mon, 27 May 2024 09:45:57 +0300 Subject: [PATCH] Add model and property file for parameters --- .../octopus/vcsfacade/Configuration.kt | 62 +++++++++++++++++++ .../src/main/resources/test-properties.yaml | 18 ++++++ 2 files changed, 80 insertions(+) create mode 100644 test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/Configuration.kt create mode 100644 test-common/src/main/resources/test-properties.yaml diff --git a/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/Configuration.kt b/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/Configuration.kt new file mode 100644 index 0000000..666b544 --- /dev/null +++ b/test-common/src/main/kotlin/org/octopusden/octopus/vcsfacade/Configuration.kt @@ -0,0 +1,62 @@ +package org.octopusden.octopus.vcsfacade + +import org.yaml.snakeyaml.Yaml + +private const val PROPERTY_FILE = "test-properties.yaml" +const val TEST_PROFILE = "test.profile" +const val GITLAB = "gitlab" +const val GITEA = "gitea" +const val BITBUCKET = "bitbucket" + +object Configuration { + val model: ConfigModel by lazy { + val yaml = Yaml() + val inputStream = ConfigModel::class.java.getClassLoader().getResourceAsStream(PROPERTY_FILE) + requireNotNull(inputStream) { "$PROPERTY_FILE not found" } + overrideWithPropVariables(yaml.loadAs(inputStream, ConfigModel::class.java)) + } + + private fun overrideWithPropVariables(configModel: ConfigModel): ConfigModel { + configModel.bitbucket.host = System.getProperty("bitbucketHost", configModel.bitbucket.host) + configModel.bitbucket.url = System.getProperty("bitbucketUrl", configModel.bitbucket.url) + configModel.gitea.host = System.getProperty("giteaHost", configModel.gitea.host) + configModel.gitea.url = System.getProperty("giteaUrl", configModel.gitea.url) + configModel.gitlab.host = System.getProperty("gitlabHost", configModel.gitlab.host) + configModel.gitlab.url = System.getProperty("gitlabUrl", configModel.gitlab.url) + return configModel + } +} + +/** + * Configuration model representing the structure of the test-properties.yaml file. + */ +data class ConfigModel( + var bitbucket: VcsModel = VcsModel("admin", "admin", "bitbucket:7990", "http://localhost:7990"), + var gitlab: VcsModel = VcsModel("root", "VomkaEa6PD1OIgY7dQVbPUuO8wi9RMCaZw/i9yPXcI0=", "gitlab:8990", "http://localhost:8990"), + var gitea: VcsModel = VcsModel("test-admin", "test-admin", "gitea:3000", "http://localhost:3000"), + + var project: String = "test-project", + var repository: String = "test-repository", + var repository2: String = "test-repository-2", + var mainBranch: String = "master", + var featureBranch: String = "feature/FEATURE-1", + var messageInit: String = "initial commit", + var message1: String = "TEST-1 First commit", + var message2: String = "TEST-1 Second commit", + var message3: String = "TEST-2 Third commit", + var featureMessage: String = "FEATURE-1 First commit", + var tag1: String = "commit-1-tag", + var tag2: String = "commit-2-tag", + var tag3: String = "commit-3-tag", + var defaultId: String = "0123456789abcde", +) + +/** + * Configuration model representing the structure of the VCS properties. + */ +data class VcsModel( + var user: String = "", + var password: String = "", + var host: String = "", + var url: String = "", +) \ No newline at end of file diff --git a/test-common/src/main/resources/test-properties.yaml b/test-common/src/main/resources/test-properties.yaml new file mode 100644 index 0000000..f043e68 --- /dev/null +++ b/test-common/src/main/resources/test-properties.yaml @@ -0,0 +1,18 @@ +bitbucket: + host: "bitbucket:7990" + user: "admin" + password: "admin" + url: "http://bitbucket:7990" + +gitlab: + host: "gitlab:8990" + user: "root" + password: "VomkaEa6PD1OIgY7dQVbPUuO8wi9RMCaZw/i9yPXcI0=" + +gitea: + host: "gitea:3000" + user: "test-admin" + password: "test-admin" + +vcsFacadeUrl: "http://vcs-facade:8080" +