From af919441a805e1a2087988fd00e7ec64b34c96e6 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Thu, 17 Aug 2023 19:29:45 +0200 Subject: [PATCH 1/7] Release/v1.1.1-221 created Signed-off-by: Uladzislau --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 13bb1301a..1d70e0a01 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ apply(plugin = "kotlin") apply(plugin = "org.jetbrains.intellij") group = "eu.ibagroup" -version = "1.1.0-221" +version = "1.1.1-221" val remoteRobotVersion = "0.11.18" val okHttp3Version = "4.10.0" val kotestVersion = "5.5.5" From 7345e6eb582a81ce37736e17331ca514e43df47a Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Thu, 17 Aug 2023 19:31:33 +0200 Subject: [PATCH 2/7] IJMP-1230 Trying to fix PurgeJobAction tests --- build.gradle.kts | 4 +- .../actions/PurgeJobActionTestSpec.kt | 624 +++++++++--------- 2 files changed, 313 insertions(+), 315 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1d70e0a01..a1d0d6f08 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,7 +23,7 @@ apply(plugin = "org.jetbrains.intellij") group = "eu.ibagroup" version = "1.1.1-221" -val remoteRobotVersion = "0.11.18" +val remoteRobotVersion = "0.11.19" val okHttp3Version = "4.10.0" val kotestVersion = "5.5.5" @@ -61,7 +61,7 @@ dependencies { implementation("org.jgrapht:jgrapht-core:1.5.1") implementation("org.zowe.sdk:zowe-kotlin-sdk:0.4.0") implementation("com.segment.analytics.java:analytics:3.3.1") - implementation("com.ibm.mq:com.ibm.mq.allclient:9.3.0.0") + implementation("com.ibm.mq:com.ibm.mq.allclient:9.3.3.0") testImplementation("io.mockk:mockk:1.13.5") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2") testImplementation("io.kotest:kotest-assertions-core:$kotestVersion") diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt index 3331aacf3..0f2a0931b 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt @@ -1,315 +1,313 @@ package eu.ibagroup.formainframe.explorer.actions -// TODO: this test suite needs to be reworked (?) as it gives StackOverflowError. May be the problem with MockK/Kotest - -// import com.intellij.notification.NotificationType -// import com.intellij.openapi.actionSystem.AnActionEvent -// import com.intellij.openapi.actionSystem.DataKey -// import com.intellij.openapi.application.ApplicationManager -// import com.intellij.openapi.progress.ProgressIndicator -// import com.intellij.openapi.project.Project -// import com.intellij.openapi.vfs.VirtualFile -// import com.intellij.testFramework.LightProjectDescriptor -// import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -// import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl -// import eu.ibagroup.formainframe.api.ZosmfApi -// import eu.ibagroup.formainframe.config.connect.ConnectionConfig -// import eu.ibagroup.formainframe.config.connect.CredentialService -// import eu.ibagroup.formainframe.config.ws.JobsFilter -// import eu.ibagroup.formainframe.dataops.DataOpsManager -// import eu.ibagroup.formainframe.dataops.Operation -// import eu.ibagroup.formainframe.dataops.UnitRemoteQueryImpl -// import eu.ibagroup.formainframe.dataops.attributes.FileAttributes -// import eu.ibagroup.formainframe.dataops.attributes.JobsRequester -// import eu.ibagroup.formainframe.dataops.attributes.RemoteJobAttributes -// import eu.ibagroup.formainframe.dataops.log.JobLogFetcher -// import eu.ibagroup.formainframe.dataops.log.MFLogger -// import eu.ibagroup.formainframe.explorer.Explorer -// import eu.ibagroup.formainframe.explorer.JesWorkingSetImpl -// import eu.ibagroup.formainframe.explorer.ui.ErrorNode -// import eu.ibagroup.formainframe.explorer.ui.JesExplorerView -// import eu.ibagroup.formainframe.explorer.ui.JesFilterNode -// import eu.ibagroup.formainframe.explorer.ui.JobNode -// import eu.ibagroup.formainframe.explorer.ui.NodeData -// import eu.ibagroup.formainframe.explorer.ui.getExplorerView -// import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl -// import eu.ibagroup.formainframe.ui.build.jobs.JobBuildTreeView -// import eu.ibagroup.formainframe.utils.gson -// import eu.ibagroup.formainframe.utils.service -// import eu.ibagroup.formainframe.vfs.MFVirtualFile -// import io.kotest.assertions.assertSoftly -// import io.kotest.core.spec.style.ShouldSpec -// import io.kotest.matchers.shouldBe -// import io.mockk.clearAllMocks -// import io.mockk.every -// import io.mockk.justRun -// import io.mockk.mockk -// import io.mockk.mockkObject -// import io.mockk.spyk -// import org.zowe.kotlinsdk.CancelJobPurgeOutRequest -// import org.zowe.kotlinsdk.JESApi -// import org.zowe.kotlinsdk.Job -// import retrofit2.Call -// import retrofit2.Response - -// class PurgeJobActionTestSpec : ShouldSpec({ -// beforeSpec { -// // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE -// val factory = IdeaTestFixtureFactory.getFixtureFactory() -// val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR -// val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") -// val fixture = fixtureBuilder.fixture -// val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( -// fixture, -// LightTempDirTestFixtureImpl(true) -// ) -// myFixture.setUp() -// } -// afterSpec { -// clearAllMocks() -// } -// context("explorer module: actions/PurgeJobAction") { -// context("actionPerformed") { -// val purgeAction = PurgeJobAction() -// val mockActionEventForJesEx = mockk() -// val jesExplorerView = mockk() - -// val job = mockk() -// every { job.jobName } returns "name" -// every { job.jobId } returns "id" -// val connectionConfig = mockk() -// every { connectionConfig.uuid } returns "uuid" -// val jobsFilter = spyk( -// JobsFilter( -// "owner", -// "prefix", -// "id" -// ) -// ) -// mockkObject(gson) -// every { gson.hint(Job::class).fromJson(any() as String, Job::class.java) } returns job - -// mockkObject(CredentialService) -// every { CredentialService.instance.getUsernameByKey(any()) } returns "user" -// every { CredentialService.instance.getPasswordByKey(any()) } returns "pas" - -// every { mockActionEventForJesEx.getExplorerView() } returns jesExplorerView - -// val jobNode = mockk() -// val virtualFile = mockk() - -// val nodeData = spyk( -// NodeData( -// jobNode, -// virtualFile, -// null -// ) -// ) -// every { jesExplorerView.mySelectedNodesData } returns listOf(nodeData) - -// val parentNode = mockk() -// val query = spyk( -// UnitRemoteQueryImpl( -// jobsFilter, -// connectionConfig -// ) -// ) -// every { parentNode.query } returns query -// justRun { parentNode.cleanCache() } - -// val jesApi = mockk() -// val call = mockk>>() -// mockkObject(ZosmfApi) -// every { ZosmfApi.instance.hint(JESApi::class).getApi(any(), any()) } returns jesApi -// every { jesApi.getFilteredJobs(any(), any(), any(), any(), any(), any(), any(), any()) } returns call - -// val response = mockk>>() -// val jobList = mutableListOf(job, job) -// every { call.execute() } returns response -// every { -// hint(List::class) -// response.body() -// } answers { -// if (jobList.isNotEmpty()) { -// jobList.removeFirst() -// jobList -// } else { -// null -// } -// } -// every { response.isSuccessful } returns true - -// every { jobNode.virtualFile } returns virtualFile -// every { jobNode.parent } returns parentNode - -// val explorer = mockk>() -// every { jobNode.explorer } returns explorer -// every { explorer.componentManager } returns ApplicationManager.getApplication() - -// lateinit var dataOpsManager: TestDataOpsManagerImpl - -// val project = mockk() -// every { -// mockActionEventForJesEx.project -// } returns project - -// every { -// jesExplorerView.explorer -// } returns explorer - -// val mockRequest = mockk() -// val jobAttr = spyk( -// RemoteJobAttributes( -// job, -// "test", -// mutableListOf(JobsRequester(connectionConfig, jobsFilter)) -// ) -// ) -// every { jobAttr.clone() } returns jobAttr - -// val mockActionEventForJobsLog = mockk() -// val jobsLogView = mockk() - -// every { mockActionEventForJobsLog.getData(any() as DataKey) } returns jobsLogView -// every { mockActionEventForJobsLog.project } returns project - -// val mockkLogger = mockk>() -// val mockkFetcher = mockk() - -// every { jobsLogView.getJobLogger() } returns mockkLogger -// every { -// hint(JobLogFetcher::class) -// mockkLogger.logFetcher -// } returns mockkFetcher -// every { mockkFetcher.getCachedJobStatus() } returns job -// every { jobsLogView.getConnectionConfig() } returns connectionConfig - -// should("perform purge on job successfully") { - -// dataOpsManager = ApplicationManager.getApplication().service() as TestDataOpsManagerImpl -// dataOpsManager.testInstance = object : TestDataOpsManagerImpl(explorer.componentManager) { -// override fun tryToGetAttributes(file: VirtualFile): FileAttributes { -// return jobAttr -// } - -// override fun performOperation(operation: Operation, progressIndicator: ProgressIndicator): R { -// return mockRequest as R -// } - -// } - -// var isOperationSucceededForJesEx = false -// every { -// explorer.showNotification(any(), any(), NotificationType.INFORMATION, any()) -// } answers { -// isOperationSucceededForJesEx = true -// } - -// var isOperationSucceededForJobsLog = false -// every { -// jobsLogView.showNotification(any(), any(), any(), NotificationType.INFORMATION) -// } answers { -// isOperationSucceededForJobsLog = true -// } - -// var isVisibleInJes = false -// every { mockActionEventForJesEx.presentation.isVisible = true } answers { isVisibleInJes = true } - -// every { job.status } returns mockk() -// var isEnabledInJobsLog = true -// every { mockActionEventForJobsLog.presentation.isEnabled = false } answers { isEnabledInJobsLog = false } - -// purgeAction.actionPerformed(mockActionEventForJesEx) -// purgeAction.update(mockActionEventForJesEx) -// purgeAction.actionPerformed(mockActionEventForJobsLog) -// purgeAction.update(mockActionEventForJobsLog) - -// assertSoftly { -// isOperationSucceededForJesEx shouldBe true -// isOperationSucceededForJobsLog shouldBe true -// isVisibleInJes shouldBe true -// isEnabledInJobsLog shouldBe true -// purgeAction.isDumbAware shouldBe true -// } - -// } -// should("perform purge on job with error") { - -// val updateJesAction = mockk() -// val jesViewForUpdate = mockk() -// every { updateJesAction.getExplorerView() } returns jesViewForUpdate -// every { jesViewForUpdate.mySelectedNodesData } returns listOf() - -// val updateJesAction2 = mockk() -// val jesViewForUpdate2 = mockk() -// every { updateJesAction2.getExplorerView() } returns jesViewForUpdate2 -// val errorNode = mockk>() -// every { jesViewForUpdate2.mySelectedNodesData } returns listOf( -// NodeData( -// errorNode, -// virtualFile, -// null -// ) -// ) - -// dataOpsManager = ApplicationManager.getApplication().service() as TestDataOpsManagerImpl -// dataOpsManager.testInstance = object : TestDataOpsManagerImpl(explorer.componentManager) { -// override fun tryToGetAttributes(file: VirtualFile): FileAttributes { -// return jobAttr -// } - -// override fun performOperation(operation: Operation, progressIndicator: ProgressIndicator): R { -// throw IllegalStateException("No operation is expected to be performed.") -// } -// } - -// var isOperationFailedForJesEx = false -// every { -// explorer.showNotification(any(), any(), NotificationType.ERROR, any()) -// } answers { -// isOperationFailedForJesEx = true -// } - -// var isOperationFailedForJobsLog = false -// every { -// jobsLogView.showNotification(any(), any(), any(), NotificationType.ERROR) -// } answers { -// isOperationFailedForJobsLog = true -// } - -// var isOperationFailedForNoContextAction = false -// val mockActionEventWithoutDataContext = mockk() -// every { mockActionEventWithoutDataContext.getData(any() as DataKey) } returns null -// every { mockActionEventWithoutDataContext.presentation.isEnabledAndVisible = false } answers { -// isOperationFailedForNoContextAction = true -// } - -// every { job.status } returns null -// var isEnabledInJobsLog = true -// every { mockActionEventForJobsLog.presentation.isEnabled = false } answers { isEnabledInJobsLog = false } - -// var isVisibleForJes = true -// every { updateJesAction.presentation.isVisible = false } answers { isVisibleForJes = false } -// var isVisibleForJes2 = true -// every { updateJesAction2.presentation.isVisible = false } answers { isVisibleForJes2 = false } - -// purgeAction.actionPerformed(mockActionEventForJesEx) -// purgeAction.actionPerformed(mockActionEventForJobsLog) -// purgeAction.actionPerformed(mockActionEventWithoutDataContext) -// purgeAction.update(mockActionEventWithoutDataContext) -// purgeAction.update(mockActionEventForJobsLog) -// purgeAction.update(updateJesAction) -// purgeAction.update(updateJesAction2) - -// assertSoftly { -// isOperationFailedForJesEx shouldBe true -// isOperationFailedForJobsLog shouldBe true -// isEnabledInJobsLog shouldBe false -// isVisibleForJes shouldBe false -// isVisibleForJes2 shouldBe false -// isOperationFailedForNoContextAction shouldBe true -// } -// } -// } -// } -// }) +import com.intellij.notification.NotificationType +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.DataKey +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory +import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl +import eu.ibagroup.formainframe.api.ZosmfApi +import eu.ibagroup.formainframe.config.connect.ConnectionConfig +import eu.ibagroup.formainframe.config.connect.CredentialService +import eu.ibagroup.formainframe.config.ws.JobsFilter +import eu.ibagroup.formainframe.dataops.DataOpsManager +import eu.ibagroup.formainframe.dataops.Operation +import eu.ibagroup.formainframe.dataops.UnitRemoteQueryImpl +import eu.ibagroup.formainframe.dataops.attributes.FileAttributes +import eu.ibagroup.formainframe.dataops.attributes.JobsRequester +import eu.ibagroup.formainframe.dataops.attributes.RemoteJobAttributes +import eu.ibagroup.formainframe.dataops.log.JobLogFetcher +import eu.ibagroup.formainframe.dataops.log.MFLogger +import eu.ibagroup.formainframe.explorer.Explorer +import eu.ibagroup.formainframe.explorer.JesWorkingSetImpl +import eu.ibagroup.formainframe.explorer.ui.ErrorNode +import eu.ibagroup.formainframe.explorer.ui.JesExplorerView +import eu.ibagroup.formainframe.explorer.ui.JesFilterNode +import eu.ibagroup.formainframe.explorer.ui.JobNode +import eu.ibagroup.formainframe.explorer.ui.NodeData +import eu.ibagroup.formainframe.explorer.ui.getExplorerView +import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.ui.build.jobs.JobBuildTreeView +import eu.ibagroup.formainframe.utils.gson +import eu.ibagroup.formainframe.utils.service +import eu.ibagroup.formainframe.vfs.MFVirtualFile +import io.kotest.assertions.assertSoftly +import io.kotest.core.spec.style.ShouldSpec +import io.kotest.matchers.shouldBe +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.justRun +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.spyk +import org.zowe.kotlinsdk.CancelJobPurgeOutRequest +import org.zowe.kotlinsdk.JESApi +import org.zowe.kotlinsdk.Job +import retrofit2.Call +import retrofit2.Response + +class PurgeJobActionTestSpec : ShouldSpec({ + beforeSpec { + // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE + val factory = IdeaTestFixtureFactory.getFixtureFactory() + val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR + val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") + val fixture = fixtureBuilder.fixture + val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( + fixture, + LightTempDirTestFixtureImpl(true) + ) + myFixture.setUp() + } + afterSpec { + clearAllMocks() + } + context("explorer module: actions/PurgeJobAction") { + context("actionPerformed") { + val purgeAction = PurgeJobAction() + val mockActionEventForJesEx = mockk() + val jesExplorerView = mockk() + + val job = mockk() + every { job.jobName } returns "name" + every { job.jobId } returns "id" + val connectionConfig = mockk() + every { connectionConfig.uuid } returns "uuid" + val jobsFilter = spyk( + JobsFilter( + "owner", + "prefix", + "id" + ) + ) + mockkObject(gson) + every { gson.hint(Job::class).fromJson(any() as String, Job::class.java) } returns job + + mockkObject(CredentialService) + every { CredentialService.instance.getUsernameByKey(any()) } returns "user" + every { CredentialService.instance.getPasswordByKey(any()) } returns "pas" + + every { mockActionEventForJesEx.getExplorerView() } returns jesExplorerView + + val jobNode = mockk() + val virtualFile = mockk() + + val nodeData = spyk( + NodeData( + jobNode, + virtualFile, + null + ) + ) + every { jesExplorerView.mySelectedNodesData } returns listOf(nodeData) + + val parentNode = mockk() + val query = spyk( + UnitRemoteQueryImpl( + jobsFilter, + connectionConfig + ) + ) + every { parentNode.query } returns query + justRun { parentNode.cleanCache() } + + val jesApi = mockk() + val call = mockk>>() + mockkObject(ZosmfApi) + every { ZosmfApi.instance.hint(JESApi::class).getApi(any(), any()) } returns jesApi + every { jesApi.getFilteredJobs(any(), any(), any(), any(), any(), any(), any(), any()) } returns call + + val response = mockk>>() + val jobList = mutableListOf(job, job) + every { call.execute() } returns response + every { + hint(List::class) + response.body() + } answers { + if (jobList.isNotEmpty()) { + jobList.removeFirst() + jobList + } else { + null + } + } + every { response.isSuccessful } returns true + + every { jobNode.virtualFile } returns virtualFile + every { jobNode.parent } returns parentNode + + val explorer = mockk>() + every { jobNode.explorer } returns explorer + every { explorer.componentManager } returns ApplicationManager.getApplication() + + lateinit var dataOpsManager: TestDataOpsManagerImpl + + val project = mockk() + every { + mockActionEventForJesEx.project + } returns project + + every { + jesExplorerView.explorer + } returns explorer + + val mockRequest = mockk() + val jobAttr = spyk( + RemoteJobAttributes( + job, + "test", + mutableListOf(JobsRequester(connectionConfig, jobsFilter)) + ) + ) + every { jobAttr.clone() } returns jobAttr + + val mockActionEventForJobsLog = mockk() + val jobsLogView = mockk() + + every { mockActionEventForJobsLog.getData(any() as DataKey) } returns jobsLogView + every { mockActionEventForJobsLog.project } returns project + + val mockkLogger = mockk>() + val mockkFetcher = mockk() + + every { jobsLogView.getJobLogger() } returns mockkLogger + every { + hint(JobLogFetcher::class) + mockkLogger.logFetcher + } returns mockkFetcher + every { mockkFetcher.getCachedJobStatus() } returns job + every { jobsLogView.getConnectionConfig() } returns connectionConfig + + should("perform purge on job successfully") { + + dataOpsManager = ApplicationManager.getApplication().service() as TestDataOpsManagerImpl + dataOpsManager.testInstance = object : TestDataOpsManagerImpl(explorer.componentManager) { + override fun tryToGetAttributes(file: VirtualFile): FileAttributes { + return jobAttr + } + + override fun performOperation(operation: Operation, progressIndicator: ProgressIndicator): R { + return mockRequest as R + } + + } + + var isOperationSucceededForJesEx = false + every { + explorer.showNotification(any(), any(), NotificationType.INFORMATION, any()) + } answers { + isOperationSucceededForJesEx = true + } + + var isOperationSucceededForJobsLog = false + every { + jobsLogView.showNotification(any(), any(), any(), NotificationType.INFORMATION) + } answers { + isOperationSucceededForJobsLog = true + } + + var isVisibleInJes = false + every { mockActionEventForJesEx.presentation.isVisible = true } answers { isVisibleInJes = true } + + every { job.status } returns mockk() + var isEnabledInJobsLog = true + every { mockActionEventForJobsLog.presentation.isEnabled = false } answers { isEnabledInJobsLog = false } + + purgeAction.actionPerformed(mockActionEventForJesEx) + purgeAction.update(mockActionEventForJesEx) + purgeAction.actionPerformed(mockActionEventForJobsLog) + purgeAction.update(mockActionEventForJobsLog) + + assertSoftly { + isOperationSucceededForJesEx shouldBe true + isOperationSucceededForJobsLog shouldBe true + isVisibleInJes shouldBe true + isEnabledInJobsLog shouldBe true + purgeAction.isDumbAware shouldBe true + } + + } + should("perform purge on job with error") { + + val updateJesAction = mockk() + val jesViewForUpdate = mockk() + every { updateJesAction.getExplorerView() } returns jesViewForUpdate + every { jesViewForUpdate.mySelectedNodesData } returns listOf() + + val updateJesAction2 = mockk() + val jesViewForUpdate2 = mockk() + every { updateJesAction2.getExplorerView() } returns jesViewForUpdate2 + val errorNode = mockk>() + every { jesViewForUpdate2.mySelectedNodesData } returns listOf( + NodeData( + errorNode, + virtualFile, + null + ) + ) + + dataOpsManager = ApplicationManager.getApplication().service() as TestDataOpsManagerImpl + dataOpsManager.testInstance = object : TestDataOpsManagerImpl(explorer.componentManager) { + override fun tryToGetAttributes(file: VirtualFile): FileAttributes { + return jobAttr + } + + override fun performOperation(operation: Operation, progressIndicator: ProgressIndicator): R { + throw IllegalStateException("No operation is expected to be performed.") + } + } + + var isOperationFailedForJesEx = false + every { + explorer.showNotification(any(), any(), NotificationType.ERROR, any()) + } answers { + isOperationFailedForJesEx = true + } + + var isOperationFailedForJobsLog = false + every { + jobsLogView.showNotification(any(), any(), any(), NotificationType.ERROR) + } answers { + isOperationFailedForJobsLog = true + } + + var isOperationFailedForNoContextAction = false + val mockActionEventWithoutDataContext = mockk() + every { mockActionEventWithoutDataContext.getData(any() as DataKey) } returns null + every { mockActionEventWithoutDataContext.presentation.isEnabledAndVisible = false } answers { + isOperationFailedForNoContextAction = true + } + + every { job.status } returns null + var isEnabledInJobsLog = true + every { mockActionEventForJobsLog.presentation.isEnabled = false } answers { isEnabledInJobsLog = false } + + var isVisibleForJes = true + every { updateJesAction.presentation.isVisible = false } answers { isVisibleForJes = false } + var isVisibleForJes2 = true + every { updateJesAction2.presentation.isVisible = false } answers { isVisibleForJes2 = false } + + purgeAction.actionPerformed(mockActionEventForJesEx) + purgeAction.actionPerformed(mockActionEventForJobsLog) + purgeAction.actionPerformed(mockActionEventWithoutDataContext) + purgeAction.update(mockActionEventWithoutDataContext) + purgeAction.update(mockActionEventForJobsLog) + purgeAction.update(updateJesAction) + purgeAction.update(updateJesAction2) + + assertSoftly { + isOperationFailedForJesEx shouldBe true + isOperationFailedForJobsLog shouldBe true + isEnabledInJobsLog shouldBe false + isVisibleForJes shouldBe false + isVisibleForJes2 shouldBe false + isOperationFailedForNoContextAction shouldBe true + } + } + } + } +}) From 3539c857ca889e0af824594c0aaf4b53f4700099 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Fri, 18 Aug 2023 18:55:12 +0200 Subject: [PATCH 3/7] IJMP-1230 Testing Signed-off-by: Uladzislau --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index a1d0d6f08..7a6a1fe09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ group = "eu.ibagroup" version = "1.1.1-221" val remoteRobotVersion = "0.11.19" val okHttp3Version = "4.10.0" -val kotestVersion = "5.5.5" +val kotestVersion = "5.6.2" repositories { mavenCentral() From 5561832662533c89ce28cb3c7e35aaa6a55731e5 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Mon, 21 Aug 2023 11:51:34 +0200 Subject: [PATCH 4/7] IJMP-1230 Just testing Signed-off-by: Uladzislau --- .../explorer/actions/PurgeJobActionTestSpec.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt index 0f2a0931b..536187245 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt @@ -54,13 +54,8 @@ class PurgeJobActionTestSpec : ShouldSpec({ beforeSpec { // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) + val lightFixture = factory.createLightFixtureBuilder("for-mainframe").fixture + val myFixture = factory.createCodeInsightFixture(lightFixture) myFixture.setUp() } afterSpec { @@ -85,7 +80,7 @@ class PurgeJobActionTestSpec : ShouldSpec({ ) ) mockkObject(gson) - every { gson.hint(Job::class).fromJson(any() as String, Job::class.java) } returns job + every { gson.hint(Job::class).fromJson(any(), Job::class.java) } returns job mockkObject(CredentialService) every { CredentialService.instance.getUsernameByKey(any()) } returns "user" From 450aa9c4aa5b2347f7ef2c3f79fb58f0086ada77 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Mon, 21 Aug 2023 12:32:48 +0200 Subject: [PATCH 5/7] IJMP-1230 Kotlin JVM version bump to test if it fixes the error --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7a6a1fe09..63ccfa91f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("org.jetbrains.intellij") version "1.14.2" - kotlin("jvm") version "1.7.10" + kotlin("jvm") version "1.8.10" java id("org.jetbrains.kotlinx.kover") version "0.6.1" } From 646cab5f0aa6e0e09b5bdf5ef4afb682bbac8e32 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Mon, 21 Aug 2023 15:19:26 +0200 Subject: [PATCH 6/7] IJMP-1230 Some changes for tests --- src/main/resources/META-INF/plugin.xml | 8 +- .../formainframe/config/ConfigTestSpec.kt | 50 +++-- .../dataops/OperationsTestSpec.kt | 42 ++--- .../dataops/SyncToolbarProviderTestSpec.kt | 34 ++-- .../formainframe/editor/EditorTestSpec.kt | 48 ++--- .../editor/EditorUtilsTestSpec.kt | 29 +-- .../formainframe/explorer/ExplorerTestSpec.kt | 19 +- .../explorer/FilesWorkingSetImplTestSpec.kt | 19 +- .../actions/AllocateDatasetActionTestSpec.kt | 21 +-- .../actions/AllocateLikeActionTestSpec.kt | 21 +-- .../actions/EditMaskActionTestSpec.kt | 19 +- .../actions/GetJobPropertiesActionTestSpec.kt | 23 +-- .../actions/PurgeJobActionTestSpec.kt | 16 +- .../explorer/actions/RenameActionTestSpec.kt | 21 +-- .../ui/ChangeEncodingDialogTestSpec.kt | 36 ++-- .../ui/ExplorerPasteProviderTestSpec.kt | 22 +-- .../ui/FileExplorerViewDropTargetTestSpec.kt | 178 +++++++++++++----- .../explorer/ui/UssFileNodeTestSpec.kt | 21 +-- .../testutils/WithApplicationShouldSpec.kt | 38 ++++ .../TestAnalyticsServiceImpl.kt | 2 +- .../TestCredentialsServiceImpl.kt | 7 +- .../testServiceImpl/TestDataOpsManagerImpl.kt | 2 +- .../testServiceImpl/TestZosmfApiImpl.kt | 5 +- .../utils/EncodingUtilsTestSpec.kt | 33 +--- 24 files changed, 325 insertions(+), 389 deletions(-) create mode 100644 src/test/kotlin/eu/ibagroup/formainframe/testutils/WithApplicationShouldSpec.kt rename src/test/kotlin/eu/ibagroup/formainframe/{ => testutils}/testServiceImpl/TestAnalyticsServiceImpl.kt (96%) rename src/test/kotlin/eu/ibagroup/formainframe/{ => testutils}/testServiceImpl/TestCredentialsServiceImpl.kt (89%) rename src/test/kotlin/eu/ibagroup/formainframe/{ => testutils}/testServiceImpl/TestDataOpsManagerImpl.kt (98%) rename src/test/kotlin/eu/ibagroup/formainframe/{ => testutils}/testServiceImpl/TestZosmfApiImpl.kt (94%) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 79893f918..1f55f7260 100755 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -344,11 +344,11 @@ Example of how to see the output:
+ testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestAnalyticsServiceImpl"/> + testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestCredentialsServiceImpl"/> + testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl"/> + testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestZosmfApiImpl"/> diff --git a/src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt index 53889b147..00b685417 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt @@ -12,12 +12,15 @@ package eu.ibagroup.formainframe.config import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl -import eu.ibagroup.formainframe.config.connect.* +import eu.ibagroup.formainframe.config.connect.ConnectionConfig +import eu.ibagroup.formainframe.config.connect.Credentials +import eu.ibagroup.formainframe.config.connect.CredentialsConfigDeclaration +import eu.ibagroup.formainframe.config.connect.ZOSMFConnectionConfigDeclaration +import eu.ibagroup.formainframe.config.connect.getOwner +import eu.ibagroup.formainframe.config.connect.getUsername import eu.ibagroup.formainframe.config.connect.ui.zosmf.ConnectionDialogState import eu.ibagroup.formainframe.config.connect.ui.zosmf.ConnectionsTableModel +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.dataops.DataOpsManager @@ -26,34 +29,27 @@ import eu.ibagroup.formainframe.dataops.operations.TsoOperation import eu.ibagroup.formainframe.dataops.operations.TsoOperationMode import eu.ibagroup.formainframe.explorer.Explorer import eu.ibagroup.formainframe.explorer.WorkingSet -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.ui.build.tso.TSOWindowFactory import eu.ibagroup.formainframe.utils.crudable.Crudable import eu.ibagroup.formainframe.utils.service import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import io.mockk.* +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 org.zowe.kotlinsdk.MessageType import org.zowe.kotlinsdk.TsoData import org.zowe.kotlinsdk.TsoResponse import org.zowe.kotlinsdk.annotations.ZVersion import kotlin.reflect.KFunction -class ConfigTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class ConfigTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } @@ -65,8 +61,12 @@ class ConfigTestSpec : ShouldSpec({ fun mockConfigService() { val mockConfigServiceInstance = mockk() - every { mockConfigServiceInstance.getConfigDeclaration(ConnectionConfig::class.java) } returns ZOSMFConnectionConfigDeclaration(crudable) - every { mockConfigServiceInstance.getConfigDeclaration(Credentials::class.java) } returns CredentialsConfigDeclaration(crudable) + every { + mockConfigServiceInstance.getConfigDeclaration(ConnectionConfig::class.java) + } returns ZOSMFConnectionConfigDeclaration(crudable) + every { + mockConfigServiceInstance.getConfigDeclaration(Credentials::class.java) + } returns CredentialsConfigDeclaration(crudable) mockkObject(ConfigService) every { ConfigService.instance } returns mockConfigServiceInstance @@ -277,16 +277,14 @@ class ConfigTestSpec : ShouldSpec({ // getOwner should("get owner by connection config when owner is not empty") { val owner = getOwner( - ConnectionConfig( - "", "", "", true, ZVersion.ZOS_2_3, "ZOSMFAD") + ConnectionConfig("", "", "", true, ZVersion.ZOS_2_3, "ZOSMFAD") ) assertSoftly { owner shouldBe "ZOSMFAD" } } should("get owner by connection config when owner is empty") { val owner = getOwner( - ConnectionConfig( - "", "", "", true, ZVersion.ZOS_2_3, "") + ConnectionConfig("", "", "", true, ZVersion.ZOS_2_3, "") ) assertSoftly { owner shouldBe "ZOSMF" } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/dataops/OperationsTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/dataops/OperationsTestSpec.kt index f43da9a2f..e85ad7e90 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/dataops/OperationsTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/dataops/OperationsTestSpec.kt @@ -15,13 +15,18 @@ import com.intellij.openapi.fileEditor.impl.LoadTextUtil import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.api.ZosmfApi import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.config.ws.DSMask -import eu.ibagroup.formainframe.dataops.attributes.* +import eu.ibagroup.formainframe.dataops.attributes.FileAttributes +import eu.ibagroup.formainframe.dataops.attributes.MFRemoteFileAttributes +import eu.ibagroup.formainframe.dataops.attributes.MaskedRequester +import eu.ibagroup.formainframe.dataops.attributes.RemoteDatasetAttributes +import eu.ibagroup.formainframe.dataops.attributes.RemoteDatasetAttributesService +import eu.ibagroup.formainframe.dataops.attributes.RemoteMemberAttributes +import eu.ibagroup.formainframe.dataops.attributes.RemoteUssAttributes +import eu.ibagroup.formainframe.dataops.attributes.Requester +import eu.ibagroup.formainframe.dataops.attributes.UssRequester import eu.ibagroup.formainframe.dataops.content.synchronizer.ContentSynchronizer import eu.ibagroup.formainframe.dataops.content.synchronizer.DocumentedSyncProvider import eu.ibagroup.formainframe.dataops.content.synchronizer.LF_LINE_SEPARATOR @@ -29,8 +34,9 @@ import eu.ibagroup.formainframe.dataops.operations.DeleteOperation import eu.ibagroup.formainframe.dataops.operations.mover.CrossSystemMemberOrUssFileOrSequentialToUssDirMover import eu.ibagroup.formainframe.dataops.operations.mover.MoveCopyOperation import eu.ibagroup.formainframe.dataops.operations.mover.RemoteToLocalFileMover -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl -import eu.ibagroup.formainframe.testServiceImpl.TestZosmfApiImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestZosmfApiImpl import eu.ibagroup.formainframe.utils.castOrNull import eu.ibagroup.formainframe.utils.changeFileEncodingTo import eu.ibagroup.formainframe.utils.service @@ -38,10 +44,14 @@ import eu.ibagroup.formainframe.utils.setUssFileTag import eu.ibagroup.formainframe.vfs.MFVirtualFile import io.kotest.assertions.assertSoftly import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain -import io.mockk.* +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.spyk +import io.mockk.unmockkAll import org.zowe.kotlinsdk.DataAPI import org.zowe.kotlinsdk.FilePath import org.zowe.kotlinsdk.XIBMDataType @@ -61,7 +71,7 @@ inline fun mockkRequesters( every { attributes.requesters } returns mutableListOf(connectionConfigToRequester(connection)) } -inline fun > prepareBareOperation( +inline fun > prepareBareOperation( isCrossystem: Boolean = false, sourceConnectionConfigToRequester: (ConnectionConfig) -> Requester<*>, destConnectionConfigToRequester: (ConnectionConfig) -> Requester<*> @@ -83,19 +93,7 @@ inline fun > ) } -class OperationsTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class OperationsTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/dataops/SyncToolbarProviderTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/dataops/SyncToolbarProviderTestSpec.kt index cc660e65b..4908fdff9 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/dataops/SyncToolbarProviderTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/dataops/SyncToolbarProviderTestSpec.kt @@ -15,28 +15,18 @@ import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.DefaultActionGroup import com.intellij.openapi.project.Project -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.dataops.content.synchronizer.SyncToolbarProvider +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.spyk +import io.mockk.unmockkAll -class SyncToolbarProviderTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class SyncToolbarProviderTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } @@ -52,7 +42,9 @@ class SyncToolbarProviderTestSpec : ShouldSpec({ var isResolved = false val mockedActionGroupForTest = mockk() every { ActionManager.getInstance() } returns mockedActionManagerInstance - every { mockedActionManagerInstance.getAction(any() as String)} answers { + every { + mockedActionManagerInstance.getAction(any() as String) + } answers { isResolved = true mockedActionGroupForTest } @@ -67,7 +59,7 @@ class SyncToolbarProviderTestSpec : ShouldSpec({ var isResolved = false val mockedNotActionGroupForTest = mockk() every { ActionManager.getInstance() } returns mockedActionManagerInstance - every { mockedActionManagerInstance.getAction(any() as String)} returns mockedNotActionGroupForTest + every { mockedActionManagerInstance.getAction(any() as String) } returns mockedNotActionGroupForTest every { mockedActionManagerInstance.registerAction(any() as String, any() as DefaultActionGroup) } answers { isResolved = true } @@ -81,4 +73,4 @@ class SyncToolbarProviderTestSpec : ShouldSpec({ unmockkAll() } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt index d61366cdd..cc01e4d68 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt @@ -10,7 +10,10 @@ package eu.ibagroup.formainframe.editor -import com.intellij.codeInspection.* +// import com.intellij.openapi.ui.isComponentUnderMouse // TODO: needed in v1.*.*-223 and greater +import com.intellij.codeInspection.InspectionManager +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.codeInspection.ProblemHighlightType import com.intellij.lang.Language import com.intellij.lang.injection.InjectedLanguageManager import com.intellij.lang.properties.charset.Native2AsciiCharset @@ -19,7 +22,6 @@ import com.intellij.openapi.components.ComponentManager import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.fileEditor.impl.LoadTextUtil import com.intellij.openapi.project.Project -// import com.intellij.openapi.ui.isComponentUnderMouse // TODO: needed in v1.*.*-223 and greater import com.intellij.openapi.util.Ref import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.text.StringUtil @@ -28,9 +30,6 @@ import com.intellij.psi.FileViewProvider import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.SmartPointerManager -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import com.intellij.util.containers.ContainerUtil import com.intellij.util.messages.Topic import eu.ibagroup.formainframe.config.ConfigService @@ -45,37 +44,40 @@ import eu.ibagroup.formainframe.dataops.content.synchronizer.DocumentedSyncProvi import eu.ibagroup.formainframe.editor.inspection.MFLossyEncodingInspection import eu.ibagroup.formainframe.explorer.Explorer import eu.ibagroup.formainframe.explorer.WorkingSet -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl -import eu.ibagroup.formainframe.utils.* +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.utils.checkEncodingCompatibility +import eu.ibagroup.formainframe.utils.isComponentUnderMouse +import eu.ibagroup.formainframe.utils.sendTopic +import eu.ibagroup.formainframe.utils.service +import eu.ibagroup.formainframe.utils.showSaveAnywayDialog import eu.ibagroup.formainframe.vfs.MFVirtualFile import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkConstructor +import io.mockk.mockkObject +import io.mockk.mockkStatic +import io.mockk.spyk +import io.mockk.unmockkAll +import io.mockk.unmockkStatic import java.awt.Component import java.awt.Point import java.awt.event.FocusEvent import java.nio.ByteBuffer import java.nio.CharBuffer -import java.nio.charset.* +import java.nio.charset.Charset +import java.nio.charset.CharsetDecoder +import java.nio.charset.CharsetEncoder +import java.nio.charset.CoderResult import javax.swing.JComponent import javax.swing.SwingUtilities import kotlin.reflect.KFunction import kotlin.reflect.full.declaredFunctions -class EditorTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class EditorTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorUtilsTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorUtilsTestSpec.kt index 4dbb166a9..cb8afa4f3 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorUtilsTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorUtilsTestSpec.kt @@ -15,27 +15,18 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.EditorModificationUtil import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.Runs +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.unmockkAll -class EditorUtilsTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class EditorUtilsTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } @@ -86,4 +77,4 @@ class EditorUtilsTestSpec : ShouldSpec({ unmockkAll() } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ExplorerTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ExplorerTestSpec.kt index 20fb09327..2740e0a1a 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ExplorerTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ExplorerTestSpec.kt @@ -10,25 +10,10 @@ package eu.ibagroup.formainframe.explorer -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl -import io.kotest.core.spec.style.ShouldSpec +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import io.mockk.clearAllMocks -class ExplorerTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class ExplorerTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/FilesWorkingSetImplTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/FilesWorkingSetImplTestSpec.kt index 95f3ee229..56b283787 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/FilesWorkingSetImplTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/FilesWorkingSetImplTestSpec.kt @@ -11,9 +11,6 @@ package eu.ibagroup.formainframe.explorer import com.intellij.openapi.Disposable -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.ConfigService import eu.ibagroup.formainframe.config.ConfigStateV2 import eu.ibagroup.formainframe.config.configCrudable @@ -22,11 +19,11 @@ import eu.ibagroup.formainframe.config.makeCrudableWithoutListeners import eu.ibagroup.formainframe.config.ws.DSMask import eu.ibagroup.formainframe.config.ws.FilesWorkingSetConfig import eu.ibagroup.formainframe.config.ws.UssPath +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import eu.ibagroup.formainframe.utils.gson import eu.ibagroup.formainframe.utils.optional import eu.ibagroup.formainframe.utils.toMutableList import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.clearAllMocks import io.mockk.every @@ -37,19 +34,7 @@ import io.mockk.unmockkAll import java.util.* import java.util.stream.Stream -class FilesWorkingSetImplTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class FilesWorkingSetImplTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateDatasetActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateDatasetActionTestSpec.kt index acd8af686..6beebd61b 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateDatasetActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateDatasetActionTestSpec.kt @@ -17,9 +17,6 @@ import com.intellij.openapi.components.ComponentManager import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.ui.showOkNoDialog -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.analytics.AnalyticsService import eu.ibagroup.formainframe.analytics.events.AnalyticsEvent import eu.ibagroup.formainframe.common.ui.StatefulDialog @@ -43,10 +40,10 @@ import eu.ibagroup.formainframe.explorer.ui.JobNode import eu.ibagroup.formainframe.explorer.ui.LibraryNode import eu.ibagroup.formainframe.explorer.ui.NodeData import eu.ibagroup.formainframe.explorer.ui.getExplorerView -import eu.ibagroup.formainframe.testServiceImpl.TestAnalyticsServiceImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestAnalyticsServiceImpl import eu.ibagroup.formainframe.utils.service import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.Runs import io.mockk.clearAllMocks @@ -64,19 +61,7 @@ import javax.swing.Icon import javax.swing.SwingUtilities import kotlin.reflect.KFunction -class AllocateDatasetActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class AllocateDatasetActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateLikeActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateLikeActionTestSpec.kt index bdb4f5896..a92bb88d5 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateLikeActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/AllocateLikeActionTestSpec.kt @@ -18,9 +18,6 @@ import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages.showWarningDialog import com.intellij.openapi.ui.showOkNoDialog -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.analytics.AnalyticsService import eu.ibagroup.formainframe.analytics.events.AnalyticsEvent import eu.ibagroup.formainframe.common.ui.StatefulDialog @@ -44,10 +41,10 @@ import eu.ibagroup.formainframe.explorer.ui.JobNode import eu.ibagroup.formainframe.explorer.ui.LibraryNode import eu.ibagroup.formainframe.explorer.ui.NodeData import eu.ibagroup.formainframe.explorer.ui.getExplorerView -import eu.ibagroup.formainframe.testServiceImpl.TestAnalyticsServiceImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestAnalyticsServiceImpl import eu.ibagroup.formainframe.utils.service import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.Runs import io.mockk.clearAllMocks @@ -67,19 +64,7 @@ import javax.swing.Icon import javax.swing.SwingUtilities import kotlin.reflect.KFunction -class AllocateLikeActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class AllocateLikeActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/EditMaskActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/EditMaskActionTestSpec.kt index 77f38c7c1..af5a294c7 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/EditMaskActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/EditMaskActionTestSpec.kt @@ -11,9 +11,6 @@ package eu.ibagroup.formainframe.explorer.actions import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.ConfigService import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.config.connect.CredentialService @@ -30,10 +27,10 @@ import eu.ibagroup.formainframe.explorer.ui.FileExplorerView import eu.ibagroup.formainframe.explorer.ui.NodeData import eu.ibagroup.formainframe.explorer.ui.UssDirNode import eu.ibagroup.formainframe.explorer.ui.getExplorerView +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import eu.ibagroup.formainframe.utils.MaskType import eu.ibagroup.formainframe.utils.crudable.Crudable import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.clearAllMocks import io.mockk.every @@ -43,19 +40,7 @@ import io.mockk.mockkObject import io.mockk.unmockkAll import java.util.* -class EditMaskActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class EditMaskActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/GetJobPropertiesActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/GetJobPropertiesActionTestSpec.kt index e2b203fbe..48fd29da2 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/GetJobPropertiesActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/GetJobPropertiesActionTestSpec.kt @@ -5,9 +5,6 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.config.ws.JobsFilter import eu.ibagroup.formainframe.dataops.DataOpsManager @@ -27,11 +24,11 @@ import eu.ibagroup.formainframe.explorer.ui.SpoolFileNode import eu.ibagroup.formainframe.explorer.ui.SpoolFilePropertiesDialog import eu.ibagroup.formainframe.explorer.ui.SpoolFileState import eu.ibagroup.formainframe.explorer.ui.getExplorerView -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.gson import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.vfs.MFVirtualFile -import io.kotest.core.spec.style.ShouldSpec import io.mockk.clearAllMocks import io.mockk.every import io.mockk.mockk @@ -43,19 +40,7 @@ import io.mockk.verify import org.zowe.kotlinsdk.Job import org.zowe.kotlinsdk.SpoolFile -class GetJobPropertiesActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class GetJobPropertiesActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } @@ -176,4 +161,4 @@ class GetJobPropertiesActionTestSpec : ShouldSpec({ } } } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt index 536187245..4b4b1ee6e 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/PurgeJobActionTestSpec.kt @@ -7,9 +7,6 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.api.ZosmfApi import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.config.connect.CredentialService @@ -30,13 +27,13 @@ import eu.ibagroup.formainframe.explorer.ui.JesFilterNode import eu.ibagroup.formainframe.explorer.ui.JobNode import eu.ibagroup.formainframe.explorer.ui.NodeData import eu.ibagroup.formainframe.explorer.ui.getExplorerView -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.ui.build.jobs.JobBuildTreeView import eu.ibagroup.formainframe.utils.gson import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.vfs.MFVirtualFile import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.clearAllMocks import io.mockk.every @@ -50,14 +47,7 @@ import org.zowe.kotlinsdk.Job import retrofit2.Call import retrofit2.Response -class PurgeJobActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val lightFixture = factory.createLightFixtureBuilder("for-mainframe").fixture - val myFixture = factory.createCodeInsightFixture(lightFixture) - myFixture.setUp() - } +class PurgeJobActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/RenameActionTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/RenameActionTestSpec.kt index 1e0d6b5b7..2189d0c22 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/RenameActionTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/actions/RenameActionTestSpec.kt @@ -14,9 +14,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.ConfigService import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.dataops.DataOpsManager @@ -24,29 +21,17 @@ import eu.ibagroup.formainframe.dataops.Operation import eu.ibagroup.formainframe.dataops.attributes.* import eu.ibagroup.formainframe.explorer.Explorer import eu.ibagroup.formainframe.explorer.ui.* -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.* import eu.ibagroup.formainframe.utils.crudable.Crudable import eu.ibagroup.formainframe.vfs.MFVirtualFile import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.* import java.util.* -class RenameActionTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class RenameActionTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ChangeEncodingDialogTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ChangeEncodingDialogTestSpec.kt index b9780e890..16504f004 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ChangeEncodingDialogTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ChangeEncodingDialogTestSpec.kt @@ -18,9 +18,6 @@ import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.Messages import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.encoding.EncodingUtil.Magic8 -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.common.message import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.dataops.DataOpsManager @@ -29,31 +26,30 @@ import eu.ibagroup.formainframe.dataops.content.synchronizer.ContentSynchronizer import eu.ibagroup.formainframe.dataops.content.synchronizer.DocumentedSyncProvider import eu.ibagroup.formainframe.explorer.Explorer import eu.ibagroup.formainframe.explorer.WorkingSet -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl -import eu.ibagroup.formainframe.utils.* +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.utils.castOrNull +import eu.ibagroup.formainframe.utils.reloadIn +import eu.ibagroup.formainframe.utils.saveIn +import eu.ibagroup.formainframe.utils.service +import eu.ibagroup.formainframe.utils.updateFileTag import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkConstructor +import io.mockk.mockkObject +import io.mockk.mockkStatic +import io.mockk.spyk +import io.mockk.unmockkAll import java.awt.event.ActionEvent import java.nio.charset.Charset import javax.swing.Action import javax.swing.Icon import kotlin.reflect.full.declaredFunctions -class ChangeEncodingDialogTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class ChangeEncodingDialogTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ExplorerPasteProviderTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ExplorerPasteProviderTestSpec.kt index 6f97ebe15..3dcf5ffe4 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ExplorerPasteProviderTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/ExplorerPasteProviderTestSpec.kt @@ -20,9 +20,6 @@ import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.Messages import com.intellij.openapi.ui.showYesNoDialog import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.common.ui.cleanInvalidateOnExpand import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.config.ws.FilesWorkingSetConfig @@ -37,12 +34,12 @@ import eu.ibagroup.formainframe.explorer.AbstractExplorerBase import eu.ibagroup.formainframe.explorer.FileExplorer import eu.ibagroup.formainframe.explorer.FileExplorerContentProvider import eu.ibagroup.formainframe.explorer.FilesWorkingSet -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.castOrNull import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.vfs.MFVirtualFile import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.mockk.Runs import io.mockk.clearAllMocks @@ -58,20 +55,7 @@ import javax.swing.Icon import javax.swing.tree.DefaultMutableTreeNode import kotlin.reflect.KFunction -class ExplorerPasteProviderTestSpec : ShouldSpec({ - - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class ExplorerPasteProviderTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/FileExplorerViewDropTargetTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/FileExplorerViewDropTargetTestSpec.kt index 9123a0de7..9f6d6fe7b 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/FileExplorerViewDropTargetTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/FileExplorerViewDropTargetTestSpec.kt @@ -11,7 +11,11 @@ package eu.ibagroup.formainframe.explorer.ui import com.intellij.ide.PasteProvider -import com.intellij.ide.dnd.* +import com.intellij.ide.dnd.DnDAction +import com.intellij.ide.dnd.DnDDragStartBean +import com.intellij.ide.dnd.DnDEvent +import com.intellij.ide.dnd.DnDSource +import com.intellij.ide.dnd.TransferableWrapper import com.intellij.ide.projectView.ProjectViewNode import com.intellij.ide.projectView.impl.ProjectViewImpl import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode @@ -22,23 +26,32 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiElement -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import com.intellij.ui.awt.RelativeRectangle import com.intellij.ui.treeStructure.Tree import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.dataops.DataOpsManager -import eu.ibagroup.formainframe.dataops.attributes.* -import eu.ibagroup.formainframe.explorer.* -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.dataops.attributes.AttributesService +import eu.ibagroup.formainframe.dataops.attributes.FileAttributes +import eu.ibagroup.formainframe.dataops.attributes.MaskedRequester +import eu.ibagroup.formainframe.dataops.attributes.RemoteDatasetAttributes +import eu.ibagroup.formainframe.dataops.attributes.RemoteMemberAttributes +import eu.ibagroup.formainframe.dataops.attributes.RemoteUssAttributes +import eu.ibagroup.formainframe.dataops.attributes.UssRequester +import eu.ibagroup.formainframe.explorer.Explorer +import eu.ibagroup.formainframe.explorer.FilesWorkingSetImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.vfs.MFVirtualFile import groovy.lang.Tuple4 import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.mockkStatic +import io.mockk.spyk import java.awt.Point import java.awt.Rectangle import java.awt.datatransfer.DataFlavor @@ -48,19 +61,7 @@ import javax.swing.tree.DefaultMutableTreeNode import javax.swing.tree.TreeNode import javax.swing.tree.TreePath -class FileExplorerViewDropTargetTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class FileExplorerViewDropTargetTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } @@ -132,9 +133,11 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ isPastePerformed = true return } + override fun isPastePossible(dataContext: DataContext): Boolean { return true } + override fun isPasteEnabled(dataContext: DataContext): Boolean { return true } @@ -157,6 +160,7 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ override fun canStartDragging(action: DnDAction?, dragOrigin: Point): Boolean { TODO("Not yet implemented") } + override fun startDragging(action: DnDAction?, dragOrigin: Point): DnDDragStartBean { TODO("Not yet implemented") } @@ -186,7 +190,7 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } } - should ("perform paste from local/remote through the cut provider") { + should("perform paste from local/remote through the cut provider") { every { mockedDnDEvent.attachedObject } answers { FileExplorerViewDragSource.ExplorerTransferableWrapper(mockedJTree) } @@ -201,7 +205,7 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } } - should ("perform paste from local/remote if no cut/copy provider enabled") { + should("perform paste from local/remote if no cut/copy provider enabled") { every { mockedDnDEvent.attachedObject } answers { FileExplorerViewDragSource.ExplorerTransferableWrapper(mockedJTree) } @@ -221,7 +225,8 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } should("perform paste from mainframe z/OS datasets to the USS files within one remote system") { - val dataOpsManagerService = ApplicationManager.getApplication().service() as TestDataOpsManagerImpl + val dataOpsManagerService = + ApplicationManager.getApplication().service() as TestDataOpsManagerImpl every { mockedFileExplorer.componentManager } returns ApplicationManager.getApplication() val mockedAttributeService = mockk>() val mockedParentDatasetAttributes = mockk() @@ -281,8 +286,14 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { requester2.connectionConfig } returns conn2 every { targetAttributes.requesters } returns mutableListOf(requester1) every { mockedParentDatasetAttributes.requesters } returns mutableListOf(requester2) - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileTarget) } returns targetAttributes - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileSource) } returns sourceAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileTarget) + } returns targetAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileSource) + } returns sourceAttributes every { mockedCopyPasterProvider.cutProvider.isCutEnabled(any() as DataContext) } returns true fileExplorerViewDropTarget.drop(mockedDnDEvent) @@ -338,8 +349,14 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { requester2.connectionConfig } returns conn2 every { targetAttributes.requesters } returns mutableListOf(requester1) every { sourceAttributes.requesters } returns mutableListOf(requester2) - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileTarget) } returns targetAttributes - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileSource) } returns sourceAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileTarget) + } returns targetAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileSource) + } returns sourceAttributes every { mockedCopyPasterProvider.cutProvider.isCutEnabled(any() as DataContext) } returns true fileExplorerViewDropTarget.drop(mockedDnDEvent) @@ -395,8 +412,14 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { requester2.connectionConfig } returns conn2 every { targetAttributes.requesters } returns mutableListOf(requester1) every { sourceAttributes.requesters } returns mutableListOf(requester2) - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileTarget) } returns targetAttributes - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileSource) } returns sourceAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileTarget) + } returns targetAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileSource) + } returns sourceAttributes every { mockedCopyPasterProvider.cutProvider.isCutEnabled(any() as DataContext) } returns false fileExplorerViewDropTarget.drop(mockedDnDEvent) @@ -452,8 +475,14 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { requester2.connectionConfig } returns conn2 every { targetAttributes.requesters } returns mutableListOf(requester1) every { sourceAttributes.requesters } returns mutableListOf(requester2) - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileTarget) } returns targetAttributes - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileSource) } returns sourceAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileTarget) + } returns targetAttributes + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileSource) + } returns sourceAttributes every { mockedCopyPasterProvider.copyProvider.isCopyEnabled(any() as DataContext) } returns true fileExplorerViewDropTarget.drop(mockedDnDEvent) @@ -470,7 +499,12 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { defaultSourceTargetBounds.v1 } returns defaultSources every { defaultSourceTargetBounds.v2 } returns defaultTarget every { mockedDnDEvent.isDataFlavorSupported(any() as DataFlavor) } returns true - every { mockedCopyPasterProvider.isPastePossibleFromPath(any() as List, any() as List) } returns true + every { + mockedCopyPasterProvider.isPastePossibleFromPath( + any() as List, + any() as List + ) + } returns true every { mockedJTree.parent } returns mockk() every { mockedJTree.isShowing } returns false fileExplorerViewDropTarget.update(mockedDnDEvent) @@ -556,9 +590,17 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { mockedFileExplorer.componentManager } returns mockk() every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) } returns mockk() val sourceAttributes = mockk() - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileSource) } returns sourceAttributes - - every { mockedCopyPasterProvider.isPastePossible(any() as List, any() as List>) } returns true + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileSource) + } returns sourceAttributes + + every { + mockedCopyPasterProvider.isPastePossible( + any() as List, + any() as List> + ) + } returns true fileExplorerViewDropTarget.update(mockedDnDEvent) assertSoftly { isDropPossible shouldBe true @@ -568,7 +610,12 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } should("highlight is not possible if target virtual file is not null and paste is not possible") { - every { mockedCopyPasterProvider.isPastePossible(any() as List, any() as List>) } returns false + every { + mockedCopyPasterProvider.isPastePossible( + any() as List, + any() as List> + ) + } returns false fileExplorerViewDropTarget.update(mockedDnDEvent) assertSoftly { isDragHighlighted shouldBe false @@ -582,6 +629,7 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ override fun canStartDragging(action: DnDAction?, dragOrigin: Point): Boolean { TODO("Not yet implemented") } + override fun startDragging(action: DnDAction?, dragOrigin: Point): DnDDragStartBean { TODO("Not yet implemented") } @@ -609,8 +657,16 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ val mockedVirtualFileTarget = mockk() every { mockedNodeTarget.virtualFile } returns mockedVirtualFileTarget val targetAttributes = mockk() - every { mockedFileExplorer.componentManager.getService(DataOpsManager::class.java).tryToGetAttributes(mockedVirtualFileTarget) } returns targetAttributes - every { mockedCopyPasterProvider.isPastePossibleForFiles(any() as List, any() as List) } returns true + every { + mockedFileExplorer.componentManager.getService(DataOpsManager::class.java) + .tryToGetAttributes(mockedVirtualFileTarget) + } returns targetAttributes + every { + mockedCopyPasterProvider.isPastePossibleForFiles( + any() as List, + any() as List + ) + } returns true fileExplorerViewDropTarget.update(mockedDnDEvent) assertSoftly { @@ -654,14 +710,23 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { defaultSourceTest.lastPathComponent } returns mockedStructureTreeModelNodeSource every { mockedStructureTreeModelNodeSource.userObject } returns mockedNodeSource every { mockedNodeSource.virtualFile } returns mockedVirtualFileSource - every { mockedFileExplorer.componentManager.service().tryToGetAttributes(mockedVirtualFileSource) } returns mockedSourceAttributes + every { + mockedFileExplorer.componentManager.service().tryToGetAttributes(mockedVirtualFileSource) + } returns mockedSourceAttributes every { target.lastPathComponent } returns mockedStructureTreeModelNodeTarget every { mockedStructureTreeModelNodeTarget.userObject } returns mockedNodeTarget every { mockedNodeTarget.virtualFile } returns mockedVirtualFileTarget - every { mockedFileExplorer.componentManager.service().tryToGetAttributes(mockedVirtualFileTarget) } returns mockedTargetAttributes + every { + mockedFileExplorer.componentManager.service().tryToGetAttributes(mockedVirtualFileTarget) + } returns mockedTargetAttributes - every { fileExplorerViewDropTarget["isCrossSystemCopy"](any() as Collection, any() as TreePath) } returns false + every { + fileExplorerViewDropTarget["isCrossSystemCopy"]( + any() as Collection, + any() as TreePath + ) + } returns false every { mockedCopyPasterProvider.pasteProvider } returns userDefinedExplorerPasteProvider @@ -753,24 +818,32 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { mockedDnDEvent.point } returns mockedPoint every { mockedDnDEvent.currentOverComponent } returns mockedJTree - every { mockedJTree.getClosestPathForLocation(any() as Int, any() as Int) } returns TreePath(arrayOf("project", "project", "test1", "test2")) + every { + mockedJTree.getClosestPathForLocation(any(), any()) + } returns TreePath(arrayOf("project", "project", "test1", "test2")) every { mockedJTree.getPathBounds(any() as TreePath) } returns Rectangle(50, 200, 100, 50) val mockedDnDWrapper = FileExplorerViewDragSource.ExplorerTransferableWrapper(mockedJTree) - val mockedDefaultWrapper = object : TransferableWrapper { + val mockedDefaultWrapper = object : TransferableWrapper { override fun asFileList(): MutableList? { TODO("Not yet implemented") } + override fun getTreeNodes(): Array? { TODO("Not yet implemented") } + override fun getPsiElements(): Array? { TODO("Not yet implemented") } } mockkObject(mockedDnDWrapper) mockkObject(mockedDefaultWrapper) - every { mockedDnDWrapper.treePaths } returns arrayOf(TreePath(arrayOf("u/root", "/test_1", "/u/ZOSMFAD", "test_2"))) - every { mockedDefaultWrapper.treePaths } returns arrayOf(TreePath(arrayOf("u/root", "/test_1", "/u/ZOSMFAD", "test_2"))) + every { + mockedDnDWrapper.treePaths + } returns arrayOf(TreePath(arrayOf("u/root", "/test_1", "/u/ZOSMFAD", "test_2"))) + every { + mockedDefaultWrapper.treePaths + } returns arrayOf(TreePath(arrayOf("u/root", "/test_1", "/u/ZOSMFAD", "test_2"))) mockkStatic(FileExplorerViewDragSource::class) mockkStatic(FileExplorerViewDragSource.ExplorerTransferableWrapper::class) @@ -819,7 +892,9 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ every { ProjectViewImpl.getInstance(mockedProject).currentProjectViewPane } returns mockk() every { ProjectViewImpl.getInstance(mockedProject).currentProjectViewPane.tree } returns mockedProjectTree every { mockedDnDEvent.currentOverComponent } returns mockedProjectTree - every { mockedProjectTree.getClosestPathForLocation(any() as Int, any() as Int) } returns TreePath(arrayOf("project", "project", "test1", "test2")) + every { + mockedProjectTree.getClosestPathForLocation(any(), any()) + } returns TreePath(arrayOf("project", "project", "test1", "test2")) every { mockedProjectTree.getPathBounds(any() as TreePath) } returns Rectangle(50, 200, 100, 50) fileExplorerViewDropTarget.drop(mockedDnDEvent) assertSoftly { @@ -871,13 +946,16 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } should("perform drop with defined getSourcesTargetAndBounds when transfer data (sources) is not an instance of TransferableWrapper") { - every { mockedProjectTree.getClosestPathForLocation(any() as Int, any() as Int) } returns TreePath(arrayOf("project", "project", "test1", "test2")) + every { + mockedProjectTree.getClosestPathForLocation(any(), any()) + } returns TreePath(arrayOf("project", "project", "test1", "test2")) every { mockedProjectTree.getPathBounds(any() as TreePath) } returns Rectangle(50, 200, 100, 50) every { mockedDnDEvent.attachedObject } answers { object : DnDSource { override fun canStartDragging(action: DnDAction?, dragOrigin: Point): Boolean { TODO("Not yet implemented") } + override fun startDragging(action: DnDAction?, dragOrigin: Point): DnDDragStartBean { TODO("Not yet implemented") } @@ -902,4 +980,4 @@ class FileExplorerViewDropTargetTestSpec : ShouldSpec({ } } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/UssFileNodeTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/UssFileNodeTestSpec.kt index f880ca7a1..feb4e06d4 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/UssFileNodeTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/explorer/ui/UssFileNodeTestSpec.kt @@ -23,9 +23,6 @@ import com.intellij.openapi.ui.DialogWrapper import com.intellij.openapi.ui.Messages import com.intellij.openapi.ui.showYesNoDialog import com.intellij.openapi.vfs.VirtualFile -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.dataops.DataOpsManager import eu.ibagroup.formainframe.dataops.attributes.FileAttributes @@ -39,13 +36,13 @@ import eu.ibagroup.formainframe.explorer.FileExplorer import eu.ibagroup.formainframe.explorer.FileExplorerContentProvider import eu.ibagroup.formainframe.explorer.UIComponentManager import eu.ibagroup.formainframe.explorer.WorkingSet -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.isBeingEditingNow import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.vfs.MFVirtualFile import eu.ibagroup.formainframe.vfs.MFVirtualFileSystem import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.mockk.Runs @@ -60,19 +57,7 @@ import javax.swing.Icon import javax.swing.tree.TreePath import kotlin.reflect.KFunction -class UssFileNodeTestSpec : ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } +class UssFileNodeTestSpec : WithApplicationShouldSpec({ afterSpec { clearAllMocks() } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/testutils/WithApplicationShouldSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/testutils/WithApplicationShouldSpec.kt new file mode 100644 index 000000000..9b8d0417d --- /dev/null +++ b/src/test/kotlin/eu/ibagroup/formainframe/testutils/WithApplicationShouldSpec.kt @@ -0,0 +1,38 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright IBA Group 2020 + */ + +package eu.ibagroup.formainframe.testutils + +import com.intellij.openapi.application.Application +import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory +import io.kotest.core.spec.Spec +import io.kotest.core.spec.style.ShouldSpec + +/** + * [ShouldSpec] wrapper that provides implemented beforeSpec, initializing an [Application] + * instance to be able to use and mock services for tests + */ +abstract class WithApplicationShouldSpec(body: ShouldSpec.() -> Unit = {}) : ShouldSpec() { + + /** + * Fixture setup to have access to the [Application] instance + */ + override suspend fun beforeSpec(spec: Spec) { + super.beforeSpec(spec) + val factory = IdeaTestFixtureFactory.getFixtureFactory() + val lightFixture = factory.createLightFixtureBuilder("for-mainframe").fixture + val appFixture = factory.createCodeInsightFixture(lightFixture) + appFixture.setUp() + } + + init { + body() + } +} diff --git a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestAnalyticsServiceImpl.kt b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestAnalyticsServiceImpl.kt similarity index 96% rename from src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestAnalyticsServiceImpl.kt rename to src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestAnalyticsServiceImpl.kt index 934c2b90a..703516bbb 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestAnalyticsServiceImpl.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestAnalyticsServiceImpl.kt @@ -8,7 +8,7 @@ * Copyright IBA Group 2020 */ -package eu.ibagroup.formainframe.testServiceImpl +package eu.ibagroup.formainframe.testutils.testServiceImpl import eu.ibagroup.formainframe.analytics.AnalyticsService import eu.ibagroup.formainframe.analytics.events.AnalyticsEvent diff --git a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestCredentialsServiceImpl.kt b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestCredentialsServiceImpl.kt similarity index 89% rename from src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestCredentialsServiceImpl.kt rename to src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestCredentialsServiceImpl.kt index 2bafea561..e78af8681 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestCredentialsServiceImpl.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestCredentialsServiceImpl.kt @@ -8,12 +8,12 @@ * Copyright IBA Group 2020 */ -package eu.ibagroup.formainframe.testServiceImpl +package eu.ibagroup.formainframe.testutils.testServiceImpl import eu.ibagroup.formainframe.config.connect.CredentialService -class TestCredentialsServiceImpl: CredentialService { - var testInstance = object: CredentialService { +class TestCredentialsServiceImpl : CredentialService { + var testInstance = object : CredentialService { override fun getUsernameByKey(connectionConfigUuid: String): String { return "testUser" } @@ -29,6 +29,7 @@ class TestCredentialsServiceImpl: CredentialService { } } + override fun getUsernameByKey(connectionConfigUuid: String): String? { return this.testInstance.getUsernameByKey(connectionConfigUuid) } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestDataOpsManagerImpl.kt b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestDataOpsManagerImpl.kt similarity index 98% rename from src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestDataOpsManagerImpl.kt rename to src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestDataOpsManagerImpl.kt index 43d061687..cc7e8c99e 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestDataOpsManagerImpl.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestDataOpsManagerImpl.kt @@ -8,7 +8,7 @@ * Copyright IBA Group 2020 */ -package eu.ibagroup.formainframe.testServiceImpl +package eu.ibagroup.formainframe.testutils.testServiceImpl import com.intellij.execution.ui.ConsoleView import com.intellij.openapi.components.ComponentManager diff --git a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestZosmfApiImpl.kt b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestZosmfApiImpl.kt similarity index 94% rename from src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestZosmfApiImpl.kt rename to src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestZosmfApiImpl.kt index 2c2a4a284..44cc29090 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/testServiceImpl/TestZosmfApiImpl.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/testutils/testServiceImpl/TestZosmfApiImpl.kt @@ -8,12 +8,12 @@ * Copyright IBA Group 2020 */ -package eu.ibagroup.formainframe.testServiceImpl +package eu.ibagroup.formainframe.testutils.testServiceImpl import eu.ibagroup.formainframe.api.ZosmfApi import eu.ibagroup.formainframe.config.connect.ConnectionConfig -class TestZosmfApiImpl: ZosmfApi { +class TestZosmfApiImpl : ZosmfApi { var testInstance = object : ZosmfApi { override fun getApi(apiClass: Class, connectionConfig: ConnectionConfig): Api { TODO("Not yet implemented") @@ -36,6 +36,7 @@ class TestZosmfApiImpl: ZosmfApi { } } + override fun getApi(apiClass: Class, connectionConfig: ConnectionConfig): Api { return this.testInstance.getApi(apiClass, connectionConfig) } diff --git a/src/test/kotlin/eu/ibagroup/formainframe/utils/EncodingUtilsTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/utils/EncodingUtilsTestSpec.kt index bae49be61..8ddc53ed7 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/utils/EncodingUtilsTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/utils/EncodingUtilsTestSpec.kt @@ -28,9 +28,6 @@ import com.intellij.openapi.vfs.encoding.EncodingUtil.Magic8 import com.intellij.profile.codeInspection.InspectionProjectProfileManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl import eu.ibagroup.formainframe.config.connect.ConnectionConfig import eu.ibagroup.formainframe.dataops.DataOpsManager import eu.ibagroup.formainframe.dataops.attributes.RemoteUssAttributes @@ -39,11 +36,16 @@ import eu.ibagroup.formainframe.dataops.content.synchronizer.DocumentedSyncProvi import eu.ibagroup.formainframe.explorer.Explorer import eu.ibagroup.formainframe.explorer.WorkingSet import eu.ibagroup.formainframe.explorer.ui.ChangeEncodingDialog -import eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl +import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec +import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.shouldBe -import io.mockk.* +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkConstructor +import io.mockk.mockkObject +import io.mockk.mockkStatic +import io.mockk.unmockkAll import java.nio.ByteBuffer import java.nio.CharBuffer import java.nio.charset.Charset @@ -53,22 +55,7 @@ import java.nio.charset.UnsupportedCharsetException import javax.swing.Icon import kotlin.reflect.full.declaredFunctions -class EncodingUtilsTestSpec: ShouldSpec({ - beforeSpec { - // FIXTURE SETUP TO HAVE ACCESS TO APPLICATION INSTANCE - val factory = IdeaTestFixtureFactory.getFixtureFactory() - val projectDescriptor = LightProjectDescriptor.EMPTY_PROJECT_DESCRIPTOR - val fixtureBuilder = factory.createLightFixtureBuilder(projectDescriptor, "for-mainframe") - val fixture = fixtureBuilder.fixture - val myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture( - fixture, - LightTempDirTestFixtureImpl(true) - ) - myFixture.setUp() - } - afterSpec { - clearAllMocks() - } +class EncodingUtilsTestSpec : WithApplicationShouldSpec({ context("utils module: encodingUtils") { val text = "text" @@ -387,4 +374,4 @@ class EncodingUtilsTestSpec: ShouldSpec({ unmockkAll() } -}) \ No newline at end of file +}) From d1ebcdc84536451b54d6f1fe0842df6c16b4cbe8 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Tue, 22 Aug 2023 16:03:16 +0200 Subject: [PATCH 7/7] Small fix --- .../kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt index bbcf23365..66c02b2c0 100644 --- a/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt +++ b/src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt @@ -47,7 +47,6 @@ import eu.ibagroup.formainframe.explorer.WorkingSet import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec import eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl import eu.ibagroup.formainframe.utils.checkEncodingCompatibility -import eu.ibagroup.formainframe.utils.isComponentUnderMouse import eu.ibagroup.formainframe.utils.sendTopic import eu.ibagroup.formainframe.utils.service import eu.ibagroup.formainframe.utils.showSaveAnywayDialog