Skip to content

Commit

Permalink
FBP-100. Added tests for default flow sequence selector
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jul 1, 2023
1 parent 0317480 commit e7c8478
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnProcess
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnProcessBody
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.*
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.events.boundary.BpmnBoundaryErrorEvent
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.gateways.BpmnExclusiveGateway
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.subprocess.BpmnSubProcess
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.tasks.BpmnSendEventTask
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.tasks.BpmnServiceTask
Expand Down Expand Up @@ -54,6 +55,7 @@ import java.nio.charset.StandardCharsets
import java.util.*
import javax.swing.Icon
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JTable
import javax.swing.SwingConstants
import javax.swing.plaf.basic.BasicArrowButton
Expand Down Expand Up @@ -111,6 +113,7 @@ abstract class BaseUiTest {
protected val sendEventTaskBpmnId = BpmnElementId("sendEventTask")
protected val sendEventTaskBpmnIdFilled = BpmnElementId("sendEventTaskFilled")
protected val sequenceFlowBpmnId = BpmnElementId("sequenceFlow")
protected val exclusiveGatewayBpmnId = BpmnElementId("exclusiveGateway")

protected val optionalBoundaryErrorEventDiagramId = DiagramElementId("DIAGRAM-boundaryErrorEvent")
protected val subprocessInSubProcessDiagramId = DiagramElementId("DIAGRAM-nestedSubProcess")
Expand All @@ -119,8 +122,9 @@ abstract class BaseUiTest {
protected val serviceTaskEndDiagramId = DiagramElementId("DIAGRAM-endServiceTask")
protected val userTaskDiagramId = DiagramElementId("DIAGRAM-userTask")
protected val sendEventTaskDiagramId = DiagramElementId("DIAGRAM-sendEventTask")

protected val sequenceFlowDiagramId = DiagramElementId("DIAGRAM-sequenceFlow")
protected val exclusiveGatewayDiagramId = DiagramElementId("DIAGRAM-exclusiveGateway")

protected var bpmnSendEventTask = BpmnSendEventTask(sendEventTaskBpmnId, eventExtensionElements = listOf())
protected val bpmnServiceTaskStart = BpmnServiceTask(serviceTaskStartBpmnId, "Start service task", "Start service task docs")
protected val bpmnUserTask = BpmnUserTask(userTaskBpmnId, "Name user task", formPropertiesExtension = listOf(ExtensionFormProperty("Property ID", "Name property", null
Expand All @@ -131,13 +135,17 @@ abstract class BaseUiTest {
protected val bpmnNestedSubProcess = BpmnSubProcess(subprocessInSubProcessBpmnId, triggeredByEvent = false, transactionalSubprocess = false)
protected val bpmnServiceTaskEnd = BpmnServiceTask(serviceTaskEndBpmnId)
protected val bpmnSequenceFlow = BpmnSequenceFlow(sequenceFlowBpmnId)
protected val bpmnExclusiveGateway = BpmnExclusiveGateway(exclusiveGatewayBpmnId)

protected val diagramServiceTaskStart = ShapeElement(serviceTaskStartDiagramId, bpmnServiceTaskStart.id, BoundsElement(startElemX, startElemY, taskSize, taskSize))
protected val diagramServiceTaskEnd = ShapeElement(serviceTaskEndDiagramId, bpmnServiceTaskEnd.id, BoundsElement(endElemX, endElemY, taskSize, taskSize))
protected val diagramUserTask = ShapeElement(userTaskDiagramId, bpmnUserTask.id, BoundsElement(userTaskElemX, userTaskElemY, taskSize, taskSize))
protected val diagramSendEventTask = ShapeElement(sendEventTaskDiagramId, bpmnSendEventTask.id, BoundsElement(startElemX, startElemY, taskSize, taskSize))
protected val diagramSubProcess = ShapeElement(subprocessDiagramId, subprocessBpmnId, BoundsElement(subProcessElemX, subProcessElemY, subProcessSize, subProcessSize))
protected val diagramNestedSubProcess = ShapeElement(subprocessInSubProcessDiagramId, subprocessInSubProcessBpmnId, BoundsElement(subProcessElemX, subProcessElemY, nestedSubProcessSize, nestedSubProcessSize))
protected val diagramSequenceFlow = EdgeElement(sequenceFlowDiagramId, sequenceFlowBpmnId, listOf(WaypointElement(endElemX, endElemY), WaypointElement(endElemX - 20.0f, endElemY - 20.0f), WaypointElement(endElemX - 30.0f, endElemY - 30.0f)))
protected val diagramExclusiveGateway = ShapeElement(exclusiveGatewayDiagramId, bpmnExclusiveGateway.id, BoundsElement(startElemX, startElemY, taskSize, taskSize))


protected val icons = mock<IconProvider>()
protected val renderer = spy(DefaultBpmnProcessRenderer(project, icons))
Expand Down Expand Up @@ -196,6 +204,7 @@ abstract class BaseUiTest {
protected val checkboxFieldFactory = { id: BpmnElementId, type: PropertyType, value: Boolean -> boolFieldsConstructed.computeIfAbsent(Pair(id, type)) {
val res = mock<SelectedValueAccessor>()
whenever(res.isSelected).thenReturn(value)
whenever(res.component).thenReturn(JCheckBox())
return@computeIfAbsent res
} }
protected val buttonFactory = { id: BpmnElementId, type: FunctionalGroupType -> buttonsConstructed.computeIfAbsent(Pair(id, type)) {
Expand Down Expand Up @@ -772,6 +781,24 @@ abstract class BaseUiTest {
initializeCanvas()
}

protected fun prepareExclusiveGatewayAttachedToServiceTaskWithFlowSequence() {
val process = basicProcess.copy(
basicProcess.process.copy(
body = basicProcessBody.copy(
exclusiveGateway = listOf(bpmnExclusiveGateway),
serviceTask = listOf(bpmnServiceTaskEnd),
sequenceFlow = listOf(bpmnSequenceFlow.copy(sourceRef = exclusiveGatewayBpmnId.id))
)
),
listOf(DiagramElement(
diagramMainElementId,
PlaneElement(diagramMainPlaneElementId, basicProcess.process.id, listOf(diagramExclusiveGateway, diagramServiceTaskEnd), listOf(diagramSequenceFlow)))
)
)
whenever(parser.parse("")).thenReturn(process)
initializeCanvas()
}

protected fun elemAreaById(id: DiagramElementId) = renderResult?.areas?.get(id)!!

protected fun findFirstNewLinkElem() = renderResult?.areas?.keys?.firstOrNull { it.id.contains(newLink) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.valb3r.bpmn.intellij.plugin

import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.argumentCaptor
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.EventPropagatableToXml
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.core.events.BooleanValueUpdatedEvent
import com.valb3r.bpmn.intellij.plugin.core.events.StringValueUpdatedEvent
import com.valb3r.bpmn.intellij.plugin.core.newelements.registerNewElementsFactory
import com.valb3r.bpmn.intellij.plugin.core.properties.propertiesVisualizer
import com.valb3r.bpmn.intellij.plugin.core.tests.BaseUiTest
import com.valb3r.bpmn.intellij.plugin.flowable.parser.FlowableObjectFactory
import org.amshove.kluent.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import javax.swing.JCheckBox
import javax.swing.table.DefaultTableModel

internal class FlowSequenceTest: BaseUiTest() {

@BeforeEach
fun prepare() {
registerNewElementsFactory(project, FlowableObjectFactory())
}

@Test
fun `No Default flow selection on flow sequence element without gateway`() {
prepareOneSubProcessWithServiceTaskAndAttachedBoundaryEventOneNestedSubprocessAndServiceTaskWithSequence()
clickOnId(sequenceFlowDiagramId)
val propertiesVisible = (0 until propertiesTable.model.rowCount).map { propertiesTable.model.getValueAt(it, 0) as String }
propertiesVisible.shouldNotContain(PropertyType.DEFAULT_FLOW_ON_SEQUENCE.caption)
}

@Test
fun `Default flow selection present on flow sequence element with gateway`() {
prepareExclusiveGatewayAttachedToServiceTaskWithFlowSequence()
clickOnId(sequenceFlowDiagramId)

val propertiesVisible = (0 until propertiesTable.model.rowCount).map { propertiesTable.model.getValueAt(it, 0) as String }
propertiesVisible.shouldContain(PropertyType.DEFAULT_FLOW_ON_SEQUENCE.caption)

whenever(boolFieldsConstructed[Pair(sequenceFlowBpmnId, PropertyType.DEFAULT_FLOW_ON_SEQUENCE)]!!.isSelected).thenReturn(true)
propertiesVisualizer(project).clear()

argumentCaptor<List<EventPropagatableToXml>>().apply {
verify(fileCommitter).executeCommitAndGetHash(any(), capture(), any(), any())
firstValue.shouldHaveSize(2)
val xmlOnlyUpdate = firstValue.filterIsInstance<StringValueUpdatedEvent>().shouldHaveSingleItem()
val uiOnlyUpdate = firstValue.filterIsInstance<BooleanValueUpdatedEvent>().shouldHaveSingleItem()
xmlOnlyUpdate.bpmnElementId.shouldBeEqualTo(exclusiveGatewayBpmnId)
xmlOnlyUpdate.property.shouldBeEqualTo(PropertyType.DEFAULT_FLOW)
uiOnlyUpdate.bpmnElementId.shouldBeEqualTo(sequenceFlowBpmnId)
uiOnlyUpdate.property.shouldBeEqualTo(PropertyType.DEFAULT_FLOW_ON_SEQUENCE)
}

}
}

0 comments on commit e7c8478

Please sign in to comment.