Skip to content

Commit 576d8b8

Browse files
committed
Add integration tests for solution file management features
- Added tests for uploading, downloading, listing, and deleting solution files. - Updated API documentation for the solution file endpoints. - Removed usage of the local Maven repository in `build.gradle.kts`.
1 parent 9b89242 commit 576d8b8

File tree

3 files changed

+135
-2
lines changed

3 files changed

+135
-2
lines changed

api/src/integrationTest/kotlin/com/cosmotech/api/home/solution/SolutionControllerTests.kt

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import com.cosmotech.solution.api.SolutionApiService
2525
import com.cosmotech.solution.domain.*
2626
import io.mockk.every
2727
import io.mockk.mockk
28+
import org.apache.commons.io.IOUtils
2829
import org.json.JSONObject
2930
import org.junit.jupiter.api.BeforeEach
3031
import org.junit.jupiter.api.Test
3132
import org.springframework.beans.factory.annotation.Autowired
3233
import org.springframework.boot.test.context.SpringBootTest
3334
import org.springframework.http.MediaType
35+
import org.springframework.mock.web.MockMultipartFile
3436
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document
3537
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
3638
import org.springframework.test.context.ActiveProfiles
@@ -1411,4 +1413,135 @@ class SolutionControllerTests : ControllerTestBase() {
14111413
.andDo(
14121414
document("organizations/{organization_id}/solutions/{solution_id}/security/users/GET"))
14131415
}
1416+
1417+
@Test
1418+
@WithMockOauth2User
1419+
fun get_solution_files() {
1420+
1421+
val solutionId =
1422+
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
1423+
1424+
mvc.perform(
1425+
get("/organizations/$organizationId/solutions/$solutionId/files")
1426+
.contentType(MediaType.APPLICATION_JSON))
1427+
.andExpect(status().is2xxSuccessful)
1428+
.andDo(MockMvcResultHandlers.print())
1429+
.andDo(document("organizations/{organization_id}/solutions/{solution_id}/files/GET"))
1430+
}
1431+
1432+
@Test
1433+
@WithMockOauth2User
1434+
fun create_solution_files() {
1435+
val solutionId =
1436+
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
1437+
val fileName = "test.txt"
1438+
val fileToUpload =
1439+
this::class.java.getResourceAsStream("/solution/$fileName")
1440+
?: throw IllegalStateException(
1441+
"$fileName file used for organizations/{organization_id}/solutions/{solution_id}/files/POST endpoint documentation cannot be null")
1442+
1443+
val mockFile =
1444+
MockMultipartFile(
1445+
"file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload))
1446+
1447+
mvc.perform(
1448+
multipart("/organizations/$organizationId/solutions/$solutionId/files")
1449+
.file(mockFile)
1450+
.param("overwrite", "true")
1451+
.param("destination", "path/to/a/directory/")
1452+
.accept(MediaType.APPLICATION_JSON)
1453+
.with(csrf()))
1454+
.andExpect(status().is2xxSuccessful)
1455+
.andExpect(jsonPath("$.fileName").value("path/to/a/directory/$fileName"))
1456+
.andDo(MockMvcResultHandlers.print())
1457+
.andDo(document("organizations/{organization_id}/solutions/{solution_id}/files/POST"))
1458+
}
1459+
1460+
@Test
1461+
@WithMockOauth2User
1462+
fun delete_solution_files() {
1463+
1464+
val solutionId =
1465+
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
1466+
1467+
mvc.perform(
1468+
delete("/organizations/$organizationId/solutions/$solutionId/files")
1469+
.accept(MediaType.APPLICATION_JSON)
1470+
.with(csrf()))
1471+
.andExpect(status().is2xxSuccessful)
1472+
.andDo(MockMvcResultHandlers.print())
1473+
.andDo(document("organizations/{organization_id}/solutions/{solution_id}/files/DELETE"))
1474+
}
1475+
1476+
@Test
1477+
@WithMockOauth2User
1478+
fun delete_solution_file() {
1479+
val solutionId =
1480+
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
1481+
1482+
val fileName = "test.txt"
1483+
val fileToUpload =
1484+
this::class.java.getResourceAsStream("/solution/$fileName")
1485+
?: throw IllegalStateException(
1486+
"$fileName file used for organizations/{organization_id}/solutions/{solution_id}/files/POST endpoint documentation cannot be null")
1487+
1488+
val mockFile =
1489+
MockMultipartFile(
1490+
"file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload))
1491+
1492+
val destination = "path/to/a/directory/"
1493+
mvc.perform(
1494+
multipart("/organizations/$organizationId/solutions/$solutionId/files")
1495+
.file(mockFile)
1496+
.param("overwrite", "true")
1497+
.param("destination", destination)
1498+
.accept(MediaType.APPLICATION_JSON)
1499+
.with(csrf()))
1500+
1501+
mvc.perform(
1502+
delete("/organizations/$organizationId/solutions/$solutionId/files/delete")
1503+
.param("file_name", destination + fileName)
1504+
.accept(MediaType.APPLICATION_JSON)
1505+
.with(csrf()))
1506+
.andExpect(status().is2xxSuccessful)
1507+
.andDo(MockMvcResultHandlers.print())
1508+
.andDo(
1509+
document("organizations/{organization_id}/solutions/{solution_id}/files/delete/DELETE"))
1510+
}
1511+
1512+
@Test
1513+
@WithMockOauth2User
1514+
fun download_solution_file() {
1515+
1516+
val solutionId =
1517+
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
1518+
1519+
val fileName = "test.txt"
1520+
val fileToUpload =
1521+
this::class.java.getResourceAsStream("/solution/$fileName")
1522+
?: throw IllegalStateException(
1523+
"$fileName file used for organizations/{organization_id}/solutions/{solution_id}/files/POST endpoint documentation cannot be null")
1524+
1525+
val mockFile =
1526+
MockMultipartFile(
1527+
"file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload))
1528+
1529+
val destination = "path/to/a/directory/"
1530+
mvc.perform(
1531+
multipart("/organizations/$organizationId/solutions/$solutionId/files")
1532+
.file(mockFile)
1533+
.param("overwrite", "true")
1534+
.param("destination", destination)
1535+
.accept(MediaType.APPLICATION_JSON)
1536+
.with(csrf()))
1537+
1538+
mvc.perform(
1539+
get("/organizations/$organizationId/solutions/$solutionId/files/download")
1540+
.param("file_name", destination + fileName)
1541+
.accept(MediaType.APPLICATION_OCTET_STREAM))
1542+
.andExpect(status().is2xxSuccessful)
1543+
.andDo(MockMvcResultHandlers.print())
1544+
.andDo(
1545+
document("organizations/{organization_id}/solutions/{solution_id}/files/download/GET"))
1546+
}
14141547
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test file for solution files endpoint!

build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ version = scmVersion.version
5656

5757
// Dependencies version
5858
val kotlinJvmTarget = 21
59-
val cosmotechApiCommonVersion = "2.1.2-JREY-add_authorizedMimeTypes_for_solutions-SNAPSHOT"
59+
val cosmotechApiCommonVersion = "2.1.1-SNAPSHOT"
6060
val redisOmSpringVersion = "0.9.7"
6161
val kotlinCoroutinesVersion = "1.10.2"
6262
val oktaSpringBootVersion = "3.0.7"
@@ -125,7 +125,6 @@ allprojects {
125125
configurations { all { resolutionStrategy { force("com.redis.om:redis-om-spring:0.9.10") } } }
126126

127127
repositories {
128-
mavenLocal()
129128
maven {
130129
name = "GitHubPackages"
131130
url = uri("https://maven.pkg.github.com/Cosmo-Tech/cosmotech-api-common")

0 commit comments

Comments
 (0)