-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathSentrySpringSubscriptionHandlerTest.kt
More file actions
98 lines (93 loc) · 3.4 KB
/
SentrySpringSubscriptionHandlerTest.kt
File metadata and controls
98 lines (93 loc) · 3.4 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package io.sentry.spring7.graphql
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
import graphql.language.Document
import graphql.language.OperationDefinition
import graphql.schema.DataFetchingEnvironment
import io.sentry.IScopes
import io.sentry.graphql.ExceptionReporter
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame
import org.junit.jupiter.api.assertThrows
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.check
import org.mockito.kotlin.mock
import org.mockito.kotlin.same
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.graphql.execution.SubscriptionPublisherException
import reactor.core.publisher.Flux
class SentrySpringSubscriptionHandlerTest {
@Test
fun `reports exception`() {
val exception = IllegalStateException("some exception")
val scopes = mock<IScopes>()
val exceptionReporter = mock<ExceptionReporter>()
val parameters = mock<InstrumentationFieldFetchParameters>()
val dataFetchingEnvironment = mock<DataFetchingEnvironment>()
val document =
Document.newDocument()
.definition(
OperationDefinition.newOperationDefinition()
.operation(OperationDefinition.Operation.QUERY)
.name("testQuery")
.build()
)
.build()
whenever(dataFetchingEnvironment.document).thenReturn(document)
whenever(parameters.environment).thenReturn(dataFetchingEnvironment)
val resultObject =
SentrySpringSubscriptionHandler()
.onSubscriptionResult(Flux.error<Any>(exception), scopes, exceptionReporter, parameters)
assertThrows<IllegalStateException> { (resultObject as Flux<Any>).blockFirst() }
verify(exceptionReporter)
.captureThrowable(
same(exception),
check {
assertEquals(true, it.isSubscription)
assertSame(scopes, it.scopes)
assertEquals("query testQuery \n", it.query)
},
anyOrNull(),
)
}
@Test
fun `unwraps SubscriptionPublisherException and reports cause`() {
val exception = IllegalStateException("some exception")
val wrappedException = SubscriptionPublisherException(emptyList(), exception)
val scopes = mock<IScopes>()
val exceptionReporter = mock<ExceptionReporter>()
val parameters = mock<InstrumentationFieldFetchParameters>()
val dataFetchingEnvironment = mock<DataFetchingEnvironment>()
val document =
Document.newDocument()
.definition(
OperationDefinition.newOperationDefinition()
.operation(OperationDefinition.Operation.QUERY)
.name("testQuery")
.build()
)
.build()
whenever(dataFetchingEnvironment.document).thenReturn(document)
whenever(parameters.environment).thenReturn(dataFetchingEnvironment)
val resultObject =
SentrySpringSubscriptionHandler()
.onSubscriptionResult(
Flux.error<Any>(wrappedException),
scopes,
exceptionReporter,
parameters,
)
assertThrows<SubscriptionPublisherException> { (resultObject as Flux<Any>).blockFirst() }
verify(exceptionReporter)
.captureThrowable(
same(exception),
check {
assertEquals(true, it.isSubscription)
assertSame(scopes, it.scopes)
assertEquals("query testQuery \n", it.query)
},
anyOrNull(),
)
}
}