Skip to content

Commit

Permalink
IJMP-1230 Some changes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KUGDev committed Aug 21, 2023
1 parent 450aa9c commit 646cab5
Show file tree
Hide file tree
Showing 24 changed files with 325 additions and 389 deletions.
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,23 @@ Example of how to see the output:<br/>

<applicationService preload="true" serviceInterface="eu.ibagroup.formainframe.analytics.AnalyticsService"
serviceImplementation="eu.ibagroup.formainframe.analytics.AnalyticsServiceImpl"
testServiceImplementation="eu.ibagroup.formainframe.testServiceImpl.TestAnalyticsServiceImpl"/>
testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestAnalyticsServiceImpl"/>

<applicationService serviceInterface="eu.ibagroup.formainframe.config.connect.CredentialService"
serviceImplementation="eu.ibagroup.formainframe.config.connect.CredentialServiceImpl"
testServiceImplementation="eu.ibagroup.formainframe.testServiceImpl.TestCredentialsServiceImpl"/>
testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestCredentialsServiceImpl"/>


<applicationService serviceInterface="eu.ibagroup.formainframe.config.ConfigSandbox"
serviceImplementation="eu.ibagroup.formainframe.config.ConfigSandboxImpl"/>

<applicationService serviceInterface="eu.ibagroup.formainframe.dataops.DataOpsManager" preload="true"
serviceImplementation="eu.ibagroup.formainframe.dataops.DataOpsManagerImpl"
testServiceImplementation="eu.ibagroup.formainframe.testServiceImpl.TestDataOpsManagerImpl"/>
testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestDataOpsManagerImpl"/>

<applicationService serviceInterface="eu.ibagroup.formainframe.api.ZosmfApi"
serviceImplementation="eu.ibagroup.formainframe.api.ZosmfApiImpl"
testServiceImplementation="eu.ibagroup.formainframe.testServiceImpl.TestZosmfApiImpl"/>
testServiceImplementation="eu.ibagroup.formainframe.testutils.testServiceImpl.TestZosmfApiImpl"/>

<applicationService serviceInterface="eu.ibagroup.formainframe.analytics.PolicyProvider"
serviceImplementation="eu.ibagroup.formainframe.analytics.PolicyProviderImpl"/>
Expand Down
50 changes: 24 additions & 26 deletions src/test/kotlin/eu/ibagroup/formainframe/config/ConfigTestSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -65,8 +61,12 @@ class ConfigTestSpec : ShouldSpec({

fun mockConfigService() {
val mockConfigServiceInstance = mockk<ConfigService>()
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
Expand Down Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,43 @@ 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
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
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
Expand All @@ -61,7 +71,7 @@ inline fun mockkRequesters(
every { attributes.requesters } returns mutableListOf(connectionConfigToRequester(connection))
}

inline fun <reified S: FileAttributes, reified D: MFRemoteFileAttributes<*, *>> prepareBareOperation(
inline fun <reified S : FileAttributes, reified D : MFRemoteFileAttributes<*, *>> prepareBareOperation(
isCrossystem: Boolean = false,
sourceConnectionConfigToRequester: (ConnectionConfig) -> Requester<*>,
destConnectionConfigToRequester: (ConnectionConfig) -> Requester<*>
Expand All @@ -83,19 +93,7 @@ inline fun <reified S: FileAttributes, reified D: MFRemoteFileAttributes<*, *>>
)
}

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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -52,7 +42,9 @@ class SyncToolbarProviderTestSpec : ShouldSpec({
var isResolved = false
val mockedActionGroupForTest = mockk<ActionGroup>()
every { ActionManager.getInstance() } returns mockedActionManagerInstance
every { mockedActionManagerInstance.getAction(any() as String)} answers {
every {
mockedActionManagerInstance.getAction(any() as String)
} answers {
isResolved = true
mockedActionGroupForTest
}
Expand All @@ -67,7 +59,7 @@ class SyncToolbarProviderTestSpec : ShouldSpec({
var isResolved = false
val mockedNotActionGroupForTest = mockk<AnAction>()
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
}
Expand All @@ -81,4 +73,4 @@ class SyncToolbarProviderTestSpec : ShouldSpec({

unmockkAll()
}
})
})
48 changes: 25 additions & 23 deletions src/test/kotlin/eu/ibagroup/formainframe/editor/EditorTestSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
}
Expand Down
Loading

0 comments on commit 646cab5

Please sign in to comment.