From 413e94ab8cd2118e9e8f6b734a9fee4da34ab444 Mon Sep 17 00:00:00 2001 From: okanmercan Date: Wed, 11 Oct 2023 11:00:23 +0300 Subject: [PATCH] :recycle: refactor(MappingExecutionEndpointTest): Simplify id extraction process. --- .../project/MappingExecutionEndpointTest.scala | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tofhir-server/src/test/scala/io/tofhir/server/project/MappingExecutionEndpointTest.scala b/tofhir-server/src/test/scala/io/tofhir/server/project/MappingExecutionEndpointTest.scala index 34117b7df..dcd48f728 100644 --- a/tofhir-server/src/test/scala/io/tofhir/server/project/MappingExecutionEndpointTest.scala +++ b/tofhir-server/src/test/scala/io/tofhir/server/project/MappingExecutionEndpointTest.scala @@ -14,10 +14,9 @@ import io.tofhir.server.BaseEndpointTest import io.tofhir.server.model.{ResourceFilter, TestResourceCreationRequest} import io.tofhir.server.util.{FileOperations, TestUtil} import org.apache.spark.sql.SparkSession -import org.json4s.JsonAST.{JString, JValue} +import org.json4s._ import org.json4s.jackson.JsonMethods import org.json4s.jackson.Serialization.writePretty -import org.json4s._ import java.io.File import java.nio.file.Paths @@ -96,20 +95,7 @@ class MappingExecutionEndpointTest extends BaseEndpointTest { val jValue = JsonMethods.parse(responseAs[String]) - // Define a custom extractor to extract "id" values - object IdExtractor { - def unapply(json: JValue): Option[String] = { - json \ "id" match { - case JString(id) => Some(id) - case _ => None - } - } - } - - // Extract the first "id" value using pattern matching - firstId = jValue.children.collectFirst { - case IdExtractor(id) => id - } + firstId = (jValue.asInstanceOf[JArray].arr.head.asInstanceOf[JObject] \ "id").extractOpt[String] } // Rerun the previous job