Skip to content

Commit 135ef76

Browse files
fix wrongly deletion on update runTemplate
fix deletion of other runTemplates when using updateSolutionrunTemplate add tests to check correct functionnement
1 parent 296be1c commit 135ef76

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

doc/licenses/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<div class='header'>
124124
<h1>cosmotech-api-parent 2.3.12-SNAPSHOT</h1>
125125
<h2>Dependency License Report</h2>
126-
<h2 class='timestamp'><em>2023-08-29 12:02:56 CEST</em>.</h2></div>
126+
<h2 class='timestamp'><em>2023-09-07 15:51:29 CEST</em>.</h2></div>
127127
<h3>cosmotech-api-parent</h3>
128128
<ul>
129129
<li><a class='license' href='#cosmotech-api-parent_Apache_License,_Version_2.0'><span class='name'>Apache License, Version 2.0</span> <span class='badge'>373</span></a></li>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1
2+
3+
Java Native Access (JNA) is licensed under the LGPL, version 2.1
4+
or later, or (from version 4.0 onward) the Apache License,
5+
version 2.0.
6+
7+
You can freely decide which license you want to apply to the project.
8+
9+
You may obtain a copy of the LGPL License at:
10+
11+
http://www.gnu.org/licenses/licenses.html
12+
13+
A copy is also included in the downloadable source code package
14+
containing JNA, in file "LGPL2.1", under the same directory
15+
as this file.
16+
17+
You may obtain a copy of the Apache License at:
18+
19+
http://www.apache.org/licenses/
20+
21+
A copy is also included in the downloadable source code package
22+
containing JNA, in file "AL2.0", under the same directory
23+
as this file.
24+
25+
Commercial support may be available, please e-mail
26+
twall[at]users[dot]sf[dot]net.

solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceIntegrationTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ class SolutionServiceIntegrationTest : CsmRedisTestBase() {
8787
solutionRegistered = solutionApiService.createSolution(organizationRegistered.id!!, solution)
8888
}
8989

90+
@Test
91+
fun `test verify updateRunTemplate works as intended`() {
92+
93+
val solution =
94+
Solution(
95+
"id",
96+
organizationRegistered.id!!,
97+
"key",
98+
"name",
99+
runTemplates = mutableListOf(RunTemplate(id = "one"), RunTemplate(id = "two")))
100+
solutionRegistered = solutionApiService.createSolution(organizationRegistered.id!!, solution)
101+
102+
val endTemplates =
103+
solutionApiService.updateSolutionRunTemplate(
104+
organizationRegistered.id!!,
105+
solutionRegistered.id!!,
106+
"one",
107+
RunTemplate(id = "one", name = "name_one"))
108+
109+
val expectedSolution =
110+
Solution(
111+
"id",
112+
organizationRegistered.id!!,
113+
"key",
114+
"name",
115+
runTemplates =
116+
mutableListOf(RunTemplate(id = "one", name = "name_one"), RunTemplate(id = "two")))
117+
// Assert that no runTemplate were deleted
118+
assertEquals(expectedSolution.runTemplates!!.size, endTemplates.size)
119+
assertEquals(expectedSolution.runTemplates!!, endTemplates)
120+
}
121+
90122
@Test
91123
fun `test CRUD operations on Solution`() {
92124

solution/src/main/kotlin/com/cosmotech/solution/service/SolutionServiceImpl.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,16 @@ internal class SolutionServiceImpl(
213213
runTemplateId: String,
214214
runTemplate: RunTemplate
215215
): List<RunTemplate> {
216+
216217
val existingSolution = findSolutionById(organizationId, solutionId)
217-
val runTemplates =
218-
existingSolution.runTemplates?.filter { it.id == runTemplateId }?.toMutableList()
219-
if (runTemplates == null || runTemplates.isEmpty()) {
220-
throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
221-
}
222-
var hasChanged = false
223-
for (existingRunTemplate in runTemplates) {
224-
hasChanged =
225-
hasChanged || existingRunTemplate.compareToAndMutateIfNeeded(runTemplate).isNotEmpty()
226-
}
218+
val runTemplateToChange =
219+
existingSolution.runTemplates?.first { it.id == runTemplateId }
220+
?: throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
227221

228-
if (hasChanged) {
229-
existingSolution.runTemplates = runTemplates
230-
solutionRepository.save(existingSolution)
231-
}
232-
return runTemplates
222+
runTemplateToChange.compareToAndMutateIfNeeded(runTemplate).isNotEmpty()
223+
solutionRepository.save(existingSolution)
224+
225+
return existingSolution.runTemplates!!.toList()
233226
}
234227

235228
@EventListener(OrganizationUnregistered::class)

0 commit comments

Comments
 (0)