-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathContentTestSpec.kt
247 lines (205 loc) · 7.67 KB
/
ContentTestSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Copyright (c) 2020-2024 IBA Group.
*
* 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
*
* Contributors:
* IBA Group
* Zowe Community
*/
package eu.ibagroup.formainframe.dataops
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import eu.ibagroup.formainframe.dataops.content.service.SyncProcessService
import eu.ibagroup.formainframe.dataops.content.service.SyncProcessServiceImpl
import eu.ibagroup.formainframe.dataops.content.synchronizer.checkFileForSync
import eu.ibagroup.formainframe.dataops.content.synchronizer.checkForSync
import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec
import eu.ibagroup.formainframe.testutils.testServiceImpl.TestSyncProcessServiceImpl
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import kotlin.reflect.KFunction
class ContentTestSpec : WithApplicationShouldSpec({
afterSpec {
clearAllMocks()
}
context("dataops module: content/synchronizer") {
var wasWarningShown = false
val virtualFileMock = mockk<VirtualFile>()
every { virtualFileMock.name } returns "fileName"
val syncProcessService = SyncProcessService.getService() as TestSyncProcessServiceImpl
beforeEach {
wasWarningShown = false
val showWarningDialogRef: (Project, String, String) -> Unit = Messages::showWarningDialog
mockkStatic(showWarningDialogRef as KFunction<*>)
every { Messages.showWarningDialog(any<Project>(), any<String>(), any<String>()) } answers {
wasWarningShown = true
}
syncProcessService.testInstance = TestSyncProcessServiceImpl()
}
afterEach {
unmockkAll()
}
// syncUtils.removeLastNewLine
should("remove last blank line") {}
should("not remove last non-blank line") {}
// syncUtils.checkFileForSync
should("check file when it is syncing") {
syncProcessService.testInstance = object : TestSyncProcessServiceImpl() {
override fun isFileSyncingNow(file: VirtualFile): Boolean {
return true
}
}
val result = checkFileForSync(mockk(), virtualFileMock)
assertSoftly {
result shouldBe true
wasWarningShown shouldBe true
}
}
should("check file when it is not syncing") {
val result = checkFileForSync(mockk(), virtualFileMock)
assertSoftly {
result shouldBe false
wasWarningShown shouldBe false
}
}
should("check file and dependent files when are they syncing") {
syncProcessService.testInstance = object : TestSyncProcessServiceImpl() {
override fun isFileSyncingNow(file: VirtualFile): Boolean {
return true
}
override fun areDependentFilesSyncingNow(file: VirtualFile): Boolean {
return true
}
}
val result = checkFileForSync(mockk(), virtualFileMock, checkDependentFiles = true)
assertSoftly {
result shouldBe true
wasWarningShown shouldBe true
}
}
should("check file and dependent files when are they not syncing") {
val result = checkFileForSync(mockk(), virtualFileMock, checkDependentFiles = true)
assertSoftly {
result shouldBe false
wasWarningShown shouldBe false
}
}
// syncUtils.checkForSync
should("check that any file is syncing") {
syncProcessService.testInstance = object : TestSyncProcessServiceImpl() {
override fun isAnyFileSyncingNow(): Boolean {
return true
}
}
val result = checkForSync(mockk())
assertSoftly {
result shouldBe true
wasWarningShown shouldBe true
}
}
should("check that no file is syncing") {
val result = checkForSync()
assertSoftly {
result shouldBe false
wasWarningShown shouldBe false
}
}
// SyncAction.actionPerformed
should("synchronize the file with the remote file") {}
// MemberContentSynchronizer.fetchRemoteContentBytes
should("fetch remote content bytes") {}
// MemberContentSynchronizer.uploadNewContent
should("upload new content to the mainframe") {}
// DocumentedSyncProvider.putInitialContent
should("put initial file content when the file is read-only") {}
}
context("dataops module: content/adapters") {
// SeqDatasetContentAdapter.adaptContentToMainframe
should("adapt content for the dataset with variable length") {}
should("adapt content for the dataset with variable print length") {}
should("adapt content for the dataset with fixed length") {}
// SeqDatasetContentAdapter.adaptContentFromMainframe
should("adapt content for the dataset from mainframe with variable print length") {}
}
context("dataops module: content/service") {
val syncProcessService = SyncProcessServiceImpl()
val virtualFileMock = mockk<VirtualFile>()
val progressIndicatorMock = mockk<ProgressIndicator>()
beforeEach {
syncProcessService.startFileSync(virtualFileMock, progressIndicatorMock)
val isAncestorRef: (VirtualFile, VirtualFile, Boolean) -> Boolean = VfsUtilCore::isAncestor
mockkStatic(isAncestorRef as KFunction<*>)
}
afterEach {
syncProcessService.stopFileSync(virtualFileMock)
unmockkAll()
}
// SyncProcessServiceImpl.isFileSyncingNow
should("file is syncing now") {
every { progressIndicatorMock.isRunning } returns true
val result = syncProcessService.isFileSyncingNow(virtualFileMock)
assertSoftly {
result shouldBe true
}
}
should("file is not syncing now") {
every { progressIndicatorMock.isRunning } returns false
val result = syncProcessService.isFileSyncingNow(virtualFileMock)
assertSoftly {
result shouldBe false
}
}
// SyncProcessServiceImpl.areDependentFilesSyncingNow
should("dependent files are syncing now") {
every { progressIndicatorMock.isRunning } returns true
every { VfsUtilCore.isAncestor(virtualFileMock, any(), true) } returns true
val result = syncProcessService.areDependentFilesSyncingNow(virtualFileMock)
assertSoftly {
result shouldBe true
}
}
should("dependent files are not syncing now") {
every { progressIndicatorMock.isRunning } returns true
every { VfsUtilCore.isAncestor(virtualFileMock, any(), true) } returns false
val result = syncProcessService.areDependentFilesSyncingNow(virtualFileMock)
assertSoftly {
result shouldBe false
}
}
should("dependent files are not syncing now because no sync is running") {
every { progressIndicatorMock.isRunning } returns false
val result = syncProcessService.areDependentFilesSyncingNow(virtualFileMock)
assertSoftly {
result shouldBe false
}
}
// SyncProcessServiceImpl.isAnyFileSyncingNow
should("any file is syncing now") {
every { progressIndicatorMock.isRunning } returns true
val result = syncProcessService.isAnyFileSyncingNow()
assertSoftly {
result shouldBe true
}
}
should("no file is syncing now") {
every { progressIndicatorMock.isRunning } returns false
val result = syncProcessService.isAnyFileSyncingNow()
assertSoftly {
result shouldBe false
}
}
}
})