diff --git a/src/main/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceImpl.kt b/src/main/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceImpl.kt index bba73979..b55a5084 100644 --- a/src/main/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceImpl.kt +++ b/src/main/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceImpl.kt @@ -19,11 +19,14 @@ import com.intellij.notification.NotificationType import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.application.runReadAction import com.intellij.openapi.application.runWriteAction -import com.intellij.openapi.components.service +import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages import com.intellij.openapi.vfs.VirtualFileManager +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking import org.zowe.explorer.config.ConfigService import org.zowe.explorer.config.connect.ConnectionConfig import org.zowe.explorer.config.connect.CredentialService @@ -180,7 +183,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService } } } catch (e: Exception) { - NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file") + NotificationsService.errorNotification(e, project = myProject, custTitle = "Error with Zowe config file") return null } } @@ -239,42 +242,99 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService } /** - * Checks the zowe connection using InfoOperation. It is also needed to load zos version and + * Checks all passed zowe connections using InfoOperation in parallel. It is also needed to load zos version and * real owner of the connection (acceptable for alias users). - * IMPORTANT!!! It modifies passed connection object by setting zVersion and owner. - * @param zoweConnection connection to check and prepare. - * @throws Throwable if something went wrong (connection was not established or one of requests was failed ...) + * IMPORTANT!!! It modifies passed connection objects by setting zVersion and owner. + * @param zoweConnections list of connection to check and prepare. + * @param type of zowe config + * @throws ProcessCanceledException if connection has been canceled by user + * @return a pair of lists with successfully tested connections and invalid connections */ - private fun testAndPrepareConnection(zoweConnection: ConnectionConfig) { - val throwable = runTask("Testing Connection to ${zoweConnection.url}", myProject) { indicator -> - return@runTask try { - runCatching { - DataOpsManager.getService().performOperation(InfoOperation(zoweConnection), indicator) - }.onSuccess { - indicator.text = "Retrieving z/OS information" - val systemInfo = DataOpsManager.getService().performOperation(ZOSInfoOperation(zoweConnection), indicator) - zoweConnection.zVersion = when (systemInfo.zosVersion) { - "04.25.00" -> ZVersion.ZOS_2_2 - "04.26.00" -> ZVersion.ZOS_2_3 - "04.27.00" -> ZVersion.ZOS_2_4 - "04.28.00" -> ZVersion.ZOS_2_5 - "04.29.00" -> ZVersion.ZOS_3_1 - else -> ZVersion.ZOS_2_1 + @Throws(ProcessCanceledException::class) + private fun testAndPrepareConnections( + zoweConnections: List, + type: ZoweConfigType + ): Pair, MutableList> { + val succeededConnections = mutableListOf() + val failedConnections = mutableListOf() + val results = mutableListOf>() + var throwable: ProcessCanceledException? = null + runTask("Testing Connections...", myProject, cancellable = true) { indicator -> + runBlocking { + for (zosmfConnection in zoweConnections) { + results.add(async { + val zoweConnection: ConnectionConfig = prepareConnection(zosmfConnection, type) + try { + runCatching { + if (!indicator.isCanceled) { + indicator.text = if (zoweConnections.size == 1) + "Testing Connection to ${zoweConnection.url}" + else + "Testing Connection to ${zoweConnections.size} connections" + DataOpsManager.getService().performOperation(InfoOperation(zoweConnection), indicator) + } else { + throw ProcessCanceledException() + } + }.onSuccess { + if (!indicator.isCanceled) { + + indicator.text = if (zoweConnections.size == 1) + "Retrieving z/OS information for ${zoweConnection.url}" + else + "Retrieving z/OS information for ${zoweConnections.size} connections" + val systemInfo = + DataOpsManager.getService().performOperation( + ZOSInfoOperation(zoweConnection), + indicator + ) + zoweConnection.zVersion = when (systemInfo.zosVersion) { + "04.25.00" -> ZVersion.ZOS_2_2 + "04.26.00" -> ZVersion.ZOS_2_3 + "04.27.00" -> ZVersion.ZOS_2_4 + "04.28.00" -> ZVersion.ZOS_2_5 + "04.29.00" -> ZVersion.ZOS_3_1 + else -> ZVersion.ZOS_2_1 + } + } else { + throw ProcessCanceledException() + } + }.onSuccess { + if (!indicator.isCanceled) { + indicator.text = if (zoweConnections.size == 1) + "Retrieving user information for ${zoweConnection.url}" + else + "Retrieving user information for ${zoweConnections.size} connections" + zoweConnection.owner = whoAmI(zoweConnection) ?: "" + } else { + throw ProcessCanceledException() + } + }.onFailure { + if (indicator.isCanceled) + throw ProcessCanceledException() + else { + throw it + } + } + } catch (t: Throwable) { + if (t is ProcessCanceledException) + throwable = t + failedConnections.add(zoweConnection) + return@async zoweConnection + } + succeededConnections.add(zoweConnection) + return@async zoweConnection } - }.onSuccess { - indicator.text = "Retrieving user information" - zoweConnection.owner = whoAmI(zoweConnection) ?: "" - }.onFailure { - throw it + ) } - null - } catch (t: Throwable) { - t } } if (throwable != null) { - throw throwable + throw ProcessCanceledException() + } + runBlocking { + results.map { it.await() } } + return succeededConnections to failedConnections } /** @@ -290,19 +350,46 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService this.globalZoweConfig zoweConfig ?: throw Exception("Cannot get $type Zowe config") - val (allPreparedConn, failedConnections) = testAndPrepareAllZosmfConnections(zoweConfig, type) + val allConnectionsToTest = zoweConfig.getListOfZosmfConections() + val uniqueConnectionsToTest = allConnectionsToTest.filterIndexed { _, element -> + allConnectionsToTest.filter { + it.host == element.host && + it.zosmfPort == element.zosmfPort && + it.user == element.user && + it.password == element.password && + it.protocol == element.protocol && + it.rejectUnauthorized == element.rejectUnauthorized && + it.basePath == element.basePath && + it.encoding == element.encoding && + it.responseTimeout == element.responseTimeout + }.sortedWith(compareBy { it.profileName.length })[0] == element + } + val duplicatedConnections = (allConnectionsToTest + uniqueConnectionsToTest).groupBy { it.profileName } + .filter { it.value.size == 1 } + .flatMap { it.value } + + val (succeededConnections, failedConnections) = + testAndPrepareConnections(uniqueConnectionsToTest, type) + + for (tmpZOSMFConn in duplicatedConnections) { + println(succeededConnections) + println(failedConnections) + restoreFullConnectionList(tmpZOSMFConn, succeededConnections, type) + restoreFullConnectionList(tmpZOSMFConn, failedConnections, type) + } + if (checkConnection and failedConnections.isNotEmpty()) { val andMore = if (failedConnections.size > 3) "..." else "" notifyUiOnConnectionFailure( - "Connection failed to:", - "${failedConnections.joinToString(separator = ",

") { it.url }} $andMore", + "Unsuccessfully tested profiles:", + "${failedConnections.joinToString(separator = ",

") { getProfileNameFromConnName(it.name) }} $andMore", type ) } val conToAdd = if (checkConnection) - allPreparedConn.subtract(failedConnections.toSet()) + succeededConnections else - allPreparedConn + succeededConnections + failedConnections conToAdd.forEach { zosmfConnection -> val connectionOpt = configCrudable.addOrUpdate(zosmfConnection) if (!connectionOpt.isEmpty) { @@ -315,7 +402,43 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService } } catch (e: Exception) { - NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file") + if (e !is ProcessCanceledException) + NotificationsService.errorNotification( + e, + project = myProject, + custTitle = "Error with Zowe config file" + ) + else { /* Nothing to do */ + } + } + } + + /** + * ResRestore connection lists after testing + * @param tmpZOSMFConn duplicated connection to restore. + * @param connListToRestore list with tested connections (succeeded or failed) + * @param type of zowe config + */ + private fun restoreFullConnectionList( + tmpZOSMFConn: ZOSConnection, + connListToRestore: MutableList, + type: ZoweConfigType + ) { + val tmpConn = tmpZOSMFConn.toConnectionConfig(uuid = UUID.randomUUID().toString(), type = type) + val tmpDuplicatedConnList = connListToRestore.filter { + it.isAllowSelfSigned == tmpConn.isAllowSelfSigned && + it.url == tmpConn.url && + it.name != tmpConn.name && + CredentialService.getUsername(it) == tmpZOSMFConn.user && + CredentialService.getPassword(it).contentEquals(tmpZOSMFConn.password.toCharArray()) + } + if (tmpDuplicatedConnList.isNotEmpty()) { + val tmpDuplConn = tmpDuplicatedConnList[0].clone() + tmpDuplConn.name = tmpConn.name + tmpDuplConn.uuid = tmpConn.uuid + CredentialService.getService() + .setCredentials(tmpConn.uuid, tmpZOSMFConn.user, tmpZOSMFConn.password.toCharArray()) + connListToRestore.add(tmpDuplConn) } } @@ -338,31 +461,6 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService return zoweConnection } - /** - * Convert all zosmf connections from zowe config file to ConnectionConfig and tests them - * @param zoweConfig - * @param type of zowe config - * @return pair of lists, one is the connections list, the second is the list of URLs which did not pass the test - */ - private fun testAndPrepareAllZosmfConnections( - zoweConfig: ZoweConfig, - type: ZoweConfigType - ): Pair, List> { - return zoweConfig.getListOfZosmfConections() - .fold( - mutableListOf() to mutableListOf() - ) { (allConnectionConfigs, failedURLs), zosmfConnection -> - val zoweConnection = prepareConnection(zosmfConnection, type) - try { - testAndPrepareConnection(zoweConnection) - } catch (t: Throwable) { - failedURLs.add(zoweConnection) - } - allConnectionConfigs.add(zoweConnection) - allConnectionConfigs to failedURLs - } - } - /** * @see ZoweConfigService.deleteZoweConfig */ @@ -398,7 +496,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService } } catch (e: Exception) { - NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file") + NotificationsService.errorNotification(e, project = myProject, custTitle = "Error with Zowe config file") } } @@ -421,13 +519,13 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService var host = "localhost" var port = "10443" if (matcher.matches()) { - if (matcher.group(2) != null) + if (!matcher.group(2).isNullOrBlank()) host = matcher.group(2) - if (matcher.group(3) != null) + if (!matcher.group(3).isNullOrBlank()) port = matcher.group(3).substring(1) } - val content = getResourceAsStreamWrappable(ZoweConfigServiceImpl::class.java.classLoader ,"files/${ZOWE_CONFIG_NAME}") + val content = getResourceAsStreamWrappable(ZoweConfigServiceImpl::class.java.classLoader, "files/${ZOWE_CONFIG_NAME}") .use { iS -> iS?.readAllBytes()?.let { String(it, charset) } } ?.replace("".toRegex(), port) ?.replace("".toRegex(), "\"$host\"") @@ -521,6 +619,7 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService if (findAllZosmfExistingConnection(type).isEmpty()) return ZoweConfigState.NEED_TO_ADD val zoweConfigZosmfConnections = zoweConfig.getListOfZosmfConections() + return zoweConfigZosmfConnections .fold(ZoweConfigState.SYNCHRONIZED) { prevZoweConfigState, zosConnection -> val existingConnection = findExistingConnection(type, zosConnection.profileName) diff --git a/src/test/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceTestSpec.kt b/src/test/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceTestSpec.kt index 01da5bb8..2669dbf0 100644 --- a/src/test/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceTestSpec.kt +++ b/src/test/kotlin/org/zowe/explorer/zowe/service/ZoweConfigServiceTestSpec.kt @@ -18,6 +18,7 @@ import com.intellij.notification.NotificationGroupManager import com.intellij.notification.NotificationType import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.application.runWriteAction +import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.project.Project import com.intellij.openapi.ui.Messages @@ -299,6 +300,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -316,6 +319,82 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ assertSoftly { addOrUpdateCalledCount shouldBe 1 } } + should("cancel testing Zowe config connections") { + val testFailProfileName5 = "test_profile_name_fail5" + var extractSecurePropertiesCalledCount = 0 + var cancelationCount = 0 + + dataOpsManagerServiceMock.testInstance = object : TestDataOpsManagerImpl() { + override fun performOperation(operation: Operation, progressIndicator: ProgressIndicator): R { + return when (operation) { + is InfoOperation -> { + infoOperationCount += 1 + if ((operation as InfoOperation).connectionConfig.uuid==("throw")){ + cancelationCount += 1 + throw ProcessCanceledException() + } + else { + mockk() as R + } + } + else -> { + mockk() as R + } + } + } + } + + val globalZoweConfig: ZoweConfig = mockk { + every { + extractSecureProperties(any>(), any()) + } answers { + extractSecurePropertiesCalledCount += 1 + } + every { + getListOfZosmfConections() + } returns listOf( + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName5 + every { basePath } returns "test/base/path/" + every { host } returns "testFailHost5" + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns null + every { encoding } returns 1047 + every { responseTimeout } returns 600 + } + ) + } + + every { parseConfigJsonRef(any()) } returns globalZoweConfig + + every { + configServiceCrudableMock.find(any>(), any>()) + } answers { + listOf( + mockk { + every { uuid } returns "throw" + every { zVersion } returns ZVersion.ZOS_2_4 + every { name } returns "$ZOWE_PROJECT_PREFIX${ZoweConfigType.GLOBAL}-$testFailProfileName5" + every { zoweConfigPath } returns System.getProperty("user.home").replace("((\\*)|(/*))$", "") + "/.zowe/" + ZOWE_CONFIG_NAME + } + ) + .filter(secondArg>()::test) + .stream() + } + + val zoweConfigService = ZoweConfigServiceImpl(projectMock) + + zoweConfigService + .addOrUpdateZoweConfig(scanProject = true, checkConnection = true, ZoweConfigType.GLOBAL) + assertSoftly { cancelationCount shouldBe 1 } + assertSoftly { setCredentialsCalledCount shouldBe 1 } + assertSoftly { infoOperationCount shouldBe 1 } + + } + should("add a new connection for the local Zowe config, scanning a project, with failed connections and their check") { val testSuccessProfileName = "test_profile_name_success" val testFailProfileName1 = "test_profile_name_fail1" @@ -370,9 +449,9 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ } answers { if ( notificationType == NotificationType.ERROR - && title.contains("Connection failed to") - && details.contains(testFailHost1) - && details.contains(testFailHost2) + && title.contains("Unsuccessfully tested profiles:") + && details.contains(testFailProfileName1) + && details.contains(testFailProfileName2) ) { isCorrectConnectionErrorNotificationTrigerred = true } @@ -400,6 +479,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns null + every { encoding } returns 1047 + every { responseTimeout } returns 600 }, mockk { every { user } returns "TSTUSR" @@ -410,6 +491,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 }, mockk { every { user } returns "TSTUSR" @@ -420,6 +503,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -503,6 +588,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -543,10 +630,17 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ val testFailProfileName2 = "test_profile_name_fail2" val testFailProfileName3 = "test_profile_name_fail3" val testFailProfileName4 = "test_profile_name_fail4" + val testFailProfileName5 = "test_profile_name_fail5" + val testFailProfileName6 = "test_profile_name_fail6" + val testFailProfileName7 = "test_profile_name_fail7" + val testFailProfileName8 = "test_profile_name_fail8" + val testFailProfileName9 = "test_profile_name_fail9" + val testFailProfileName10 = "test_profile_name_fail10" + val testFailProfileName11 = "test_profile_name_fail11" val testFailHost1 = "test1.com" - val testFailHost2 = "test2.com" - val testFailHost3 = "test3.com" - val testFailHost4 = "test4.com" + val testSuccessHost = "test3.com" + val testUsername = "TSTUSR" + val testPassword = "TSTPWD" var extractSecurePropertiesCalledCount = 0 var isCorrectConnectionErrorNotificationTrigerred = false @@ -556,7 +650,7 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ return when (operation) { is InfoOperation -> { infoOperationCount += 1 - if (infoOperationCount <= 2) { + if (infoOperationCount <= 8) { throw Exception() } else { mockk() as R @@ -595,11 +689,11 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ } answers { if ( notificationType == NotificationType.ERROR - && title.contains("Connection failed to") - && details.contains(testFailHost1) - && details.contains(testFailHost2) - && details.contains(testFailHost3) - && details.contains(testFailHost4) + && title.contains("Unsuccessfully tested profiles:") + && details.contains(testFailProfileName1) + && details.contains(testFailProfileName2) + && details.contains(testFailProfileName3) + && details.contains(testFailProfileName4) && details.contains("...") ) { isCorrectConnectionErrorNotificationTrigerred = true @@ -623,51 +717,145 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { user } returns "TSTUSR" every { password } returns "TSTPWD" every { profileName } returns testFailProfileName1 - every { basePath } returns "test/base/path/" + every { basePath } returns "test/base/path" every { host } returns testFailHost1 every { zosmfPort } returns "1234" every { protocol } returns "https" - every { rejectUnauthorized } returns null + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 }, mockk { - every { user } returns "TSTUSR" + every { user } returns "TSTUSR1" every { password } returns "TSTPWD" every { profileName } returns testFailProfileName2 every { basePath } returns "test/base/path" - every { host } returns testFailHost2 + every { host } returns testFailHost1 every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 }, mockk { every { user } returns "TSTUSR" - every { password } returns "TSTPWD" + every { password } returns "TSTPWD1" every { profileName } returns testFailProfileName3 every { basePath } returns "test/base/path" - every { host } returns testFailHost3 + every { host } returns testFailHost1 every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 }, mockk { every { user } returns "TSTUSR" every { password } returns "TSTPWD" every { profileName } returns testFailProfileName4 + every { basePath } returns "test/base/path/" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 + }, + + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName5 + every { basePath } returns "test/base/path" + every { host } returns testFailHost1 + every { zosmfPort } returns "12345" + every { protocol } returns "https" + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 + }, + mockk { + every { user } returns "TSTUSR1" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName6 + every { basePath } returns "test/base/path" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "http" + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 + }, + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName7 + every { basePath } returns "test/base/path" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 + }, + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName8 + every { basePath } returns "test/base/path7" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns null + every { encoding } returns 1047 + every { responseTimeout } returns 600 + }, + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName9 every { basePath } returns "test/base/path" - every { host } returns testFailHost4 + every { host } returns testFailHost1 every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns false + every { encoding } returns 1048 + every { responseTimeout } returns 600 }, mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName10 + every { basePath } returns "test/base/path" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 601 + }, + mockk { + every { user } returns "TSTUSR" + every { password } returns "TSTPWD" + every { profileName } returns testFailProfileName11 + every { basePath } returns "test/base/path" + every { host } returns testFailHost1 + every { zosmfPort } returns "1234" + every { protocol } returns "https" + every { rejectUnauthorized } returns false + every { encoding } returns 1047 + every { responseTimeout } returns 600 + },mockk { every { user } returns "TSTUSR" every { password } returns "TSTPWD" every { profileName } returns testSuccessProfileName every { basePath } returns "test/base/path" - every { host } returns "test3.com" + every { host } returns testSuccessHost every { zosmfPort } returns "1234" every { protocol } returns "https" every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -713,15 +901,29 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ Optional.empty() } + credentialServiceMock.testInstance = object : TestCredentialsServiceImpl() { + override fun getUsernameByKey(connectionConfigUuid: String): String { + return testUsername + } + + override fun getPasswordByKey(connectionConfigUuid: String): CharArray { + return testPassword.toCharArray() + } + + override fun setCredentials(connectionConfigUuid: String, username: String, password: CharArray) { + setCredentialsCalledCount += 1 + } + } + val zoweConfigService = ZoweConfigServiceImpl(projectMock) zoweConfigService .addOrUpdateZoweConfig(scanProject = true, checkConnection = true, ZoweConfigType.GLOBAL) - assertSoftly { setCredentialsCalledCount shouldBe 5 } + assertSoftly { setCredentialsCalledCount shouldBe 12 } assertSoftly { onConfigSavedCalledCount shouldBe 0 } assertSoftly { extractSecurePropertiesCalledCount shouldBe 1 } - assertSoftly { infoOperationCount shouldBe 5 } + assertSoftly { infoOperationCount shouldBe 11 } assertSoftly { zosInfoOperationCount shouldBe 3 } assertSoftly { isCorrectConnectionErrorNotificationTrigerred shouldBe true } assertSoftly { addOrUpdateCalledCount shouldBe 1 } @@ -1223,6 +1425,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns testPort every { protocol } returns testProtocol every { rejectUnauthorized } returns !testIsAllowSelfSigned + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -1264,6 +1468,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns testPort every { protocol } returns testProtocol every { rejectUnauthorized } returns true + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -1305,6 +1511,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns testPort every { protocol } returns testProtocol every { rejectUnauthorized } returns !testIsAllowSelfSigned + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -1346,6 +1554,8 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ every { zosmfPort } returns testPort every { protocol } returns testProtocol every { rejectUnauthorized } returns !testIsAllowSelfSigned + every { encoding } returns 1047 + every { responseTimeout } returns 600 } ) } @@ -1381,4 +1591,4 @@ class ZoweConfigServiceTestSpec : WithApplicationShouldSpec({ } } } -}) \ No newline at end of file +})