Skip to content

Commit 2e94209

Browse files
committed
refactor: cleanup and renaming
1 parent e81f121 commit 2e94209

11 files changed

Lines changed: 75 additions & 79 deletions

File tree

src/main/kotlin/io/sdkman/broker/App.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import io.sdkman.broker.application.service.CandidateDownloadService
1818
import io.sdkman.broker.application.service.CandidateDownloadServiceImpl
1919
import io.sdkman.broker.application.service.HealthService
2020
import io.sdkman.broker.application.service.HealthServiceImpl
21-
import io.sdkman.broker.application.service.ReleaseService
22-
import io.sdkman.broker.application.service.ReleaseServiceImpl
21+
import io.sdkman.broker.application.service.MetaService
22+
import io.sdkman.broker.application.service.MetaServiceImpl
2323
import io.sdkman.broker.application.service.SdkmanCliDownloadServiceImpl
2424
import io.sdkman.broker.application.service.SdkmanNativeDownloadServiceImpl
2525
import io.sdkman.broker.config.DefaultAppConfig
@@ -49,8 +49,8 @@ object App {
4949

5050
// Initialize services
5151
val healthService = HealthServiceImpl(applicationRepository, postgresHealthRepository)
52-
val releaseService = ReleaseServiceImpl()
53-
val versionService = CandidateDownloadServiceImpl(versionRepository, auditRepository)
52+
val releaseService = MetaServiceImpl()
53+
val candidateDownloadService = CandidateDownloadServiceImpl(versionRepository, auditRepository)
5454
val sdkmanCliDownloadService = SdkmanCliDownloadServiceImpl()
5555
val sdkmanNativeDownloadService = SdkmanNativeDownloadServiceImpl()
5656

@@ -59,7 +59,7 @@ object App {
5959
configureApp(
6060
healthService,
6161
releaseService,
62-
versionService,
62+
candidateDownloadService,
6363
sdkmanCliDownloadService,
6464
sdkmanNativeDownloadService
6565
)
@@ -70,7 +70,7 @@ object App {
7070
@OptIn(ExperimentalSerializationApi::class)
7171
fun Application.configureApp(
7272
healthService: HealthService,
73-
releaseService: ReleaseService,
73+
metaService: MetaService,
7474
candidateDownloadService: CandidateDownloadService,
7575
sdkmanCliDownloadService: SdkmanCliDownloadService,
7676
sdkmanNativeDownloadService: SdkmanNativeDownloadService
@@ -89,6 +89,6 @@ fun Application.configureApp(
8989
}
9090

9191
// Configure routes
92-
metaRoutes(healthService, releaseService)
92+
metaRoutes(healthService, metaService)
9393
downloadRoutes(candidateDownloadService, sdkmanCliDownloadService, sdkmanNativeDownloadService)
9494
}

src/main/kotlin/io/sdkman/broker/adapter/primary/rest/MetaRoutes.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import io.ktor.server.response.respond
77
import io.ktor.server.routing.get
88
import io.ktor.server.routing.routing
99
import io.sdkman.broker.application.service.HealthService
10-
import io.sdkman.broker.application.service.ReleaseError
11-
import io.sdkman.broker.application.service.ReleaseService
10+
import io.sdkman.broker.application.service.MetaError
11+
import io.sdkman.broker.application.service.MetaService
1212
import kotlinx.serialization.Serializable
1313

1414
fun Application.metaRoutes(
1515
healthService: HealthService,
16-
releaseService: ReleaseService
16+
metaService: MetaService
1717
) {
1818
routing {
1919
get("/meta/health") {
@@ -25,7 +25,7 @@ fun Application.metaRoutes(
2525
}
2626

2727
get("/meta/release") {
28-
releaseService.getRelease()
28+
metaService.getReleaseVersion()
2929
.fold(
3030
{ error ->
3131
call.respond(
@@ -53,8 +53,8 @@ data class ReleaseResponse(val release: String)
5353
@Serializable
5454
data class ReleaseErrorResponse(val error: String)
5555

56-
private val ReleaseError.cause: Throwable
56+
private val MetaError.cause: Throwable
5757
get() =
5858
when (this) {
59-
is ReleaseError.ReleaseFileError -> cause
59+
is MetaError.MetaFileError -> cause
6060
}

src/main/kotlin/io/sdkman/broker/application/service/ReleaseService.kt renamed to src/main/kotlin/io/sdkman/broker/application/service/MetaService.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@ package io.sdkman.broker.application.service
22

33
import arrow.core.Either
44
import arrow.core.flatMap
5+
import arrow.core.getOrElse
56
import arrow.core.left
67
import arrow.core.right
78
import arrow.core.toOption
89
import java.util.Properties
910

10-
interface ReleaseService {
11-
fun getRelease(): Either<ReleaseError, String>
11+
interface MetaService {
12+
fun getReleaseVersion(): Either<MetaError, String>
1213
}
1314

14-
class ReleaseServiceImpl(
15-
private val classLoader: ClassLoader = ReleaseServiceImpl::class.java.classLoader
16-
) : ReleaseService {
15+
class MetaServiceImpl(
16+
private val classLoader: ClassLoader = MetaServiceImpl::class.java.classLoader
17+
) : MetaService {
1718
companion object {
1819
private const val RELEASE_PROPERTIES = "release.properties"
1920
private const val RELEASE_KEY = "release"
2021
}
2122

22-
override fun getRelease(): Either<ReleaseError, String> =
23+
override fun getReleaseVersion(): Either<MetaError, String> =
2324
loadPropertiesFile()
2425
.flatMap { properties -> getReleaseFromProperties(properties) }
2526

26-
private fun loadPropertiesFile(): Either<ReleaseError, Properties> =
27+
private fun loadPropertiesFile(): Either<MetaError, Properties> =
2728
Either.catch {
2829
val properties = Properties()
2930
classLoader.getResourceAsStream(RELEASE_PROPERTIES).toOption()
@@ -34,21 +35,18 @@ class ReleaseServiceImpl(
3435
properties
3536
}
3637
)
37-
}.mapLeft { ReleaseError.ReleaseFileError(it) }
38+
}.mapLeft { MetaError.MetaFileError(it) }
3839

39-
private fun getReleaseFromProperties(properties: Properties): Either<ReleaseError, String> =
40+
private fun getReleaseFromProperties(properties: Properties): Either<MetaError, String> =
4041
properties.getProperty(RELEASE_KEY).toOption()
4142
.filter { it.isNotBlank() }
42-
.fold(
43-
{
44-
ReleaseError.ReleaseFileError(
45-
IllegalStateException("Release property not found in $RELEASE_PROPERTIES")
46-
).left()
47-
},
48-
{ it.right() }
49-
)
43+
.map { it.right() }
44+
.getOrElse {
45+
MetaError.MetaFileError(IllegalStateException("Release property not found in $RELEASE_PROPERTIES"))
46+
.left()
47+
}
5048
}
5149

52-
sealed class ReleaseError {
53-
data class ReleaseFileError(val cause: Throwable) : ReleaseError()
50+
sealed class MetaError {
51+
data class MetaFileError(val cause: Throwable) : MetaError()
5452
}

src/main/kotlin/io/sdkman/broker/domain/model/Application.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import arrow.core.Either
44
import arrow.core.left
55
import arrow.core.right
66

7-
data class Application private constructor(
8-
val alive: AliveStatus
9-
) {
7+
data class Application private constructor(val alive: AliveStatus) {
108
companion object {
119
fun of(alive: String): Either<ApplicationError, Application> =
1210
AliveStatus.of(alive).map { status ->

src/test/kotlin/io/sdkman/broker/acceptance/HealthCheckAcceptanceSpec.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HealthCheckAcceptanceSpec : ShouldSpec() {
3333
application {
3434
configureAppForTesting(
3535
TestDependencyInjection.healthService,
36-
TestDependencyInjection.releaseService,
36+
TestDependencyInjection.metaService,
3737
TestDependencyInjection.versionService
3838
)
3939
}
@@ -58,7 +58,7 @@ class HealthCheckAcceptanceSpec : ShouldSpec() {
5858
application {
5959
configureAppForTesting(
6060
TestDependencyInjection.healthService,
61-
TestDependencyInjection.releaseService,
61+
TestDependencyInjection.metaService,
6262
TestDependencyInjection.versionService
6363
)
6464
}
@@ -85,7 +85,7 @@ class HealthCheckAcceptanceSpec : ShouldSpec() {
8585
application {
8686
configureAppForTesting(
8787
TestDependencyInjection.healthService,
88-
TestDependencyInjection.releaseService,
88+
TestDependencyInjection.metaService,
8989
TestDependencyInjection.versionService
9090
)
9191
}
@@ -109,7 +109,7 @@ class HealthCheckAcceptanceSpec : ShouldSpec() {
109109
application {
110110
configureAppForTesting(
111111
TestDependencyInjection.healthServiceInvalidCredentials,
112-
TestDependencyInjection.releaseService,
112+
TestDependencyInjection.metaService,
113113
TestDependencyInjection.versionService
114114
)
115115
}

src/test/kotlin/io/sdkman/broker/acceptance/ReleaseEndpointAcceptanceSpec.kt renamed to src/test/kotlin/io/sdkman/broker/acceptance/MetaReleaseEndpointAcceptanceSpec.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import io.ktor.client.call.body
88
import io.ktor.client.request.get
99
import io.ktor.http.HttpStatusCode
1010
import io.ktor.server.testing.testApplication
11-
import io.sdkman.broker.application.service.ReleaseError
12-
import io.sdkman.broker.application.service.ReleaseService
11+
import io.sdkman.broker.application.service.MetaError
12+
import io.sdkman.broker.application.service.MetaService
1313
import io.sdkman.broker.support.TestDependencyInjection
1414
import io.sdkman.broker.support.configureAppForTesting
1515
import org.junit.jupiter.api.Tag
1616

1717
@Tag("acceptance")
18-
class ReleaseEndpointAcceptanceSpec : ShouldSpec({
18+
class MetaReleaseEndpointAcceptanceSpec : ShouldSpec({
1919

2020
should("return 200 OK with release when release.properties file is present") {
2121
// given: a running application and the release.properties file is present
@@ -24,7 +24,7 @@ class ReleaseEndpointAcceptanceSpec : ShouldSpec({
2424
application {
2525
configureAppForTesting(
2626
TestDependencyInjection.healthService,
27-
TestDependencyInjection.releaseService,
27+
TestDependencyInjection.metaService,
2828
TestDependencyInjection.versionService
2929
)
3030
}
@@ -46,9 +46,9 @@ class ReleaseEndpointAcceptanceSpec : ShouldSpec({
4646
testApplication {
4747
// Using a service that can't find the file
4848
val mockService =
49-
object : ReleaseService {
50-
override fun getRelease(): Either<ReleaseError, String> =
51-
ReleaseError.ReleaseFileError(
49+
object : MetaService {
50+
override fun getReleaseVersion(): Either<MetaError, String> =
51+
MetaError.MetaFileError(
5252
IllegalStateException("Could not load release.properties")
5353
).left()
5454
}

src/test/kotlin/io/sdkman/broker/acceptance/VersionDownloadAcceptanceSpec.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
3838
application {
3939
configureAppForTesting(
4040
TestDependencyInjection.healthService,
41-
TestDependencyInjection.releaseService,
41+
TestDependencyInjection.metaService,
4242
TestDependencyInjection.versionService
4343
)
4444
}
@@ -78,7 +78,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
7878
application {
7979
configureAppForTesting(
8080
TestDependencyInjection.healthService,
81-
TestDependencyInjection.releaseService,
81+
TestDependencyInjection.metaService,
8282
TestDependencyInjection.versionService
8383
)
8484
}
@@ -103,7 +103,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
103103
application {
104104
configureAppForTesting(
105105
TestDependencyInjection.healthService,
106-
TestDependencyInjection.releaseService,
106+
TestDependencyInjection.metaService,
107107
TestDependencyInjection.versionService
108108
)
109109
}
@@ -121,7 +121,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
121121
application {
122122
configureAppForTesting(
123123
TestDependencyInjection.healthService,
124-
TestDependencyInjection.releaseService,
124+
TestDependencyInjection.metaService,
125125
TestDependencyInjection.versionService
126126
)
127127
}
@@ -150,7 +150,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
150150
application {
151151
configureAppForTesting(
152152
TestDependencyInjection.healthService,
153-
TestDependencyInjection.releaseService,
153+
TestDependencyInjection.metaService,
154154
TestDependencyInjection.versionService
155155
)
156156
}
@@ -179,7 +179,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
179179
application {
180180
configureAppForTesting(
181181
TestDependencyInjection.healthService,
182-
TestDependencyInjection.releaseService,
182+
TestDependencyInjection.metaService,
183183
TestDependencyInjection.versionService
184184
)
185185
}
@@ -214,7 +214,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
214214
application {
215215
configureAppForTesting(
216216
TestDependencyInjection.healthService,
217-
TestDependencyInjection.releaseService,
217+
TestDependencyInjection.metaService,
218218
TestDependencyInjection.versionService
219219
)
220220
}
@@ -261,7 +261,7 @@ class VersionDownloadAcceptanceSpec : ShouldSpec({
261261
application {
262262
configureAppForTesting(
263263
TestDependencyInjection.healthService,
264-
TestDependencyInjection.releaseService,
264+
TestDependencyInjection.metaService,
265265
TestDependencyInjection.versionService
266266
)
267267
}

src/test/kotlin/io/sdkman/broker/acceptance/VersionDownloadAuditAcceptanceSpec.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class VersionDownloadAuditAcceptanceSpec : ShouldSpec({
4646
application {
4747
configureAppForTesting(
4848
TestDependencyInjection.healthService,
49-
TestDependencyInjection.releaseService,
49+
TestDependencyInjection.metaService,
5050
TestDependencyInjection.versionService
5151
)
5252
}
@@ -103,7 +103,7 @@ class VersionDownloadAuditAcceptanceSpec : ShouldSpec({
103103
application {
104104
configureAppForTesting(
105105
TestDependencyInjection.healthService,
106-
TestDependencyInjection.releaseService,
106+
TestDependencyInjection.metaService,
107107
TestDependencyInjection.versionService
108108
)
109109
}
@@ -159,7 +159,7 @@ class VersionDownloadAuditAcceptanceSpec : ShouldSpec({
159159
application {
160160
configureAppForTesting(
161161
TestDependencyInjection.healthService,
162-
TestDependencyInjection.releaseService,
162+
TestDependencyInjection.metaService,
163163
TestDependencyInjection.versionService
164164
)
165165
}
@@ -190,7 +190,7 @@ class VersionDownloadAuditAcceptanceSpec : ShouldSpec({
190190
application {
191191
configureAppForTesting(
192192
TestDependencyInjection.healthService,
193-
TestDependencyInjection.releaseService,
193+
TestDependencyInjection.metaService,
194194
TestDependencyInjection.versionService
195195
)
196196
}
@@ -222,7 +222,7 @@ class VersionDownloadAuditAcceptanceSpec : ShouldSpec({
222222
application {
223223
configureAppForTesting(
224224
TestDependencyInjection.healthService,
225-
TestDependencyInjection.releaseService,
225+
TestDependencyInjection.metaService,
226226
TestDependencyInjection.versionService
227227
)
228228
}

0 commit comments

Comments
 (0)