Skip to content

Commit

Permalink
Extract paramaters from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Jun 10, 2024
1 parent a1aa45a commit c977a27
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.octopusden.octopus.vcsfacade

import java.util.Date
import org.octopusden.octopus.infrastructure.common.test.TestClient
import org.octopusden.octopus.vcsfacade.TestService.Companion.VCS_FACADE_API_URL
import org.octopusden.octopus.vcsfacade.client.common.dto.CreatePullRequest
import org.octopusden.octopus.vcsfacade.client.common.dto.SearchIssuesInRangesRequest
import org.octopusden.octopus.vcsfacade.client.impl.ClassicVcsFacadeClient
Expand Down Expand Up @@ -59,7 +58,7 @@ abstract class BaseVcsFacadeFunctionalTest(

companion object {
private val client = ClassicVcsFacadeClient(object : VcsFacadeClientParametersProvider {
override fun getApiUrl() = VCS_FACADE_API_URL
override fun getApiUrl() = Configuration.model.vcsFacadeUrl
override fun getTimeRetryInMillis() = 180000
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.octopusden.octopus.vcsfacade
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.octopusden.octopus.infastructure.bitbucket.test.BitbucketTestClient

@EnabledIfSystemProperty(named = "test.profile", matches = "bitbucket")
@EnabledIfSystemProperty(named = TEST_PROFILE, matches = BITBUCKET)
class VcsFacadeFunctionalTestBitbucket : BaseVcsFacadeFunctionalTest(
TestService.Bitbucket(BITBUCKET_HOST, BITBUCKET_EXTERNAL_HOST),
BitbucketTestClient("http://$BITBUCKET_HOST", BITBUCKET_USER, BITBUCKET_PASSWORD, BITBUCKET_EXTERNAL_HOST)
TestService.Bitbucket(Configuration.model.bitbucket.host, Configuration.model.bitbucket.externalHost),
BitbucketTestClient(
Configuration.model.bitbucket.url,
Configuration.model.bitbucket.user,
Configuration.model.bitbucket.password,
Configuration.model.bitbucket.externalHost
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ import org.octopusden.octopus.infrastructure.common.test.dto.NewChangeSet
import org.octopusden.octopus.infrastructure.gitea.test.GiteaTestClient
import org.octopusden.octopus.vcsfacade.client.common.dto.CreatePullRequest

@EnabledIfSystemProperty(named = "test.profile", matches = "gitea")
@EnabledIfSystemProperty(named = TEST_PROFILE, matches = GITEA)
class VcsFacadeFunctionalTestGitea : BaseVcsFacadeFunctionalTest(
TestService.Gitea(GITEA_HOST, GITEA_EXTERNAL_HOST, true),
GiteaTestClient("http://$GITEA_HOST", GITEA_USER, GITEA_PASSWORD, GITEA_EXTERNAL_HOST)
TestService.Gitea(
Configuration.model.gitea.host,
Configuration.model.gitea.externalHost,
true),
GiteaTestClient(
Configuration.model.gitea.url,
Configuration.model.gitea.user,
Configuration.model.gitea.password,
Configuration.model.gitea.externalHost
)
) {
@BeforeAll
fun beforeAllVcsFacadeFunctionalTestGitea() {
val url = URI("http://$GITEA_HOST/api/v1/repos/$GROUP/$REPOSITORY_2/hooks").toURL()
val url = URI("http://${Configuration.model.gitea.host}/api/v1/repos/$GROUP/$REPOSITORY_2/hooks").toURL()
with(url.openConnection() as HttpURLConnection) {
setRequestMethod("POST")
setRequestProperty(
"Authorization",
"Basic " + Base64.getEncoder().encodeToString("$GITEA_USER:$GITEA_PASSWORD".toByteArray())
"Basic " + Base64.getEncoder().encodeToString("${Configuration.model.gitea.user}:${Configuration.model.gitea.password}".toByteArray())
)
setRequestProperty("Content-Type", "application/json")
setRequestProperty("Accept", "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ package org.octopusden.octopus.vcsfacade
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.octopusden.octopus.infrastructure.gitlab.test.GitlabTestClient

@EnabledIfSystemProperty(named = "test.profile", matches = "gitlab")
@EnabledIfSystemProperty(named = TEST_PROFILE, matches = GITLAB)
class VcsFacadeFunctionalTestGitlab : BaseVcsFacadeFunctionalTest(
TestService.Gitlab(GITLAB_HOST, GITLAB_EXTERNAL_HOST),
GitlabTestClient("http://$GITLAB_HOST", GITLAB_USER, GITLAB_PASSWORD, GITLAB_EXTERNAL_HOST)
TestService.Gitlab(
Configuration.model.gitlab.host,
Configuration.model.gitlab.externalHost
),
GitlabTestClient(
Configuration.model.gitlab.url,
Configuration.model.gitlab.user,
Configuration.model.gitlab.password,
Configuration.model.gitlab.externalHost
)
)
22 changes: 22 additions & 0 deletions server/src/test/resources/test-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bitbucket:
host: "localhost:7990"
externalHost: "bitbucket:7990"
user: "admin"
password: "admin"
url: "http://localhost:7990"

gitlab:
host: "localhost:8990"
externalHost: "gitlab:8990"
user: "root"
password: "VomkaEa6PD1OIgY7dQVbPUuO8wi9RMCaZw/i9yPXcI0="
url: "http://localhost:8990"

gitea:
host: "localhost:3000"
externalHost: "gitea:3000"
user: "test-admin"
password: "test-admin"
url: "http://localhost:3000"

vcsFacadeUrl: "http://localhost:8080"
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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"

/**
* Configuration object that reads the test-properties.yaml file and provides access to its properties.
*/
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.externalHost = System.getProperty("bitbucketExternalHost", configModel.bitbucket.externalHost)
configModel.bitbucket.url = System.getProperty("bitbucketUrl", configModel.bitbucket.url)
configModel.gitea.host = System.getProperty("giteaHost", configModel.gitea.host)
configModel.gitea.externalHost = System.getProperty("giteaExternalHost", configModel.gitea.externalHost)
configModel.gitea.url = System.getProperty("giteaUrl", configModel.gitea.url)
configModel.gitlab.host = System.getProperty("gitlabHost", configModel.gitlab.host)
configModel.gitlab.externalHost = System.getProperty("gitlabExternalHost", configModel.gitlab.externalHost)
configModel.gitlab.url = System.getProperty("gitlabUrl", configModel.gitlab.url)
configModel.vcsFacadeUrl = System.getProperty("vcsFacadeUrl", configModel.vcsFacadeUrl)
return configModel
}
}

/**
* Configuration model representing the structure of the test-properties.yaml file.
*/
data class ConfigModel(
var bitbucket: VcsModel = VcsModel(
"admin",
"admin",
"localhost:7990",
"bitbucket:7990",
"http://localhost:7990"),
var gitlab: VcsModel = VcsModel(
"root",
"VomkaEa6PD1OIgY7dQVbPUuO8wi9RMCaZw/i9yPXcI0=",
"localhost:3000",
"gitlab:8990",
"http://localhost:8990"
),
var gitea: VcsModel = VcsModel(
"test-admin",
"test-admin",
"localhost:8990",
"gitea:3000",
"http://localhost:3000"),

var vcsFacadeUrl: String = "http://localhost:8080",
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 externalHost: String = "",
var url: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ sealed class TestService(
class Bitbucket(
host: String, externalHost: String? = null
) : TestService(host, externalHost) {
override val type = "bitbucket"
override val type = BITBUCKET

override fun sshUrl(group: String, repository: String) =
"ssh://git@$effectiveHost/$group/$repository.git"
Expand All @@ -113,14 +113,14 @@ sealed class TestService(
class Gitea(
host: String, externalHost: String? = null, private val useColon: Boolean = false
) : TestService(host, externalHost) {
override val type = "gitea"
override val type = GITEA

override fun sshUrl(group: String, repository: String) =
"ssh://git@$effectiveHost${if (useColon) ":" else "/"}$group/$repository.git"

fun scan(group: String, repository: String) {
val query = "sshUrl=${URLEncoder.encode(sshUrl(group, repository), StandardCharsets.UTF_8)}"
val url = URI("$VCS_FACADE_API_URL/rest/api/1/indexer/gitea/scan?$query").toURL()
val url = URI("${Configuration.model.vcsFacadeUrl}/rest/api/1/indexer/gitea/scan?$query").toURL()
with(url.openConnection() as HttpURLConnection) {
setRequestMethod("POST")
if (getResponseCode() / 100 != 2) {
Expand All @@ -134,14 +134,13 @@ sealed class TestService(
class Gitlab(
host: String, externalHost: String? = null
) : TestService(host, externalHost) {
override val type = "gitlab"
override val type = GITLAB

override fun sshUrl(group: String, repository: String) =
"ssh://git@$effectiveHost:$group/$repository.git"
}

companion object {
const val VCS_FACADE_API_URL = "http://localhost:8080" //TODO: use some custom port?

private val OBJECT_MAPPER = ObjectMapper().registerKotlinModule()

Expand Down
22 changes: 22 additions & 0 deletions test-common/src/main/resources/test-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bitbucket:
host: "localhost:7990"
externalHost: "bitbucket:7990"
user: "admin"
password: "admin"
url: "http://localhost:7990"

gitlab:
host: "localhost:8990"
externalHost: "gitlab:8990"
user: "root"
password: "VomkaEa6PD1OIgY7dQVbPUuO8wi9RMCaZw/i9yPXcI0="
url: "http://localhost:8990"

gitea:
host: "localhost:3000"
externalHost: "gitea:3000"
user: "test-admin"
password: "test-admin"
url: "http://localhost:3000"

vcsFacadeUrl: "http://localhost:8080"

0 comments on commit c977a27

Please sign in to comment.