Created
February 7, 2019 11:58
-
-
Save l0co/b0289baa669b691f3e97b727fc10c077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProcessTestEnvironment: EventLogger(DefaultClockImpl(), ObjectMapper()) { | |
| var processInstance: ProcessInstance? = null | |
| var exception: Throwable? = null // [1] the exception thrown by the process, if any | |
| set(value) { | |
| logger.debug("Exception thrown", value) | |
| field = value | |
| } | |
| val events: List<Map<String, Any>> = mutableListOf() | |
| protected val eventFlusher: AbstractEventFlusher = object: AbstractEventFlusher() { | |
| override fun closeFailure(commandContext: CommandContext?) { | |
| } | |
| override fun afterSessionsFlush(commandContext: CommandContext?) { | |
| } | |
| override fun closing(commandContext: CommandContext?) { | |
| // [2] extract data from event handlers | |
| for (eventHandler in eventHandlers) { | |
| val eventLogEntryEntity = eventHandler.generateEventLogEntry(commandContext) | |
| val map = objectMapper.readValue(eventLogEntryEntity.data, HashMap::class.java) as HashMap<String, Any> | |
| map[FIELD_TYPE] = eventLogEntryEntity.type | |
| (events as MutableList).add(map) | |
| } | |
| } | |
| } | |
| override fun createEventFlusher(): EventFlusher = eventFlusher | |
| override fun onEvent(event: FlowableEvent?) { | |
| // [3] getting the process instance on process start | |
| if (event is FlowableProcessStartedEventImpl && event.entity is ExecutionEntityImpl) { | |
| processInstance = (event.entity as ExecutionEntityImpl).processInstance | |
| } | |
| super.onEvent(event) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment