diff --git a/bpmn-intellij-plugin-common-tests/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/core/tests/BaseUiTest.kt b/bpmn-intellij-plugin-common-tests/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/core/tests/BaseUiTest.kt index 398ec7ae..2a0988f8 100644 --- a/bpmn-intellij-plugin-common-tests/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/core/tests/BaseUiTest.kt +++ b/bpmn-intellij-plugin-common-tests/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/core/tests/BaseUiTest.kt @@ -57,6 +57,7 @@ import javax.swing.Icon import javax.swing.JButton import javax.swing.JCheckBox import javax.swing.JTable +import javax.swing.JTextField import javax.swing.SwingConstants import javax.swing.plaf.basic.BasicArrowButton import javax.swing.table.TableColumn @@ -194,6 +195,7 @@ abstract class BaseUiTest { protected val editorFactory = { id: BpmnElementId, type: PropertyType, value: String -> textFieldsConstructed.computeIfAbsent(Pair(id, type)) { val res = mock() whenever(res.text).thenReturn(value) + whenever(res.component).thenReturn(JTextField()) return@computeIfAbsent res } } protected val multiLineEditorFactory = { id: BpmnElementId, type: PropertyType, value: String -> multiLineTextFieldsConstructed.computeIfAbsent(Pair(id, type)) { diff --git a/bpmn-intellij-plugin-core/src/test/kotlin/com/valb3r/bpmn/intellij/plugin/ValidationTest.kt b/bpmn-intellij-plugin-core/src/test/kotlin/com/valb3r/bpmn/intellij/plugin/ValidationTest.kt new file mode 100644 index 00000000..80698724 --- /dev/null +++ b/bpmn-intellij-plugin-core/src/test/kotlin/com/valb3r/bpmn/intellij/plugin/ValidationTest.kt @@ -0,0 +1,47 @@ +package com.valb3r.bpmn.intellij.plugin + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.never +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType +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.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import javax.swing.JTextField + +internal class ValidationTest: BaseUiTest() { + + @BeforeEach + fun prepare() { + registerNewElementsFactory(project, FlowableObjectFactory()) + prepareTwoServiceTaskView() + } + + @Test + fun `Invalid ID (duplicate) not propagated`() { + clickOnId(serviceTaskEndDiagramId) + val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!! + whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id) + (idField.component as JTextField).text = serviceTaskStartBpmnId.id + + propertiesVisualizer(project).clear() + + verify(fileCommitter, never()).executeCommitAndGetHash(any(), any(), any(), any()) + } + + @Test + fun `Valid ID (not duplicate) propagated`() { + clickOnId(serviceTaskEndDiagramId) + val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!! + whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id + '1') + (idField.component as JTextField).text = serviceTaskStartBpmnId.id + '1' + + propertiesVisualizer(project).clear() + + verify(fileCommitter).executeCommitAndGetHash(any(), any(), any(), any()) + } +} \ No newline at end of file