1
+ package de.otto.babbage.core.config
2
+
3
+ import io.kotest.matchers.collections.shouldContain
4
+ import io.micrometer.common.KeyValue
5
+ import org.junit.jupiter.api.Test
6
+ import org.mockito.Mockito
7
+ import org.springframework.http.HttpMethod
8
+ import org.springframework.http.HttpStatusCode
9
+ import org.springframework.web.reactive.function.client.ClientRequest
10
+ import org.springframework.web.reactive.function.client.ClientRequestObservationContext
11
+ import org.springframework.web.reactive.function.client.ClientResponse
12
+ import java.net.URI
13
+
14
+ internal class ClientRequestMetricsTagContributorTest {
15
+
16
+ @Test
17
+ fun `should create key value pairs for web client request` () {
18
+ // given
19
+ val url = " http://www.otto.de/first/second/third"
20
+ val clientRequest = ClientRequest .create(HttpMethod .GET , URI .create(url))
21
+ val clientResponse = ClientResponse .create(HttpStatusCode .valueOf(200 )).build()
22
+ val observationContext = ClientRequestObservationContext (clientRequest)
23
+ observationContext.setResponse(clientResponse)
24
+
25
+ // when
26
+ val result = ClientRequestMetricsTagContributor ().getLowCardinalityKeyValues(observationContext)
27
+
28
+ // then
29
+ result shouldContain KeyValue .of(" method" , " GET" )
30
+ result shouldContain KeyValue .of(" uri" , " /first" )
31
+ result shouldContain KeyValue .of(" client.name" , " www.otto.de" )
32
+ result shouldContain KeyValue .of(" status" , " 200" )
33
+ result shouldContain KeyValue .of(" outcome" , " SUCCESS" )
34
+ }
35
+
36
+ @Test
37
+ fun `should create fallback key value pairs for empty request` () {
38
+ // given
39
+ val mockedContext = Mockito .mock(ClientRequestObservationContext ::class .java)
40
+
41
+ // when
42
+ val result = ClientRequestMetricsTagContributor ().getLowCardinalityKeyValues(mockedContext)
43
+
44
+ // then
45
+ result shouldContain KeyValue .of(" method" , " undefined" )
46
+ result shouldContain KeyValue .of(" uri" , " undefined" )
47
+ result shouldContain KeyValue .of(" client.name" , " none" )
48
+ result shouldContain KeyValue .of(" status" , " undefined" )
49
+ result shouldContain KeyValue .of(" outcome" , " UNKNOWN" )
50
+ }
51
+ }
0 commit comments