@@ -19,9 +19,8 @@ import io.mockk.clearMocks
19
19
import io.mockk.every
20
20
import io.mockk.mockk
21
21
import io.mockk.verify
22
- import org.axonframework.messaging.responsetypes.AbstractResponseType
23
- import org.axonframework.messaging.responsetypes.InstanceResponseType
24
22
import org.axonframework.queryhandling.QueryGateway
23
+ import org.axonframework.queryhandling.SubscriptionQueryResult
25
24
import java.util.*
26
25
import java.util.concurrent.CompletableFuture
27
26
import java.util.concurrent.TimeUnit
@@ -47,6 +46,8 @@ internal class QueryGatewayExtensionsTest {
47
46
private val streamInstanceReturnValue = Stream .of(" Value" )
48
47
private val streamMultipleReturnValue = Stream .of(listOf (" Value" , " Second Value" ))
49
48
private val streamOptionalReturnValue = Stream .of(Optional .of(" Value" ))
49
+ private val subscriptionQueryResult = ExampleSubscriptionQueryResult ()
50
+
50
51
51
52
@BeforeTest
52
53
fun before () {
@@ -62,6 +63,7 @@ internal class QueryGatewayExtensionsTest {
62
63
every { subjectGateway.scatterGather(queryName, exampleQuery, matchInstanceResponseType<String >(), timeout, timeUnit) } returns streamInstanceReturnValue
63
64
every { subjectGateway.scatterGather(queryName, exampleQuery, matchMultipleInstancesResponseType<String >(), timeout, timeUnit) } returns streamMultipleReturnValue
64
65
every { subjectGateway.scatterGather(queryName, exampleQuery, matchOptionalResponseType<String >(), timeout, timeUnit) } returns streamOptionalReturnValue
66
+ every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType<String >(), matchInstanceResponseType<UpdateType >()) } returns subscriptionQueryResult
65
67
}
66
68
67
69
@AfterTest
@@ -78,15 +80,37 @@ internal class QueryGatewayExtensionsTest {
78
80
}
79
81
}
80
82
83
+ @Test
84
+ fun `Query without queryName should invoke subscription query method with correct generic parameters` () {
85
+ val queryResult = subjectGateway.subscriptionQuery<ExampleQuery , String , UpdateType >(query = exampleQuery)
86
+ assertSame(queryResult, subscriptionQueryResult)
87
+ verify(exactly = 1 ) {
88
+ subjectGateway.subscriptionQuery(exampleQuery, matchExpectedResponseType(String ::class .java), matchExpectedResponseType(UpdateType ::class .java))
89
+ }
90
+ }
91
+
81
92
@Test
82
93
fun `Query without queryName should invoke query method and not require explicit generic types` () {
83
- val queryResult: CompletableFuture <String > = subjectGateway.query(query = exampleQuery)
94
+ val queryResult: CompletableFuture <String > = subjectGateway.query(query = exampleQuery)
84
95
assertSame(queryResult, instanceReturnValue)
85
96
verify(exactly = 1 ) {
86
97
subjectGateway.query(exampleQuery, matchExpectedResponseType(String ::class .java))
87
98
}
88
99
}
89
100
101
+ @Test
102
+ fun `Query without queryName should invoke subscription query method and not require explicit generic types` () {
103
+ val queryResult: SubscriptionQueryResult <String , UpdateType > = subjectGateway.subscriptionQuery(query = exampleQuery)
104
+ assertSame(queryResult, subscriptionQueryResult)
105
+ verify(exactly = 1 ) {
106
+ subjectGateway.subscriptionQuery(
107
+ exampleQuery,
108
+ matchExpectedResponseType(String ::class .java),
109
+ matchExpectedResponseType(UpdateType ::class .java)
110
+ )
111
+ }
112
+ }
113
+
90
114
@Test
91
115
fun `Query without queryName Optional should invoke query method with correct generic parameters` () {
92
116
val queryResult = subjectGateway.queryOptional<String , ExampleQuery >(query = exampleQuery)
@@ -127,7 +151,7 @@ internal class QueryGatewayExtensionsTest {
127
151
}
128
152
129
153
val queryResult = nullableQueryGateway.query<String ?, ExampleQuery >(query = exampleQuery)
130
-
154
+
131
155
assertSame(queryResult, nullInstanceReturnValue)
132
156
assertEquals(nullInstanceReturnValue.get(), null )
133
157
verify(exactly = 1 ) { nullableQueryGateway.query(exampleQuery, matchExpectedResponseType(String ::class .java)) }
@@ -185,7 +209,7 @@ internal class QueryGatewayExtensionsTest {
185
209
fun `Query should handle nullable responses` () {
186
210
val nullInstanceReturnValue: CompletableFuture <String ?> = CompletableFuture .completedFuture(null )
187
211
val nullableQueryGateway = mockk<QueryGateway > {
188
- every { query(queryName, exampleQuery, matchInstanceResponseType<String ?>() ) } returns nullInstanceReturnValue
212
+ every { query(queryName, exampleQuery, matchInstanceResponseType<String ?>()) } returns nullInstanceReturnValue
189
213
}
190
214
191
215
val queryResult = nullableQueryGateway.query<String ?, ExampleQuery >(queryName = queryName, query = exampleQuery)
@@ -195,36 +219,36 @@ internal class QueryGatewayExtensionsTest {
195
219
verify(exactly = 1 ) { nullableQueryGateway.query(queryName, exampleQuery, matchExpectedResponseType(String ::class .java)) }
196
220
}
197
221
198
- @Test
199
- fun `ScatterGather for Single should invoke scatterGather method with correct generic parameters` () {
200
- val result = subjectGateway.scatterGather<String , ExampleQuery >(
201
- query = exampleQuery,
202
- timeout = timeout,
203
- timeUnit = timeUnit
204
- )
222
+ @Test
223
+ fun `ScatterGather for Single should invoke scatterGather method with correct generic parameters` () {
224
+ val result = subjectGateway.scatterGather<String , ExampleQuery >(
225
+ query = exampleQuery,
226
+ timeout = timeout,
227
+ timeUnit = timeUnit
228
+ )
205
229
206
- assertSame(result, streamInstanceReturnValue)
207
- verify(exactly = 1 ) { subjectGateway.scatterGather(exampleQuery, matchExpectedResponseType(String ::class .java), timeout, timeUnit) }
208
- }
230
+ assertSame(result, streamInstanceReturnValue)
231
+ verify(exactly = 1 ) { subjectGateway.scatterGather(exampleQuery, matchExpectedResponseType(String ::class .java), timeout, timeUnit) }
232
+ }
209
233
210
- @Test
211
- fun `ScatterGather for Multiple should invoke scatterGather method with correct generic parameters` () {
212
- val result = subjectGateway.scatterGatherMany<String , ExampleQuery >(
213
- query = exampleQuery,
214
- timeout = timeout,
215
- timeUnit = timeUnit
216
- )
234
+ @Test
235
+ fun `ScatterGather for Multiple should invoke scatterGather method with correct generic parameters` () {
236
+ val result = subjectGateway.scatterGatherMany<String , ExampleQuery >(
237
+ query = exampleQuery,
238
+ timeout = timeout,
239
+ timeUnit = timeUnit
240
+ )
217
241
218
- assertSame(result, streamMultipleReturnValue)
219
- verify(exactly = 1 ) { subjectGateway.scatterGather(exampleQuery, matchMultipleInstancesResponseType<String >(), timeout, timeUnit) }
220
- }
242
+ assertSame(result, streamMultipleReturnValue)
243
+ verify(exactly = 1 ) { subjectGateway.scatterGather(exampleQuery, matchMultipleInstancesResponseType<String >(), timeout, timeUnit) }
244
+ }
221
245
222
246
@Test
223
247
fun `ScatterGather for Optional should invoke scatterGather method with correct generic parameters` () {
224
248
val result = subjectGateway.scatterGatherOptional<String , ExampleQuery >(
225
- query = exampleQuery,
226
- timeout = timeout,
227
- timeUnit = timeUnit
249
+ query = exampleQuery,
250
+ timeout = timeout,
251
+ timeUnit = timeUnit
228
252
)
229
253
230
254
assertSame(result, streamOptionalReturnValue)
@@ -234,10 +258,10 @@ internal class QueryGatewayExtensionsTest {
234
258
@Test
235
259
fun `ScatterGather for Single should invoke scatterGather method with explicit query name` () {
236
260
val result = subjectGateway.scatterGather<String , ExampleQuery >(
237
- queryName = queryName,
238
- query = exampleQuery,
239
- timeout = timeout,
240
- timeUnit = timeUnit
261
+ queryName = queryName,
262
+ query = exampleQuery,
263
+ timeout = timeout,
264
+ timeUnit = timeUnit
241
265
)
242
266
243
267
assertSame(result, streamInstanceReturnValue)
@@ -247,10 +271,10 @@ internal class QueryGatewayExtensionsTest {
247
271
@Test
248
272
fun `ScatterGather for Multiple should invoke scatterGather method with explicit query name` () {
249
273
val result = subjectGateway.scatterGatherMany<String , ExampleQuery >(
250
- queryName = queryName,
251
- query = exampleQuery,
252
- timeout = timeout,
253
- timeUnit = timeUnit
274
+ queryName = queryName,
275
+ query = exampleQuery,
276
+ timeout = timeout,
277
+ timeUnit = timeUnit
254
278
)
255
279
256
280
assertSame(result, streamMultipleReturnValue)
@@ -260,10 +284,10 @@ internal class QueryGatewayExtensionsTest {
260
284
@Test
261
285
fun `ScatterGather for Optional should invoke scatterGather method with explicit query name` () {
262
286
val result = subjectGateway.scatterGatherOptional<String , ExampleQuery >(
263
- queryName = queryName,
264
- query = exampleQuery,
265
- timeout = timeout,
266
- timeUnit = timeUnit
287
+ queryName = queryName,
288
+ query = exampleQuery,
289
+ timeout = timeout,
290
+ timeUnit = timeUnit
267
291
)
268
292
269
293
assertSame(result, streamOptionalReturnValue)
0 commit comments