Skip to content

Commit

Permalink
IJMP-977: fix display of warning if create ws/jws without masks/filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzianis Lisiankou committed Jan 25, 2024
1 parent 940d496 commit 4fd0b22
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ abstract class AbstractWsDialog<Connection : ConnectionConfigBase, WSConfig : Wo
var initialState: WSDState = state.clone(wsdStateClass)
) : DialogWrapper(false), StatefulComponent<WSDState> {

companion object {

// TODO: Remove when it becomes possible to mock class constructor with init section.
/** Wrapper for init() method. It is necessary only for test purposes for now. */
private fun initialize(init: () -> Unit) {
init()
}
}

abstract val wsConfigClass: Class<out WSConfig>
abstract val connectionClass: Class<out Connection>

Expand Down Expand Up @@ -155,6 +164,14 @@ abstract class AbstractWsDialog<Connection : ConnectionConfigBase, WSConfig : Wo
}
}

/** Register validator that enables OK action if validation map is empty */
override fun init() {
initialize { super.init() }
panel.registerValidators(myDisposable) { map ->
isOKActionEnabled = map.isEmpty()
}
}

override fun createCenterPanel(): JComponent {
return panel
}
Expand Down
48 changes: 42 additions & 6 deletions src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ package eu.ibagroup.formainframe.config

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.ui.ValidationInfo
import eu.ibagroup.formainframe.config.connect.ConnectionConfig
import eu.ibagroup.formainframe.config.connect.Credentials
import eu.ibagroup.formainframe.config.connect.CredentialsConfigDeclaration
Expand All @@ -24,6 +26,9 @@ import eu.ibagroup.formainframe.config.connect.ui.zosmf.initEmptyUuids
import eu.ibagroup.formainframe.config.connect.whoAmI
import eu.ibagroup.formainframe.config.ws.FilesWorkingSetConfig
import eu.ibagroup.formainframe.config.ws.JesWorkingSetConfig
import eu.ibagroup.formainframe.config.ws.ui.AbstractWsDialog
import eu.ibagroup.formainframe.config.ws.ui.FilesWorkingSetDialogState
import eu.ibagroup.formainframe.config.ws.ui.files.FilesWorkingSetDialog
import eu.ibagroup.formainframe.dataops.DataOpsManager
import eu.ibagroup.formainframe.dataops.Operation
import eu.ibagroup.formainframe.dataops.operations.TsoOperation
Expand All @@ -38,16 +43,14 @@ import eu.ibagroup.formainframe.utils.service
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import io.mockk.*
import org.zowe.kotlinsdk.MessageType
import org.zowe.kotlinsdk.TsoData
import org.zowe.kotlinsdk.TsoResponse
import org.zowe.kotlinsdk.annotations.ZVersion
import java.util.*
import java.util.stream.Stream
import javax.swing.JComponent
import kotlin.reflect.KFunction

class ConfigTestSpec : WithApplicationShouldSpec({
Expand Down Expand Up @@ -322,6 +325,31 @@ class ConfigTestSpec : WithApplicationShouldSpec({
should("check if the sandbox is modified") {}
}
context("config module: ws") {

lateinit var crudableMockk: Crudable

beforeEach {
mockkObject(AbstractWsDialog)
every { AbstractWsDialog["initialize"](any<() -> Unit>()) } returns Unit

crudableMockk = mockk<Crudable>()
every { crudableMockk.getAll(ConnectionConfig::class.java) } returns Stream.of()
every {
crudableMockk.getByUniqueKey(ConnectionConfig::class.java, any<String>())
} returns Optional.of(ConnectionConfig())

mockkConstructor(DialogPanel::class)
every { anyConstructed<DialogPanel>().registerValidators(any(), any()) } answers {
val componentValidityChangedCallback = secondArg<(Map<JComponent, ValidationInfo>) -> Unit>()
componentValidityChangedCallback(mapOf())
}
}

afterEach {
unmockkAll()
clearAllMocks()
}

// WSNameColumn.validateEntered
should("check that the entered working set name is not empty") {}
should("check that the entered working set name is not blank") {}
Expand All @@ -335,5 +363,13 @@ class ConfigTestSpec : WithApplicationShouldSpec({
should("check that the error appears on any errors for file masks") {}
should("check that the error appears on empty file working set") {}
should("check that the error appears on adding the same file mask again") {}
// ui/AbstractWsDialog.init
should("check that OK action is enabled if validation map is empty") {

val dialog = FilesWorkingSetDialog(crudableMockk, FilesWorkingSetDialogState())

verify { anyConstructed<DialogPanel>().registerValidators(any(), any()) }
assertSoftly { dialog.isOKActionEnabled shouldBe true }
}
}
})

0 comments on commit 4fd0b22

Please sign in to comment.