diff --git a/build.gradle.kts b/build.gradle.kts index 1925fda06..68ff7f551 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ buildscript { plugins { id("org.sonarqube") version "3.3" 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" } @@ -32,10 +32,10 @@ apply(plugin = "org.jetbrains.intellij") apply(from = "gradle/sonar.gradle") group = "org.zowe" -version = "1.1.0-221" -val remoteRobotVersion = "0.11.18" +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() @@ -71,7 +71,7 @@ dependencies { implementation("org.jgrapht:jgrapht-core:1.5.1") implementation("com.starxg:java-keytar:1.0.0") implementation("org.zowe.sdk:zowe-kotlin-sdk:0.4.0") - 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/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 3eeff6727..36b8781be 100755 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -334,18 +334,18 @@ Thank you for considering IBA Group for your mainframe needs. + testServiceImplementation="org.zowe.explorer.testutils.testServiceImpl.TestCredentialsServiceImpl"/> + testServiceImplementation="org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl"/> + testServiceImplementation="org.zowe.explorer.testutils.testServiceImpl.TestZosmfApiImpl"/> diff --git a/src/test/kotlin/org/zowe/explorer/config/ConfigTestSpec.kt b/src/test/kotlin/org/zowe/explorer/config/ConfigTestSpec.kt index 9c40ed799..0a32fc913 100644 --- a/src/test/kotlin/org/zowe/explorer/config/ConfigTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/config/ConfigTestSpec.kt @@ -12,19 +12,6 @@ package org.zowe.explorer.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 io.kotest.assertions.assertSoftly -import io.kotest.core.spec.style.ShouldSpec -import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNotBe -import io.mockk.clearAllMocks -import io.mockk.every -import io.mockk.mockk -import io.mockk.mockkObject -import io.mockk.mockkStatic -import io.mockk.unmockkAll import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.connect.Credentials import org.zowe.explorer.config.connect.CredentialsConfigDeclaration @@ -42,29 +29,27 @@ import org.zowe.explorer.dataops.operations.TsoOperation import org.zowe.explorer.dataops.operations.TsoOperationMode import org.zowe.explorer.explorer.Explorer import org.zowe.explorer.explorer.WorkingSet -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.ui.build.tso.TSOWindowFactory import org.zowe.explorer.utils.crudable.Crudable import org.zowe.explorer.utils.service +import io.kotest.assertions.assertSoftly +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import io.mockk.clearAllMocks +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.mockkStatic +import io.mockk.unmockkAll import 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() } @@ -76,12 +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 @@ -292,18 +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, null, "ZOSMFAD" - ) + ConnectionConfig("", "", "", true, ZVersion.ZOS_2_3, null, "ZOSMFAD") ) assertSoftly { owner shouldBe "ZOSMFAD" } } should("get owner by connection config when owner is empty") { val owner = getOwner( - ConnectionConfig( - "", "", "", true, ZVersion.ZOS_2_3, null, "" - ) + ConnectionConfig("", "", "", true, ZVersion.ZOS_2_3, null, "") ) assertSoftly { owner shouldBe "ZOSMF" } diff --git a/src/test/kotlin/org/zowe/explorer/dataops/OperationsTestSpec.kt b/src/test/kotlin/org/zowe/explorer/dataops/OperationsTestSpec.kt index 00f61ac87..e2d152c57 100644 --- a/src/test/kotlin/org/zowe/explorer/dataops/OperationsTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.api.ZosmfApi import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.ws.DSMask -import org.zowe.explorer.dataops.attributes.* +import org.zowe.explorer.dataops.attributes.FileAttributes +import org.zowe.explorer.dataops.attributes.MFRemoteFileAttributes +import org.zowe.explorer.dataops.attributes.MaskedRequester +import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributes +import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributesService +import org.zowe.explorer.dataops.attributes.RemoteMemberAttributes +import org.zowe.explorer.dataops.attributes.RemoteUssAttributes +import org.zowe.explorer.dataops.attributes.Requester +import org.zowe.explorer.dataops.attributes.UssRequester import org.zowe.explorer.dataops.content.synchronizer.ContentSynchronizer import org.zowe.explorer.dataops.content.synchronizer.DocumentedSyncProvider import org.zowe.explorer.dataops.content.synchronizer.LF_LINE_SEPARATOR @@ -29,8 +34,9 @@ import org.zowe.explorer.dataops.operations.DeleteOperation import org.zowe.explorer.dataops.operations.mover.CrossSystemMemberOrUssFileOrSequentialToUssDirMover import org.zowe.explorer.dataops.operations.mover.MoveCopyOperation import org.zowe.explorer.dataops.operations.mover.RemoteToLocalFileMover -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl -import org.zowe.explorer.testServiceImpl.TestZosmfApiImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.testServiceImpl.TestZosmfApiImpl import org.zowe.explorer.utils.castOrNull import org.zowe.explorer.utils.changeFileEncodingTo import org.zowe.explorer.utils.service @@ -38,10 +44,14 @@ import org.zowe.explorer.utils.setUssFileTag import org.zowe.explorer.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/org/zowe/explorer/dataops/SyncToolbarProviderTestSpec.kt b/src/test/kotlin/org/zowe/explorer/dataops/SyncToolbarProviderTestSpec.kt index d700a4382..827cc9a09 100644 --- a/src/test/kotlin/org/zowe/explorer/dataops/SyncToolbarProviderTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.dataops.content.synchronizer.SyncToolbarProvider +import org.zowe.explorer.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 } diff --git a/src/test/kotlin/org/zowe/explorer/editor/EditorTestSpec.kt b/src/test/kotlin/org/zowe/explorer/editor/EditorTestSpec.kt index 2981171cf..027fd7363 100644 --- a/src/test/kotlin/org/zowe/explorer/editor/EditorTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/editor/EditorTestSpec.kt @@ -10,7 +10,10 @@ package org.zowe.explorer.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 org.zowe.explorer.config.ConfigService @@ -45,37 +44,40 @@ import org.zowe.explorer.dataops.content.synchronizer.DocumentedSyncProvider import org.zowe.explorer.editor.inspection.MFLossyEncodingInspection import org.zowe.explorer.explorer.Explorer import org.zowe.explorer.explorer.WorkingSet -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl -import org.zowe.explorer.utils.* +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.utils.checkEncodingCompatibility +import org.zowe.explorer.utils.isComponentUnderMouse +import org.zowe.explorer.utils.sendTopic +import org.zowe.explorer.utils.service +import org.zowe.explorer.utils.showSaveAnywayDialog import org.zowe.explorer.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/org/zowe/explorer/editor/EditorUtilsTestSpec.kt b/src/test/kotlin/org/zowe/explorer/editor/EditorUtilsTestSpec.kt index 2986e57f9..cd123745d 100644 --- a/src/test/kotlin/org/zowe/explorer/editor/EditorUtilsTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.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() } diff --git a/src/test/kotlin/org/zowe/explorer/explorer/ExplorerTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/ExplorerTestSpec.kt index 3130f1557..ed4096735 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/ExplorerTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/ExplorerTestSpec.kt @@ -10,25 +10,10 @@ package org.zowe.explorer.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 org.zowe.explorer.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/org/zowe/explorer/explorer/FilesWorkingSetImplTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/FilesWorkingSetImplTestSpec.kt index 373e1b7d9..bb3959314 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/FilesWorkingSetImplTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/FilesWorkingSetImplTestSpec.kt @@ -11,9 +11,6 @@ package org.zowe.explorer.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 org.zowe.explorer.config.ConfigService import org.zowe.explorer.config.ConfigStateV2 import org.zowe.explorer.config.configCrudable @@ -22,11 +19,11 @@ import org.zowe.explorer.config.makeCrudableWithoutListeners import org.zowe.explorer.config.ws.DSMask import org.zowe.explorer.config.ws.FilesWorkingSetConfig import org.zowe.explorer.config.ws.UssPath +import org.zowe.explorer.testutils.WithApplicationShouldSpec import org.zowe.explorer.utils.gson import org.zowe.explorer.utils.optional import org.zowe.explorer.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/org/zowe/explorer/explorer/actions/AllocateDatasetActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateDatasetActionTestSpec.kt index c5d72e33c..fdfab5554 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateDatasetActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateDatasetActionTestSpec.kt @@ -12,14 +12,10 @@ package org.zowe.explorer.explorer.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.Presentation -import com.intellij.openapi.application.ApplicationManager 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 org.zowe.explorer.common.ui.StatefulDialog import org.zowe.explorer.common.ui.cleanInvalidateOnExpand import org.zowe.explorer.common.ui.showUntilDone @@ -41,9 +37,8 @@ import org.zowe.explorer.explorer.ui.JobNode import org.zowe.explorer.explorer.ui.LibraryNode import org.zowe.explorer.explorer.ui.NodeData import org.zowe.explorer.explorer.ui.getExplorerView -import org.zowe.explorer.utils.service +import org.zowe.explorer.testutils.WithApplicationShouldSpec 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 @@ -61,19 +56,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/org/zowe/explorer/explorer/actions/AllocateLikeActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateLikeActionTestSpec.kt index 60ce95d7f..b10d4140e 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateLikeActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/actions/AllocateLikeActionTestSpec.kt @@ -12,15 +12,11 @@ package org.zowe.explorer.explorer.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.Presentation -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.ComponentManager 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 org.zowe.explorer.common.ui.StatefulDialog import org.zowe.explorer.common.ui.cleanInvalidateOnExpand import org.zowe.explorer.common.ui.showUntilDone @@ -42,9 +38,8 @@ import org.zowe.explorer.explorer.ui.JobNode import org.zowe.explorer.explorer.ui.LibraryNode import org.zowe.explorer.explorer.ui.NodeData import org.zowe.explorer.explorer.ui.getExplorerView -import org.zowe.explorer.utils.service +import org.zowe.explorer.testutils.WithApplicationShouldSpec 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 +59,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/org/zowe/explorer/explorer/actions/EditMaskActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/EditMaskActionTestSpec.kt index 645f8a9e8..b3d15f3e6 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/EditMaskActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/actions/EditMaskActionTestSpec.kt @@ -11,9 +11,6 @@ package org.zowe.explorer.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 org.zowe.explorer.config.ConfigService import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.connect.CredentialService @@ -30,10 +27,10 @@ import org.zowe.explorer.explorer.ui.FileExplorerView import org.zowe.explorer.explorer.ui.NodeData import org.zowe.explorer.explorer.ui.UssDirNode import org.zowe.explorer.explorer.ui.getExplorerView +import org.zowe.explorer.testutils.WithApplicationShouldSpec import org.zowe.explorer.utils.MaskType import org.zowe.explorer.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/org/zowe/explorer/explorer/actions/GetJobPropertiesActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/GetJobPropertiesActionTestSpec.kt index 22e2ab9b5..3fd0f32d5 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/GetJobPropertiesActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.ws.JobsFilter import org.zowe.explorer.dataops.DataOpsManager @@ -27,11 +24,11 @@ import org.zowe.explorer.explorer.ui.SpoolFileNode import org.zowe.explorer.explorer.ui.SpoolFilePropertiesDialog import org.zowe.explorer.explorer.ui.SpoolFileState import org.zowe.explorer.explorer.ui.getExplorerView -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.utils.gson import org.zowe.explorer.utils.service import org.zowe.explorer.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() } diff --git a/src/test/kotlin/org/zowe/explorer/explorer/actions/PurgeJobActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/PurgeJobActionTestSpec.kt index 6d9d34322..7c28f640d 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/PurgeJobActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/actions/PurgeJobActionTestSpec.kt @@ -1,315 +1,298 @@ package org.zowe.explorer.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 org.zowe.explorer.api.ZosmfApi -// import org.zowe.explorer.config.connect.ConnectionConfig -// import org.zowe.explorer.config.connect.CredentialService -// import org.zowe.explorer.config.ws.JobsFilter -// import org.zowe.explorer.dataops.DataOpsManager -// import org.zowe.explorer.dataops.Operation -// import org.zowe.explorer.dataops.UnitRemoteQueryImpl -// import org.zowe.explorer.dataops.attributes.FileAttributes -// import org.zowe.explorer.dataops.attributes.JobsRequester -// import org.zowe.explorer.dataops.attributes.RemoteJobAttributes -// import org.zowe.explorer.dataops.log.JobLogFetcher -// import org.zowe.explorer.dataops.log.MFLogger -// import org.zowe.explorer.explorer.Explorer -// import org.zowe.explorer.explorer.JesWorkingSetImpl -// import org.zowe.explorer.explorer.ui.ErrorNode -// import org.zowe.explorer.explorer.ui.JesExplorerView -// import org.zowe.explorer.explorer.ui.JesFilterNode -// import org.zowe.explorer.explorer.ui.JobNode -// import org.zowe.explorer.explorer.ui.NodeData -// import org.zowe.explorer.explorer.ui.getExplorerView -// import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl -// import org.zowe.explorer.ui.build.jobs.JobBuildTreeView -// import org.zowe.explorer.utils.gson -// import org.zowe.explorer.utils.service -// import org.zowe.explorer.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 org.zowe.explorer.api.ZosmfApi +import org.zowe.explorer.config.connect.ConnectionConfig +import org.zowe.explorer.config.connect.CredentialService +import org.zowe.explorer.config.ws.JobsFilter +import org.zowe.explorer.dataops.DataOpsManager +import org.zowe.explorer.dataops.Operation +import org.zowe.explorer.dataops.UnitRemoteQueryImpl +import org.zowe.explorer.dataops.attributes.FileAttributes +import org.zowe.explorer.dataops.attributes.JobsRequester +import org.zowe.explorer.dataops.attributes.RemoteJobAttributes +import org.zowe.explorer.dataops.log.JobLogFetcher +import org.zowe.explorer.dataops.log.MFLogger +import org.zowe.explorer.explorer.Explorer +import org.zowe.explorer.explorer.JesWorkingSetImpl +import org.zowe.explorer.explorer.ui.ErrorNode +import org.zowe.explorer.explorer.ui.JesExplorerView +import org.zowe.explorer.explorer.ui.JesFilterNode +import org.zowe.explorer.explorer.ui.JobNode +import org.zowe.explorer.explorer.ui.NodeData +import org.zowe.explorer.explorer.ui.getExplorerView +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.ui.build.jobs.JobBuildTreeView +import org.zowe.explorer.utils.gson +import org.zowe.explorer.utils.service +import org.zowe.explorer.vfs.MFVirtualFile +import io.kotest.assertions.assertSoftly +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 : WithApplicationShouldSpec({ + 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(), 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 + } + } + } + } +}) diff --git a/src/test/kotlin/org/zowe/explorer/explorer/actions/RenameActionTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/actions/RenameActionTestSpec.kt index 63762eaa6..f0798ca0e 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/actions/RenameActionTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.config.ConfigService import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager @@ -24,29 +21,17 @@ import org.zowe.explorer.dataops.Operation import org.zowe.explorer.dataops.attributes.* import org.zowe.explorer.explorer.Explorer import org.zowe.explorer.explorer.ui.* -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.utils.* import org.zowe.explorer.utils.crudable.Crudable import org.zowe.explorer.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/org/zowe/explorer/explorer/ui/ChangeEncodingDialogTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/ui/ChangeEncodingDialogTestSpec.kt index f0a6cc80e..4b695c4ea 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/ui/ChangeEncodingDialogTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.common.message import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager @@ -29,31 +26,30 @@ import org.zowe.explorer.dataops.content.synchronizer.ContentSynchronizer import org.zowe.explorer.dataops.content.synchronizer.DocumentedSyncProvider import org.zowe.explorer.explorer.Explorer import org.zowe.explorer.explorer.WorkingSet -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl -import org.zowe.explorer.utils.* +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.utils.castOrNull +import org.zowe.explorer.utils.reloadIn +import org.zowe.explorer.utils.saveIn +import org.zowe.explorer.utils.service +import org.zowe.explorer.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/org/zowe/explorer/explorer/ui/ExplorerPasteProviderTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/ui/ExplorerPasteProviderTestSpec.kt index cababf5fd..9c06ea741 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/ui/ExplorerPasteProviderTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.common.ui.cleanInvalidateOnExpand import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.ws.FilesWorkingSetConfig @@ -37,12 +34,12 @@ import org.zowe.explorer.explorer.AbstractExplorerBase import org.zowe.explorer.explorer.FileExplorer import org.zowe.explorer.explorer.FileExplorerContentProvider import org.zowe.explorer.explorer.FilesWorkingSet -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.utils.castOrNull import org.zowe.explorer.utils.service import org.zowe.explorer.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/org/zowe/explorer/explorer/ui/FileExplorerViewDropTargetTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/ui/FileExplorerViewDropTargetTestSpec.kt index 22490eb9c..17c4e6ade 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/ui/FileExplorerViewDropTargetTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/explorer/ui/FileExplorerViewDropTargetTestSpec.kt @@ -11,7 +11,11 @@ package org.zowe.explorer.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 org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager -import org.zowe.explorer.dataops.attributes.* -import org.zowe.explorer.explorer.* -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.dataops.attributes.AttributesService +import org.zowe.explorer.dataops.attributes.FileAttributes +import org.zowe.explorer.dataops.attributes.MaskedRequester +import org.zowe.explorer.dataops.attributes.RemoteDatasetAttributes +import org.zowe.explorer.dataops.attributes.RemoteMemberAttributes +import org.zowe.explorer.dataops.attributes.RemoteUssAttributes +import org.zowe.explorer.dataops.attributes.UssRequester +import org.zowe.explorer.explorer.Explorer +import org.zowe.explorer.explorer.FilesWorkingSetImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.utils.service import org.zowe.explorer.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") } diff --git a/src/test/kotlin/org/zowe/explorer/explorer/ui/UssFileNodeTestSpec.kt b/src/test/kotlin/org/zowe/explorer/explorer/ui/UssFileNodeTestSpec.kt index 773a030da..9439c16e2 100644 --- a/src/test/kotlin/org/zowe/explorer/explorer/ui/UssFileNodeTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager import org.zowe.explorer.dataops.attributes.FileAttributes @@ -39,13 +36,13 @@ import org.zowe.explorer.explorer.FileExplorer import org.zowe.explorer.explorer.FileExplorerContentProvider import org.zowe.explorer.explorer.UIComponentManager import org.zowe.explorer.explorer.WorkingSet -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.testutils.testServiceImpl.TestDataOpsManagerImpl import org.zowe.explorer.utils.isBeingEditingNow import org.zowe.explorer.utils.service import org.zowe.explorer.vfs.MFVirtualFile import org.zowe.explorer.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/org/zowe/explorer/testutils/WithApplicationShouldSpec.kt b/src/test/kotlin/org/zowe/explorer/testutils/WithApplicationShouldSpec.kt new file mode 100644 index 000000000..bd007e3f4 --- /dev/null +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.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("zowe-explorer").fixture + val appFixture = factory.createCodeInsightFixture(lightFixture) + appFixture.setUp() + } + + init { + body() + } +} diff --git a/src/test/kotlin/org/zowe/explorer/testServiceImpl/TestCredentialsServiceImpl.kt b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestCredentialsServiceImpl.kt similarity index 89% rename from src/test/kotlin/org/zowe/explorer/testServiceImpl/TestCredentialsServiceImpl.kt rename to src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestCredentialsServiceImpl.kt index f85905a86..1678a0fbd 100644 --- a/src/test/kotlin/org/zowe/explorer/testServiceImpl/TestCredentialsServiceImpl.kt +++ b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestCredentialsServiceImpl.kt @@ -8,12 +8,12 @@ * Copyright IBA Group 2020 */ -package org.zowe.explorer.testServiceImpl +package org.zowe.explorer.testutils.testServiceImpl import org.zowe.explorer.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/org/zowe/explorer/testServiceImpl/TestDataOpsManagerImpl.kt b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestDataOpsManagerImpl.kt similarity index 99% rename from src/test/kotlin/org/zowe/explorer/testServiceImpl/TestDataOpsManagerImpl.kt rename to src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestDataOpsManagerImpl.kt index c9f0c6cbd..3c828c42f 100644 --- a/src/test/kotlin/org/zowe/explorer/testServiceImpl/TestDataOpsManagerImpl.kt +++ b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestDataOpsManagerImpl.kt @@ -8,7 +8,7 @@ * Copyright IBA Group 2020 */ -package org.zowe.explorer.testServiceImpl +package org.zowe.explorer.testutils.testServiceImpl import com.intellij.execution.ui.ConsoleView import com.intellij.openapi.components.ComponentManager diff --git a/src/test/kotlin/org/zowe/explorer/testServiceImpl/TestZosmfApiImpl.kt b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestZosmfApiImpl.kt similarity index 94% rename from src/test/kotlin/org/zowe/explorer/testServiceImpl/TestZosmfApiImpl.kt rename to src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestZosmfApiImpl.kt index 96e464b81..29092418d 100644 --- a/src/test/kotlin/org/zowe/explorer/testServiceImpl/TestZosmfApiImpl.kt +++ b/src/test/kotlin/org/zowe/explorer/testutils/testServiceImpl/TestZosmfApiImpl.kt @@ -8,12 +8,12 @@ * Copyright IBA Group 2020 */ -package org.zowe.explorer.testServiceImpl +package org.zowe.explorer.testutils.testServiceImpl import org.zowe.explorer.api.ZosmfApi import org.zowe.explorer.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/org/zowe/explorer/utils/EncodingUtilsTestSpec.kt b/src/test/kotlin/org/zowe/explorer/utils/EncodingUtilsTestSpec.kt index 26dea8004..7b6ed5291 100644 --- a/src/test/kotlin/org/zowe/explorer/utils/EncodingUtilsTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/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 org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.dataops.DataOpsManager import org.zowe.explorer.dataops.attributes.RemoteUssAttributes @@ -39,11 +36,16 @@ import org.zowe.explorer.dataops.content.synchronizer.DocumentedSyncProvider import org.zowe.explorer.explorer.Explorer import org.zowe.explorer.explorer.WorkingSet import org.zowe.explorer.explorer.ui.ChangeEncodingDialog -import org.zowe.explorer.testServiceImpl.TestDataOpsManagerImpl +import org.zowe.explorer.testutils.WithApplicationShouldSpec +import org.zowe.explorer.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"