Skip to content

Commit

Permalink
✅ Fix the tests w.r.t updated schema repository functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaci authored and dogukan10 committed Aug 26, 2024
1 parent b57beff commit ad44b11
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ object FileUtils {

object FileExtensions extends Enumeration {
type FileExtensions = Value
final val StructureDefinition = Value(".StructureDefinition")
final val CSV = Value(".csv")
final val JSON = Value(".json")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class ProjectMappingFolderRepository(mappingRepositoryFolderPath: String, projec
* @return
*/
private def getFileForMapping(projectId: String, fhirMapping: FhirMapping): Future[File] = {
val projectFuture: Future[Option[Project]] = projectFolderRepository.getProject(projectId)
projectFuture.map(project => {
projectFolderRepository.getProject(projectId).map(project => {
if (project.isEmpty) throw new IllegalStateException(s"This should not be possible. ProjectId: $projectId does not exist in the project folder repository.")
val file: File = FileUtils.getPath(mappingRepositoryFolderPath, project.get.id, getFileName(fhirMapping.id)).toFile
// If the project folder does not exist, create it
if (!file.getParentFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ class SchemaFolderRepository(schemaRepositoryFolderPath: String, projectFolderRe
*/
private def initMap(schemaRepositoryFolderPath: String): mutable.Map[String, mutable.Map[String, SchemaDefinition]] = {
val schemaDefinitionMap = mutable.Map[String, mutable.Map[String, SchemaDefinition]]()
logger.info(s"Initializing the Schema Repository from path $schemaRepositoryFolderPath.")
val schemaFolder = FileUtils.getPath(schemaRepositoryFolderPath).toFile
logger.info(s"Initializing the Schema Repository from path ${schemaFolder.getAbsolutePath}.")
if (!schemaFolder.exists()) {
schemaFolder.mkdirs()
}
Expand Down
2 changes: 1 addition & 1 deletion tofhir-server/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tofhir {

# A path to a file/directory from where any File system readings should use within the mappingjob definition.
# e.g., FileSystemSourceSettings.dataFolderPath or LocalFhirTerminologyServiceSettings.folderPath
context-path = "conf"
context-path = "test-conf"

mappings = {
repository = { # The repository where the mapping definition are kept.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class MappingExecutionEndpointTest extends BaseEndpointTest with OnFhirTestConta
val projects: JArray = TestUtil.getProjectJsonFile(toFhirEngineConfig)
(projects.arr.find(p => (p \ "id").extract[String] == projectId).get \ "schemas").asInstanceOf[JArray].arr.length shouldEqual expectedSchemaCount
// check schema folder is created
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${otherObservationSourceSchema.id}${FileExtensions.StructureDefinition}${FileExtensions.JSON}").toFile should exist
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${otherObservationSourceSchema.id}${FileExtensions.JSON}").toFile should exist
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.tofhir.server.endpoint.MetadataEndpoint
import io.tofhir.server.model.Metadata
import org.json4s.jackson.JsonMethods
import io.tofhir.common.model.Json4sSupport.formats
import io.tofhir.engine.config.ToFhirConfig

import java.io.File

Expand All @@ -26,8 +27,8 @@ class MetadataEndpointTest extends BaseEndpointTest {
metadata.repositoryNames.contexts shouldEqual "mapping-contexts"
metadata.repositoryNames.jobs shouldEqual "mapping-jobs"
metadata.repositoryNames.terminologySystems shouldEqual "terminology-systems"
metadata.archiving.erroneousRecordsFolder shouldEqual s"conf${File.separator}erroneous-records-folder"
metadata.archiving.archiveFolder shouldEqual s"conf${File.separator}archive-folder"
metadata.archiving.erroneousRecordsFolder shouldEqual s"${ToFhirConfig.engineConfig.contextPath}${File.separator}erroneous-records-folder"
metadata.archiving.archiveFolder shouldEqual s"${ToFhirConfig.engineConfig.contextPath}${File.separator}archive-folder"
metadata.archiving.streamArchivingFrequency shouldEqual 5000
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SchemaEndpointTest extends BaseEndpointTest with OnFhirTestContainer {
), sourceBinding = SqlSource(query = Some("select * from death"), preprocessSql = Some("select person_id, death_date, death_datetime, cause_source_value from test")))


// first schema schema to be created
// first schema to be created
val schema1: SchemaDefinition = SchemaDefinition(url = "https://example.com/fhir/StructureDefinition/schema", `type` = "Ty", name = "name", description = Some("description"), rootDefinition = None, fieldDefinitions = None)
// second schema to be created
val schema2: SchemaDefinition = SchemaDefinition(url = "https://example.com/fhir/StructureDefinition/schema2", `type` = "Ty2", name = "name2", description = Some("description2"), rootDefinition = None, fieldDefinitions = None)
Expand Down Expand Up @@ -95,15 +95,15 @@ class SchemaEndpointTest extends BaseEndpointTest with OnFhirTestContainer {
val projects: JArray = TestUtil.getProjectJsonFile(toFhirEngineConfig)
(projects.arr.find(p => (p \ "id").extract[String] == projectId).get \ "schemas").asInstanceOf[JArray].arr.length shouldEqual 1
// check schema folder is created
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema1.id}${FileExtensions.StructureDefinition}${FileExtensions.JSON}").toFile should exist
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema1.id}${FileExtensions.JSON}").toFile should exist
}
// create the second schema
Post(s"/${webServerConfig.baseUri}/${ProjectEndpoint.SEGMENT_PROJECTS}/$projectId/${SchemaDefinitionEndpoint.SEGMENT_SCHEMAS}", HttpEntity(ContentTypes.`application/json`, writePretty(schema2))) ~> route ~> check {
status shouldEqual StatusCodes.Created
// validate that schema metadata file is updated
val projects: JArray = TestUtil.getProjectJsonFile(toFhirEngineConfig)
(projects.arr.find(p => (p \ "id").extract[String] == projectId).get \ "schemas").asInstanceOf[JArray].arr.length shouldEqual 2
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema2.id}${FileExtensions.StructureDefinition}${FileExtensions.JSON}").toFile should exist
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema2.id}${FileExtensions.JSON}").toFile should exist
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class SchemaEndpointTest extends BaseEndpointTest with OnFhirTestContainer {
}
// update a schema with invalid id
Put(s"/${webServerConfig.baseUri}/${ProjectEndpoint.SEGMENT_PROJECTS}/$projectId/${SchemaDefinitionEndpoint.SEGMENT_SCHEMAS}/123123", HttpEntity(ContentTypes.`application/json`, writePretty(schema2))) ~> route ~> check {
status shouldEqual StatusCodes.NotFound
status shouldEqual StatusCodes.BadRequest
}
}

Expand All @@ -172,7 +172,7 @@ class SchemaEndpointTest extends BaseEndpointTest with OnFhirTestContainer {
val projects: JArray = TestUtil.getProjectJsonFile(toFhirEngineConfig)
(projects.arr.find(p => (p \ "id").extract[String] == projectId).get \ "schemas").asInstanceOf[JArray].arr.length shouldEqual 1
// check schema folder is deleted
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema1.id}${FileExtensions.StructureDefinition}${FileExtensions.JSON}").toFile shouldNot exist
FileUtils.getPath(toFhirEngineConfig.schemaRepositoryFolderPath, projectId, s"${schema1.id}${FileExtensions.JSON}").toFile shouldNot exist
}
// delete a schema with invalid id
Delete(s"/${webServerConfig.baseUri}/${ProjectEndpoint.SEGMENT_PROJECTS}/$projectId/${SchemaDefinitionEndpoint.SEGMENT_SCHEMAS}/123123") ~> route ~> check {
Expand Down Expand Up @@ -468,7 +468,7 @@ class SchemaEndpointTest extends BaseEndpointTest with OnFhirTestContainer {
"import StructureDefinition from a FHIR server" in {
// settings to import a StructureDefinition named 'CustomPatient' from the onFHIR
val schemaID = "CustomPatient"
val importSchemaSettings = ImportSchemaSettings(onFhirClient.getBaseUrl(),schemaID, None)
val importSchemaSettings = ImportSchemaSettings(onFhirClient.getBaseUrl(), schemaID, None)
// import the StructureDefinition from onFHIR
Post(s"/${webServerConfig.baseUri}/${ProjectEndpoint.SEGMENT_PROJECTS}/$projectId/${SchemaDefinitionEndpoint.SEGMENT_SCHEMAS}/${SchemaDefinitionEndpoint.SEGMENT_IMPORT}", HttpEntity(ContentTypes.`application/json`, writePretty(importSchemaSettings))) ~> route ~> check {
status shouldEqual StatusCodes.OK
Expand Down

0 comments on commit ad44b11

Please sign in to comment.