2
2
// Licensed under the MIT license.
3
3
package com.cosmotech.api.home.solution
4
4
5
+ import com.cosmotech.api.containerregistry.ContainerRegistryService
5
6
import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_EMAIL
6
7
import com.cosmotech.api.home.ControllerTestBase
7
8
import com.cosmotech.api.home.ControllerTestUtils.OrganizationUtils.constructOrganizationCreateRequest
@@ -15,21 +16,27 @@ import com.cosmotech.api.home.organization.OrganizationConstants.NEW_USER_ROLE
15
16
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_KEY
16
17
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_NAME
17
18
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_REPOSITORY
19
+ import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_SDK_VERSION
18
20
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_SIMULATOR
19
21
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_VERSION
20
22
import com.cosmotech.api.rbac.ROLE_ADMIN
21
23
import com.cosmotech.api.rbac.ROLE_NONE
22
24
import com.cosmotech.api.rbac.ROLE_VIEWER
25
+ import com.cosmotech.solution.api.SolutionApiService
23
26
import com.cosmotech.solution.domain.*
27
+ import io.mockk.every
28
+ import io.mockk.mockk
24
29
import org.json.JSONArray
25
30
import org.json.JSONObject
26
31
import org.junit.jupiter.api.BeforeEach
27
32
import org.junit.jupiter.api.Test
33
+ import org.springframework.beans.factory.annotation.Autowired
28
34
import org.springframework.boot.test.context.SpringBootTest
29
35
import org.springframework.http.MediaType
30
36
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document
31
37
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
32
38
import org.springframework.test.context.ActiveProfiles
39
+ import org.springframework.test.util.ReflectionTestUtils
33
40
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*
34
41
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
35
42
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
@@ -39,10 +46,18 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
39
46
@SpringBootTest(webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
40
47
class SolutionControllerTests : ControllerTestBase () {
41
48
49
+ @Autowired lateinit var solutionApiService: SolutionApiService
42
50
private lateinit var organizationId: String
43
51
52
+ private var containerRegistryService: ContainerRegistryService = mockk(relaxed = true )
53
+
44
54
@BeforeEach
45
55
fun beforeEach () {
56
+ ReflectionTestUtils .setField(
57
+ solutionApiService, " containerRegistryService" , containerRegistryService)
58
+ every { containerRegistryService.getImageLabel(any(), any(), any()) } returns
59
+ SOLUTION_SDK_VERSION
60
+
46
61
organizationId = createOrganizationAndReturnId(mvc, constructOrganizationCreateRequest())
47
62
}
48
63
@@ -78,6 +93,7 @@ class SolutionControllerTests : ControllerTestBase() {
78
93
.andExpect(jsonPath(" $[0].name" ).value(firstSolutionName))
79
94
.andExpect(jsonPath(" $[0].ownerId" ).value(PLATFORM_ADMIN_EMAIL ))
80
95
.andExpect(jsonPath(" $[0].organizationId" ).value(organizationId))
96
+ .andExpect(jsonPath(" $[0].sdkVersion" ).value(SOLUTION_SDK_VERSION ))
81
97
.andExpect(jsonPath(" $[0].security.default" ).value(ROLE_NONE ))
82
98
.andExpect(jsonPath(" $[0].security.accessControlList[0].role" ).value(ROLE_ADMIN ))
83
99
.andExpect(jsonPath(" $[0].security.accessControlList[0].id" ).value(PLATFORM_ADMIN_EMAIL ))
@@ -86,6 +102,7 @@ class SolutionControllerTests : ControllerTestBase() {
86
102
.andExpect(jsonPath(" $[1].name" ).value(secondSolutionName))
87
103
.andExpect(jsonPath(" $[1].ownerId" ).value(PLATFORM_ADMIN_EMAIL ))
88
104
.andExpect(jsonPath(" $[1].organizationId" ).value(organizationId))
105
+ .andExpect(jsonPath(" $[1].sdkVersion" ).value(SOLUTION_SDK_VERSION ))
89
106
.andExpect(jsonPath(" $[1].security.default" ).value(ROLE_NONE ))
90
107
.andExpect(jsonPath(" $[1].security.accessControlList[0].role" ).value(ROLE_ADMIN ))
91
108
.andExpect(jsonPath(" $[1].security.accessControlList[0].id" ).value(PLATFORM_ADMIN_EMAIL ))
@@ -152,7 +169,6 @@ class SolutionControllerTests : ControllerTestBase() {
152
169
mutableListOf (parameterGroupId),
153
170
10 ))
154
171
155
- val sdkVersion = " this_is_the_sdk_version"
156
172
val url = " this_is_the_solution_url"
157
173
val security =
158
174
SolutionSecurity (
@@ -174,7 +190,6 @@ class SolutionControllerTests : ControllerTestBase() {
174
190
parameters,
175
191
parameterGroups,
176
192
runTemplates,
177
- sdkVersion,
178
193
url,
179
194
security)
180
195
@@ -218,6 +233,7 @@ class SolutionControllerTests : ControllerTestBase() {
218
233
.andExpect(jsonPath(" $.url" ).value(url))
219
234
.andExpect(jsonPath(" $.tags" ).value(tags))
220
235
.andExpect(jsonPath(" $.organizationId" ).value(organizationId))
236
+ .andExpect(jsonPath(" $.sdkVersion" ).value(SOLUTION_SDK_VERSION ))
221
237
.andExpect(jsonPath(" $.security.default" ).value(ROLE_NONE ))
222
238
.andExpect(jsonPath(" $.security.accessControlList[0].role" ).value(ROLE_ADMIN ))
223
239
.andExpect(jsonPath(" $.security.accessControlList[0].id" ).value(PLATFORM_ADMIN_EMAIL ))
@@ -286,7 +302,6 @@ class SolutionControllerTests : ControllerTestBase() {
286
302
mutableListOf (parameterGroupId),
287
303
10 ))
288
304
289
- val sdkVersion = " this_is_the_sdk_version"
290
305
val url = " this_is_the_solution_url"
291
306
val security =
292
307
SolutionSecurity (
@@ -308,7 +323,6 @@ class SolutionControllerTests : ControllerTestBase() {
308
323
parameters,
309
324
parameterGroups,
310
325
runTemplates,
311
- sdkVersion,
312
326
url,
313
327
security)
314
328
@@ -361,6 +375,7 @@ class SolutionControllerTests : ControllerTestBase() {
361
375
.andExpect(jsonPath(" $.url" ).value(url))
362
376
.andExpect(jsonPath(" $.tags" ).value(tags))
363
377
.andExpect(jsonPath(" $.organizationId" ).value(organizationId))
378
+ .andExpect(jsonPath(" $.sdkVersion" ).value(SOLUTION_SDK_VERSION ))
364
379
.andExpect(jsonPath(" $.security.default" ).value(ROLE_NONE ))
365
380
.andExpect(jsonPath(" $.security.accessControlList[0].role" ).value(ROLE_ADMIN ))
366
381
.andExpect(jsonPath(" $.security.accessControlList[0].id" ).value(PLATFORM_ADMIN_EMAIL ))
@@ -394,7 +409,6 @@ class SolutionControllerTests : ControllerTestBase() {
394
409
395
410
val description = " this_is_a_description"
396
411
val tags = mutableListOf (" tag1" , " tag2" )
397
- val sdkVersion = " this_is_the_sdk_version"
398
412
val url = " this_is_the_solution_url"
399
413
400
414
val solutionUpdateRequest =
@@ -407,7 +421,6 @@ class SolutionControllerTests : ControllerTestBase() {
407
421
description,
408
422
true ,
409
423
tags,
410
- sdkVersion,
411
424
url)
412
425
413
426
mvc.perform(
@@ -426,6 +439,7 @@ class SolutionControllerTests : ControllerTestBase() {
426
439
.andExpect(jsonPath(" $.url" ).value(url))
427
440
.andExpect(jsonPath(" $.tags" ).value(tags))
428
441
.andExpect(jsonPath(" $.organizationId" ).value(organizationId))
442
+ .andExpect(jsonPath(" $.sdkVersion" ).value(SOLUTION_SDK_VERSION ))
429
443
.andExpect(jsonPath(" $.security.default" ).value(ROLE_NONE ))
430
444
.andExpect(jsonPath(" $.security.accessControlList[0].role" ).value(ROLE_ADMIN ))
431
445
.andExpect(jsonPath(" $.security.accessControlList[0].id" ).value(PLATFORM_ADMIN_EMAIL ))
0 commit comments