Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build_test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
service:
- testPrefix: Organization
packageName: .organization
- testPrefix: Workspace
packageName: .workspace
- testPrefix: Solution
packageName: .solution
- testPrefix: Home
packageName: ""
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package com.cosmotech.api.home

import com.cosmotech.organization.domain.Organization
import com.cosmotech.solution.domain.Solution
import com.cosmotech.workspace.domain.Workspace
import com.redis.om.spring.RediSearchIndexer
import com.redis.testcontainers.RedisServer
import com.redis.testcontainers.RedisStackContainer
Expand Down Expand Up @@ -47,6 +49,8 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
fun beforeEach(restDocumentationContextProvider: RestDocumentationContextProvider) {

rediSearchIndexer.createIndexFor(Organization::class.java)
rediSearchIndexer.createIndexFor(Workspace::class.java)
rediSearchIndexer.createIndexFor(Solution::class.java)

this.mvc =
MockMvcBuilders.webAppContextSetup(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
// Copyright (c) Cosmo Tech.
// Licensed under the MIT license.
package com.cosmotech.api.home

import com.cosmotech.api.home.organization.OrganizationConstants.ORGANIZATION_NAME
import com.cosmotech.api.home.solution.SolutionConstants.RequestContent.MINIMAL_SOLUTION_REQUEST_CREATION
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_KEY
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_NAME
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_REPOSITORY
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_SIMULATOR
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_VERSION
import com.cosmotech.api.home.workspace.WorkspaceConstants.WORKSPACE_KEY
import com.cosmotech.api.home.workspace.WorkspaceConstants.WORKSPACE_NAME
import com.cosmotech.organization.domain.OrganizationCreateRequest
import com.cosmotech.organization.domain.OrganizationSecurity
import com.cosmotech.solution.domain.*
import com.cosmotech.workspace.domain.*
import org.json.JSONObject
import org.springframework.http.MediaType
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post

class ControllerTestUtils {

object OrganizationUtils{
@JvmStatic
fun createOrganizationAndReturnId(mvc: MockMvc, organizationCreateRequest: OrganizationCreateRequest): String = JSONObject(
mvc
.perform(
post("/organizations")
.contentType(MediaType.APPLICATION_JSON)
.content(JSONObject(organizationCreateRequest).toString())
.accept(MediaType.APPLICATION_JSON)
.with(csrf())
).andReturn().response.contentAsString
).getString("id")

@JvmStatic
fun constructOrganizationCreateRequest(name: String = ORGANIZATION_NAME,
security: OrganizationSecurity? = null):OrganizationCreateRequest {
return OrganizationCreateRequest(
name = name,
security = security
)
}

}


object SolutionUtils{

@JvmStatic
fun createSolutionAndReturnId(mvc: MockMvc, organizationId:String,
solutionCreateRequest: SolutionCreateRequest): String = JSONObject(mvc
.perform(
post("/organizations/$organizationId/solutions")
.contentType(MediaType.APPLICATION_JSON)
.content(
JSONObject(solutionCreateRequest).toString()
)
.accept(MediaType.APPLICATION_JSON)
.with(csrf())
).andReturn().response.contentAsString)
.getString("id")


@JvmStatic
fun createWorkspaceAndReturnId(mvc: MockMvc, organizationId:String,
workspaceCreateRequest: WorkspaceCreateRequest): String = JSONObject(
mvc
.perform(
post("/organizations/$organizationId/workspaces")
.contentType(MediaType.APPLICATION_JSON)
.content(JSONObject(workspaceCreateRequest).toString())
.accept(MediaType.APPLICATION_JSON)
.with(csrf())
).andReturn().response.contentAsString
).getString("id")

@JvmStatic
fun constructSolutionCreateRequest(key: String = SOLUTION_KEY,
name: String = SOLUTION_NAME,
repository: String = SOLUTION_REPOSITORY,
version: String = SOLUTION_VERSION,
csmSimulator: String = SOLUTION_SIMULATOR,
description: String="",
alwaysPull: Boolean? = null,
tags:MutableList<String> = mutableListOf(),
parameters: MutableList<RunTemplateParameter> = mutableListOf(),
parameterGroups: MutableList<RunTemplateParameterGroup> = mutableListOf(),
runTemplates: MutableList<RunTemplate> = mutableListOf(),
sdkVersion: String="",
url: String="",
security: SolutionSecurity? = null
):SolutionCreateRequest {
return SolutionCreateRequest(
key = key,
name = name,
repository = repository,
version = version,
csmSimulator = csmSimulator,
description = description,
alwaysPull = alwaysPull,
tags = tags,
parameters = parameters,
parameterGroups = parameterGroups,
runTemplates = runTemplates,
sdkVersion = sdkVersion,
url = url,
security = security,

)
}


@JvmStatic
fun constructSolutionUpdateRequest(key: String = SOLUTION_KEY,
name: String = SOLUTION_NAME,
repository: String = SOLUTION_REPOSITORY,
version: String = SOLUTION_VERSION,
csmSimulator: String = SOLUTION_SIMULATOR,
description: String="",
alwaysPull: Boolean? = null,
tags:MutableList<String> = mutableListOf(),
sdkVersion: String="",
url: String="",
):SolutionUpdateRequest {
return SolutionUpdateRequest(
key = key,
name = name,
repository = repository,
version = version,
csmSimulator = csmSimulator,
description = description,
alwaysPull = alwaysPull,
tags = tags,
sdkVersion = sdkVersion,
url = url
)
}

}

object WorkspaceUtils{
@JvmStatic
fun createWorkspaceAndReturnId(mvc: MockMvc, organizationId:String,
workspaceKey:String,
workspaceName:String,
solutionId:String): String = JSONObject(
mvc
.perform(
post("/organizations/$organizationId/workspaces")
.contentType(MediaType.APPLICATION_JSON)
.content(
JSONObject(
constructWorkspaceCreateRequest(
key = workspaceKey,
name = workspaceName,
solutionId = solutionId)
).toString())
.accept(MediaType.APPLICATION_JSON)
.with(csrf())
).andReturn().response.contentAsString
).getString("id")

@JvmStatic
fun createWorkspaceAndReturnId(mvc: MockMvc, organizationId:String,
workspaceCreateRequest: WorkspaceCreateRequest): String = JSONObject(
mvc
.perform(
post("/organizations/$organizationId/workspaces")
.contentType(MediaType.APPLICATION_JSON)
.content(JSONObject(workspaceCreateRequest).toString())
.accept(MediaType.APPLICATION_JSON)
.with(csrf())
).andReturn().response.contentAsString
).getString("id")

@JvmStatic
fun constructWorkspaceCreateRequest(key: String = WORKSPACE_KEY,
name: String = WORKSPACE_NAME,
solutionId:String,
description: String="",
version: String="",
runTemplateFilter: MutableList<String> = mutableListOf(),
defaultRunTemplateDataset: MutableMap<String,Any> = mutableMapOf(),
datasetCopy: Boolean?= null,
security: WorkspaceSecurity? = null,
url: String="",
iframes: MutableMap<String,Any> = mutableMapOf(),
options: MutableMap<String,Any> = mutableMapOf(),
tags:MutableList<String> = mutableListOf()):WorkspaceCreateRequest {
return WorkspaceCreateRequest(
key = key,
name = name,
solution = WorkspaceSolution(
solutionId = solutionId,
runTemplateFilter = runTemplateFilter,
defaultRunTemplateDataset = defaultRunTemplateDataset,
),
description = description,
version = version,
datasetCopy = datasetCopy,
security = security,
tags = tags,
webApp = WorkspaceWebApp(
url = url,
iframes = iframes,
options = options
)
)
}

@JvmStatic
fun constructWorkspaceUpdateRequest(key: String,
name: String,
solutionId:String,
description: String="",
runTemplateFilter: MutableList<String> = mutableListOf(),
defaultRunTemplateDataset: MutableMap<String,Any> = mutableMapOf(),
datasetCopy: Boolean?= null,
url: String="",
iframes: MutableMap<String,Any> = mutableMapOf(),
options: MutableMap<String,Any> = mutableMapOf(),
tags:MutableList<String> = mutableListOf()
): WorkspaceUpdateRequest {

return WorkspaceUpdateRequest(
key = key,
name = name,
solution = WorkspaceSolution(
solutionId = solutionId,
runTemplateFilter = runTemplateFilter,
defaultRunTemplateDataset = defaultRunTemplateDataset
),
description = description,
datasetCopy = datasetCopy,
tags = tags,
webApp = WorkspaceWebApp(
url = url,
iframes = iframes,
options = options
)
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package com.cosmotech.api.home.organization

import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_EMAIL
import com.cosmotech.api.rbac.ROLE_ADMIN
import com.cosmotech.api.rbac.ROLE_NONE

/**
* Constant class that contains:
* Constant class that contains for Organization endpoints:
* - default payload (RequestContent) for API calls
* -default error messages (Errors) returned by API
* - default error messages (Errors) returned by API
*/
object OrganizationConstants {

Expand All @@ -19,7 +20,7 @@ object OrganizationConstants {

object RequestContent {
const val MINIMAL_ORGANIZATION_REQUEST_CREATION = """{"name":"$ORGANIZATION_NAME"}"""
const val ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES = """{"name":"$ORGANIZATION_NAME","security":{"default":"none","accessControlList":[{"id":"$PLATFORM_ADMIN_EMAIL", "role":"$ROLE_ADMIN"},{"id":"$NEW_USER_ID", "role":"$NEW_USER_ROLE"}] }}"""
const val ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES = """{"name":"$ORGANIZATION_NAME","security":{"default":"$ROLE_NONE","accessControlList":[{"id":"$PLATFORM_ADMIN_EMAIL", "role":"$ROLE_ADMIN"},{"id":"$NEW_USER_ID", "role":"$NEW_USER_ROLE"}] }}"""
const val EMPTY_NAME_ORGANIZATION_REQUEST_CREATION = """{"name":""}"""
const val MINIMAL_ORGANIZATION_REQUEST_UPDATE = """{"name":"$NEW_ORGANIZATION_NAME"}"""
const val MINIMAL_ORGANIZATION_ACCESS_CONTROL_REQUEST = """{"id":"$NEW_USER_ID","role":"$NEW_USER_ROLE"}"""
Expand Down
Loading
Loading