Skip to content

Commit

Permalink
OCTOPUS-489 Improve usability of components-registry-service-client (#18
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ozonophore committed Sep 25, 2023
1 parent 0763230 commit 43f9908
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion components-registry-service-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,7 +97,7 @@ interface ComponentsRegistryServiceClient {
fun getSupportedGroupIds(): Set<String>

@RequestLine("GET rest/api/2/common/version-names")
fun getVersionNames(): Map<String, String>
fun getVersionNames(): VersionNamesDTO

@RequestLine("GET rest/api/2/components-registry/service/status")
fun getServiceStatus(): ServiceStatusDTO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,7 +92,7 @@ class ClassicComponentsRegistryServiceClient(
override fun getSupportedGroupIds(): Set<String> =
client.getSupportedGroupIds()

override fun getVersionNames(): Map<String, String> =
override fun getVersionNames(): VersionNamesDTO =
client.getVersionNames()

override fun getServiceStatus(): ServiceStatusDTO =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,7 +105,7 @@ class ComponentRegistryServiceClientTest : BaseComponentsRegistryServiceTest() {

override fun getSupportedGroupIds(): Set<String> = componentsRegistryClient.getSupportedGroupIds()

override fun getVersionNames(): Map<String, String> = componentsRegistryClient.getVersionNames()
override fun getVersionNames(): VersionNamesDTO = componentsRegistryClient.getVersionNames()

override fun getDependencyAliasToComponentMapping(): Map<String, String> =
componentsRegistryClient.getDependencyAliasToComponentMapping()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand All @@ -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<String, String> {
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,15 +63,14 @@ class ComponentsRegistryServiceControllerTest : BaseComponentsRegistryServiceTes
.response
.toObject(object : TypeReference<Set<String>>() {})

override fun getVersionNames(): Map<String, String> =
mvc.perform(
MockMvcRequestBuilders.get(URI.create("/rest/api/2/common/version-names"))
.accept(APPLICATION_JSON)
)
.andExpect(status().isOk)
.andReturn()
.response
.toObject(object : TypeReference<Map<String, String>>() {})
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +88,7 @@ abstract class BaseComponentsRegistryServiceTest {
//common
protected abstract fun getAllJiraComponentVersionRanges(): Collection<JiraComponentVersionRangeDTO>
protected abstract fun getSupportedGroupIds(): Set<String>
abstract fun getVersionNames(): Map<String, String>
abstract fun getVersionNames(): VersionNamesDTO
protected abstract fun getDependencyAliasToComponentMapping(): Map<String, String>

protected abstract fun getComponentV1(component: String): ComponentV1
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 43f9908

Please sign in to comment.