-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BuildController, LegacyRelengClient, tests (#2)
* BuildController, LegacyRelengClient, tests * Fix FT * releng.host -> releng.url * Replace hardcoded status codes with HttpStatusCode.*
- Loading branch information
Showing
43 changed files
with
617 additions
and
109 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.23" | ||
groovy | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(gradleApi()) | ||
implementation("org.mock-server:mockserver-client-java:5.15.0") | ||
} |
69 changes: 69 additions & 0 deletions
69
buildSrc/src/main/kotlin/org/octopusden/task/MigrateMockData.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,69 @@ | ||
package org.octopusden.task | ||
|
||
import com.google.common.io.Files | ||
import com.google.common.net.HttpHeaders | ||
import org.apache.http.entity.ContentType | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
import org.mockserver.client.MockServerClient | ||
import org.mockserver.model.HttpRequest | ||
import org.mockserver.model.HttpResponse | ||
import org.mockserver.model.HttpStatusCode | ||
import java.io.File | ||
import java.nio.charset.Charset | ||
|
||
|
||
open class MigrateMockData : DefaultTask() { | ||
|
||
private val mockServerClient = MockServerClient("localhost", 1080) | ||
|
||
@get:Input | ||
lateinit var testDataDir: String | ||
|
||
@TaskAction | ||
fun startMockServer() { | ||
mockServerClient.reset() | ||
endpointToResponseFileName.forEach { | ||
generateMockserverData(it.key.first, it.key.second, testDataDir + File.separator + it.value, HttpStatusCode.OK_200.code()) | ||
} | ||
endpointNotFoundToResponseFileName.forEach { | ||
generateMockserverData(it.key.first, it.key.second, testDataDir + File.separator + it.value, HttpStatusCode.NOT_FOUND_404.code()) | ||
} | ||
} | ||
|
||
private fun generateMockserverData(endpoint: String, params: Map<String, String>, filename: String, status: Int) { | ||
val body = Files.asCharSource(File(filename), Charset.defaultCharset()).read() | ||
val request = HttpRequest.request() | ||
.withMethod("GET") | ||
.withPath(endpoint) | ||
params.forEach { | ||
request.withQueryStringParameter(it.key, it.value) | ||
} | ||
mockServerClient.`when`(request) | ||
.respond { | ||
logger.debug( | ||
"MockServer request: ${it.method} ${it.path} ${it.queryStringParameterList.joinToString(",")} ${ | ||
it.pathParameterList.joinToString( | ||
"," | ||
) | ||
}" | ||
) | ||
HttpResponse.response() | ||
.withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.mimeType) | ||
.withBody(body) | ||
.withStatusCode(status) | ||
} | ||
} | ||
|
||
companion object { | ||
private val endpointToResponseFileName = mapOf( | ||
"/rest/release-engineering/3/component/ReleaseManagementService/builds" to emptyMap<String, String>() to "releng/builds.json", | ||
"/rest/release-engineering/3/component/ReleaseManagementService/version/1.0.1/build" to emptyMap<String, String>() to "releng/build_1.0.1.json", | ||
"/rest/release-engineering/3/component/ReleaseManagementService/version/1.0.2/build" to emptyMap<String, String>() to "releng/build_1.0.2.json", | ||
) | ||
private val endpointNotFoundToResponseFileName = mapOf( | ||
"/rest/release-engineering/3/component/ReleaseManagementService/version/1.0.3/build" to emptyMap<String, String>() to "releng/build-not-exist-error.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
10 changes: 10 additions & 0 deletions
10
.../org/octopusden/octopus/releasemanagementservice/client/ReleaseManagementServiceClient.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,9 +1,19 @@ | ||
package org.octopusden.octopus.releasemanagementservice.client | ||
|
||
import feign.Param | ||
import feign.RequestLine | ||
import org.octopusden.octopus.releasemanagementservice.client.common.dto.BuildDTO | ||
import org.octopusden.octopus.releasemanagementservice.client.common.dto.ServiceInfoDTO | ||
import org.octopusden.octopus.releasemanagementservice.client.common.dto.ShortBuildDTO | ||
|
||
interface ReleaseManagementServiceClient { | ||
|
||
@RequestLine("GET /actuator/info") | ||
fun getServiceInfo(): ServiceInfoDTO | ||
|
||
@RequestLine("GET /builds/component/{component}") | ||
fun getBuilds(@Param("component") component: String): Collection<ShortBuildDTO> | ||
|
||
@RequestLine("GET /builds/component/{component}/version/{version}") | ||
fun getBuild(@Param("component") component: String, @Param("version") version: String): BuildDTO | ||
} |
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
3 changes: 3 additions & 0 deletions
3
...main/kotlin/org/octopusden/octopus/releasemanagementservice/client/common/dto/BuildDTO.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,3 @@ | ||
package org.octopusden.octopus.releasemanagementservice.client.common.dto | ||
|
||
data class BuildDTO(val component: String, val version: String, val status: BuildStatus, val dependencies: Collection<ShortBuildDTO>, val commits: Collection<CommitDTO>) |
7 changes: 7 additions & 0 deletions
7
...n/kotlin/org/octopusden/octopus/releasemanagementservice/client/common/dto/BuildStatus.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,7 @@ | ||
package org.octopusden.octopus.releasemanagementservice.client.common.dto | ||
|
||
enum class BuildStatus { | ||
BUILD, | ||
RC, | ||
RELEASE | ||
} |
3 changes: 3 additions & 0 deletions
3
...ain/kotlin/org/octopusden/octopus/releasemanagementservice/client/common/dto/CommitDTO.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,3 @@ | ||
package org.octopusden.octopus.releasemanagementservice.client.common.dto | ||
|
||
data class CommitDTO(val repository: String, val sha: String) |
3 changes: 3 additions & 0 deletions
3
...kotlin/org/octopusden/octopus/releasemanagementservice/client/common/dto/ShortBuildDTO.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,3 @@ | ||
package org.octopusden.octopus.releasemanagementservice.client.common.dto | ||
|
||
data class ShortBuildDTO(val component: String, val version: String, val status: BuildStatus) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
releng: | ||
url: http://mockserver:1080 | ||
|
||
management: | ||
endpoints: | ||
web: | ||
|
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
19 changes: 18 additions & 1 deletion
19
ft/src/ft/kotlin/org/octopusden/octopus/releasemanagementservice/ActuatorTest.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,8 +1,25 @@ | ||
package org.octopusden.octopus.releasemanagementservice | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.octopusden.octopus.releasemanagementservice.client.common.dto.ServiceInfoDTO | ||
import org.octopusden.octopus.releasemanagementservice.client.impl.ClassicReleaseManagementServiceClient | ||
import org.octopusden.octopus.releasemanagementservice.client.impl.ReleaseManagementServiceClientParametersProvider | ||
|
||
class ActuatorTest : BaseReleaseManagementServiceFuncTest() { | ||
class ActuatorTest : BaseActuatorTest(), BaseReleaseManagementServiceFuncTest { | ||
|
||
override fun getObjectMapper(): ObjectMapper = mapper | ||
|
||
override fun getServiceInfo(): ServiceInfoDTO = client.getServiceInfo() | ||
|
||
companion object { | ||
@JvmStatic | ||
private val mapper = jacksonObjectMapper() | ||
@JvmStatic | ||
private val client = | ||
ClassicReleaseManagementServiceClient(object : ReleaseManagementServiceClientParametersProvider { | ||
override fun getApiUrl() = "http://localhost:8080" | ||
override fun getTimeRetryInMillis() = 180000 | ||
}) | ||
} | ||
} |
14 changes: 1 addition & 13 deletions
14
...n/org/octopusden/octopus/releasemanagementservice/BaseReleaseManagementServiceFuncTest.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,15 +1,3 @@ | ||
package org.octopusden.octopus.releasemanagementservice | ||
|
||
import org.octopusden.octopus.releasemanagementservice.client.impl.ClassicReleaseManagementServiceClient | ||
import org.octopusden.octopus.releasemanagementservice.client.impl.ReleaseManagementServiceClientParametersProvider | ||
|
||
abstract class BaseReleaseManagementServiceFuncTest : BaseReleaseManagementServiceTest() { | ||
companion object { | ||
@JvmStatic | ||
protected val client = | ||
ClassicReleaseManagementServiceClient(object : ReleaseManagementServiceClientParametersProvider { | ||
override fun getApiUrl() = "http://localhost:8080" | ||
override fun getTimeRetryInMillis() = 180000 | ||
}) | ||
} | ||
} | ||
interface BaseReleaseManagementServiceFuncTest : BaseReleaseManagementServiceTest |
41 changes: 41 additions & 0 deletions
41
ft/src/ft/kotlin/org/octopusden/octopus/releasemanagementservice/BuildControllerTest.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,41 @@ | ||
package org.octopusden.octopus.releasemanagementservice | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.octopusden.octopus.releasemanagementservice.client.common.dto.* | ||
import org.octopusden.octopus.releasemanagementservice.client.common.exception.NotFoundException | ||
import org.octopusden.octopus.releasemanagementservice.client.impl.ClassicReleaseManagementServiceClient | ||
import org.octopusden.octopus.releasemanagementservice.client.impl.ReleaseManagementServiceClientParametersProvider | ||
|
||
class BuildControllerTest : BaseBuildControllerTest(), BaseReleaseManagementServiceFuncTest { | ||
|
||
override fun getObjectMapper(): ObjectMapper = mapper | ||
|
||
override fun getBuilds(component: String): Collection<ShortBuildDTO> { | ||
return client.getBuilds(component) | ||
} | ||
|
||
override fun getBuild(component: String, version: String): BuildDTO { | ||
return client.getBuild(component, version) | ||
} | ||
|
||
override fun getNotExistedBuildErrorResponse(component: String, version: String): ErrorResponse { | ||
try { | ||
client.getBuild(component, version) | ||
return ErrorResponse(ReleaseManagementServiceErrorCode.OTHER, "Failure expected") | ||
} catch (e: NotFoundException) { | ||
return ErrorResponse(ReleaseManagementServiceErrorCode.NOT_FOUND, e.message!!) | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
private val mapper = jacksonObjectMapper() | ||
@JvmStatic | ||
private val client = | ||
ClassicReleaseManagementServiceClient(object : ReleaseManagementServiceClientParametersProvider { | ||
override fun getApiUrl() = "http://localhost:8080" | ||
override fun getTimeRetryInMillis() = 180000 | ||
}) | ||
} | ||
} |
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.