generated from leanix/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebSocketClientConfigTests.kt
More file actions
66 lines (59 loc) · 2.68 KB
/
WebSocketClientConfigTests.kt
File metadata and controls
66 lines (59 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package net.leanix.githubagent.config
import com.fasterxml.jackson.databind.ObjectMapper
import io.mockk.coEvery
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import net.leanix.githubagent.handler.BrokerStompSessionHandler
import net.leanix.githubagent.services.LeanIXAuthService
import net.leanix.githubagent.shared.GitHubAgentProperties
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.messaging.simp.stomp.StompHeaders
import org.springframework.messaging.simp.stomp.StompSession
import org.springframework.web.socket.WebSocketHttpHeaders
import org.springframework.web.socket.messaging.WebSocketStompClient
class WebSocketClientConfigTests {
private lateinit var webSocketClientConfig: WebSocketClientConfig
private lateinit var stompClient: WebSocketStompClient
private lateinit var stompSession: StompSession
private lateinit var authService: LeanIXAuthService
private lateinit var leanIXProperties: LeanIXProperties
private lateinit var gitHubEnterpriseProperties: GitHubEnterpriseProperties
private lateinit var leanIXAuthService: LeanIXAuthService
@BeforeEach
fun setUp() {
val brokerStompSessionHandler = mockk<BrokerStompSessionHandler>()
val objectMapper = mockk<ObjectMapper>()
leanIXProperties = mockk()
gitHubEnterpriseProperties = mockk()
stompClient = mockk()
stompSession = mockk()
authService = mockk()
leanIXAuthService = mockk()
webSocketClientConfig = WebSocketClientConfig(
brokerStompSessionHandler,
objectMapper,
leanIXAuthService,
leanIXProperties,
gitHubEnterpriseProperties
)
GitHubAgentProperties.GITHUB_AGENT_VERSION = "test-version"
}
@Test
fun `initSession should fail after max retry attempts`() = runBlocking {
coEvery { authService.getBearerToken() } returns "validToken"
coEvery { leanIXProperties.wsBaseUrl } returns "ws://test.url"
coEvery { gitHubEnterpriseProperties.baseUrl } returns "http://github.enterprise.url"
coEvery { gitHubEnterpriseProperties.gitHubAppId } returns "appId"
coEvery { leanIXAuthService.getBearerToken() } returns "bearer token"
coEvery {
stompClient.connectAsync(
any<String>(), any<WebSocketHttpHeaders>(),
any<StompHeaders>(), any<BrokerStompSessionHandler>()
)
} throws RuntimeException("Connection failed")
val session = runCatching { webSocketClientConfig.initSession() }.getOrNull()
assertEquals(null, session)
}
}