Skip to content

Commit

Permalink
using metadata flavor of the fmodel - fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
idugalic committed Nov 26, 2023
1 parent ee954a0 commit d6a9fda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package com.fraktalio.example.fmodelspringdemo.adapter.web.rsocket
import com.fraktalio.example.fmodelspringdemo.application.Aggregate
import com.fraktalio.example.fmodelspringdemo.domain.Command
import com.fraktalio.example.fmodelspringdemo.domain.Event
import com.fraktalio.fmodel.application.handleOptimistically
import com.fraktalio.fmodel.application.handleOptimisticallyWithMetaData
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.messaging.handler.annotation.Payload
import org.springframework.stereotype.Controller
import java.util.*

@Controller
class AggregateRsocketCommandController(private val aggregate: Aggregate) {
@OptIn(ExperimentalCoroutinesApi::class)
@MessageMapping("commands")
fun handleCommand(@Payload commands: Flow<Command>): Flow<Event?> =
aggregate.handleOptimistically(commands).map { it.first }
aggregate.handleOptimisticallyWithMetaData(commands.map { Pair(it, mapOf("commandId" to UUID.randomUUID())) })
.map { it.first }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fraktalio.example.fmodelspringdemo.application

import com.fraktalio.example.fmodelspringdemo.domain.*
import com.fraktalio.fmodel.application.publishOptimisticallyTo
import com.fraktalio.fmodel.application.publishOptimisticallyWithMetaDataTo
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
Expand All @@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.TestConstructor
import org.springframework.test.context.TestConstructor.AutowireMode.ALL
import java.math.BigDecimal
import java.util.*


@SpringBootTest
Expand Down Expand Up @@ -47,7 +48,8 @@ class AggregateTest(private val aggregate: Aggregate) {

val events =
flowOf(createRestaurantCommand, changeRestaurantMenuCommand, placeOrderCommand, markOrderAsPreparedCommand)
.publishOptimisticallyTo(aggregate)
.map { Pair(it, mapOf("commandId" to UUID.randomUUID())) }
.publishOptimisticallyWithMetaDataTo(aggregate)
.map { it.first }
.toList()

Expand Down

0 comments on commit d6a9fda

Please sign in to comment.