Skip to content

Commit 555b90e

Browse files
authored
Merge pull request #4 from AxonFramework/master
Merge master
2 parents d4ce3eb + ab706a1 commit 555b90e

File tree

8 files changed

+103
-19
lines changed

8 files changed

+103
-19
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ updates:
55
schedule:
66
interval: daily
77
open-pull-requests-limit: 10
8+
# Specify labels for pull requests
9+
labels:
10+
- "Type: Dependency Upgrade"
11+
- "Priority 1: Must"
12+
# Add reviewers
13+
reviewers:
14+
- "sandjelkovic"
15+
- "smcvb"

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Kotlin Extension Build and Tests
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
66
build:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2010-2020. Axon Framework
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.axonframework.extensions.kotlin
18+
19+
import org.axonframework.messaging.MetaData
20+
import org.axonframework.modelling.command.Aggregate
21+
import org.axonframework.modelling.command.AggregateLifecycle
22+
import org.axonframework.modelling.command.ApplyMore
23+
24+
/**
25+
* Alias for [AggregateLifecycle.apply] method.
26+
* @param payload payload of the event message to be applied.
27+
* @return fluent instance to apply more.
28+
*/
29+
fun applyEvent(payload: Any): ApplyMore = AggregateLifecycle.apply(payload)
30+
31+
/**
32+
* Alias for [AggregateLifecycle.apply] method.
33+
* @param payload payload of the event message to be applied.
34+
* @param metaData metadata to be included into the event message.
35+
* @return fluent instance to apply more.
36+
*/
37+
fun applyEvent(payload: Any, metaData: MetaData): ApplyMore = AggregateLifecycle.apply(payload, metaData)
38+
39+
/**
40+
* Create new aggregate instance.
41+
* @param [T] aggregate type.
42+
* @param factoryMethod factory method.
43+
*/
44+
inline fun <reified T : Any> createNew(noinline factoryMethod: () -> T): Aggregate<T> = AggregateLifecycle.createNew(T::class.java, factoryMethod)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2010-2020. Axon Framework
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.axonframework.extensions.kotlin
17+
18+
import org.axonframework.eventsourcing.EventSourcingRepository
19+
import org.axonframework.modelling.command.GenericJpaRepository
20+
21+
/**
22+
* Reified version of the static builder for event souring repository.
23+
* @param [T] aggregate type.
24+
* @return event sourcing repository builder for aggregate [T]
25+
*/
26+
inline fun <reified T : Any> eventSourcingRepositoryBuilder() = EventSourcingRepository.builder(T::class.java)
27+
28+
29+
/**
30+
* Reified version of the static builder for JPA repository.
31+
* @param [T] aggregate type.
32+
* @return Generic JPA repository builder for aggregate [T]
33+
*/
34+
inline fun <reified T : Any> genericJpaRepositoryBuilder() = GenericJpaRepository.builder(T::class.java)

kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/CommandGatewayExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import org.axonframework.messaging.MetaData
2929
* @param [C] the type of payload of the command
3030
* @see CommandGateway.send
3131
*/
32-
fun <C : Any, R : Any?> CommandGateway.send(
32+
inline fun <reified C : Any, reified R : Any?> CommandGateway.send(
3333
command: C,
34-
onSuccess: (commandMessage: CommandMessage<out C>, result: R, metaData: MetaData) -> Unit = { _, _, _ -> },
35-
onError: (commandMessage: CommandMessage<out C>, exception: Throwable, metaData: MetaData) -> Unit = { _, _, _ -> }
34+
noinline onSuccess: (commandMessage: CommandMessage<out C>, result: R, metaData: MetaData) -> Unit = { _, _, _ -> },
35+
noinline onError: (commandMessage: CommandMessage<out C>, exception: Throwable, metaData: MetaData) -> Unit = { _, _, _ -> }
3636
): Unit = this.send(command, ResultDiscriminatorCommandCallback<C, R>(onSuccess, onError))

kotlin/src/main/kotlin/org/axonframework/extensions/kotlin/ResultDiscriminatorCommandCallback.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ import org.axonframework.commandhandling.CommandResultMessage
2121
import org.axonframework.messaging.MetaData
2222

2323
/**
24-
* Implementation of the [CommandCallback] that is appropriate for dedicated [onError] and [onSuccess] callbacks
24+
* Implementation of the [CommandCallback] that is appropriate for dedicated [onError] and [onSuccess] callbacks.
2525
* @param onError Callback to handle failed execution. Defaults to an empty function
2626
* @param onSuccess Callback to handle successful execution. Defaults to an empty function
2727
* @param [R] the type of result of the command handling
2828
* @param [C] the type of payload of the command
2929
* @see CommandCallback
3030
* @author Stefan Andjelkovic
3131
*/
32-
internal class ResultDiscriminatorCommandCallback<C, R>(
32+
class ResultDiscriminatorCommandCallback<C, R>(
3333
val onSuccess: (commandMessage: CommandMessage<out C>, result: R, metaData: MetaData) -> Unit,
3434
val onError: (commandMessage: CommandMessage<out C>, exception: Throwable, metaData: MetaData) -> Unit
3535
) : CommandCallback<C, R> {
3636
override fun onResult(commandMessage: CommandMessage<out C>, commandResultMessage: CommandResultMessage<out R>) {
37-
val metaData = commandResultMessage.metaData ?: MetaData.emptyInstance()
37+
val metaData: MetaData = commandResultMessage.metaData ?: MetaData.emptyInstance()
3838
if (commandResultMessage.isExceptional) {
3939
onError(commandMessage, commandResultMessage.exceptionResult(), metaData)
4040
} else {

kotlin/src/test/kotlin/org/axonframework/extensions/kotlin/CommandGatewayExtensionsTest.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@
1515
*/
1616
package org.axonframework.extensions.kotlin
1717

18-
import io.mockk.Runs
19-
import io.mockk.every
20-
import io.mockk.just
21-
import io.mockk.mockk
22-
import io.mockk.verify
18+
import io.mockk.*
2319
import org.axonframework.commandhandling.CommandCallback
24-
import org.axonframework.commandhandling.CommandMessage
2520
import org.axonframework.commandhandling.gateway.CommandGateway
2621
import org.axonframework.messaging.MetaData
27-
import java.util.concurrent.TimeUnit
2822
import kotlin.test.Test
2923

3024
/**
@@ -41,7 +35,11 @@ internal class CommandGatewayExtensionsTest {
4135
fun `Send extension should invoke correct method on the gateway`() {
4236
every { subjectGateway.send(exampleCommand, any<CommandCallback<ExampleCommand, Any>>()) } just Runs
4337

44-
subjectGateway.send<ExampleCommand, Any>(command = exampleCommand, onError = { _, _, _ -> }, onSuccess = { _, _, _ -> })
38+
subjectGateway.send(
39+
command = exampleCommand,
40+
onError = { _, _, _ -> },
41+
onSuccess = { _, _: Any, _ -> }
42+
)
4543

4644
verify { subjectGateway.send(exampleCommand, any<CommandCallback<ExampleCommand, Any>>()) }
4745
}
@@ -52,8 +50,8 @@ internal class CommandGatewayExtensionsTest {
5250

5351
subjectGateway.send(
5452
command = exampleCommand,
55-
onError = { _: Any, _: Throwable, _: MetaData -> },
56-
onSuccess = { _: CommandMessage<out ExampleCommand>, _: Any, _: MetaData -> }
53+
onError = { _, _: Throwable, _: MetaData -> },
54+
onSuccess = { _, _: Any, _: MetaData -> }
5755
)
5856

5957
verify { subjectGateway.send(exampleCommand, any<CommandCallback<ExampleCommand, Any>>()) }

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3636
<kotlin.version>1.4.10</kotlin.version>
3737
<kotlin-logging.version>1.12.0</kotlin-logging.version>
38-
<jackson-kotlin.version>2.11.2</jackson-kotlin.version>
39-
<mockk.version>1.10.0</mockk.version>
38+
<jackson-kotlin.version>2.11.3</jackson-kotlin.version>
39+
<mockk.version>1.10.2</mockk.version>
4040
<junit.jupiter.version>5.7.0</junit.jupiter.version>
4141
<slf4j.version>1.7.30</slf4j.version>
4242
<log4j.version>2.13.3</log4j.version>

0 commit comments

Comments
 (0)