From 1024066ffaf81db49d88446af719ae27ebc2f943 Mon Sep 17 00:00:00 2001 From: "radoslaw.sobies" Date: Mon, 11 Apr 2022 16:11:05 +0200 Subject: [PATCH 1/8] inline extension functions added --- kotlin/pom.xml | 6 + .../kotlin/QueryGatewayExtensions.kt | 19 +++- .../kotlin/QueryGatewayExtensionsTest.kt | 104 +++++++++++------- .../extensions/kotlin/testObjects.kt | 21 ++++ 4 files changed, 107 insertions(+), 43 deletions(-) diff --git a/kotlin/pom.xml b/kotlin/pom.xml index e310c5c6..ca7272a2 100644 --- a/kotlin/pom.xml +++ b/kotlin/pom.xml @@ -39,6 +39,12 @@ axon-configuration provided + + io.projectreactor + reactor-core + 3.4.5 + test + diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index e9053e14..afb7617a 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -18,6 +18,7 @@ package org.axonframework.extensions.kotlin import org.axonframework.messaging.responsetypes.ResponseTypes import org.axonframework.queryhandling.QueryGateway +import org.axonframework.queryhandling.SubscriptionQueryResult import java.util.* import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit @@ -40,9 +41,21 @@ import java.util.stream.Stream * @see ResponseTypes * @since 0.1.0 */ -inline fun QueryGateway.queryMany(query: Q): CompletableFuture> { - return this.query(query, ResponseTypes.multipleInstancesOf(R::class.java)) -} +inline fun QueryGateway.queryMany(query: Q): CompletableFuture> = this.query(query, ResponseTypes.multipleInstancesOf(R::class.java)) + +/** + * Reified version of [QueryGateway.subscriptionQuery] + * which expects a collection as a response using [org.axonframework.messaging.responsetypes.MultipleInstancesResponseType] + * @param query Query to send + * @param Q the type of payload of the query + * @param R the type of result of the query + * @return [SubscriptionQueryResult] wrapping the result of the query + * @see QueryGateway.subscriptionQuery + * @see ResponseTypes + * @since 0.1.0 + */ +inline fun QueryGateway.subscriptionQuery(query: Q): SubscriptionQueryResult = + this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) /** * Reified version of [QueryGateway.query] with explicit query name diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt index 90a64f53..e987d3c2 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt @@ -19,9 +19,8 @@ import io.mockk.clearMocks import io.mockk.every import io.mockk.mockk import io.mockk.verify -import org.axonframework.messaging.responsetypes.AbstractResponseType -import org.axonframework.messaging.responsetypes.InstanceResponseType import org.axonframework.queryhandling.QueryGateway +import org.axonframework.queryhandling.SubscriptionQueryResult import java.util.* import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit @@ -47,6 +46,8 @@ internal class QueryGatewayExtensionsTest { private val streamInstanceReturnValue = Stream.of("Value") private val streamMultipleReturnValue = Stream.of(listOf("Value", "Second Value")) private val streamOptionalReturnValue = Stream.of(Optional.of("Value")) + private val subscriptionQueryResult = ExampleSubscriptionQueryResult() + @BeforeTest fun before() { @@ -62,6 +63,7 @@ internal class QueryGatewayExtensionsTest { every { subjectGateway.scatterGather(queryName, exampleQuery, matchInstanceResponseType(), timeout, timeUnit) } returns streamInstanceReturnValue every { subjectGateway.scatterGather(queryName, exampleQuery, matchMultipleInstancesResponseType(), timeout, timeUnit) } returns streamMultipleReturnValue every { subjectGateway.scatterGather(queryName, exampleQuery, matchOptionalResponseType(), timeout, timeUnit) } returns streamOptionalReturnValue + every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType(), matchInstanceResponseType()) } returns subscriptionQueryResult } @AfterTest @@ -78,15 +80,37 @@ internal class QueryGatewayExtensionsTest { } } + @Test + fun `Query without queryName should invoke subscription query method with correct generic parameters`() { + val queryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery(exampleQuery, matchExpectedResponseType(String::class.java), matchExpectedResponseType(UpdateType::class.java)) + } + } + @Test fun `Query without queryName should invoke query method and not require explicit generic types`() { - val queryResult:CompletableFuture = subjectGateway.query(query = exampleQuery) + val queryResult: CompletableFuture = subjectGateway.query(query = exampleQuery) assertSame(queryResult, instanceReturnValue) verify(exactly = 1) { subjectGateway.query(exampleQuery, matchExpectedResponseType(String::class.java)) } } + @Test + fun `Query without queryName should invoke subscription query method and not require explicit generic types`() { + val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery( + exampleQuery, + matchExpectedResponseType(String::class.java), + matchExpectedResponseType(UpdateType::class.java) + ) + } + } + @Test fun `Query without queryName Optional should invoke query method with correct generic parameters`() { val queryResult = subjectGateway.queryOptional(query = exampleQuery) @@ -127,7 +151,7 @@ internal class QueryGatewayExtensionsTest { } val queryResult = nullableQueryGateway.query(query = exampleQuery) - + assertSame(queryResult, nullInstanceReturnValue) assertEquals(nullInstanceReturnValue.get(), null) verify(exactly = 1) { nullableQueryGateway.query(exampleQuery, matchExpectedResponseType(String::class.java)) } @@ -185,7 +209,7 @@ internal class QueryGatewayExtensionsTest { fun `Query should handle nullable responses`() { val nullInstanceReturnValue: CompletableFuture = CompletableFuture.completedFuture(null) val nullableQueryGateway = mockk { - every { query(queryName, exampleQuery, matchInstanceResponseType() ) } returns nullInstanceReturnValue + every { query(queryName, exampleQuery, matchInstanceResponseType()) } returns nullInstanceReturnValue } val queryResult = nullableQueryGateway.query(queryName = queryName, query = exampleQuery) @@ -195,36 +219,36 @@ internal class QueryGatewayExtensionsTest { verify(exactly = 1) { nullableQueryGateway.query(queryName, exampleQuery, matchExpectedResponseType(String::class.java)) } } - @Test - fun `ScatterGather for Single should invoke scatterGather method with correct generic parameters`() { - val result = subjectGateway.scatterGather( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit - ) + @Test + fun `ScatterGather for Single should invoke scatterGather method with correct generic parameters`() { + val result = subjectGateway.scatterGather( + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit + ) - assertSame(result, streamInstanceReturnValue) - verify(exactly = 1) { subjectGateway.scatterGather(exampleQuery, matchExpectedResponseType(String::class.java), timeout, timeUnit) } - } + assertSame(result, streamInstanceReturnValue) + verify(exactly = 1) { subjectGateway.scatterGather(exampleQuery, matchExpectedResponseType(String::class.java), timeout, timeUnit) } + } - @Test - fun `ScatterGather for Multiple should invoke scatterGather method with correct generic parameters`() { - val result = subjectGateway.scatterGatherMany( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit - ) + @Test + fun `ScatterGather for Multiple should invoke scatterGather method with correct generic parameters`() { + val result = subjectGateway.scatterGatherMany( + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit + ) - assertSame(result, streamMultipleReturnValue) - verify(exactly = 1) { subjectGateway.scatterGather(exampleQuery, matchMultipleInstancesResponseType(), timeout, timeUnit) } - } + assertSame(result, streamMultipleReturnValue) + verify(exactly = 1) { subjectGateway.scatterGather(exampleQuery, matchMultipleInstancesResponseType(), timeout, timeUnit) } + } @Test fun `ScatterGather for Optional should invoke scatterGather method with correct generic parameters`() { val result = subjectGateway.scatterGatherOptional( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamOptionalReturnValue) @@ -234,10 +258,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Single should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGather( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamInstanceReturnValue) @@ -247,10 +271,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Multiple should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGatherMany( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamMultipleReturnValue) @@ -260,10 +284,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Optional should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGatherOptional( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamOptionalReturnValue) diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt index 99c89613..2da722af 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt @@ -1,6 +1,9 @@ package org.axonframework.extensions.kotlin import org.axonframework.modelling.command.TargetAggregateIdentifier +import org.axonframework.queryhandling.SubscriptionQueryResult +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono /** * Simple Query class to be used in tests. @@ -11,3 +14,21 @@ internal data class ExampleQuery(val value: Number) * Simple Command class to be used in tests. */ internal data class ExampleCommand(@TargetAggregateIdentifier val id: String) + +internal data class UpdateType(val dummy:String) + +internal class ExampleSubscriptionQueryResult:SubscriptionQueryResult { + override fun cancel(): Boolean { + TODO("Not yet implemented") + } + + override fun initialResult(): Mono { + TODO("Not yet implemented") + } + + override fun updates(): Flux { + TODO("Not yet implemented") + } + + +} From 6b0262f0bdedf848452fbf6971c402289f21aee1 Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 20:03:13 +0200 Subject: [PATCH 2/8] inline extension functions added --- .../axonframework/extensions/kotlin/QueryGatewayExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index afb7617a..86a87b04 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -72,7 +72,7 @@ inline fun QueryGateway.subscriptionQuery(quer inline fun QueryGateway.queryMany(queryName: String, query: Q): CompletableFuture> { return this.query(queryName, query, ResponseTypes.multipleInstancesOf(R::class.java)) } - +// /** * Reified version of [QueryGateway.query] * which expects a single object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType] From f480d401b8128c373a4959d5b547de52d7837ac5 Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 20:06:56 +0200 Subject: [PATCH 3/8] inline extension functions added --- .../axonframework/extensions/kotlin/QueryGatewayExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index 86a87b04..afb7617a 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -72,7 +72,7 @@ inline fun QueryGateway.subscriptionQuery(quer inline fun QueryGateway.queryMany(queryName: String, query: Q): CompletableFuture> { return this.query(queryName, query, ResponseTypes.multipleInstancesOf(R::class.java)) } -// + /** * Reified version of [QueryGateway.query] * which expects a single object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType] From 465d3339c28238e398d75ced04d30ecfed414e3f Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 20:32:13 +0200 Subject: [PATCH 4/8] inline extension functions added --- .../kotlin/QueryGatewayExtensions.kt | 47 +++++++---- .../kotlin/QueryGatewayExtensionsTest.kt | 84 ++++++++++++++----- 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index afb7617a..056b1bbe 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -43,20 +43,6 @@ import java.util.stream.Stream */ inline fun QueryGateway.queryMany(query: Q): CompletableFuture> = this.query(query, ResponseTypes.multipleInstancesOf(R::class.java)) -/** - * Reified version of [QueryGateway.subscriptionQuery] - * which expects a collection as a response using [org.axonframework.messaging.responsetypes.MultipleInstancesResponseType] - * @param query Query to send - * @param Q the type of payload of the query - * @param R the type of result of the query - * @return [SubscriptionQueryResult] wrapping the result of the query - * @see QueryGateway.subscriptionQuery - * @see ResponseTypes - * @since 0.1.0 - */ -inline fun QueryGateway.subscriptionQuery(query: Q): SubscriptionQueryResult = - this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) - /** * Reified version of [QueryGateway.query] with explicit query name * which expects a collection as a response using [org.axonframework.messaging.responsetypes.MultipleInstancesResponseType] @@ -244,4 +230,35 @@ inline fun QueryGateway.scatterGatherOptional(query: Q, t inline fun QueryGateway.scatterGatherOptional(queryName: String, query: Q, timeout: Long, timeUnit: TimeUnit): Stream> { return this.scatterGather(queryName, query, ResponseTypes.optionalInstanceOf(R::class.java), timeout, timeUnit) -} \ No newline at end of file +} + +/** + * Reified version of [QueryGateway.subscriptionQuery] + * which expects a single object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType] + * @param query Query to send + * @param Q the type of payload of the query + * @param I the type of initial response + * @param U the type of update response + * @return [SubscriptionQueryResult] wrapping the result of the query + * @see QueryGateway.subscriptionQuery + * @see ResponseTypes + * @since 0.1.0 + */ +inline fun QueryGateway.subscriptionQuery(query: Q): SubscriptionQueryResult = + this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) + +/** + * Reified version of [QueryGateway.subscriptionQuery] + * which expects a single object as a response using [org.axonframework.messaging.responsetypes.InstanceResponseType] + * @param queryName Name of the query + * @param query Query to send + * @param Q the type of payload of the query + * @param I the type of initial response + * @param U the type of update response + * @return [SubscriptionQueryResult] wrapping the result of the query + * @see QueryGateway.subscriptionQuery + * @see ResponseTypes + * @since 0.1.0 + */ +inline fun QueryGateway.subscriptionQuery(queryName: String, query: Q): SubscriptionQueryResult = + this.subscriptionQuery(queryName, query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) \ No newline at end of file diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt index e987d3c2..9f37da99 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt @@ -64,6 +64,14 @@ internal class QueryGatewayExtensionsTest { every { subjectGateway.scatterGather(queryName, exampleQuery, matchMultipleInstancesResponseType(), timeout, timeUnit) } returns streamMultipleReturnValue every { subjectGateway.scatterGather(queryName, exampleQuery, matchOptionalResponseType(), timeout, timeUnit) } returns streamOptionalReturnValue every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType(), matchInstanceResponseType()) } returns subscriptionQueryResult + every { + subjectGateway.subscriptionQuery( + queryName, + exampleQuery, + matchInstanceResponseType(), + matchInstanceResponseType() + ) + } returns subscriptionQueryResult } @AfterTest @@ -80,15 +88,6 @@ internal class QueryGatewayExtensionsTest { } } - @Test - fun `Query without queryName should invoke subscription query method with correct generic parameters`() { - val queryResult = subjectGateway.subscriptionQuery(query = exampleQuery) - assertSame(queryResult, subscriptionQueryResult) - verify(exactly = 1) { - subjectGateway.subscriptionQuery(exampleQuery, matchExpectedResponseType(String::class.java), matchExpectedResponseType(UpdateType::class.java)) - } - } - @Test fun `Query without queryName should invoke query method and not require explicit generic types`() { val queryResult: CompletableFuture = subjectGateway.query(query = exampleQuery) @@ -98,23 +97,9 @@ internal class QueryGatewayExtensionsTest { } } - @Test - fun `Query without queryName should invoke subscription query method and not require explicit generic types`() { - val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(query = exampleQuery) - assertSame(queryResult, subscriptionQueryResult) - verify(exactly = 1) { - subjectGateway.subscriptionQuery( - exampleQuery, - matchExpectedResponseType(String::class.java), - matchExpectedResponseType(UpdateType::class.java) - ) - } - } - @Test fun `Query without queryName Optional should invoke query method with correct generic parameters`() { val queryResult = subjectGateway.queryOptional(query = exampleQuery) - assertSame(queryResult, optionalReturnValue) verify(exactly = 1) { subjectGateway.query(exampleQuery, matchExpectedResponseType(String::class.java)) } } @@ -294,4 +279,57 @@ internal class QueryGatewayExtensionsTest { verify(exactly = 1) { subjectGateway.scatterGather(queryName, exampleQuery, matchOptionalResponseType(), timeout, timeUnit) } } + @Test + fun `Query without queryName should invoke subscription query method with correct generic parameters`() { + val queryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery( + exampleQuery, + matchExpectedResponseType(String::class.java), + matchExpectedResponseType(UpdateType::class.java) + ) + } + } + + @Test + fun `Query without queryName should invoke subscriptionQuery method and not require explicit generic types`() { + val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery( + exampleQuery, + matchExpectedResponseType(String::class.java), + matchExpectedResponseType(UpdateType::class.java) + ) + } + } + + @Test + fun `Query should invoke subscriptionQuery method with correct generic parameters`() { + val queryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery( + queryName, + exampleQuery, + matchExpectedResponseType(String::class.java), + matchExpectedResponseType(UpdateType::class.java) + ) + } + } + + @Test + fun `Query should invoke subscriptionQuery method and not require explicit generic types`() { + val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) + assertSame(queryResult, subscriptionQueryResult) + verify(exactly = 1) { + subjectGateway.subscriptionQuery( + queryName, + exampleQuery, + matchExpectedResponseType(String::class.java), + matchExpectedResponseType(UpdateType::class.java) + ) + } + } } From 3e2a51012d213b04241d938203c602ff771b0b58 Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 20:42:49 +0200 Subject: [PATCH 5/8] inline extension functions added --- .../kotlin/QueryGatewayExtensionsTest.kt | 31 +++++++++---------- .../extensions/kotlin/testObjects.kt | 21 +++++++++---- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt index 9f37da99..42ab61c1 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt @@ -48,7 +48,6 @@ internal class QueryGatewayExtensionsTest { private val streamOptionalReturnValue = Stream.of(Optional.of("Value")) private val subscriptionQueryResult = ExampleSubscriptionQueryResult() - @BeforeTest fun before() { every { subjectGateway.query(exampleQuery, matchInstanceResponseType()) } returns instanceReturnValue @@ -63,13 +62,13 @@ internal class QueryGatewayExtensionsTest { every { subjectGateway.scatterGather(queryName, exampleQuery, matchInstanceResponseType(), timeout, timeUnit) } returns streamInstanceReturnValue every { subjectGateway.scatterGather(queryName, exampleQuery, matchMultipleInstancesResponseType(), timeout, timeUnit) } returns streamMultipleReturnValue every { subjectGateway.scatterGather(queryName, exampleQuery, matchOptionalResponseType(), timeout, timeUnit) } returns streamOptionalReturnValue - every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType(), matchInstanceResponseType()) } returns subscriptionQueryResult + every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType(), matchInstanceResponseType()) } returns subscriptionQueryResult every { subjectGateway.subscriptionQuery( queryName, exampleQuery, - matchInstanceResponseType(), - matchInstanceResponseType() + matchInstanceResponseType(), + matchInstanceResponseType() ) } returns subscriptionQueryResult } @@ -281,54 +280,54 @@ internal class QueryGatewayExtensionsTest { @Test fun `Query without queryName should invoke subscription query method with correct generic parameters`() { - val queryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + val queryResult = subjectGateway.subscriptionQuery(query = exampleQuery) assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( exampleQuery, - matchExpectedResponseType(String::class.java), - matchExpectedResponseType(UpdateType::class.java) + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @Test fun `Query without queryName should invoke subscriptionQuery method and not require explicit generic types`() { - val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(query = exampleQuery) + val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(query = exampleQuery) assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( exampleQuery, - matchExpectedResponseType(String::class.java), - matchExpectedResponseType(UpdateType::class.java) + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @Test fun `Query should invoke subscriptionQuery method with correct generic parameters`() { - val queryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) + val queryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( queryName, exampleQuery, - matchExpectedResponseType(String::class.java), - matchExpectedResponseType(UpdateType::class.java) + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @Test fun `Query should invoke subscriptionQuery method and not require explicit generic types`() { - val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) + val queryResult: SubscriptionQueryResult = subjectGateway.subscriptionQuery(queryName = queryName, query = exampleQuery) assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( queryName, exampleQuery, - matchExpectedResponseType(String::class.java), - matchExpectedResponseType(UpdateType::class.java) + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt index 2da722af..b3fbc0ca 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/testObjects.kt @@ -15,20 +15,29 @@ internal data class ExampleQuery(val value: Number) */ internal data class ExampleCommand(@TargetAggregateIdentifier val id: String) -internal data class UpdateType(val dummy:String) +/** + * Class used as update response type in subscriptionQuery method. + */ +internal data class UpdateResponseType(val dummy: String) + +/** + * Class used as initial response type in subscriptionQuery method. + */ +internal data class InitialResponseType(val dummy: String) -internal class ExampleSubscriptionQueryResult:SubscriptionQueryResult { +/** + * Dummy class used as return object from subscriptionQuery method in the mock. + */ +internal class ExampleSubscriptionQueryResult : SubscriptionQueryResult { override fun cancel(): Boolean { TODO("Not yet implemented") } - override fun initialResult(): Mono { + override fun initialResult(): Mono { TODO("Not yet implemented") } - override fun updates(): Flux { + override fun updates(): Flux { TODO("Not yet implemented") } - - } From 88147d32ccb660ea06e6f39dcf825c860cabc242 Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 21:08:13 +0200 Subject: [PATCH 6/8] inline extension functions added --- .../kotlin/QueryGatewayExtensions.kt | 16 ++-- .../kotlin/QueryGatewayExtensionsTest.kt | 78 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index 056b1bbe..716e1bbc 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -135,7 +135,7 @@ inline fun QueryGateway.queryOptional(queryName: String, * @since 0.2.0 */ inline fun QueryGateway.scatterGather(query: Q, timeout: Long, - timeUnit: TimeUnit): Stream { + timeUnit: TimeUnit): Stream { return this.scatterGather(query, ResponseTypes.instanceOf(R::class.java), timeout, timeUnit) } @@ -154,7 +154,7 @@ inline fun QueryGateway.scatterGather(query: Q, timeout: * @since 0.2.0 */ inline fun QueryGateway.scatterGather(queryName: String, query: Q, timeout: Long, - timeUnit: TimeUnit): Stream { + timeUnit: TimeUnit): Stream { return this.scatterGather(queryName, query, ResponseTypes.instanceOf(R::class.java), timeout, timeUnit) } @@ -172,7 +172,7 @@ inline fun QueryGateway.scatterGather(queryName: String, * @since 0.2.0 */ inline fun QueryGateway.scatterGatherMany(query: Q, timeout: Long, - timeUnit: TimeUnit): Stream> { + timeUnit: TimeUnit): Stream> { return this.scatterGather(query, ResponseTypes.multipleInstancesOf(R::class.java), timeout, timeUnit) } @@ -191,7 +191,7 @@ inline fun QueryGateway.scatterGatherMany(query: Q, timeo * @since 0.2.0 */ inline fun QueryGateway.scatterGatherMany(queryName: String, query: Q, timeout: Long, - timeUnit: TimeUnit): Stream> { + timeUnit: TimeUnit): Stream> { return this.scatterGather(queryName, query, ResponseTypes.multipleInstancesOf(R::class.java), timeout, timeUnit) } @@ -209,7 +209,7 @@ inline fun QueryGateway.scatterGatherMany(queryName: Stri * @since 0.2.0 */ inline fun QueryGateway.scatterGatherOptional(query: Q, timeout: Long, - timeUnit: TimeUnit): Stream> { + timeUnit: TimeUnit): Stream> { return this.scatterGather(query, ResponseTypes.optionalInstanceOf(R::class.java), timeout, timeUnit) } @@ -228,7 +228,7 @@ inline fun QueryGateway.scatterGatherOptional(query: Q, t * @since 0.2.0 */ inline fun QueryGateway.scatterGatherOptional(queryName: String, query: Q, timeout: Long, - timeUnit: TimeUnit): Stream> { + timeUnit: TimeUnit): Stream> { return this.scatterGather(queryName, query, ResponseTypes.optionalInstanceOf(R::class.java), timeout, timeUnit) } @@ -245,7 +245,7 @@ inline fun QueryGateway.scatterGatherOptional(queryName: * @since 0.1.0 */ inline fun QueryGateway.subscriptionQuery(query: Q): SubscriptionQueryResult = - this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) + this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) /** * Reified version of [QueryGateway.subscriptionQuery] @@ -261,4 +261,4 @@ inline fun QueryGateway.subscriptionQuery(quer * @since 0.1.0 */ inline fun QueryGateway.subscriptionQuery(queryName: String, query: Q): SubscriptionQueryResult = - this.subscriptionQuery(queryName, query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) \ No newline at end of file + this.subscriptionQuery(queryName, query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) \ No newline at end of file diff --git a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt index 42ab61c1..5e95f89e 100644 --- a/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt +++ b/kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensionsTest.kt @@ -65,10 +65,10 @@ internal class QueryGatewayExtensionsTest { every { subjectGateway.subscriptionQuery(exampleQuery, matchInstanceResponseType(), matchInstanceResponseType()) } returns subscriptionQueryResult every { subjectGateway.subscriptionQuery( - queryName, - exampleQuery, - matchInstanceResponseType(), - matchInstanceResponseType() + queryName, + exampleQuery, + matchInstanceResponseType(), + matchInstanceResponseType() ) } returns subscriptionQueryResult } @@ -206,9 +206,9 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Single should invoke scatterGather method with correct generic parameters`() { val result = subjectGateway.scatterGather( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamInstanceReturnValue) @@ -218,9 +218,9 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Multiple should invoke scatterGather method with correct generic parameters`() { val result = subjectGateway.scatterGatherMany( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamMultipleReturnValue) @@ -230,9 +230,9 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Optional should invoke scatterGather method with correct generic parameters`() { val result = subjectGateway.scatterGatherOptional( - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamOptionalReturnValue) @@ -242,10 +242,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Single should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGather( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamInstanceReturnValue) @@ -255,10 +255,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Multiple should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGatherMany( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamMultipleReturnValue) @@ -268,10 +268,10 @@ internal class QueryGatewayExtensionsTest { @Test fun `ScatterGather for Optional should invoke scatterGather method with explicit query name`() { val result = subjectGateway.scatterGatherOptional( - queryName = queryName, - query = exampleQuery, - timeout = timeout, - timeUnit = timeUnit + queryName = queryName, + query = exampleQuery, + timeout = timeout, + timeUnit = timeUnit ) assertSame(result, streamOptionalReturnValue) @@ -284,9 +284,9 @@ internal class QueryGatewayExtensionsTest { assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( - exampleQuery, - matchExpectedResponseType(InitialResponseType::class.java), - matchExpectedResponseType(UpdateResponseType::class.java) + exampleQuery, + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @@ -297,9 +297,9 @@ internal class QueryGatewayExtensionsTest { assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( - exampleQuery, - matchExpectedResponseType(InitialResponseType::class.java), - matchExpectedResponseType(UpdateResponseType::class.java) + exampleQuery, + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @@ -310,10 +310,10 @@ internal class QueryGatewayExtensionsTest { assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( - queryName, - exampleQuery, - matchExpectedResponseType(InitialResponseType::class.java), - matchExpectedResponseType(UpdateResponseType::class.java) + queryName, + exampleQuery, + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } @@ -324,10 +324,10 @@ internal class QueryGatewayExtensionsTest { assertSame(queryResult, subscriptionQueryResult) verify(exactly = 1) { subjectGateway.subscriptionQuery( - queryName, - exampleQuery, - matchExpectedResponseType(InitialResponseType::class.java), - matchExpectedResponseType(UpdateResponseType::class.java) + queryName, + exampleQuery, + matchExpectedResponseType(InitialResponseType::class.java), + matchExpectedResponseType(UpdateResponseType::class.java) ) } } From f1688c3dcf50a59b656b0e1f7ab2020d689ca2c9 Mon Sep 17 00:00:00 2001 From: rsobies Date: Mon, 11 Apr 2022 21:17:26 +0200 Subject: [PATCH 7/8] inline extension functions added --- .../axonframework/extensions/kotlin/QueryGatewayExtensions.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index 716e1bbc..62bf091a 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -41,7 +41,9 @@ import java.util.stream.Stream * @see ResponseTypes * @since 0.1.0 */ -inline fun QueryGateway.queryMany(query: Q): CompletableFuture> = this.query(query, ResponseTypes.multipleInstancesOf(R::class.java)) +inline fun QueryGateway.queryMany(query: Q): CompletableFuture> { + return this.query(query, ResponseTypes.multipleInstancesOf(R::class.java)) +} /** * Reified version of [QueryGateway.query] with explicit query name From 6fdd32d49c70247d2effc97bc2318ca2f4a96aae Mon Sep 17 00:00:00 2001 From: rsobies Date: Wed, 13 Apr 2022 06:45:19 +0200 Subject: [PATCH 8/8] java doc update --- .../axonframework/extensions/kotlin/QueryGatewayExtensions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt index 62bf091a..fdfa12d3 100644 --- a/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt +++ b/kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/QueryGatewayExtensions.kt @@ -244,7 +244,7 @@ inline fun QueryGateway.scatterGatherOptional(queryName: * @return [SubscriptionQueryResult] wrapping the result of the query * @see QueryGateway.subscriptionQuery * @see ResponseTypes - * @since 0.1.0 + * @since 0.3.0 */ inline fun QueryGateway.subscriptionQuery(query: Q): SubscriptionQueryResult = this.subscriptionQuery(query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) @@ -260,7 +260,7 @@ inline fun QueryGateway.subscriptionQuery(quer * @return [SubscriptionQueryResult] wrapping the result of the query * @see QueryGateway.subscriptionQuery * @see ResponseTypes - * @since 0.1.0 + * @since 0.3.0 */ inline fun QueryGateway.subscriptionQuery(queryName: String, query: Q): SubscriptionQueryResult = this.subscriptionQuery(queryName, query, ResponseTypes.instanceOf(I::class.java), ResponseTypes.instanceOf(U::class.java)) \ No newline at end of file