From 43f99089b0070b47b12ae4c2d8809ba6e80f8212 Mon Sep 17 00:00:00 2001 From: ALEXEY ZVEREV Date: Mon, 25 Sep 2023 13:08:43 +0300 Subject: [PATCH] OCTOPUS-489 Improve usability of components-registry-service-client (#18) --- .../build.gradle | 2 +- .../client/ComponentsRegistryServiceClient.kt | 3 ++- .../ClassicComponentsRegistryServiceClient.kt | 3 ++- .../ComponentRegistryServiceClientTest.kt | 3 ++- .../registry/core/dto/VersionNamesDTO.kt | 14 ++++++++++++++ .../server/controller/CommonControllerV2.kt | 14 ++++++-------- .../ComponentsRegistryServiceControllerTest.kt | 18 +++++++++--------- .../test/BaseComponentsRegistryServiceTest.kt | 12 ++++++------ 8 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 components-registry-service-core/src/main/kotlin/org/octopusden/octopus/components/registry/core/dto/VersionNamesDTO.kt diff --git a/components-registry-service-client/build.gradle b/components-registry-service-client/build.gradle index 532559c..a7fb74a 100644 --- a/components-registry-service-client/build.gradle +++ b/components-registry-service-client/build.gradle @@ -6,7 +6,7 @@ plugins { } dependencies { - implementation project(":components-registry-service-core") + api project(":components-registry-service-core") implementation "com.fasterxml.jackson.core:jackson-databind" implementation(platform("io.github.openfeign:feign-bom:12.2")) diff --git a/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/ComponentsRegistryServiceClient.kt b/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/ComponentsRegistryServiceClient.kt index 9fd7585..84baa05 100644 --- a/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/ComponentsRegistryServiceClient.kt +++ b/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/ComponentsRegistryServiceClient.kt @@ -15,6 +15,7 @@ import org.octopusden.octopus.components.registry.core.dto.JiraComponentVersionD import org.octopusden.octopus.components.registry.core.dto.JiraComponentVersionRangeDTO import org.octopusden.octopus.components.registry.core.dto.ServiceStatusDTO import org.octopusden.octopus.components.registry.core.dto.VCSSettingsDTO +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO import org.octopusden.octopus.components.registry.core.dto.VersionRequest import org.octopusden.octopus.components.registry.core.dto.VersionedComponent import org.octopusden.octopus.components.registry.core.exceptions.NotFoundException @@ -96,7 +97,7 @@ interface ComponentsRegistryServiceClient { fun getSupportedGroupIds(): Set @RequestLine("GET rest/api/2/common/version-names") - fun getVersionNames(): Map + fun getVersionNames(): VersionNamesDTO @RequestLine("GET rest/api/2/components-registry/service/status") fun getServiceStatus(): ServiceStatusDTO diff --git a/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/impl/ClassicComponentsRegistryServiceClient.kt b/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/impl/ClassicComponentsRegistryServiceClient.kt index 53180be..6e68334 100644 --- a/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/impl/ClassicComponentsRegistryServiceClient.kt +++ b/components-registry-service-client/src/main/kotlin/org/octopusden/octopus/components/registry/client/impl/ClassicComponentsRegistryServiceClient.kt @@ -21,6 +21,7 @@ import feign.httpclient.ApacheHttpClient import feign.jackson.JacksonDecoder import feign.jackson.JacksonEncoder import feign.slf4j.Slf4jLogger +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO class ClassicComponentsRegistryServiceClient( apiUrlProvider: ClassicComponentsRegistryServiceClientUrlProvider, @@ -91,7 +92,7 @@ class ClassicComponentsRegistryServiceClient( override fun getSupportedGroupIds(): Set = client.getSupportedGroupIds() - override fun getVersionNames(): Map = + override fun getVersionNames(): VersionNamesDTO = client.getVersionNames() override fun getServiceStatus(): ServiceStatusDTO = diff --git a/components-registry-service-client/src/test/kotlin/org/octopusden/octopus/components/registry/client/ComponentRegistryServiceClientTest.kt b/components-registry-service-client/src/test/kotlin/org/octopusden/octopus/components/registry/client/ComponentRegistryServiceClientTest.kt index 8590290..751bf11 100644 --- a/components-registry-service-client/src/test/kotlin/org/octopusden/octopus/components/registry/client/ComponentRegistryServiceClientTest.kt +++ b/components-registry-service-client/src/test/kotlin/org/octopusden/octopus/components/registry/client/ComponentRegistryServiceClientTest.kt @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.api.parallel.ResourceLock +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.web.server.LocalServerPort import org.springframework.test.context.ActiveProfiles @@ -104,7 +105,7 @@ class ComponentRegistryServiceClientTest : BaseComponentsRegistryServiceTest() { override fun getSupportedGroupIds(): Set = componentsRegistryClient.getSupportedGroupIds() - override fun getVersionNames(): Map = componentsRegistryClient.getVersionNames() + override fun getVersionNames(): VersionNamesDTO = componentsRegistryClient.getVersionNames() override fun getDependencyAliasToComponentMapping(): Map = componentsRegistryClient.getDependencyAliasToComponentMapping() diff --git a/components-registry-service-core/src/main/kotlin/org/octopusden/octopus/components/registry/core/dto/VersionNamesDTO.kt b/components-registry-service-core/src/main/kotlin/org/octopusden/octopus/components/registry/core/dto/VersionNamesDTO.kt new file mode 100644 index 0000000..1296df6 --- /dev/null +++ b/components-registry-service-core/src/main/kotlin/org/octopusden/octopus/components/registry/core/dto/VersionNamesDTO.kt @@ -0,0 +1,14 @@ +package org.octopusden.octopus.components.registry.core.dto + +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty + +@JsonIgnoreProperties(ignoreUnknown = true) +data class VersionNamesDTO +@JsonCreator +constructor( + @JsonProperty("serviceBranch") val serviceBranch: String, + @JsonProperty("service") val service: String, + @JsonProperty("minor") val minor: String +) \ No newline at end of file diff --git a/components-registry-service-server/src/main/kotlin/org/octopusden/octopus/components/registry/server/controller/CommonControllerV2.kt b/components-registry-service-server/src/main/kotlin/org/octopusden/octopus/components/registry/server/controller/CommonControllerV2.kt index 6984024..04a293f 100644 --- a/components-registry-service-server/src/main/kotlin/org/octopusden/octopus/components/registry/server/controller/CommonControllerV2.kt +++ b/components-registry-service-server/src/main/kotlin/org/octopusden/octopus/components/registry/server/controller/CommonControllerV2.kt @@ -1,9 +1,11 @@ package org.octopusden.octopus.components.registry.server.controller import org.octopusden.octopus.components.registry.core.dto.JiraComponentVersionRangeDTO +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO import org.octopusden.octopus.components.registry.server.mapper.toDTO import org.octopusden.octopus.components.registry.server.service.ComponentRegistryResolver import org.octopusden.octopus.escrow.config.ConfigHelper +import org.octopusden.releng.versions.VersionNames import org.springframework.core.env.Environment import org.springframework.http.MediaType import org.springframework.web.bind.annotation.GetMapping @@ -14,7 +16,8 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("rest/api/2/common") class CommonControllerV2( private val componentRegistryResolver: ComponentRegistryResolver, - private val environment: Environment + private val environment: Environment, + private val versionNames: VersionNames ) { val configHelper: ConfigHelper = @@ -35,12 +38,7 @@ class CommonControllerV2( return configHelper.supportedGroupIds().toSet() } + @Deprecated( replaceWith = ReplaceWith("getVersionNamesV2()"), message = "Use getVersionNamesV2() instead") @GetMapping("version-names", produces = [MediaType.APPLICATION_JSON_VALUE]) - fun getVersionNames(): Map { - return mapOf( - "service-branch" to configHelper.serviceBranch(), - "service" to configHelper.service(), - "minor" to configHelper.minor(), - ) - } + fun getVersionNames(): VersionNamesDTO = VersionNamesDTO(versionNames.serviceBranch, versionNames.service, versionNames.minor) } diff --git a/components-registry-service-server/src/test/kotlin/org/octopusden/octopus/components/registry/server/ComponentsRegistryServiceControllerTest.kt b/components-registry-service-server/src/test/kotlin/org/octopusden/octopus/components/registry/server/ComponentsRegistryServiceControllerTest.kt index 92999ca..0c1e31c 100644 --- a/components-registry-service-server/src/test/kotlin/org/octopusden/octopus/components/registry/server/ComponentsRegistryServiceControllerTest.kt +++ b/components-registry-service-server/src/test/kotlin/org/octopusden/octopus/components/registry/server/ComponentsRegistryServiceControllerTest.kt @@ -21,6 +21,7 @@ import org.octopusden.octopus.components.registry.test.BaseComponentsRegistrySer import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest @@ -62,15 +63,14 @@ class ComponentsRegistryServiceControllerTest : BaseComponentsRegistryServiceTes .response .toObject(object : TypeReference>() {}) - override fun getVersionNames(): Map = - mvc.perform( - MockMvcRequestBuilders.get(URI.create("/rest/api/2/common/version-names")) - .accept(APPLICATION_JSON) - ) - .andExpect(status().isOk) - .andReturn() - .response - .toObject(object : TypeReference>() {}) + override fun getVersionNames(): VersionNamesDTO = mvc.perform( + MockMvcRequestBuilders.get(URI.create("/rest/api/2/common/version-names")) + .accept(APPLICATION_JSON) + ) + .andExpect(status().isOk) + .andReturn() + .response + .toObject(VersionNamesDTO::class.java) override fun getDependencyAliasToComponentMapping() = mvc.perform( diff --git a/test-common/src/testFixtures/kotlin/org/octopusden/octopus/components/registry/test/BaseComponentsRegistryServiceTest.kt b/test-common/src/testFixtures/kotlin/org/octopusden/octopus/components/registry/test/BaseComponentsRegistryServiceTest.kt index 92f9207..be4d515 100644 --- a/test-common/src/testFixtures/kotlin/org/octopusden/octopus/components/registry/test/BaseComponentsRegistryServiceTest.kt +++ b/test-common/src/testFixtures/kotlin/org/octopusden/octopus/components/registry/test/BaseComponentsRegistryServiceTest.kt @@ -24,6 +24,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource import org.junit.jupiter.params.provider.ValueSource +import org.octopusden.octopus.components.registry.core.dto.VersionNamesDTO import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -87,7 +88,7 @@ abstract class BaseComponentsRegistryServiceTest { //common protected abstract fun getAllJiraComponentVersionRanges(): Collection protected abstract fun getSupportedGroupIds(): Set - abstract fun getVersionNames(): Map + abstract fun getVersionNames(): VersionNamesDTO protected abstract fun getDependencyAliasToComponentMapping(): Map protected abstract fun getComponentV1(component: String): ComponentV1 @@ -136,11 +137,10 @@ abstract class BaseComponentsRegistryServiceTest { @Test fun testVersionNames() { - val map = getVersionNames() - Assertions.assertEquals(3, map.size) - Assertions.assertEquals("serviceCBranch", map["service-branch"]) - Assertions.assertEquals("serviceC", map["service"]) - Assertions.assertEquals("minorC", map["minor"]) + val value = getVersionNames() + Assertions.assertEquals("serviceCBranch", value.serviceBranch) + Assertions.assertEquals("serviceC", value.service) + Assertions.assertEquals("minorC", value.minor) } @Test