-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ test(ExecutionServiceTest): Add a checkpoint clearing test.
- Loading branch information
1 parent
b477e00
commit 1a8552f
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tofhir-server/src/test/scala/io/tofhir/server/service/ExecutionServiceTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.tofhir.server.service | ||
|
||
import akka.actor.ActorSystem | ||
import io.tofhir.engine.config.ErrorHandlingType | ||
import io.tofhir.engine.model._ | ||
import io.tofhir.server.model.ExecuteJobTask | ||
import io.tofhir.server.service.job.JobFolderRepository | ||
import io.tofhir.server.service.mapping.ProjectMappingFolderRepository | ||
import io.tofhir.server.service.schema.SchemaFolderRepository | ||
import org.apache.commons.io | ||
import org.mockito.MockitoSugar._ | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import java.io.{File, FileOutputStream} | ||
import scala.collection.mutable | ||
import scala.concurrent.ExecutionContext | ||
|
||
class ExecutionServiceTest extends AnyWordSpec with Matchers { | ||
|
||
implicit val actorSystem: ActorSystem = ActorSystem("toFhirEngineTest") | ||
implicit val executionContext: ExecutionContext = actorSystem.getDispatcher | ||
|
||
// FhirMappingJob for test | ||
val testJob: FhirMappingJob = FhirMappingJob(name = Some("testJob"), sourceSettings = Map.empty, sinkSettings = sinkSettings, mappings = Seq.apply(patientMappingTask), | ||
dataProcessingSettings = DataProcessingSettings(mappingErrorHandling = ErrorHandlingType.CONTINUE, archiveMode = ArchiveModes.OFF)) | ||
val sinkSettings: FhirSinkSettings = FileSystemSinkSettings(path = "http://example.com/fhir") | ||
val patientMappingTask: FhirMappingTask = FhirMappingTask( | ||
mappingRef = "https://aiccelerate.eu/fhir/mappings/patient-mapping", | ||
sourceContext = Map("source" -> KafkaSource(topicName = "patients", groupId = "tofhir", startingOffsets = "earliest")) | ||
) | ||
val testExecuteJobTask: ExecuteJobTask = ExecuteJobTask(clearCheckpoints = true, Option.empty, Option.empty) | ||
|
||
val mappingRepository: ProjectMappingFolderRepository = mock[ProjectMappingFolderRepository] | ||
val schemaRepository: SchemaFolderRepository = mock[SchemaFolderRepository] | ||
val mappingJobRepository: JobFolderRepository = getMockMappingJobRepository | ||
|
||
// the execution service instance for the test | ||
val executionService: ExecutionService = new ExecutionService(mappingJobRepository, mappingRepository, schemaRepository) | ||
|
||
"The Execution Service" should { | ||
"should clear checkpoint directory" in { | ||
|
||
val path: String = s"./checkpoint/${testJob.id}/${patientMappingTask.mappingRef.hashCode}" | ||
|
||
// create an example file for test | ||
val testFile: File = new File(s"${path}/test.txt") | ||
io.FileUtils.createParentDirectories(testFile) | ||
val fileOutputStream = new FileOutputStream(testFile) | ||
fileOutputStream.write("test".getBytes("UTF-8")) | ||
fileOutputStream.close() | ||
|
||
// check whether file is written to the directory | ||
val testDirectory: File = new File(path) | ||
io.FileUtils.sizeOfDirectory(testDirectory) shouldBe > (0L) | ||
|
||
// run job and expect to clear the created directory | ||
executionService.runJob("testProject", "testJob", Option.empty, Some(testExecuteJobTask)).map(_ => | ||
io.FileUtils.sizeOfDirectory(testDirectory) shouldBe 0L | ||
) | ||
} | ||
} | ||
|
||
private def getMockMappingJobRepository: JobFolderRepository = { | ||
val mockMappingJobRepository: JobFolderRepository = mock[JobFolderRepository] | ||
when(mockMappingJobRepository.getCachedMappingsJobs).thenReturn(mutable.Map("testProject" -> mutable.Map("testJob" -> testJob))) | ||
} | ||
|
||
} |