@@ -42,11 +42,11 @@ import com.redis.om.spring.RediSearchIndexer
42
42
import io.mockk.every
43
43
import io.mockk.junit5.MockKExtension
44
44
import io.mockk.mockkStatic
45
- import org.junit.jupiter.api.AfterEach
46
45
import java.util.*
47
46
import kotlin.test.assertEquals
48
47
import kotlin.test.assertNull
49
48
import kotlin.test.assertTrue
49
+ import org.junit.jupiter.api.AfterEach
50
50
import org.junit.jupiter.api.BeforeEach
51
51
import org.junit.jupiter.api.Test
52
52
import org.junit.jupiter.api.assertDoesNotThrow
@@ -56,7 +56,7 @@ import org.junit.runner.RunWith
56
56
import org.slf4j.LoggerFactory
57
57
import org.springframework.beans.factory.annotation.Autowired
58
58
import org.springframework.boot.test.context.SpringBootTest
59
- import org.springframework.core.io.UrlResource
59
+ import org.springframework.core.io.ResourceLoader
60
60
import org.springframework.test.context.ActiveProfiles
61
61
import org.springframework.test.context.junit.jupiter.SpringExtension
62
62
import org.springframework.test.context.junit4.SpringRunner
@@ -81,6 +81,7 @@ class WorkspaceServiceIntegrationTest : CsmS3TestBase() {
81
81
@Autowired lateinit var connectorApiService: ConnectorApiService
82
82
@Autowired lateinit var datasetApiService: DatasetApiService
83
83
@Autowired lateinit var csmPlatformProperties: CsmPlatformProperties
84
+ @Autowired lateinit var resourceLoader: ResourceLoader
84
85
85
86
lateinit var organization: OrganizationCreateRequest
86
87
lateinit var solution: SolutionCreateRequest
@@ -94,8 +95,6 @@ class WorkspaceServiceIntegrationTest : CsmS3TestBase() {
94
95
lateinit var connectorSaved: Connector
95
96
lateinit var datasetSaved: Dataset
96
97
97
- val resourceTestFile = this ::class .java.getResource(" /$fileName " )
98
-
99
98
@BeforeEach
100
99
fun setUp () {
101
100
mockkStatic(" com.cosmotech.api.utils.SecurityUtilsKt" )
@@ -126,13 +125,11 @@ class WorkspaceServiceIntegrationTest : CsmS3TestBase() {
126
125
}
127
126
128
127
@AfterEach
129
- fun cleanUp (){
128
+ fun cleanUp () {
130
129
every { getCurrentAuthenticatedRoles(any()) } returns listOf (" Platform.Admin" )
131
130
132
131
val workspaces = workspaceApiService.listWorkspaces(organizationSaved.id, null , null )
133
- workspaces.forEach {
134
- workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, it.id)
135
- }
132
+ workspaces.forEach { workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, it.id) }
136
133
}
137
134
138
135
@Test
@@ -164,72 +161,87 @@ class WorkspaceServiceIntegrationTest : CsmS3TestBase() {
164
161
}
165
162
166
163
@Test
167
- fun `test create workspace file` (){
164
+ fun `test create workspace file` () {
165
+
166
+ val resourceTestFile = resourceLoader.getResource(" classpath:/$fileName " )
168
167
every { getCurrentAuthenticatedRoles(any()) } returns listOf (" Platform.Admin" )
169
168
170
169
logger.info(" should create a workspace file" )
171
170
172
171
var savedFile = WorkspaceFile (" " )
173
172
assertDoesNotThrow {
174
- savedFile = workspaceApiService.createWorkspaceFile(organizationSaved.id, workspaceSaved.id, UrlResource (resourceTestFile!! ), true , null )
173
+ savedFile =
174
+ workspaceApiService.createWorkspaceFile(
175
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
175
176
}
176
177
177
178
assertEquals(fileName, savedFile.fileName)
178
179
}
179
180
180
181
@Test
181
- fun `test get workspace file` (){
182
+ fun `test get workspace file` () {
182
183
logger.info(" should get a workspace file" )
184
+ val resourceTestFile = resourceLoader.getResource(" classpath:/$fileName " )
183
185
184
- workspaceApiService.createWorkspaceFile(organizationSaved.id, workspaceSaved.id, UrlResource (resourceTestFile !! ), true , null )
185
- assertDoesNotThrow { workspaceApiService.getWorkspaceFile( organizationSaved.id, workspaceSaved.id, fileName) }
186
+ workspaceApiService.createWorkspaceFile(
187
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
186
188
187
- val fetchedFile = workspaceApiService.getWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName)
188
- assertEquals(UrlResource (resourceTestFile!! ).file, fetchedFile.file)
189
+ val fetchedFile =
190
+ workspaceApiService.getWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName)
191
+ val expectedText = resourceTestFile.inputStream.bufferedReader().use { it.readText() }
192
+ val retrievedText = fetchedFile.inputStream.bufferedReader().use { it.readText() }
193
+ assertEquals(expectedText, retrievedText)
189
194
}
190
195
191
196
@Test
192
197
fun `test list workspace files` () {
193
198
every { getCurrentAuthenticatedRoles(any()) } returns listOf (" Platform.Admin" )
194
199
195
200
logger.info(" should list all workspace file" )
201
+ val resourceTestFile = resourceLoader.getResource(" classpath:/$fileName " )
196
202
197
203
var workspaceFiles =
198
204
workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id)
199
205
assertTrue(workspaceFiles.isEmpty())
200
206
201
-
202
207
workspaceApiService.createWorkspaceFile(
203
- organizationSaved.id, workspaceSaved.id, UrlResource ( resourceTestFile!! ) , true , null )
208
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
204
209
205
210
workspaceFiles = workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id)
206
211
assertEquals(1 , workspaceFiles.size)
207
212
}
208
213
209
214
@Test
210
- fun `test delete workspace file` (){
215
+ fun `test delete workspace file` () {
211
216
logger.info(" should delete a workspace file" )
217
+ val resourceTestFile = resourceLoader.getResource(" classpath:/$fileName " )
212
218
213
219
workspaceApiService.createWorkspaceFile(
214
- organizationSaved.id, workspaceSaved.id, UrlResource ( resourceTestFile!! ) , true , null )
220
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
215
221
216
- assertDoesNotThrow { workspaceApiService.deleteWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName) }
222
+ assertDoesNotThrow {
223
+ workspaceApiService.deleteWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName)
224
+ }
217
225
218
- assertThrows<Exception > { workspaceApiService.getWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName) }
226
+ assertThrows<Exception > {
227
+ workspaceApiService.getWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName)
228
+ }
219
229
}
220
230
221
231
@Test
222
- fun `test deleteAll workspace file` (){
232
+ fun `test deleteAll workspace file` () {
223
233
logger.info(" should delete all workspace files" )
234
+ val resourceTestFile = resourceLoader.getResource(" classpath:/$fileName " )
224
235
225
236
workspaceApiService.createWorkspaceFile(
226
- organizationSaved.id, workspaceSaved.id, UrlResource ( resourceTestFile!! ) , true , null )
237
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
227
238
workspaceApiService.createWorkspaceFile(
228
- organizationSaved.id, workspaceSaved.id, UrlResource ( resourceTestFile!! ) , true , null )
239
+ organizationSaved.id, workspaceSaved.id, resourceTestFile, true , null )
229
240
230
- assertDoesNotThrow { workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, workspaceSaved.id) }
241
+ workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, workspaceSaved.id)
231
242
232
- assertEquals(0 , workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id).size)
243
+ assertEquals(
244
+ 0 , workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id).size)
233
245
}
234
246
235
247
@Test
0 commit comments