This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
-
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.
Feature/aos 2839 helse endepunkt formater (#62)
* Fixed issue where we needed to support several health endpoint formats * Refactored, generalized * Readability improvements
- Loading branch information
1 parent
5620e8a
commit 0f7ff6b
Showing
3 changed files
with
192 additions
and
14 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
121 changes: 121 additions & 0 deletions
121
src/test/kotlin/no/skatteetaten/aurora/mokey/service/HealthResponseParserTest.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,121 @@ | ||
package no.skatteetaten.aurora.mokey.service | ||
|
||
import assertk.assert | ||
import assertk.assertions.isEqualTo | ||
import com.fasterxml.jackson.databind.node.IntNode | ||
import com.fasterxml.jackson.databind.node.LongNode | ||
import com.fasterxml.jackson.databind.node.TextNode | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import no.skatteetaten.aurora.mokey.model.HealthPart | ||
import no.skatteetaten.aurora.mokey.model.HealthResponse | ||
import no.skatteetaten.aurora.mokey.model.HealthStatus | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.jupiter.api.Test | ||
|
||
class HealthResponseParserTest { | ||
|
||
@Test | ||
fun `parse flat spring-boot 1-X health endpoint response`() { | ||
@Language("JSON") | ||
val json = """{ | ||
"status": "UP", | ||
"atsServiceHelse": { | ||
"status": "UP" | ||
}, | ||
"diskSpace": { | ||
"status": "UP", | ||
"total": 10718543872, | ||
"free": 10508611584, | ||
"threshold": 10485760 | ||
}, | ||
"db": { | ||
"status": "UP", | ||
"database": "Oracle", | ||
"hello": "Hello" | ||
} | ||
}""" | ||
|
||
val response = parse(json) | ||
val expected = HealthResponse( | ||
status = HealthStatus.UP, | ||
parts = mutableMapOf( | ||
"atsServiceHelse" to HealthPart( | ||
status = HealthStatus.UP, | ||
details = mutableMapOf() | ||
), | ||
"diskSpace" to HealthPart( | ||
status = HealthStatus.UP, | ||
details = mutableMapOf( | ||
"total" to 10718543872.node(), | ||
"threshold" to 10485760.node(), | ||
"free" to 10508611584.node() | ||
) | ||
), | ||
"db" to HealthPart( | ||
status = HealthStatus.UP, | ||
details = mutableMapOf( | ||
"hello" to "Hello".node(), | ||
"database" to "Oracle".node() | ||
) | ||
) | ||
) | ||
) | ||
assert(response).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `parse nested spring-boot 2-X health endpoint response`() { | ||
@Language("JSON") | ||
val json = """{ | ||
"status": "UP", | ||
"details": { | ||
"diskSpace": { | ||
"status": "UP", | ||
"details": { | ||
"total": 10718543872, | ||
"free": 10502053888, | ||
"threshold": 10485760 | ||
} | ||
}, | ||
"db": { | ||
"status": "UP", | ||
"details": { | ||
"database": "Oracle", | ||
"hello": "Hello" | ||
} | ||
} | ||
} | ||
}""" | ||
|
||
val response = parse(json) | ||
val expected = HealthResponse( | ||
status = HealthStatus.UP, | ||
parts = mutableMapOf( | ||
"diskSpace" to HealthPart( | ||
status = HealthStatus.UP, | ||
details = mutableMapOf( | ||
"total" to 10718543872.node(), | ||
"threshold" to 10485760.node(), | ||
"free" to 10502053888.node() | ||
) | ||
), | ||
"db" to HealthPart( | ||
status = HealthStatus.UP, | ||
details = mutableMapOf( | ||
"hello" to "Hello".node(), | ||
"database" to "Oracle".node() | ||
) | ||
) | ||
) | ||
) | ||
assert(response).isEqualTo(expected) | ||
} | ||
|
||
private fun String.node() = TextNode.valueOf(this)!! | ||
|
||
private fun Int.node() = IntNode.valueOf(this)!! | ||
|
||
private fun Long.node() = LongNode.valueOf(this)!! | ||
|
||
private fun parse(json: String) = HealthResponseParser.parse(jacksonObjectMapper().readTree(json)) | ||
} |