From 74223d0caae3b00822b8028f94f20070a926acbd Mon Sep 17 00:00:00 2001 From: Benjamin Geer Date: Mon, 7 Dec 2020 14:23:37 +0100 Subject: [PATCH] refactor: Use java.nio.file.Path instead of java.io.File (DSP-1124) (#1770) --- .../org/knora/webapi/ITKnoraLiveSpec.scala | 10 +- .../e2e/v1/KnoraSipiIntegrationV1ITSpec.scala | 25 +- .../e2e/v2/KnoraSipiIntegrationV2ITSpec.scala | 503 +++++++++--------- .../GenerateContributorsFile.scala | 6 +- .../ProjectsMessagesADM.scala | 4 +- .../TriplestoreMessages.scala | 10 +- .../messages/util/FakeTriplestore.scala | 45 +- .../util/rdf/AbstractShaclValidator.scala | 2 +- .../webapi/messages/util/rdf/JsonLDUtil.scala | 2 +- .../messages/util/rdf/RdfFormatUtil.scala | 15 +- .../admin/ProjectsResponderADM.scala | 24 +- .../routing/admin/ProjectsRouteADM.scala | 5 +- .../webapi/routing/v1/AssetsRouteV1.scala | 5 +- .../knora/webapi/settings/KnoraSettings.scala | 9 +- .../triplestore/embedded/JenaTDBActor.scala | 17 +- .../http/HttpTriplestoreConnector.scala | 44 +- .../upgrade/RepositoryUpdater.scala | 19 +- .../org/knora/webapi/util/FileUtil.scala | 56 +- .../test/scala/org/knora/webapi/E2ESpec.scala | 10 +- .../test/scala/org/knora/webapi/R2RSpec.scala | 12 +- .../GenerateContributorsFileSpec.scala | 8 +- .../webapi/e2e/InstanceCheckerSpec.scala | 4 +- .../knora/webapi/e2e/v1/SipiV1R2RSpec.scala | 9 +- .../webapi/e2e/v1/StandoffV1R2RSpec.scala | 38 +- .../e2e/v2/JSONLDHandlingV2R2RSpec.scala | 8 +- .../webapi/e2e/v2/ListsRouteV2R2RSpec.scala | 20 +- .../e2e/v2/MetadataRouteV2E2ESpec.scala | 6 +- .../webapi/e2e/v2/OntologyV2R2RSpec.scala | 17 +- .../e2e/v2/ResourcesRouteV2E2ESpec.scala | 83 +-- .../webapi/e2e/v2/ResponseCheckerV2Spec.scala | 24 +- .../webapi/e2e/v2/SearchRouteV2R2RSpec.scala | 469 ++++++++-------- .../e2e/v2/StandoffRouteV2R2RSpec.scala | 8 +- .../webapi/e2e/v2/ValuesRouteV2E2ESpec.scala | 12 +- .../util/ConstructResponseUtilV2Spec.scala | 19 +- .../messages/util/rdf/JsonLDUtilSpec.scala | 18 +- .../util/rdf/KnoraResponseV2Spec.scala | 10 +- .../messages/util/rdf/RdfFormatUtilSpec.scala | 48 +- .../messages/util/standoff/XMLUtilSpec.scala | 14 +- .../ResourcesResponderV1SpecContextData.scala | 4 +- 39 files changed, 843 insertions(+), 799 deletions(-) diff --git a/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala b/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala index 200a232d31..9fc1947356 100644 --- a/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/ITKnoraLiveSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi -import java.io.File +import java.nio.file.{Files, Path, Paths} import akka.actor.{ActorRef, ActorSystem, Props} import akka.event.LoggingAdapter @@ -228,13 +228,13 @@ class ITKnoraLiveSpec(_system: ActorSystem) // Make a multipart/form-data request containing the files. val formDataParts: Seq[Multipart.FormData.BodyPart] = filesToUpload.map { fileToUpload => - val fileToSend = new File(fileToUpload.path) - assert(fileToSend.exists(), s"File ${fileToUpload.path} does not exist") + val fileToSend: Path = Paths.get(fileToUpload.path) + assert(Files.exists(fileToSend), s"File ${fileToUpload.path} does not exist") Multipart.FormData.BodyPart( "file", - HttpEntity.fromPath(fileToUpload.mimeType, fileToSend.toPath), - Map("filename" -> fileToSend.getName) + HttpEntity.fromPath(fileToUpload.mimeType, fileToSend), + Map("filename" -> fileToSend.getFileName.toString) ) } diff --git a/webapi/src/it/scala/org/knora/webapi/e2e/v1/KnoraSipiIntegrationV1ITSpec.scala b/webapi/src/it/scala/org/knora/webapi/e2e/v1/KnoraSipiIntegrationV1ITSpec.scala index ca54583f0d..f032836ccb 100644 --- a/webapi/src/it/scala/org/knora/webapi/e2e/v1/KnoraSipiIntegrationV1ITSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/e2e/v1/KnoraSipiIntegrationV1ITSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v1 -import java.io.{File, FileInputStream, FileOutputStream} import java.net.URLEncoder +import java.nio.file.{Files, Paths, StandardCopyOption} import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers._ @@ -298,24 +298,17 @@ class KnoraSipiIntegrationV1ITSpec } "create an 'p0803-incunabula:book' and an 'p0803-incunabula:page' with file parameters via XML import" in { - val fileToUpload = new File(pathToChlaus) + val fileToUpload = Paths.get(pathToChlaus) // To be able to run packaged tests inside Docker, we need to copy // the file first to a place which is shared with sipi val dest = FileUtil.createTempFile(settings, Some("jpg")) - new FileOutputStream(dest).getChannel - .transferFrom( - new FileInputStream(fileToUpload).getChannel, - 0, - Long.MaxValue - ) - - val absoluteFilePath = dest.getAbsolutePath + Files.copy(fileToUpload, dest, StandardCopyOption.REPLACE_EXISTING) // Upload the image to Sipi. val sipiUploadResponse: SipiUploadResponse = uploadToSipi( loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = absoluteFilePath, mimeType = MediaTypes.`image/tiff`)) + filesToUpload = Seq(FileToUpload(path = dest.toAbsolutePath.toString, mimeType = MediaTypes.`image/tiff`)) ) val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head @@ -370,7 +363,7 @@ class KnoraSipiIntegrationV1ITSpec val locdata = pageJson.fields("resinfo").asJsObject.fields("locdata").asJsObject val origname = locdata.fields("origname").asInstanceOf[JsString].value val imageUrl = locdata.fields("path").asInstanceOf[JsString].value - assert(origname == dest.getName) + assert(origname == dest.getFileName.toString) // Request the file from Sipi. val sipiGetRequest = Get(imageUrl) ~> addCredentials(BasicHttpCredentials(userEmail, password)) @@ -414,7 +407,7 @@ class KnoraSipiIntegrationV1ITSpec // add a mapping referring to the XSLT as the default XSL transformation - val mapping = FileUtil.readTextFile(new File(pathToMappingWithXSLT)) + val mapping = FileUtil.readTextFile(Paths.get(pathToMappingWithXSLT)) val updatedMapping = addXSLTIriToMapping(mapping, resId) @@ -449,7 +442,7 @@ class KnoraSipiIntegrationV1ITSpec } "create a sample BEOL letter" in { - val mapping = FileUtil.readTextFile(new File(pathToBEOLLetterMapping)) + val mapping = FileUtil.readTextFile(Paths.get(pathToBEOLLetterMapping)) val paramsForMapping = s""" @@ -481,7 +474,7 @@ class KnoraSipiIntegrationV1ITSpec // create a letter via bulk import - val bulkXML = FileUtil.readTextFile(new File(pathToBEOLBulkXML)) + val bulkXML = FileUtil.readTextFile(Paths.get(pathToBEOLBulkXML)) val bulkRequest = Post( baseApiUrl + "/v1/resources/xmlimport/" + URLEncoder.encode("http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF", @@ -532,7 +525,7 @@ class KnoraSipiIntegrationV1ITSpec // add a mapping referring to the XSLT as the default XSL transformation - val mapping = FileUtil.readTextFile(new File(pathToBEOLStandoffTEIMapping)) + val mapping = FileUtil.readTextFile(Paths.get(pathToBEOLStandoffTEIMapping)) val updatedMapping = addXSLTIriToMapping(mapping, resId) diff --git a/webapi/src/it/scala/org/knora/webapi/e2e/v2/KnoraSipiIntegrationV2ITSpec.scala b/webapi/src/it/scala/org/knora/webapi/e2e/v2/KnoraSipiIntegrationV2ITSpec.scala index f4df9e2ee1..5d63c38b97 100644 --- a/webapi/src/it/scala/org/knora/webapi/e2e/v2/KnoraSipiIntegrationV2ITSpec.scala +++ b/webapi/src/it/scala/org/knora/webapi/e2e/v2/KnoraSipiIntegrationV2ITSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.{Files, Paths} import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers.BasicHttpCredentials @@ -268,15 +268,15 @@ class KnoraSipiIntegrationV2ITSpec "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJLbm9yYSIsInN1YiI6Imh0dHA6Ly9yZGZoLmNoL3VzZXJzLzlYQkNyRFYzU1JhN2tTMVd3eW5CNFEiLCJhdWQiOlsiS25vcmEiLCJTaXBpIl0sImV4cCI6NDY5NDM1MTEyMiwiaWF0IjoxNTQxNzU5MTIyLCJqdGkiOiJ4bnlYeklFb1QxNmM2dkpDbHhSQllnIn0.P2Aq37G6XMLLBVMdnpDVVhWjenbVw0HTb1BpEuTWGRo" // The image to be uploaded. - val fileToSend = new File(pathToMarbles) - assert(fileToSend.exists(), s"File $pathToMarbles does not exist") + val fileToSend = Paths.get(pathToMarbles) + assert(Files.exists(fileToSend), s"File $pathToMarbles does not exist") // A multipart/form-data request containing the image. val sipiFormData = Multipart.FormData( Multipart.FormData.BodyPart( "file", - HttpEntity.fromPath(MediaTypes.`image/tiff`, fileToSend.toPath), - Map("filename" -> fileToSend.getName) + HttpEntity.fromPath(MediaTypes.`image/tiff`, fileToSend), + Map("filename" -> fileToSend.getFileName.toString) ) ) @@ -444,21 +444,22 @@ class KnoraSipiIntegrationV2ITSpec val sipiGetImageRequest = Get(savedImage.iiifUrl) checkResponseOK(sipiGetImageRequest) } - /* - "delete the temporary file if Knora rejects the request to create a file value" in { - // Upload the image to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToMarbles, mimeType = MediaTypes.`image/tiff`)) - ) - - val internalFilename = sipiUploadResponse.uploadedFiles.head.internalFilename - val temporaryUrl = sipiUploadResponse.uploadedFiles.head.temporaryUrl.replace("http://0.0.0.0:1024", baseExternalSipiUrl) - val temporaryDirectDownloadUrl = temporaryUrl + "/file" - - // JSON describing the new image to Knora. - val jsonLdEntity = - s"""{ + + "delete the temporary file if Knora rejects the request to create a file value" in { + // Upload the image to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = Seq(FileToUpload(path = pathToMarbles, mimeType = MediaTypes.`image/tiff`)) + ) + + val internalFilename = sipiUploadResponse.uploadedFiles.head.internalFilename + val temporaryUrl = + sipiUploadResponse.uploadedFiles.head.temporaryUrl.replace("http://0.0.0.0:1024", baseExternalSipiUrl) + val temporaryDirectDownloadUrl = temporaryUrl + "/file" + + // JSON describing the new image to Knora. + val jsonLdEntity = + s"""{ | "@id" : "${stillImageResourceIri.get}", | "@type" : "anything:ThingDocument", | "knora-api:hasStillImageFileValue" : { @@ -471,31 +472,32 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - // Send the JSON in a POST request to Knora. - val knoraPostRequest = Post(baseApiUrl + "/v2/values", HttpEntity(ContentTypes.`application/json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(incunabulaUserEmail, password)) - val knoraPostResponse = singleAwaitingRequest(knoraPostRequest) - assert(knoraPostResponse.status == StatusCodes.Forbidden) + // Send the JSON in a POST request to Knora. + val knoraPostRequest = Post(baseApiUrl + "/v2/values", HttpEntity(ContentTypes.`application/json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(incunabulaUserEmail, password)) + val knoraPostResponse = singleAwaitingRequest(knoraPostRequest) + assert(knoraPostResponse.status == StatusCodes.Forbidden) - // Request the temporary image from Sipi. - val sipiGetTmpFileRequest = Get(temporaryDirectDownloadUrl) - val sipiResponse = singleAwaitingRequest(sipiGetTmpFileRequest) - assert(sipiResponse.status == StatusCodes.NotFound) - } + // Request the temporary image from Sipi. + val sipiGetTmpFileRequest = Get(temporaryDirectDownloadUrl) + val sipiResponse = singleAwaitingRequest(sipiGetTmpFileRequest) + assert(sipiResponse.status == StatusCodes.NotFound) + } - "create a resource with a PDF file" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToMinimalPdf, mimeType = MediaTypes.`application/pdf`)) - ) + "create a resource with a PDF file" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = Seq(FileToUpload(path = pathToMinimalPdf, mimeType = MediaTypes.`application/pdf`)) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(minimalPdfOriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(minimalPdfOriginalFilename) - // Ask Knora to create the resource. + // Ask Knora to create the resource. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@type" : "anything:ThingDocument", | "knora-api:hasDocumentFileValue" : { | "@type" : "knora-api:DocumentFileValue", @@ -514,56 +516,58 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - pdfResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + pdfResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(pdfResourceIri.get, "UTF-8")}") - val resource: JsonLDDocument = getResponseJsonLD(knoraGetRequest) - assert(resource.requireTypeAsKnoraTypeIri.toString == "http://0.0.0.0:3333/ontology/0001/anything/v2#ThingDocument") + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(pdfResourceIri.get, "UTF-8")}") + val resource: JsonLDDocument = getResponseJsonLD(knoraGetRequest) + assert( + resource.requireTypeAsKnoraTypeIri.toString == "http://0.0.0.0:3333/ontology/0001/anything/v2#ThingDocument") - // Get the new file value from the resource. + // Get the new file value from the resource. - val savedValues: JsonLDArray = getValuesFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasDocumentFileValue.toSmartIri - ) + val savedValues: JsonLDArray = getValuesFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasDocumentFileValue.toSmartIri + ) - val savedValue: JsonLDValue = if (savedValues.value.size == 1) { - savedValues.value.head - } else { - throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") - } + val savedValue: JsonLDValue = if (savedValues.value.size == 1) { + savedValues.value.head + } else { + throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") + } - val savedValueObj: JsonLDObject = savedValue match { - case jsonLDObject: JsonLDObject => jsonLDObject - case other => throw AssertionException(s"Invalid value object: $other") - } + val savedValueObj: JsonLDObject = savedValue match { + case jsonLDObject: JsonLDObject => jsonLDObject + case other => throw AssertionException(s"Invalid value object: $other") + } - pdfValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) + pdfValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) - val savedDocument: SavedDocument = savedValueToSavedDocument(savedValueObj) - assert(savedDocument.internalFilename == uploadedFile.internalFilename) - assert(savedDocument.pageCount == 1) - assert(savedDocument.width.contains(minimalPdfWidth)) - assert(savedDocument.height.contains(minimalPdfHeight)) - } + val savedDocument: SavedDocument = savedValueToSavedDocument(savedValueObj) + assert(savedDocument.internalFilename == uploadedFile.internalFilename) + assert(savedDocument.pageCount == 1) + assert(savedDocument.width.contains(minimalPdfWidth)) + assert(savedDocument.height.contains(minimalPdfHeight)) + } - "change a PDF file value" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToTestPdf, mimeType = MediaTypes.`application/pdf`)) - ) + "change a PDF file value" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = Seq(FileToUpload(path = pathToTestPdf, mimeType = MediaTypes.`application/pdf`)) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(testPdfOriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(testPdfOriginalFilename) - // Ask Knora to update the value. + // Ask Knora to update the value. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@id" : "${pdfResourceIri.get}", | "@type" : "anything:ThingDocument", | "knora-api:hasDocumentFileValue" : { @@ -580,42 +584,44 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - pdfValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(pdfResourceIri.get, "UTF-8")}") - val resource = getResponseJsonLD(knoraGetRequest) - - // Get the new file value from the resource. - val savedValue: JsonLDObject = getValueFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasDocumentFileValue.toSmartIri, - expectedValueIri = pdfValueIri.get - ) - - val savedDocument: SavedDocument = savedValueToSavedDocument(savedValue) - assert(savedDocument.internalFilename == uploadedFile.internalFilename) - assert(savedDocument.pageCount == 1) - assert(savedDocument.width.contains(testPdfWidth)) - assert(savedDocument.height.contains(testPdfHeight)) - } - - "create a resource with a CSV file" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToCsv1, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) - ) - - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(csv1OriginalFilename) - - // Ask Knora to create the resource. - - val jsonLdEntity = - s"""{ + val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + pdfValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(pdfResourceIri.get, "UTF-8")}") + val resource = getResponseJsonLD(knoraGetRequest) + + // Get the new file value from the resource. + val savedValue: JsonLDObject = getValueFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasDocumentFileValue.toSmartIri, + expectedValueIri = pdfValueIri.get + ) + + val savedDocument: SavedDocument = savedValueToSavedDocument(savedValue) + assert(savedDocument.internalFilename == uploadedFile.internalFilename) + assert(savedDocument.pageCount == 1) + assert(savedDocument.width.contains(testPdfWidth)) + assert(savedDocument.height.contains(testPdfHeight)) + } + + "create a resource with a CSV file" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = + Seq(FileToUpload(path = pathToCsv1, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) + ) + + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(csv1OriginalFilename) + + // Ask Knora to create the resource. + + val jsonLdEntity = + s"""{ | "@type" : "knora-api:TextRepresentation", | "knora-api:hasTextFileValue" : { | "@type" : "knora-api:TextFileValue", @@ -633,53 +639,56 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri) - csvResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + val resourceIri: IRI = + responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri) + csvResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}") - val resource = getResponseJsonLD(knoraGetRequest) + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}") + val resource = getResponseJsonLD(knoraGetRequest) - // Get the new file value from the resource. + // Get the new file value from the resource. - val savedValues: JsonLDArray = getValuesFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri - ) + val savedValues: JsonLDArray = getValuesFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri + ) - val savedValue: JsonLDValue = if (savedValues.value.size == 1) { - savedValues.value.head - } else { - throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") - } + val savedValue: JsonLDValue = if (savedValues.value.size == 1) { + savedValues.value.head + } else { + throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") + } - val savedValueObj: JsonLDObject = savedValue match { - case jsonLDObject: JsonLDObject => jsonLDObject - case other => throw AssertionException(s"Invalid value object: $other") - } + val savedValueObj: JsonLDObject = savedValue match { + case jsonLDObject: JsonLDObject => jsonLDObject + case other => throw AssertionException(s"Invalid value object: $other") + } - csvValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) + csvValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) - val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValueObj) - assert(savedTextFile.internalFilename == uploadedFile.internalFilename) - } + val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValueObj) + assert(savedTextFile.internalFilename == uploadedFile.internalFilename) + } - "change a CSV file value" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToCsv2, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) - ) + "change a CSV file value" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = + Seq(FileToUpload(path = pathToCsv2, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(csv2OriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(csv2OriginalFilename) - // Ask Knora to update the value. + // Ask Knora to update the value. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@id" : "${csvResourceIri.get}", | "@type" : "knora-api:TextRepresentation", | "knora-api:hasTextFileValue" : { @@ -695,39 +704,41 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - csvValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + csvValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(csvResourceIri.get, "UTF-8")}") - val resource = getResponseJsonLD(knoraGetRequest) + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(csvResourceIri.get, "UTF-8")}") + val resource = getResponseJsonLD(knoraGetRequest) - // Get the new file value from the resource. - val savedValue: JsonLDObject = getValueFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri, - expectedValueIri = csvValueIri.get - ) + // Get the new file value from the resource. + val savedValue: JsonLDObject = getValueFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri, + expectedValueIri = csvValueIri.get + ) - val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValue) - assert(savedTextFile.internalFilename == uploadedFile.internalFilename) - } + val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValue) + assert(savedTextFile.internalFilename == uploadedFile.internalFilename) + } - "not create a resource with a still image file that's actually a text file" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToCsv1, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) - ) + "not create a resource with a still image file that's actually a text file" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = + Seq(FileToUpload(path = pathToCsv1, mimeType = MediaTypes.`text/csv`.toContentType(HttpCharsets.`UTF-8`))) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(csv1OriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(csv1OriginalFilename) - // Ask Knora to create the resource. + // Ask Knora to create the resource. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@type" : "knora-api:StillImageRepresentation", | "knora-api:hasStillImageValue" : { | "@type" : "knora-api:StillImageFileValue", @@ -745,25 +756,27 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val response = singleAwaitingRequest(request) - assert(response.status == StatusCodes.BadRequest) - } + val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val response = singleAwaitingRequest(request) + assert(response.status == StatusCodes.BadRequest) + } - "create a resource with an XML file" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToXml1, mimeType = MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`))) - ) + "create a resource with an XML file" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = + Seq(FileToUpload(path = pathToXml1, mimeType = MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`))) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(xml1OriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(xml1OriginalFilename) - // Ask Knora to create the resource. + // Ask Knora to create the resource. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@type" : "knora-api:TextRepresentation", | "knora-api:hasTextFileValue" : { | "@type" : "knora-api:TextFileValue", @@ -781,53 +794,56 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri) - xmlResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + val resourceIri: IRI = + responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, stringFormatter.validateAndEscapeIri) + xmlResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}") - val resource = getResponseJsonLD(knoraGetRequest) + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}") + val resource = getResponseJsonLD(knoraGetRequest) - // Get the new file value from the resource. + // Get the new file value from the resource. - val savedValues: JsonLDArray = getValuesFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri - ) + val savedValues: JsonLDArray = getValuesFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri + ) - val savedValue: JsonLDValue = if (savedValues.value.size == 1) { - savedValues.value.head - } else { - throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") - } + val savedValue: JsonLDValue = if (savedValues.value.size == 1) { + savedValues.value.head + } else { + throw AssertionException(s"Expected one file value, got ${savedValues.value.size}") + } - val savedValueObj: JsonLDObject = savedValue match { - case jsonLDObject: JsonLDObject => jsonLDObject - case other => throw AssertionException(s"Invalid value object: $other") - } + val savedValueObj: JsonLDObject = savedValue match { + case jsonLDObject: JsonLDObject => jsonLDObject + case other => throw AssertionException(s"Invalid value object: $other") + } - xmlValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) + xmlValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString) - val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValueObj) - assert(savedTextFile.internalFilename == uploadedFile.internalFilename) - } + val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValueObj) + assert(savedTextFile.internalFilename == uploadedFile.internalFilename) + } - "change an XML file value" in { - // Upload the file to Sipi. - val sipiUploadResponse: SipiUploadResponse = uploadToSipi( - loginToken = loginToken, - filesToUpload = Seq(FileToUpload(path = pathToXml2, mimeType = MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`))) - ) + "change an XML file value" in { + // Upload the file to Sipi. + val sipiUploadResponse: SipiUploadResponse = uploadToSipi( + loginToken = loginToken, + filesToUpload = + Seq(FileToUpload(path = pathToXml2, mimeType = MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`))) + ) - val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head - uploadedFile.originalFilename should ===(xml2OriginalFilename) + val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head + uploadedFile.originalFilename should ===(xml2OriginalFilename) - // Ask Knora to update the value. + // Ask Knora to update the value. - val jsonLdEntity = - s"""{ + val jsonLdEntity = + s"""{ | "@id" : "${xmlResourceIri.get}", | "@type" : "knora-api:TextRepresentation", | "knora-api:hasTextFileValue" : { @@ -843,23 +859,24 @@ class KnoraSipiIntegrationV2ITSpec | } |}""".stripMargin - val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password)) - val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) - xmlValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) + val request = Put(s"$baseApiUrl/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password)) + val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request) + xmlValueIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString) - // Get the resource from Knora. - val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(xmlResourceIri.get, "UTF-8")}") - val resource = getResponseJsonLD(knoraGetRequest) + // Get the resource from Knora. + val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(xmlResourceIri.get, "UTF-8")}") + val resource = getResponseJsonLD(knoraGetRequest) - // Get the new file value from the resource. - val savedValue: JsonLDObject = getValueFromResource( - resource = resource, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri, - expectedValueIri = xmlValueIri.get - ) + // Get the new file value from the resource. + val savedValue: JsonLDObject = getValueFromResource( + resource = resource, + propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasTextFileValue.toSmartIri, + expectedValueIri = xmlValueIri.get + ) - val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValue) - assert(savedTextFile.internalFilename == uploadedFile.internalFilename) - }*/ + val savedTextFile: SavedTextFile = savedValueToSavedTextFile(savedValue) + assert(savedTextFile.internalFilename == uploadedFile.internalFilename) + } } } diff --git a/webapi/src/main/scala/org/knora/webapi/contributors/GenerateContributorsFile.scala b/webapi/src/main/scala/org/knora/webapi/contributors/GenerateContributorsFile.scala index 275eb2474f..def374f8a9 100644 --- a/webapi/src/main/scala/org/knora/webapi/contributors/GenerateContributorsFile.scala +++ b/webapi/src/main/scala/org/knora/webapi/contributors/GenerateContributorsFile.scala @@ -19,8 +19,8 @@ package org.knora.webapi.contributors -import java.io.File import java.net.{URL, URLConnection} +import java.nio.file.{Path, Paths} import org.knora.webapi.exceptions.AssertionException import org.knora.webapi.messages.twirl.Contributor @@ -44,7 +44,7 @@ object GenerateContributorsFile extends App { private val conf = new GenerateContributorsFileConf(args) private val token = conf.token.toOption - private val outputFile = new File(conf.output()) + private val outputFile: Path = Paths.get(conf.output()) // Get the list of contributors. @@ -86,7 +86,7 @@ object GenerateContributorsFile extends App { org.knora.webapi.messages.twirl.queries.util.txt.generateContributorsMarkdown(contributorsSorted).toString // Write Contributors.md. - FileUtil.writeTextFile(outputFile, contributorsText) + FileUtil.writeTextFile(file = outputFile, content = contributorsText) /** * Makes an HTTP GET connection to the GitHub API. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectsMessagesADM.scala b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectsMessagesADM.scala index fc5e505e55..500cdcfdba 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectsMessagesADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/admin/responder/projectsmessages/ProjectsMessagesADM.scala @@ -19,7 +19,7 @@ package org.knora.webapi.messages.admin.responder.projectsmessages -import java.io.File +import java.nio.file.Path import java.util.UUID import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport @@ -360,7 +360,7 @@ case class ProjectOperationResponseADM(project: ProjectADM) extends KnoraRespons * * @param projectDataFile a file containing the project's data in TriG format. */ -case class ProjectDataGetResponseADM(projectDataFile: File) +case class ProjectDataGetResponseADM(projectDataFile: Path) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Components of messages diff --git a/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala b/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala index 4266459284..59279c0605 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala @@ -19,7 +19,7 @@ package org.knora.webapi.messages.store.triplestoremessages -import java.io.File +import java.nio.file.Path import java.time.Instant import akka.event.LoggingAdapter @@ -87,7 +87,7 @@ case class SparqlConstructRequest(sparql: String, featureFactoryConfig: FeatureF */ case class SparqlConstructFileRequest(sparql: String, graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig) extends TriplestoreRequest @@ -235,7 +235,7 @@ case class SparqlExtendedConstructResponse( * @param featureFactoryConfig the feature factory configuration. */ case class NamedGraphFileRequest(graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig) extends TriplestoreRequest @@ -366,7 +366,7 @@ case class UpdateRepositoryRequest() extends TriplestoreRequest * @param outputFile the output file. * @param featureFactoryConfig the feature factory configuration. */ -case class DownloadRepositoryRequest(outputFile: File, featureFactoryConfig: FeatureFactoryConfig) +case class DownloadRepositoryRequest(outputFile: Path, featureFactoryConfig: FeatureFactoryConfig) extends TriplestoreRequest /** @@ -380,7 +380,7 @@ case class FileWrittenResponse() * * @param inputFile a TriG file containing the content to be uploaded to the repository. */ -case class UploadRepositoryRequest(inputFile: File) extends TriplestoreRequest +case class UploadRepositoryRequest(inputFile: Path) extends TriplestoreRequest /** * Indicates that repository content was successfully uploaded. diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/FakeTriplestore.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/FakeTriplestore.scala index 129b0dafbf..fe7ca9caed 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/FakeTriplestore.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/FakeTriplestore.scala @@ -19,39 +19,55 @@ package org.knora.webapi.messages.util -import java.io.File +import java.nio.file.{Files, Path} import akka.event.LoggingAdapter import org.apache.commons.io.FileUtils import org.knora.webapi.util.FileUtil +import scala.collection.JavaConverters._ + /** * A fake triplestore for use in performance testing. This feature is activated in `application.conf`. */ object FakeTriplestore { - private var fakeTriplestoreDir: Option[File] = None + private var fakeTriplestoreDir: Option[Path] = None private var queryNum = 0 var data = Map.empty[String, String] - def init(dataDir: File): Unit = { + def init(dataDir: Path): Unit = { fakeTriplestoreDir = Some(dataDir) } def clear(): Unit = { - FileUtils.deleteDirectory(fakeTriplestoreDir.get) - fakeTriplestoreDir.get.mkdirs() + FileUtils.deleteDirectory(fakeTriplestoreDir.get.toFile) + Files.createDirectories(fakeTriplestoreDir.get) () } def load(): Unit = { - val dataToWrap = fakeTriplestoreDir.get.listFiles.map { queryDir => - val sparql = FileUtil.readTextFile(queryDir.listFiles.filter(_.getName.endsWith(".rq")).head) - val result = FileUtil.readTextFile(queryDir.listFiles.filter(_.getName.endsWith(".json")).head) - sparql -> result - }.toMap + val dataToWrap = Files + .newDirectoryStream(fakeTriplestoreDir.get) + .asScala + .map { queryDir => + val sparql = FileUtil.readTextFile( + Files + .newDirectoryStream(queryDir) + .asScala + .filter(_.getFileName.toString.endsWith(".rq")) + .head) + val result = FileUtil.readTextFile( + Files + .newDirectoryStream(queryDir) + .asScala + .filter(_.getFileName.toString.endsWith(".json")) + .head) + sparql -> result + } + .toMap data = new ErrorHandlingMap(dataToWrap, { key: String => s"No result has been stored in the fake triplestore for this query: $key" @@ -62,14 +78,13 @@ object FakeTriplestore { this.synchronized { log.info("Collecting data for fake triplestore") val paddedQueryNum = f"$queryNum%04d" - val queryDir = new File(fakeTriplestoreDir.get, paddedQueryNum) - queryDir.mkdirs() - val sparqlFile = new File(queryDir, s"query-$paddedQueryNum.rq") + val queryDir = fakeTriplestoreDir.get.resolve(paddedQueryNum) + Files.createDirectories(queryDir) + val sparqlFile = queryDir.resolve(s"query-$paddedQueryNum.rq") FileUtil.writeTextFile(sparqlFile, sparql) - val resultFile = new File(queryDir, s"response-$paddedQueryNum.json") + val resultFile = queryDir.resolve(s"response-$paddedQueryNum.json") FileUtil.writeTextFile(resultFile, result) queryNum += 1 } } - } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/AbstractShaclValidator.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/AbstractShaclValidator.scala index bed1904caa..cf612f2949 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/AbstractShaclValidator.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/AbstractShaclValidator.scala @@ -63,7 +63,7 @@ abstract class AbstractShaclValidator[ShaclGraphT](baseDir: Path, private val rd // Is this a Turtle file? if (file.getFileName.toString.endsWith(".ttl")) { // Yes. Parse it. - val shaclModel: RdfModel = rdfFormatUtil.fileToRdfModel(file = file.toFile, rdfFormat = Turtle) + val shaclModel: RdfModel = rdfFormatUtil.fileToRdfModel(file = file, rdfFormat = Turtle) // Convert it to a ShaclGraphT. val shaclGraph: ShaclGraphT = rdfModelToShaclGraph(shaclModel) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala index 2711c83f93..016d7bf558 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala @@ -1718,7 +1718,7 @@ object JsonLDUtil { inlineResource(iriToJsonLDObject(iriNode.iri)) } - case blankNode: BlankNode => + case _: BlankNode => // It's a blank node. It should be possible to inline it. If not, return an empty blank node. inlineResource(JsonLDObject(Map.empty)) } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtil.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtil.scala index 57f9e57cff..5b52e4255c 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtil.scala @@ -19,7 +19,8 @@ package org.knora.webapi.messages.util.rdf -import java.io._ +import java.io.{BufferedInputStream, BufferedOutputStream, InputStream, OutputStream} +import java.nio.file.{Files, Path} import akka.http.scaladsl.model.MediaType import org.knora.webapi.exceptions.{BadRequestException, InvalidRdfException} @@ -279,9 +280,9 @@ trait RdfFormatUtil { * @param rdfFormat the file format. * @return a [[RdfModel]] representing the contents of the file. */ - def fileToRdfModel(file: File, rdfFormat: NonJsonLD): RdfModel = { + def fileToRdfModel(file: Path, rdfFormat: NonJsonLD): RdfModel = { inputStreamToRdfModel( - inputStream = new BufferedInputStream(new FileInputStream(file)), + inputStream = new BufferedInputStream(Files.newInputStream(file)), rdfFormat = rdfFormat ) } @@ -293,10 +294,10 @@ trait RdfFormatUtil { * @param file the file to be written. * @param rdfFormat the file format. */ - def rdfModelToFile(rdfModel: RdfModel, file: File, rdfFormat: NonJsonLD): Unit = { + def rdfModelToFile(rdfModel: RdfModel, file: Path, rdfFormat: NonJsonLD): Unit = { rdfModelToOutputStream( rdfModel = rdfModel, - outputStream = new BufferedOutputStream(new FileOutputStream(file)), + outputStream = new BufferedOutputStream(Files.newOutputStream(file)), rdfFormat = rdfFormat ) } @@ -381,11 +382,11 @@ trait RdfFormatUtil { * @param outputFile the output file. * @param outputFormat the output file format. */ - def turtleToQuadsFile(rdfSource: RdfSource, graphIri: IRI, outputFile: File, outputFormat: QuadFormat): Unit = { + def turtleToQuadsFile(rdfSource: RdfSource, graphIri: IRI, outputFile: Path, outputFormat: QuadFormat): Unit = { var maybeBufferedFileOutputStream: Option[BufferedOutputStream] = None val processingTry: Try[Unit] = Try { - val bufferedFileOutputStream = new BufferedOutputStream(new FileOutputStream(outputFile)) + val bufferedFileOutputStream = new BufferedOutputStream(Files.newOutputStream(outputFile)) maybeBufferedFileOutputStream = Some(bufferedFileOutputStream) val formattingStreamProcessor: RdfStreamProcessor = makeFormattingStreamProcessor( diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala index afcfe52d05..fa6e6da93c 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala @@ -19,8 +19,8 @@ package org.knora.webapi.responders.admin -import java.io._ -import java.nio.file.Files +import java.io.{BufferedInputStream, BufferedOutputStream} +import java.nio.file.{Files, Path} import java.util.UUID import akka.http.scaladsl.util.FastFuture @@ -493,12 +493,12 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo * @param graphIri the IRI of the named graph. * @param tempDir the directory in which the file is to be saved. */ - case class NamedGraphTrigFile(graphIri: IRI, tempDir: File) { - lazy val dataFile: File = { + case class NamedGraphTrigFile(graphIri: IRI, tempDir: Path) { + lazy val dataFile: Path = { val filename = graphIri.replaceAll(":", "_").replaceAll("/", "_").replaceAll("""\.""", "_") + ".trig" - new File(tempDir, filename) + tempDir.resolve(filename) } } @@ -535,12 +535,12 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo * @param namedGraphTrigFiles the TriG files to combine. * @param resultFile the output file. */ - def combineGraphs(namedGraphTrigFiles: Seq[NamedGraphTrigFile], resultFile: File): Unit = { + def combineGraphs(namedGraphTrigFiles: Seq[NamedGraphTrigFile], resultFile: Path): Unit = { val rdfFormatUtil: RdfFormatUtil = RdfFeatureFactory.getRdfFormatUtil(featureFactoryConfig) var maybeBufferedFileOutputStream: Option[BufferedOutputStream] = None val trigFileTry: Try[Unit] = Try { - maybeBufferedFileOutputStream = Some(new BufferedOutputStream(new FileOutputStream(resultFile))) + maybeBufferedFileOutputStream = Some(new BufferedOutputStream(Files.newOutputStream(resultFile))) val formattingStreamProcessor: RdfStreamProcessor = rdfFormatUtil.makeFormattingStreamProcessor( outputStream = maybeBufferedFileOutputStream.get, @@ -554,13 +554,13 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo val namedGraphTry: Try[Unit] = Try { rdfFormatUtil.parseWithStreamProcessor( rdfSource = - RdfInputStreamSource(new BufferedInputStream(new FileInputStream(namedGraphTrigFile.dataFile))), + RdfInputStreamSource(new BufferedInputStream(Files.newInputStream(namedGraphTrigFile.dataFile))), rdfFormat = TriG, rdfStreamProcessor = combiningRdfProcessor ) } - namedGraphTrigFile.dataFile.delete + Files.delete(namedGraphTrigFile.dataFile) namedGraphTry match { case Success(_) => () @@ -597,8 +597,8 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo } // Make a temporary directory for the downloaded data. - tempDir = Files.createTempDirectory(project.shortname).toFile - _ = log.info("Downloading project data to temporary directory " + tempDir.getAbsolutePath) + tempDir = Files.createTempDirectory(project.shortname) + _ = log.info("Downloading project data to temporary directory " + tempDir.toAbsolutePath) // Download the project's named graphs. @@ -665,7 +665,7 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo // Stream the combined results into the output file. namedGraphTrigFiles: Seq[NamedGraphTrigFile] = projectSpecificNamedGraphTrigFiles :+ adminDataNamedGraphTrigFile :+ permissionDataNamedGraphTrigFile - resultFile: File = new File(tempDir, project.shortname + ".trig") + resultFile: Path = tempDir.resolve(project.shortname + ".trig") _ = combineGraphs(namedGraphTrigFiles = namedGraphTrigFiles, resultFile = resultFile) } yield ProjectDataGetResponseADM(resultFile) } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala index 7a85ff6824..6f05f3a904 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteADM.scala @@ -19,6 +19,7 @@ package org.knora.webapi.routing.admin +import java.nio.file.Files import java.util.UUID import akka.Done @@ -731,9 +732,9 @@ class ProjectsRouteADM(routeData: KnoraRouteData) // Stream the output file back to the client, then delete the file. - source: Source[ByteString, Unit] = FileIO.fromPath(responseMessage.projectDataFile.toPath).watchTermination() { + source: Source[ByteString, Unit] = FileIO.fromPath(responseMessage.projectDataFile).watchTermination() { case (_: Future[IOResult], result: Future[Done]) => - result.onComplete((_: Try[Done]) => responseMessage.projectDataFile.delete) + result.onComplete((_: Try[Done]) => Files.delete(responseMessage.projectDataFile)) } httpEntity = HttpEntity(ContentTypes.`application/octet-stream`, source) diff --git a/webapi/src/main/scala/org/knora/webapi/routing/v1/AssetsRouteV1.scala b/webapi/src/main/scala/org/knora/webapi/routing/v1/AssetsRouteV1.scala index af0610928f..061bc347f6 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/v1/AssetsRouteV1.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/v1/AssetsRouteV1.scala @@ -21,7 +21,8 @@ package org.knora.webapi.routing.v1 import java.awt.image.BufferedImage import java.awt.{Color, Font, Graphics} -import java.io.{ByteArrayOutputStream, File} +import java.io.ByteArrayOutputStream +import java.nio.file.Paths import akka.http.scaladsl.model.{HttpEntity, HttpResponse, MediaTypes} import akka.http.scaladsl.server.Directives._ @@ -53,7 +54,7 @@ class AssetsRouteV1(routeData: KnoraRouteData) extends KnoraRoute(routeData) wit val dummyImage = if (text.contains("http://rdfh.ch/0a077e5a93bf".toCharArray)) { //calling this should get me here: http://localhost:3333/v1/assets/http%3A%2F%2Frdfh.ch%2F0a077e5a93bf - val tmpImage = ImageIO.read(new File("_assets/4KUN_7_000169.png")) + val tmpImage = ImageIO.read(Paths.get("_assets/4KUN_7_000169.png").toFile) tmpImage } else { /* make dummy images with the image name as content */ diff --git a/webapi/src/main/scala/org/knora/webapi/settings/KnoraSettings.scala b/webapi/src/main/scala/org/knora/webapi/settings/KnoraSettings.scala index 7aa62cadd8..da9fed938a 100644 --- a/webapi/src/main/scala/org/knora/webapi/settings/KnoraSettings.scala +++ b/webapi/src/main/scala/org/knora/webapi/settings/KnoraSettings.scala @@ -19,7 +19,6 @@ package org.knora.webapi.settings -import java.io.File import java.nio.file.{Files, Path, Paths} import java.time.Instant @@ -82,8 +81,7 @@ class KnoraSettingsImpl(config: Config, log: LoggingAdapter) extends Extension { // try to create the directories if (!Files.exists(Paths.get(tmpDataDir))) { try { - val _tmpDataDir = new File(tmpDataDir) - _tmpDataDir.mkdir() + Files.createDirectories(Paths.get(tmpDataDir)) } catch { case e: Throwable => throw FileWriteException(s"Tmp data directory $tmpDataDir could not be created: ${e.getMessage}") @@ -93,8 +91,7 @@ class KnoraSettingsImpl(config: Config, log: LoggingAdapter) extends Extension { // try to create the directories if (!Files.exists(Paths.get(dataDir))) { try { - val _dataDir = new File(dataDir) - _dataDir.mkdir() + Files.createDirectories(Paths.get(dataDir)) } catch { case e: Throwable => throw FileWriteException(s"Tmp data directory $tmpDataDir could not be created: ${e.getMessage}") @@ -229,7 +226,7 @@ class KnoraSettingsImpl(config: Config, log: LoggingAdapter) extends Extension { private val fakeTriplestore: String = config.getString("app.triplestore.fake-triplestore") val prepareFakeTriplestore: Boolean = fakeTriplestore == "prepare" val useFakeTriplestore: Boolean = fakeTriplestore == "use" - val fakeTriplestoreDataDir: File = new File(config.getString("app.triplestore.fake-triplestore-data-dir")) + val fakeTriplestoreDataDir: Path = Paths.get(config.getString("app.triplestore.fake-triplestore-data-dir")) val skipAuthentication: Boolean = config.getBoolean("app.skip-authentication") diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/embedded/JenaTDBActor.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/embedded/JenaTDBActor.scala index 17cafbdb97..314800fe2e 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/embedded/JenaTDBActor.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/embedded/JenaTDBActor.scala @@ -19,7 +19,7 @@ package org.knora.webapi.store.triplestore.embedded -import java.io._ +import java.nio.file.{Files, Paths} import akka.actor.{Actor, ActorLogging, Status} import org.apache.commons.io.FileUtils @@ -62,8 +62,8 @@ class JenaTDBActor extends Actor with ActorLogging { private val persist = settings.tripleStoreConfig.getBoolean("embedded-jena-tdb.persisted") private val loadExistingData = settings.tripleStoreConfig.getBoolean("embedded-jena-tdb.loadExistingData") - private val storagePath = new File(settings.tripleStoreConfig.getString("embedded-jena-tdb.storage-path")) - private val tdbStoragePath = new File(storagePath + "/db") + private val storagePath = Paths.get(settings.tripleStoreConfig.getString("embedded-jena-tdb.storage-path")) + private val tdbStoragePath = Paths.get(storagePath + "/db") private val tsType = settings.triplestoreType @@ -88,14 +88,15 @@ class JenaTDBActor extends Actor with ActorLogging { override def preStart(): Unit = { if (persist) { if (reloadDataOnStart || !loadExistingData) { - log.debug(s"Disk backed store. Delete and Create: ${tdbStoragePath.getAbsolutePath}") + log.debug(s"Disk backed store. Delete and Create: ${tdbStoragePath.toAbsolutePath}") // only allowed, because the dataset gets created later on. - FileUtils.deleteQuietly(tdbStoragePath) + FileUtils.deleteQuietly(tdbStoragePath.toFile) } else { - log.debug(s"Disk backed store. Using: ${tdbStoragePath.getAbsolutePath}") + log.debug(s"Disk backed store. Using: ${tdbStoragePath.toAbsolutePath}") } - tdbStoragePath.mkdirs() + + Files.createDirectories(tdbStoragePath) } else { log.debug(s"In-memory store: will reload data") } @@ -448,7 +449,7 @@ class JenaTDBActor extends Actor with ActorLogging { // Set UnionDefaultGraph globally TDB.getContext.set(TDB.symUnionDefaultGraph, true) - val ds = TDBFactory.createDataset(tdbStoragePath.getAbsolutePath) + val ds = TDBFactory.createDataset(tdbStoragePath.toAbsolutePath.toString) // Lucene, on disk //val indexDirectory: Directory = new SimpleFSDirectory(new File(luceneIndexPath.getAbsolutePath)) diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala index 5f3f62d768..fec2235fb1 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala @@ -19,9 +19,9 @@ package org.knora.webapi.store.triplestore.http -import java.io._ +import java.io.BufferedInputStream import java.net.URI -import java.nio.file.{Files, Paths} +import java.nio.file.{Files, Path, Paths, StandardCopyOption} import java.util import akka.actor.{Actor, ActorLogging, ActorSystem, Status} @@ -202,14 +202,14 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat try2Message(sender(), sparqlHttpExtendedConstruct(sparqlExtendedConstructRequest), log) case SparqlConstructFileRequest(sparql: String, graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig) => try2Message(sender(), sparqlHttpConstructFile(sparql, graphIri, outputFile, outputFormat, featureFactoryConfig), log) case NamedGraphFileRequest(graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig) => try2Message(sender(), sparqlHttpGraphFile(graphIri, outputFile, outputFormat, featureFactoryConfig), log) @@ -225,9 +225,9 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat case CheckTriplestoreRequest() => try2Message(sender(), checkTriplestore(), log) case SearchIndexUpdateRequest(subjectIri: Option[String]) => try2Message(sender(), updateLuceneIndex(subjectIri), log) - case DownloadRepositoryRequest(outputFile: File, featureFactoryConfig: FeatureFactoryConfig) => + case DownloadRepositoryRequest(outputFile: Path, featureFactoryConfig: FeatureFactoryConfig) => try2Message(sender(), downloadRepository(outputFile, featureFactoryConfig), log) - case UploadRepositoryRequest(inputFile: File) => try2Message(sender(), uploadRepository(inputFile), log) + case UploadRepositoryRequest(inputFile: Path) => try2Message(sender(), uploadRepository(inputFile), log) case InsertGraphDataContentRequest(graphContent: String, graphName: String) => try2Message(sender(), insertDataGraphRequest(graphContent, graphName), log) case other => @@ -345,7 +345,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat */ private def sparqlHttpConstructFile(sparql: String, graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig): Try[FileWrittenResponse] = { val rdfFormatUtil: RdfFormatUtil = RdfFeatureFactory.getRdfFormatUtil(featureFactoryConfig) @@ -533,11 +533,13 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat val httpPost: HttpPost = new HttpPost(uriBuilder.build()) // Add the input file to the body of the request. - val inputFile = new File(elem.path) - if (!inputFile.exists) { - throw BadRequestException(s"File ${inputFile.getAbsolutePath} does not exist") + val inputFile = Paths.get(elem.path) + + if (!Files.exists(inputFile)) { + throw BadRequestException(s"File ${inputFile.toAbsolutePath} does not exist") } - val fileEntity = new FileEntity(inputFile, ContentType.create(mimeTypeTextTurtle, "UTF-8")) + + val fileEntity = new FileEntity(inputFile.toFile, ContentType.create(mimeTypeTextTurtle, "UTF-8")) httpPost.setEntity(fileEntity) val makeResponse: CloseableHttpResponse => InsertGraphDataContentResponse = returnInsertGraphDataResponse( graphName) @@ -783,7 +785,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat * @return a string containing the contents of the graph in N-Quads format. */ private def sparqlHttpGraphFile(graphIri: IRI, - outputFile: File, + outputFile: Path, outputFormat: QuadFormat, featureFactoryConfig: FeatureFactoryConfig): Try[FileWrittenResponse] = { val httpContext: HttpClientContext = makeHttpContext @@ -877,7 +879,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat * @param featureFactoryConfig the feature factory configuration. * @return a string containing the contents of the graph in N-Quads format. */ - private def downloadRepository(outputFile: File, + private def downloadRepository(outputFile: Path, featureFactoryConfig: FeatureFactoryConfig): Try[FileWrittenResponse] = { val httpContext: HttpClientContext = makeHttpContext @@ -926,10 +928,10 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat * * @param inputFile an N-Quads file containing the content to be uploaded to the repository. */ - private def uploadRepository(inputFile: File): Try[RepositoryUploadedResponse] = { + private def uploadRepository(inputFile: Path): Try[RepositoryUploadedResponse] = { val httpContext: HttpClientContext = makeHttpContext val httpPost: HttpPost = new HttpPost(repositoryUploadPath) - val fileEntity = new FileEntity(inputFile, ContentType.create(mimeTypeApplicationNQuads, "UTF-8")) + val fileEntity = new FileEntity(inputFile.toFile, ContentType.create(mimeTypeApplicationNQuads, "UTF-8")) httpPost.setEntity(fileEntity) doHttpRequest( @@ -1095,7 +1097,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat * @param response the response to be read. * @return a [[FileWrittenResponse]]. */ - def writeResponseFile(outputFile: File, + def writeResponseFile(outputFile: Path, featureFactoryConfig: FeatureFactoryConfig, maybeGraphIriAndFormat: Option[GraphIriAndFormat] = None)( response: CloseableHttpResponse): FileWrittenResponse = { @@ -1105,8 +1107,8 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat maybeGraphIriAndFormat match { case Some(GraphIriAndFormat(graphIri, quadFormat)) => // Yes. Stream the HTTP entity to a temporary Turtle file. - val turtleFile = new File(outputFile.getCanonicalPath + ".ttl") - Files.copy(responseEntity.getContent, Paths.get(turtleFile.getCanonicalPath)) + val turtleFile = Paths.get(outputFile.toString + ".ttl") + Files.copy(responseEntity.getContent, turtleFile, StandardCopyOption.REPLACE_EXISTING) // Convert the Turtle to the output format. @@ -1114,14 +1116,14 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat val processFileTry: Try[Unit] = Try { rdfFormatUtil.turtleToQuadsFile( - rdfSource = RdfInputStreamSource(new BufferedInputStream(new FileInputStream(turtleFile))), + rdfSource = RdfInputStreamSource(new BufferedInputStream(Files.newInputStream(turtleFile))), graphIri = graphIri, outputFile = outputFile, outputFormat = quadFormat ) } - turtleFile.delete() + Files.delete(turtleFile) processFileTry match { case Success(_) => () @@ -1130,7 +1132,7 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat case None => // No. Stream the HTTP entity directly to the output file. - Files.copy(responseEntity.getContent, Paths.get(outputFile.getCanonicalPath)) + Files.copy(responseEntity.getContent, outputFile) } FileWrittenResponse() diff --git a/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala b/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala index 666a0cf4ee..e477d08fcd 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/triplestore/upgrade/RepositoryUpdater.scala @@ -1,7 +1,6 @@ package org.knora.webapi.store.triplestore.upgrade -import java.io._ -import java.nio.file.Files +import java.nio.file.{Files, Path, Paths} import akka.actor.{ActorRef, ActorSystem} import akka.http.scaladsl.util.FastFuture @@ -160,24 +159,24 @@ class RepositoryUpdater(system: ActorSystem, private def updateRepositoryWithSelectedPlugins( pluginsForNeededUpdates: Seq[PluginForKnoraBaseVersion]): Future[RepositoryUpdatedResponse] = { // Was a download directory specified in the application settings? - val downloadDir: File = settings.upgradeDownloadDir match { + val downloadDir: Path = settings.upgradeDownloadDir match { case Some(configuredDir) => // Yes. Use that directory. log.info(s"Repository update using configured download directory $configuredDir") - val dirFile = new File(configuredDir) - dirFile.mkdirs() + val dirFile = Paths.get(configuredDir) + Files.createDirectories(dirFile) dirFile case None => // No. Create a temporary directory. - val dirFile = Files.createTempDirectory("knora").toFile + val dirFile = Files.createTempDirectory("knora") log.info(s"Repository update using download directory $dirFile") dirFile } // The file to save the repository in. - val downloadedRepositoryFile = new File(downloadDir, "downloaded-repository.nq") - val transformedRepositoryFile = new File(downloadDir, "transformed-repository.nq") + val downloadedRepositoryFile = downloadDir.resolve("downloaded-repository.nq") + val transformedRepositoryFile = downloadDir.resolve("transformed-repository.nq") log.info("Downloading repository file...") for { @@ -217,8 +216,8 @@ class RepositoryUpdater(system: ActorSystem, * @param transformedRepositoryFile the transformed file. * @param pluginsForNeededUpdates the plugins needed to update the repository. */ - private def doTransformations(downloadedRepositoryFile: File, - transformedRepositoryFile: File, + private def doTransformations(downloadedRepositoryFile: Path, + transformedRepositoryFile: Path, pluginsForNeededUpdates: Seq[PluginForKnoraBaseVersion]): Unit = { // Parse the input file. log.info("Reading repository file...") diff --git a/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala b/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala index 96165219aa..55af72cfdd 100644 --- a/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala @@ -19,9 +19,9 @@ package org.knora.webapi.util -import java.io.{ByteArrayOutputStream, File} +import java.io.ByteArrayOutputStream import java.nio.charset.StandardCharsets -import java.nio.file.{Files, Paths} +import java.nio.file.{Files, Path, Paths} import java.util.zip.{ZipEntry, ZipOutputStream} import com.typesafe.scalalogging.Logger @@ -42,7 +42,7 @@ object FileUtil { * @param file the destination file. * @param content the string to write. */ - def writeTextFile(file: File, content: String): Unit = { + def writeTextFile(file: Path, content: String): Unit = { writeBinaryFile(file, content.getBytes(StandardCharsets.UTF_8)) } @@ -52,10 +52,10 @@ object FileUtil { * @param file the source file. * @return the contents of the file. */ - def readTextFile(file: File): String = { + def readTextFile(file: Path): String = { // TODO: provide apt error handling - val source = Source.fromFile(file)(Codec.UTF8) + val source = Source.fromFile(file.toFile)(Codec.UTF8) try { source.mkString @@ -84,7 +84,7 @@ object FileUtil { source.mkString } catch { - case ex: Exception => + case _: Exception => throw NotFoundException(s"The requested file could not be read: $filename") } finally { if (sourceOption.nonEmpty) { @@ -100,8 +100,8 @@ object FileUtil { * @param file the destination file. * @param content the binary data to write. */ - def writeBinaryFile(file: File, content: Array[Byte]): Unit = { - Files.write(Paths.get(file.getCanonicalPath), content) + def writeBinaryFile(file: Path, content: Array[Byte]): Unit = { + Files.write(file, content) } /** @@ -137,13 +137,10 @@ object FileUtil { * @param binaryData the binary file data to be saved. * @return the location where the file has been written to. */ - def saveFileToTmpLocation(settings: KnoraSettingsImpl, binaryData: Array[Byte]): File = { - - val fileName = createTempFile(settings) - // write given file to disk - Files.write(fileName.toPath, binaryData) - - fileName + def saveFileToTmpLocation(settings: KnoraSettingsImpl, binaryData: Array[Byte]): Path = { + val file = createTempFile(settings) + Files.write(file, binaryData) + file } /** @@ -153,42 +150,39 @@ object FileUtil { * @param fileExtension the extension to be used for the temporary file name, if any, * @return the location where the file has been written to. */ - def createTempFile(settings: KnoraSettingsImpl, fileExtension: Option[String] = None): File = { + def createTempFile(settings: KnoraSettingsImpl, fileExtension: Option[String] = None): Path = { + val tempDataDir = Paths.get(settings.tmpDataDir) // check if the location for writing temporary files exists - if (!Files.exists(Paths.get(settings.tmpDataDir))) { + if (!Files.exists(tempDataDir)) { throw FileWriteException(s"Data directory ${settings.tmpDataDir} does not exist on server") } - val extension = if (fileExtension.nonEmpty) { - fileExtension.get - } else { - "bin" - } + val extension = fileExtension.getOrElse("bin") - val file: File = File.createTempFile("tmp_", "." + extension, new File(settings.tmpDataDir)) + val file: Path = Files.createTempFile(tempDataDir, "tmp_", "." + extension) - if (!file.canWrite) + if (!Files.isWritable(file)) { throw FileWriteException(s"File $file cannot be written.") + } + file } /** * Deletes a temporary file. * - * @param fileName the file to be deleted. + * @param file the file to be deleted. * @param log a logging adapter. * @return `true` if the file was deleted by this method. */ - def deleteFileFromTmpLocation(fileName: File, log: Logger): Boolean = { - - val path = fileName.toPath + def deleteFileFromTmpLocation(file: Path, log: Logger): Boolean = { - if (!fileName.canWrite) { - val ex = FileWriteException(s"File $path cannot be deleted.") + if (!Files.isWritable(file)) { + val ex = FileWriteException(s"File $file cannot be deleted.") log.error(ex.getMessage, ex) } - Files.deleteIfExists(path) + Files.deleteIfExists(file) } } diff --git a/webapi/src/test/scala/org/knora/webapi/E2ESpec.scala b/webapi/src/test/scala/org/knora/webapi/E2ESpec.scala index 87e8028a47..c49eb2c1fa 100644 --- a/webapi/src/test/scala/org/knora/webapi/E2ESpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/E2ESpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi -import java.io.File +import java.nio.file.{Files, Path, Paths} import akka.actor.{ActorRef, ActorSystem, Props} import akka.event.LoggingAdapter @@ -184,13 +184,13 @@ class E2ESpec(_system: ActorSystem) * @param writeFile if `true`, writes the response to the file and returns it, otherwise returns the current contents of the file. * @return the expected response. */ - protected def readOrWriteTextFile(responseAsString: String, file: File, writeFile: Boolean = false): String = { + protected def readOrWriteTextFile(responseAsString: String, file: Path, writeFile: Boolean = false): String = { if (writeFile) { // Per default only read access is allowed in the bazel sandbox. // This workaround allows to save test output. - val testOutputDir = sys.env("TEST_UNDECLARED_OUTPUTS_DIR") - val newOutputFile = new File(testOutputDir, file.getPath) - newOutputFile.getParentFile.mkdirs() + val testOutputDir: Path = Paths.get(sys.env("TEST_UNDECLARED_OUTPUTS_DIR")) + val newOutputFile = testOutputDir.resolve(file) + Files.createDirectories(newOutputFile.getParent) FileUtil.writeTextFile(newOutputFile, responseAsString.replaceAll(settings.externalSipiIIIFGetUrl, "IIIF_BASE_URL")) responseAsString diff --git a/webapi/src/test/scala/org/knora/webapi/R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/R2RSpec.scala index 0e96cb944e..4c2ece17e2 100644 --- a/webapi/src/test/scala/org/knora/webapi/R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/R2RSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi -import java.io.File +import java.nio.file.{Files, Path, Paths} import akka.actor.{ActorRef, ActorSystem, Props} import akka.event.LoggingAdapter @@ -155,19 +155,21 @@ class R2RSpec /** * Reads or writes a test data file. + * The written test data files can be found under: + * ./bazel-out/darwin-fastbuild/testlogs///test.outputs/outputs.zip * * @param responseAsString the API response received from Knora. * @param file the file in which the expected API response is stored. * @param writeFile if `true`, writes the response to the file and returns it, otherwise returns the current contents of the file. * @return the expected response. */ - protected def readOrWriteTextFile(responseAsString: String, file: File, writeFile: Boolean = false): String = { + protected def readOrWriteTextFile(responseAsString: String, file: Path, writeFile: Boolean = false): String = { if (writeFile) { // Per default only read access is allowed in the bazel sandbox. // This workaround allows to save test output. - val testOutputDir = sys.env("TEST_UNDECLARED_OUTPUTS_DIR") - val newOutputFile = new File(testOutputDir, file.getPath) - newOutputFile.getParentFile.mkdirs() + val testOutputDir: Path = Paths.get(sys.env("TEST_UNDECLARED_OUTPUTS_DIR")) + val newOutputFile = testOutputDir.resolve(file) + Files.createDirectories(newOutputFile.getParent) FileUtil.writeTextFile(newOutputFile, responseAsString.replaceAll(settings.externalSipiIIIFGetUrl, "IIIF_BASE_URL")) responseAsString diff --git a/webapi/src/test/scala/org/knora/webapi/contributors/GenerateContributorsFileSpec.scala b/webapi/src/test/scala/org/knora/webapi/contributors/GenerateContributorsFileSpec.scala index f2e0b62e69..6c765cc58e 100644 --- a/webapi/src/test/scala/org/knora/webapi/contributors/GenerateContributorsFileSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/contributors/GenerateContributorsFileSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.contributors -import java.io.File +import java.nio.file.{Files, Path} import org.knora.webapi.CoreSpec import org.knora.webapi.util.FileUtil @@ -30,9 +30,9 @@ import org.knora.webapi.util.FileUtil class GenerateContributorsFileSpec extends CoreSpec() { "The GenerateContributorsFile utility" should { "generate a contributors file" ignore { // GitHub returns an HTTP 403 (Forbidden) error when this is run on Travis without a GitHub API key. - val tmpContributorsFile = File.createTempFile("TestContributors", ".md") - tmpContributorsFile.deleteOnExit() - GenerateContributorsFile.main(Array("-o", s"${tmpContributorsFile.getAbsolutePath}")) + val tmpContributorsFile: Path = Files.createTempFile("TestContributors", ".md") + tmpContributorsFile.toFile.deleteOnExit() + GenerateContributorsFile.main(Array("-o", s"${tmpContributorsFile.toAbsolutePath}")) val fileContents = FileUtil.readTextFile(tmpContributorsFile) fileContents.contains("Benjamin Geer") should ===(true) } diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/InstanceCheckerSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/InstanceCheckerSpec.scala index e44911aeba..1fb812f4f2 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/InstanceCheckerSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/InstanceCheckerSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.e2e -import java.io.File +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.scaladsl.testkit.RouteTestTimeout @@ -46,7 +46,7 @@ class InstanceCheckerSpec extends E2ESpec(InstanceCheckerSpec.config) { "The InstanceChecker" should { "accept a JSON-LD instance of anything:Thing" in { - val testDing = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/Testding.jsonld")) + val testDing = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/Testding.jsonld")) jsonLDInstanceChecker.check( instanceResponse = testDing, diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala index a3f29fc615..fb5bb6d3b2 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v1/SipiV1R2RSpec.scala @@ -19,7 +19,6 @@ package org.knora.webapi.e2e.v1 -import java.io.File import java.net.URLEncoder import java.nio.file.{Files, Paths} @@ -103,17 +102,17 @@ class SipiV1R2RSpec extends R2RSpec { def createTmpFileDir(): Unit = { // check if tmp datadir exists and create it if not - if (!Files.exists(Paths.get(settings.tmpDataDir))) { + val tmpFileDir = Paths.get(settings.tmpDataDir) + + if (!Files.exists(tmpFileDir)) { try { - val tmpDir = new File(settings.tmpDataDir) - tmpDir.mkdir() + Files.createDirectories(tmpFileDir) } catch { case e: Throwable => throw FileWriteException(s"Tmp data directory ${settings.tmpDataDir} could not be created: ${e.getMessage}") } } } - } "The Resources Endpoint" should { diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v1/StandoffV1R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v1/StandoffV1R2RSpec.scala index 95d5f1a417..1cc3a83804 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v1/StandoffV1R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v1/StandoffV1R2RSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v1 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.scaladsl.model.headers.BasicHttpCredentials @@ -637,7 +637,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a mapping resource for standoff conversion for letters" in { - val mappingFileToSend = new File(RequestParams.pathToLetterMapping) + val mappingFileToSend = Paths.get(RequestParams.pathToLetterMapping) val formDataMapping = Multipart.FormData( Multipart.FormData.BodyPart( @@ -646,8 +646,8 @@ class StandoffV1R2RSpec extends R2RSpec { ), Multipart.FormData.BodyPart( "xml", - HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend.toPath), - Map("filename" -> mappingFileToSend.getName) + HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend), + Map("filename" -> mappingFileToSend.getFileName.toString) ) ) @@ -668,7 +668,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a TextValue from an XML representing a letter" in { - val xmlFileToSend = FileUtil.readTextFile(new File(RequestParams.pathToLetterXML)) + val xmlFileToSend = FileUtil.readTextFile(Paths.get(RequestParams.pathToLetterXML)) val newValueParams = s""" @@ -698,7 +698,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the XML TextValue back to XML and compare it to the XML that was originally sent" in { - val xmlFile = new File(RequestParams.pathToLetterXML) + val xmlFile = Paths.get(RequestParams.pathToLetterXML) val xmlStr = FileUtil.readTextFile(xmlFile) Get("/v1/values/" + URLEncoder.encode(firstTextValueIri.get, "UTF-8")) ~> addCredentials( @@ -726,7 +726,7 @@ class StandoffV1R2RSpec extends R2RSpec { "change a text value from XML representing a letter" in { - val xmlFileToSend = new File(RequestParams.pathToLetter2XML) + val xmlFileToSend = Paths.get(RequestParams.pathToLetter2XML) val xmlStrToSend = FileUtil.readTextFile(xmlFileToSend) val newValueParams = @@ -756,7 +756,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the changed TextValue back to XML and compare it to the XML that was originally sent" in { - val xmlFile = new File(RequestParams.pathToLetter2XML) + val xmlFile = Paths.get(RequestParams.pathToLetter2XML) val xmlStr = FileUtil.readTextFile(xmlFile) Get("/v1/values/" + URLEncoder.encode(firstTextValueIri.get, "UTF-8")) ~> addCredentials( @@ -784,7 +784,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a TextValue from complex XML representing a letter" in { - val xmlFileToSend = new File(RequestParams.pathToLetter3XML) + val xmlFileToSend = Paths.get(RequestParams.pathToLetter3XML) val xmlStrToSend = FileUtil.readTextFile(xmlFileToSend) val newValueParams = @@ -815,7 +815,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the complex TextValue back to XML and compare it to the XML that was originally sent" in { - val xmlFile = new File(RequestParams.pathToLetter3XML) + val xmlFile = Paths.get(RequestParams.pathToLetter3XML) val xmlStr = FileUtil.readTextFile(xmlFile) Get("/v1/values/" + URLEncoder.encode(secondTextValueIri.get, "UTF-8")) ~> addCredentials( @@ -843,7 +843,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a mapping resource for standoff conversion for HTML" in { - val mappingFileToSend = new File(RequestParams.pathToHTMLMapping) + val mappingFileToSend = Paths.get(RequestParams.pathToHTMLMapping) val formDataMapping = Multipart.FormData( Multipart.FormData.BodyPart( @@ -852,8 +852,8 @@ class StandoffV1R2RSpec extends R2RSpec { ), Multipart.FormData.BodyPart( "xml", - HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend.toPath), - Map("filename" -> mappingFileToSend.getName) + HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend), + Map("filename" -> mappingFileToSend.getFileName.toString) ) ) @@ -874,7 +874,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a TextValue from StandardXML representing HTML (in strict XML notation)" in { - val xmlFileToSend = new File(RequestParams.pathToStandardHTML) + val xmlFileToSend = Paths.get(RequestParams.pathToStandardHTML) val xmlStrToSend = FileUtil.readTextFile(xmlFileToSend) val newValueParams = @@ -905,7 +905,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the TextValue back to XML and compare it to the (Standard) HTML that was originally sent" in { - val htmlFile = new File(RequestParams.pathToStandardHTML) + val htmlFile = Paths.get(RequestParams.pathToStandardHTML) val htmlStr = FileUtil.readTextFile(htmlFile) Get("/v1/values/" + URLEncoder.encode(thirdTextValueIri.get, "UTF-8")) ~> addCredentials( @@ -933,7 +933,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a TextValue from StandardXML representing HTML with internal anchor link" in { - val xmlFileToSend = new File(RequestParams.pathToStandardHTMLInternalLink) + val xmlFileToSend = Paths.get(RequestParams.pathToStandardHTMLInternalLink) val xmlStrToSend = FileUtil.readTextFile(xmlFileToSend) val newValueParams = @@ -964,7 +964,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the TextValue back to XML and compare it to the (Standard) HTML with internal anchor link that was originally sent" in { - val htmlFile = new File(RequestParams.pathToStandardHTMLInternalLink) + val htmlFile = Paths.get(RequestParams.pathToStandardHTMLInternalLink) val htmlStr = FileUtil.readTextFile(htmlFile) Get("/v1/values/" + URLEncoder.encode(fourthTextValueIri.get, "UTF-8")) ~> addCredentials( @@ -992,7 +992,7 @@ class StandoffV1R2RSpec extends R2RSpec { "create a TextValue from XML representing HTML (in strict XML notation)" in { - val xmlFileToSend = new File(RequestParams.pathToHTML) + val xmlFileToSend = Paths.get(RequestParams.pathToHTML) val xmlStrToSend = FileUtil.readTextFile(xmlFileToSend) val newValueParams = @@ -1023,7 +1023,7 @@ class StandoffV1R2RSpec extends R2RSpec { "read the TextValue back to XML and compare it to the HTML that was originally sent" in { - val htmlFile = new File(RequestParams.pathToHTML) + val htmlFile = Paths.get(RequestParams.pathToHTML) val htmlStr = FileUtil.readTextFile(htmlFile) Get("/v1/values/" + URLEncoder.encode(thirdTextValueIri.get, "UTF-8")) ~> addCredentials( diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala index cb9faf5cbc..db52b45426 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/JSONLDHandlingV2R2RSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.javadsl.model.StatusCodes @@ -63,7 +63,7 @@ class JSONLDHandlingV2R2RSpec extends R2RSpec { // JSON-LD with prefixes and context object val jsonldWithPrefixes = - readOrWriteTextFile("", new File("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), writeFile = false) + readOrWriteTextFile("", Paths.get("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), writeFile = false) // expand JSON-LD with JSON-LD processor val jsonldParsedExpanded = JsonLDUtil.parseJsonLD(jsonldWithPrefixes) @@ -71,7 +71,7 @@ class JSONLDHandlingV2R2RSpec extends R2RSpec { // expected result after expansion val expectedJsonldExpandedParsed = JsonLDUtil.parseJsonLD( readOrWriteTextFile("", - new File("test_data/resourcesR2RV2/NarrenschiffFirstPageExpanded.jsonld"), + Paths.get("test_data/resourcesR2RV2/NarrenschiffFirstPageExpanded.jsonld"), writeFile = false)) compareParsedJSONLDForResourcesResponse(expectedResponse = expectedJsonldExpandedParsed, @@ -90,7 +90,7 @@ class JSONLDHandlingV2R2RSpec extends R2RSpec { val expectedJson: JsObject = JsonParser( readOrWriteTextFile("", - new File("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), + Paths.get("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), writeFile = false)).asJsObject assert(receivedJson.fields("@context") == expectedJson.fields("@context"), "@context incorrect") diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ListsRouteV2R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ListsRouteV2R2RSpec.scala index 25aac6af81..8cb079e670 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ListsRouteV2R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ListsRouteV2R2RSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.javadsl.model.StatusCodes @@ -72,7 +72,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { Get(s"/v2/lists/${URLEncoder.encode("http://rdfh.ch/lists/00FF/73d0ec0302", "UTF-8")}") ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD: JsValue = - JsonParser(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesList.jsonld"))) + JsonParser(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesList.jsonld"))) val responseJson: JsValue = JsonParser(responseAs[String]) assert(responseJson == expectedAnswerJSONLD) } @@ -83,7 +83,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { val responseStr = responseAs[String] assert(status == StatusCodes.OK, responseStr) val expectedAnswerJSONLD: JsValue = - JsonParser(FileUtil.readTextFile(new File("test_data/listsR2RV2/treelist.jsonld"))) + JsonParser(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/treelist.jsonld"))) val responseJson: JsValue = JsonParser(responseStr) assert(responseJson == expectedAnswerJSONLD) @@ -105,7 +105,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { val responseStr = responseAs[String] assert(status == StatusCodes.OK, responseStr) val expectedAnswerJSONLD: JsValue = - JsonParser(FileUtil.readTextFile(new File("test_data/listsR2RV2/othertreelist.jsonld"))) + JsonParser(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/othertreelist.jsonld"))) val responseJson: JsValue = JsonParser(responseStr) assert(responseJson == expectedAnswerJSONLD) @@ -127,7 +127,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { .addHeader(Accept(RdfMediaTypes.`text/turtle`)) ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerTurtle: RdfModel = - parseTurtle(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesList.ttl"))) + parseTurtle(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesList.ttl"))) val responseTurtle: RdfModel = parseTurtle(responseAs[String]) assert(responseTurtle == expectedAnswerTurtle) } @@ -138,7 +138,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { .addHeader(Accept(RdfMediaTypes.`application/rdf+xml`)) ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerRdfXml: RdfModel = - parseRdfXml(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesList.rdf"))) + parseRdfXml(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesList.rdf"))) val responseRdfXml: RdfModel = parseRdfXml(responseAs[String]) assert(responseRdfXml == expectedAnswerRdfXml) } @@ -148,7 +148,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { Get(s"/v2/node/${URLEncoder.encode("http://rdfh.ch/lists/00FF/4348fb82f2", "UTF-8")}") ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD: JsValue = - JsonParser(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesListNode.jsonld"))) + JsonParser(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesListNode.jsonld"))) val responseJson: JsValue = JsonParser(responseAs[String]) assert(responseJson == expectedAnswerJSONLD) } @@ -159,7 +159,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { val responseStr = responseAs[String] assert(status == StatusCodes.OK, responseStr) val expectedAnswerJSONLD: JsValue = - JsonParser(FileUtil.readTextFile(new File("test_data/listsR2RV2/treelistnode.jsonld"))) + JsonParser(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/treelistnode.jsonld"))) val responseJson: JsValue = JsonParser(responseStr) assert(responseJson == expectedAnswerJSONLD) @@ -181,7 +181,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { .addHeader(Accept(RdfMediaTypes.`text/turtle`)) ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerTurtle: RdfModel = - parseTurtle(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesListNode.ttl"))) + parseTurtle(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesListNode.ttl"))) val responseTurtle: RdfModel = parseTurtle(responseAs[String]) assert(responseTurtle == expectedAnswerTurtle) } @@ -192,7 +192,7 @@ class ListsRouteV2R2RSpec extends R2RSpec { .addHeader(Accept(RdfMediaTypes.`application/rdf+xml`)) ~> listsPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerRdfXml: RdfModel = - parseRdfXml(FileUtil.readTextFile(new File("test_data/listsR2RV2/imagesListNode.rdf"))) + parseRdfXml(FileUtil.readTextFile(Paths.get("test_data/listsR2RV2/imagesListNode.rdf"))) val responseRdfXml: RdfModel = parseRdfXml(responseAs[String]) assert(responseRdfXml == expectedAnswerRdfXml) } diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/MetadataRouteV2E2ESpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/MetadataRouteV2E2ESpec.scala index 128ddc2fe2..2adf718664 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/MetadataRouteV2E2ESpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/MetadataRouteV2E2ESpec.scala @@ -1,7 +1,7 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import akka.http.scaladsl.model.headers.{BasicHttpCredentials, RawHeader} import akka.http.scaladsl.model.{HttpEntity, HttpResponse} @@ -19,9 +19,9 @@ class MetadataRouteV2E2ESpec extends E2ESpec { private val beolProjectIRI: IRI = SharedTestDataADM.BEOL_PROJECT_IRI private val password = SharedTestDataADM.testPass - private val metadataAsTurtle: String = FileUtil.readTextFile(new File("test_data/metadataE2EV2/metadata.ttl")) + private val metadataAsTurtle: String = FileUtil.readTextFile(Paths.get("test_data/metadataE2EV2/metadata.ttl")) private val metadataAsFlatJsonLD: String = - FileUtil.readTextFile(new File("test_data/metadataE2EV2/metadata-flat.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/metadataE2EV2/metadata-flat.jsonld")) private val expectedRdfModel: RdfModel = rdfFormatUtil.parseToRdfModel( rdfStr = metadataAsTurtle, diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala index 266bbf339b..1edbda620f 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala @@ -1,6 +1,7 @@ package org.knora.webapi.e2e.v2 -import java.io.File +import java.nio.file.{Path, Paths, Files} + import java.net.URLEncoder import java.time.Instant @@ -84,9 +85,9 @@ class OntologyV2R2RSpec extends R2RSpec { fileBasename: String, maybeClientTestDataBasename: Option[String] = None, disableWrite: Boolean = false) { - def makeFile(mediaType: MediaType.NonBinary): File = { + def makeFile(mediaType: MediaType.NonBinary): Path = { val fileSuffix = mediaType.fileExtensions.head - new File(s"test_data/ontologyR2RV2/$fileBasename.$fileSuffix") + Paths.get(s"test_data/ontologyR2RV2/$fileBasename.$fileSuffix") } /** @@ -99,10 +100,10 @@ class OntologyV2R2RSpec extends R2RSpec { if (!disableWrite) { // Per default only read access is allowed in the bazel sandbox. // This workaround allows to save test output. - val testOutputDir = sys.env("TEST_UNDECLARED_OUTPUTS_DIR") + val testOutputDir = Paths.get(sys.env("TEST_UNDECLARED_OUTPUTS_DIR")) val file = makeFile(mediaType) - val newOutputFile = new File(testOutputDir, file.getPath) - newOutputFile.getParentFile.mkdirs() + val newOutputFile = testOutputDir.resolve(file) + Files.createDirectories(newOutputFile.getParent) FileUtil.writeTextFile(newOutputFile, responseStr) } } @@ -342,9 +343,9 @@ class OntologyV2R2RSpec extends R2RSpec { mediaType match { case RdfMediaTypes.`application/rdf+xml` => - val existingFile: File = httpGetTest.makeFile(mediaType) + val existingFile: Path = httpGetTest.makeFile(mediaType) - if (existingFile.exists()) { + if (Files.exists(existingFile)) { val parsedResponse: RdfModel = parseRdfXml(responseStr) val parsedExistingFile: RdfModel = parseRdfXml(httpGetTest.readFile(mediaType)) diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResourcesRouteV2E2ESpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResourcesRouteV2E2ESpec.scala index b2c4e2d734..a93c7c0190 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResourcesRouteV2E2ESpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResourcesRouteV2E2ESpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import java.time.Instant import akka.actor.ActorSystem @@ -99,7 +99,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -125,7 +125,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerTurtle = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl"), writeTestDataFiles) assert(parseTurtle(responseAsString) == parseTurtle(expectedAnswerTurtle)) } @@ -137,7 +137,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerRdfXml = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.rdf"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.rdf"), writeTestDataFiles) assert(parseRdfXml(responseAsString) == parseRdfXml(expectedAnswerRdfXml)) } @@ -150,7 +150,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandPreview.jsonld"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandPreview.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -161,7 +161,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = - readOrWriteTextFile(responseAsString, new File("test_data/resourcesR2RV2/AThing.jsonld"), writeTestDataFiles) + readOrWriteTextFile(responseAsString, Paths.get("test_data/resourcesR2RV2/AThing.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) clientTestDataCollector.addFile( @@ -184,7 +184,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -205,7 +205,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerTurtle = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.ttl"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.ttl"), writeTestDataFiles) assert(parseTurtle(responseAsString) == parseTurtle(expectedAnswerTurtle)) } @@ -219,7 +219,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerRdfXml = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.rdf"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.rdf"), writeTestDataFiles) assert(parseRdfXml(responseAsString) == parseRdfXml(expectedAnswerRdfXml)) } @@ -233,7 +233,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimplePreview.jsonld"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimplePreview.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -246,7 +246,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld"), + Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -257,7 +257,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), + Paths.get("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -269,7 +269,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithBCEDate.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithBCEDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -288,7 +288,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithBCEDate2.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithBCEDate2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -307,7 +307,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithListValue.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithListValue.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -328,7 +328,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithListValueSimple.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithListValueSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -347,7 +347,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -367,7 +367,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithLinkSimple.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithLinkSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -387,7 +387,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithTextLangComplex.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithTextLangComplex.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -408,7 +408,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithTextLangSimple.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithTextLangSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -427,7 +427,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = - readOrWriteTextFile(responseAsString, new File("test_data/resourcesR2RV2/Testding.jsonld"), writeTestDataFiles) + readOrWriteTextFile(responseAsString, Paths.get("test_data/resourcesR2RV2/Testding.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) clientTestDataCollector.addFile( @@ -456,7 +456,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithPicture.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithPicture.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -488,7 +488,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithOneHiddenResource.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithOneHiddenResource.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -509,7 +509,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithOneDeletedResource.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithOneDeletedResource.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) @@ -530,7 +530,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithVersionHistory.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithVersionHistory.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -544,7 +544,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingWithVersionHistory.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingWithVersionHistory.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -555,9 +555,10 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val response: HttpResponse = singleAwaitingRequest(request) val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/CompleteVersionHistory.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAsString, + Paths.get("test_data/resourcesR2RV2/CompleteVersionHistory.jsonld"), + writeTestDataFiles) compareJSONLDForResourceHistoryResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -570,7 +571,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/PartialVersionHistory.jsonld"), + Paths.get("test_data/resourcesR2RV2/PartialVersionHistory.jsonld"), writeTestDataFiles) compareJSONLDForResourceHistoryResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -600,7 +601,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { assert(versionResponse.status == StatusCodes.OK, versionResponseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(versionResponseAsString, - new File(s"test_data/resourcesR2RV2/ThingWithVersionHistory$arkTimestamp.jsonld"), + Paths.get(s"test_data/resourcesR2RV2/ThingWithVersionHistory$arkTimestamp.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = versionResponseAsString) @@ -631,7 +632,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val parsedReceivedJsonLD = JsonLDUtil.parseJsonLD(responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingGraphBoth.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingGraphBoth.jsonld"), writeTestDataFiles) val parsedExpectedJsonLD = JsonLDUtil.parseJsonLD(expectedAnswerJSONLD) @@ -647,7 +648,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val parsedReceivedJsonLD = JsonLDUtil.parseJsonLD(responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingGraphOutbound.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingGraphOutbound.jsonld"), writeTestDataFiles) val parsedExpectedJsonLD = JsonLDUtil.parseJsonLD(expectedAnswerJSONLD) @@ -663,7 +664,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val parsedReceivedJsonLD = JsonLDUtil.parseJsonLD(responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingGraphInbound.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingGraphInbound.jsonld"), writeTestDataFiles) val parsedExpectedJsonLD = JsonLDUtil.parseJsonLD(expectedAnswerJSONLD) @@ -681,7 +682,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingGraphBothWithExcludedProp.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingGraphBothWithExcludedProp.jsonld"), writeTestDataFiles) val parsedExpectedJsonLD = JsonLDUtil.parseJsonLD(expectedAnswerJSONLD) @@ -698,7 +699,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/ThingGraphBothWithDepth.jsonld"), + Paths.get("test_data/resourcesR2RV2/ThingGraphBothWithDepth.jsonld"), writeTestDataFiles) val parsedExpectedJsonLD = JsonLDUtil.parseJsonLD(expectedAnswerJSONLD) @@ -747,7 +748,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { val responseAsString = responseToString(response) assert(response.status == StatusCodes.OK, responseAsString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAsString, - new File("test_data/resourcesR2RV2/BooksFromIncunabula.jsonld"), + Paths.get("test_data/resourcesR2RV2/BooksFromIncunabula.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAsString) } @@ -912,7 +913,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { "create a resource whose label contains a Unicode escape and quotation marks" in { val jsonLDEntity: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/ThingWithUnicodeEscape.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/ThingWithUnicodeEscape.jsonld")) val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials( BasicHttpCredentials(anythingUserEmail, password)) val response: HttpResponse = singleAwaitingRequest(request) @@ -1440,7 +1441,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { } "create a resource containing escaped text" in { - val jsonLDEntity = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/CreateResourceWithEscape.jsonld")) + val jsonLDEntity = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/CreateResourceWithEscape.jsonld")) val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials( BasicHttpCredentials(anythingUserEmail, password)) val response: HttpResponse = singleAwaitingRequest(request) @@ -1709,7 +1710,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { "create a resource with a large text containing a lot of markup (32849 words, 6738 standoff tags)" ignore { // uses too much memory for GitHub CI // Create a resource containing the text of Hamlet. - val hamletXml = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/hamlet.xml")) + val hamletXml = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/hamlet.xml")) val jsonLDEntity = s"""{ @@ -1750,7 +1751,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) { } "read the large text and its markup as XML, and check that it matches the original XML" ignore { // depends on previous test - val hamletXml = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/hamlet.xml")) + val hamletXml = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/hamlet.xml")) // Request the newly created resource. val resourceGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(hamletResourceIri.get, "UTF-8")}") ~> addCredentials( diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerV2Spec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerV2Spec.scala index ee87760405..486476d2d2 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerV2Spec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerV2Spec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.e2e.v2 -import java.io.File +import java.nio.file.Paths import org.knora.webapi.CoreSpec import org.knora.webapi.util.FileUtil @@ -31,7 +31,8 @@ class ResponseCheckerV2Spec extends CoreSpec() { "ResponseCheckerV2" should { "not throw an exception if received and expected resource responses are the same" in { - val expectedAnswerJSONLD = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld")) + val expectedAnswerJSONLD = + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld")) ResponseCheckerV2.compareJSONLDForResourcesResponse( expectedJSONLD = expectedAnswerJSONLD, @@ -41,7 +42,7 @@ class ResponseCheckerV2Spec extends CoreSpec() { "not throw an exception if received and expected mapping responses are the same" in { val expectedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) ResponseCheckerV2.compareJSONLDForMappingCreationResponse( expectedJSONLD = expectedAnswerJSONLD, @@ -50,8 +51,9 @@ class ResponseCheckerV2Spec extends CoreSpec() { } "throw an exception if received and expected resource responses are different" in { - val expectedAnswerJSONLD = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld")) - val receivedAnswerJSONLD = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/ThingWithListValue.jsonld")) + val expectedAnswerJSONLD = + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/ThingWithLinkComplex.jsonld")) + val receivedAnswerJSONLD = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/ThingWithListValue.jsonld")) assertThrows[AssertionError] { ResponseCheckerV2.compareJSONLDForResourcesResponse( @@ -63,9 +65,9 @@ class ResponseCheckerV2Spec extends CoreSpec() { "throw an exception if the values of the received and expected resource responses are different" in { val expectedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) val receivedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandPreview.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandPreview.jsonld")) assertThrows[AssertionError] { ResponseCheckerV2.compareJSONLDForResourcesResponse( @@ -77,10 +79,10 @@ class ResponseCheckerV2Spec extends CoreSpec() { "throw an exception if the number of values of the received and expected resource responses are different" in { val expectedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/NarrenschiffFirstPage.jsonld")) // number of StillImageFileValue is wrong val receivedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/responseCheckerR2RV2/NarrenschiffFirstPageWrong.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/responseCheckerR2RV2/NarrenschiffFirstPageWrong.jsonld")) assertThrows[AssertionError] { ResponseCheckerV2.compareJSONLDForResourcesResponse( @@ -92,9 +94,9 @@ class ResponseCheckerV2Spec extends CoreSpec() { "throw an exception if received and expected mapping responses are different" in { val expectedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) val receivedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/standoffR2RV2/mappingCreationResponseWithDifferentLabel.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/standoffR2RV2/mappingCreationResponseWithDifferentLabel.jsonld")) assertThrows[AssertionError] { ResponseCheckerV2.compareJSONLDForMappingCreationResponse( diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/SearchRouteV2R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/SearchRouteV2R2RSpec.scala index 802c825ecc..6f75bf8a82 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/SearchRouteV2R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/SearchRouteV2R2RSpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.javadsl.model.StatusCodes @@ -111,7 +111,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/NarrFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/NarrFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -140,7 +140,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/searchResponseWithHiddenResource.jsonld"), + Paths.get("test_data/searchR2RV2/searchResponseWithHiddenResource.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -154,7 +154,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File(s"test_data/searchR2RV2/DingeFulltextSearch.jsonld"), + Paths.get(s"test_data/searchR2RV2/DingeFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -170,7 +170,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File(s"test_data/searchR2RV2/DingeFulltextSearchSimple.jsonld"), + Paths.get(s"test_data/searchR2RV2/DingeFulltextSearchSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -194,7 +194,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingUniform.jsonld"), + Paths.get("test_data/searchR2RV2/ThingUniform.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -208,7 +208,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingUniform.jsonld"), + Paths.get("test_data/searchR2RV2/ThingUniform.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -267,7 +267,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, responseStr) val expectedAnswerJSONLD = readOrWriteTextFile(responseStr, - new File("test_data/searchR2RV2/thingWithOptionalDateSortedDesc.jsonld"), + Paths.get("test_data/searchR2RV2/thingWithOptionalDateSortedDesc.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -345,7 +345,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -386,7 +386,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -427,7 +427,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile( responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -469,7 +469,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile( responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -542,7 +542,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -582,7 +582,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), + Paths.get("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -669,7 +669,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -714,7 +714,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -761,7 +761,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), + Paths.get("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -806,7 +806,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -852,7 +852,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -934,7 +934,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -978,9 +978,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1026,9 +1027,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1075,7 +1077,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1123,7 +1125,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1169,9 +1171,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1218,7 +1221,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1267,7 +1270,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1326,7 +1329,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/RegionsForPage.jsonld"), + Paths.get("test_data/searchR2RV2/RegionsForPage.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1389,7 +1392,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1446,7 +1449,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1495,7 +1498,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), + Paths.get("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1568,7 +1571,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1610,7 +1613,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1651,9 +1654,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1691,7 +1695,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingWithURI.jsonld"), + Paths.get("test_data/searchR2RV2/thingWithURI.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1767,7 +1771,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBoolean.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBoolean.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1817,7 +1821,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOptionalOffset0.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOptionalOffset0.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1870,7 +1874,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1926,7 +1930,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -1971,7 +1975,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2015,7 +2019,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2059,7 +2063,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2103,7 +2107,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2144,7 +2148,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithListValue.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithListValue.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2187,7 +2191,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2227,7 +2231,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2240,7 +2244,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -2257,7 +2261,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2290,7 +2294,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2322,7 +2326,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2406,7 +2410,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), + Paths.get("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2461,7 +2465,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthor.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthor.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2573,7 +2577,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2693,7 +2697,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2743,7 +2747,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/foafPerson.jsonld"), + Paths.get("test_data/searchR2RV2/foafPerson.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2786,7 +2790,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), + Paths.get("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -2844,7 +2848,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2893,7 +2897,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/incomingPagesForBook.jsonld"), + Paths.get("test_data/searchR2RV2/incomingPagesForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -2993,9 +2997,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -3029,7 +3034,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ProjectsWithOptionalPersonOrBiblio.jsonld"), + Paths.get("test_data/searchR2RV2/ProjectsWithOptionalPersonOrBiblio.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3073,7 +3078,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3115,7 +3120,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3155,7 +3160,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3194,7 +3199,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3233,7 +3238,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3269,7 +3274,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithoutName.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithoutName.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3307,7 +3312,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/booksWithPage100.jsonld"), + Paths.get("test_data/searchR2RV2/booksWithPage100.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3347,7 +3352,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/lettersByMeier.jsonld"), + Paths.get("test_data/searchR2RV2/lettersByMeier.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3381,7 +3386,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3418,7 +3423,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3455,7 +3460,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile( responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3493,7 +3498,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile( responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswerSimple.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3558,7 +3563,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3594,7 +3599,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), + Paths.get("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3670,7 +3675,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3743,7 +3748,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3783,7 +3788,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), + Paths.get("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3821,7 +3826,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3860,7 +3865,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3930,7 +3935,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -3967,9 +3972,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4008,9 +4014,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4051,7 +4058,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4093,7 +4100,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4133,9 +4140,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4176,7 +4184,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4218,7 +4226,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4264,7 +4272,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/RegionsForPage.jsonld"), + Paths.get("test_data/searchR2RV2/RegionsForPage.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4314,7 +4322,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4358,7 +4366,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4398,7 +4406,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), + Paths.get("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4465,7 +4473,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4503,7 +4511,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4540,9 +4548,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), - writeFile = false) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), + writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4611,7 +4620,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBoolean.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBoolean.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4654,7 +4663,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4704,7 +4713,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4746,7 +4755,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4788,7 +4797,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4830,7 +4839,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4870,7 +4879,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4907,7 +4916,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithListValue.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithListValue.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4944,7 +4953,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -4978,7 +4987,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5016,7 +5025,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), + Paths.get("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5062,7 +5071,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthor.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthor.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5113,7 +5122,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5163,7 +5172,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5211,7 +5220,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/foafPerson.jsonld"), + Paths.get("test_data/searchR2RV2/foafPerson.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5249,7 +5258,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), + Paths.get("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -5293,7 +5302,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5335,7 +5344,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/incomingPagesForBook.jsonld"), + Paths.get("test_data/searchR2RV2/incomingPagesForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5416,9 +5425,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -5449,7 +5459,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ProjectsWithOptionalPersonOrBiblio.jsonld"), + Paths.get("test_data/searchR2RV2/ProjectsWithOptionalPersonOrBiblio.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5484,7 +5494,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithListNodeLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithListNodeLabel.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5563,7 +5573,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingWithOptionalDateSortedDesc.jsonld"), + Paths.get("test_data/searchR2RV2/thingWithOptionalDateSortedDesc.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5653,7 +5663,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingsWithOptionalDecimalGreaterThan1.jsonld"), + Paths.get("test_data/searchR2RV2/ThingsWithOptionalDecimalGreaterThan1.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5690,7 +5700,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/booksWithPage100.jsonld"), + Paths.get("test_data/searchR2RV2/booksWithPage100.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5730,7 +5740,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/lettersByMeier.jsonld"), + Paths.get("test_data/searchR2RV2/lettersByMeier.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5764,7 +5774,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchWithTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5829,7 +5839,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinExtendedSearchNoTitleInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5867,7 +5877,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), + Paths.get("test_data/searchR2RV2/NotZeitgloeckleinExtendedSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -5945,7 +5955,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10WithSeqnumAndLinkValueInAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6017,7 +6027,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), + Paths.get("test_data/searchR2RV2/PageWithSeqnum10OnlySeqnuminAnswer.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6059,7 +6069,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), + Paths.get("test_data/searchR2RV2/pagesOfLatinNarrenschiffWithSeqnumLowerEquals10.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6097,7 +6107,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnum.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6136,7 +6146,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), + Paths.get("test_data/searchR2RV2/PagesOfNarrenschiffOrderedBySeqnumNextOffset.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6175,7 +6185,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6213,9 +6223,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6255,9 +6266,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksNotPublishedOnDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6299,7 +6311,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6342,7 +6354,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedAfterOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6383,9 +6395,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/BooksPublishedAfterDate.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6427,7 +6440,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBeforeOrOnDate.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6470,7 +6483,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), + Paths.get("test_data/searchR2RV2/BooksPublishedBetweenDates.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6505,7 +6518,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/RegionsForPage.jsonld"), + Paths.get("test_data/searchR2RV2/RegionsForPage.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6555,7 +6568,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesWithAllRequestedProps.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6599,7 +6612,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), + Paths.get("test_data/searchR2RV2/bookWithIncomingPagesOnlyLink.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6638,7 +6651,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), + Paths.get("test_data/searchR2RV2/IncomingLinksForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6674,7 +6687,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6704,7 +6717,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { BasicHttpCredentials(anythingUserEmail, password)) ~> searchPath ~> check { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingEqualsDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) checkSearchResponseNumberOfResults(responseAs[String], 1) @@ -6740,7 +6753,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingBiggerThanDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6773,7 +6786,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD: String = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingSmallerThanDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6814,7 +6827,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD: String = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithLinkToStart.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithLinkToStart.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6851,7 +6864,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD: String = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/PageOfThings.jsonld"), + Paths.get("test_data/searchR2RV2/PageOfThings.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6897,7 +6910,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBoolean.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBoolean.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6946,7 +6959,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOptionalOffset1.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -6997,7 +7010,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithBooleanOrDecimal.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7041,7 +7054,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeit.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7083,7 +7096,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7125,7 +7138,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), + Paths.get("test_data/searchR2RV2/BooksWithTitleContainingZeitgloecklein.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7162,7 +7175,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithListValue.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithListValue.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7199,7 +7212,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7235,7 +7248,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), + Paths.get("test_data/searchR2RV2/LanguageFulltextSearch.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7273,7 +7286,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), + Paths.get("test_data/searchR2RV2/LinkObjectsToBooks.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7319,7 +7332,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthor.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthor.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7369,7 +7382,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7418,7 +7431,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithPersonWithName2.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7455,7 +7468,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), + Paths.get("test_data/searchR2RV2/ThingByIriWithRequestedValues.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7499,7 +7512,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithAuthorWithInformation.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7543,7 +7556,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/incomingPagesForBook.jsonld"), + Paths.get("test_data/searchR2RV2/incomingPagesForBook.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -7626,9 +7639,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/regionsOfZeitgloecklein.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7811,7 +7825,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingReferringToSpecificListNode.jsonld"), + Paths.get("test_data/searchR2RV2/thingReferringToSpecificListNode.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7847,7 +7861,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingNotReferringToSpecificListNode.jsonld"), + Paths.get("test_data/searchR2RV2/thingNotReferringToSpecificListNode.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7911,7 +7925,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingReferringToSpecificListNodeWithSubnodes.jsonld"), + Paths.get("test_data/searchR2RV2/thingReferringToSpecificListNodeWithSubnodes.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7944,7 +7958,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/letterWithSubject.jsonld"), + Paths.get("test_data/searchR2RV2/letterWithSubject.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -7975,9 +7989,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingsWithStandoffLinks.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/thingsWithStandoffLinks.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } } @@ -8008,9 +8023,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { assert(status == StatusCodes.OK, response.toString) - val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingsWithStandoffLinks.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(responseAs[String], + Paths.get("test_data/searchR2RV2/thingsWithStandoffLinks.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } } @@ -8042,7 +8058,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingsWithStandoffLinksToSpecificThing.jsonld"), + Paths.get("test_data/searchR2RV2/thingsWithStandoffLinksToSpecificThing.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -8076,7 +8092,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/thingsWithStandoffLinksToSpecificThing.jsonld"), + Paths.get("test_data/searchR2RV2/thingsWithStandoffLinksToSpecificThing.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) } @@ -8107,7 +8123,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val expectedAnswerJSONLD = readOrWriteTextFile(responseAs[String], - new File("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithRichtextWithTermTextInParagraph.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) @@ -8118,7 +8134,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { "search for a standoff date tag indicating a date in a particular range (submitting the complex schema)" in { // First, create a standoff-to-XML mapping that can handle standoff date tags. - val mappingFileToSend = new File("test_data/test_route/texts/mappingForHTML.xml") + val mappingFileToSend = Paths.get("test_data/test_route/texts/mappingForHTML.xml") val paramsCreateHTMLMappingFromXML = s""" @@ -8142,8 +8158,8 @@ class SearchRouteV2R2RSpec extends R2RSpec { ), Multipart.FormData.BodyPart( "xml", - HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend.toPath), - Map("filename" -> mappingFileToSend.getName) + HttpEntity.fromPath(ContentTypes.`text/xml(UTF-8)`, mappingFileToSend), + Map("filename" -> mappingFileToSend.getFileName.toString) ) ) @@ -8156,7 +8172,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { // Next, create a resource with a text value containing a standoff date tag. TODO: Use API v2. - val xmlFileToSend = new File("test_data/test_route/texts/HTML.xml") + val xmlFileToSend = Paths.get("test_data/test_route/texts/HTML.xml") val newValueParams = s""" @@ -8274,7 +8290,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { "create a resource with a large text containing a lot of markup (32849 words, 6738 standoff tags)" ignore { // uses too much memory for GitHub CI // Create a resource containing the text of Hamlet. - val hamletXml = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/hamlet.xml")) + val hamletXml = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/hamlet.xml")) val jsonLDEntity = s"""{ @@ -8313,7 +8329,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { } "search for the large text and its markup and receive it as XML, and check that it matches the original XML" ignore { // depends on previous test - val hamletXml = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/hamlet.xml")) + val hamletXml = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/hamlet.xml")) val gravsearchQuery = s"""PREFIX knora-api: @@ -8496,7 +8512,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ThingWithTimeStamp.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithTimeStamp.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8527,7 +8543,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ThingWithHiddenThing.jsonld"), + Paths.get("test_data/searchR2RV2/ThingWithHiddenThing.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8576,9 +8592,10 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) checkSearchResponseNumberOfResults(searchResponseStr, expectedCount) - val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ThingFromQueryWithUnion.jsonld"), - writeTestDataFiles) + val expectedAnswerJSONLD = + readOrWriteTextFile(searchResponseStr, + Paths.get("test_data/searchR2RV2/ThingFromQueryWithUnion.jsonld"), + writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } } @@ -8687,7 +8704,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8711,7 +8728,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8736,7 +8753,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8761,7 +8778,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8785,7 +8802,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8809,7 +8826,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8833,7 +8850,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8857,7 +8874,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), + Paths.get("test_data/searchR2RV2/ZeitgloeckleinViaLabel.jsonld"), writeFile = false) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8886,7 +8903,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = readOrWriteTextFile(searchResponseStr, - new File("test_data/searchR2RV2/LetterNotToSelf.jsonld"), + Paths.get("test_data/searchR2RV2/LetterNotToSelf.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } @@ -8915,7 +8932,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = - readOrWriteTextFile(searchResponseStr, new File("test_data/searchR2RV2/LetterNotToSelf.jsonld")) + readOrWriteTextFile(searchResponseStr, Paths.get("test_data/searchR2RV2/LetterNotToSelf.jsonld")) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } } @@ -8943,7 +8960,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = - readOrWriteTextFile(searchResponseStr, new File("test_data/searchR2RV2/LetterNotToSelf.jsonld")) + readOrWriteTextFile(searchResponseStr, Paths.get("test_data/searchR2RV2/LetterNotToSelf.jsonld")) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } } @@ -8971,7 +8988,7 @@ class SearchRouteV2R2RSpec extends R2RSpec { val searchResponseStr = responseAs[String] assert(status == StatusCodes.OK, searchResponseStr) val expectedAnswerJSONLD = - readOrWriteTextFile(searchResponseStr, new File("test_data/searchR2RV2/LetterNotToSelf.jsonld")) + readOrWriteTextFile(searchResponseStr, Paths.get("test_data/searchR2RV2/LetterNotToSelf.jsonld")) compareJSONLDForResourcesResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = searchResponseStr) } } diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/StandoffRouteV2R2RSpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/StandoffRouteV2R2RSpec.scala index a5f6c29fd0..20f0231a5a 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/StandoffRouteV2R2RSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/StandoffRouteV2R2RSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.e2e.v2 -import java.io.File +import java.nio.file.Paths import akka.actor.ActorSystem import akka.http.javadsl.model.StatusCodes @@ -89,7 +89,7 @@ class StandoffRouteV2R2RSpec extends R2RSpec { "create a mapping from a XML" in { - val xmlFileToSend = new File(RequestParams.pathToLetterMapping) + val xmlFileToSend = Paths.get(RequestParams.pathToLetterMapping) val mappingParams = s""" @@ -113,7 +113,7 @@ class StandoffRouteV2R2RSpec extends R2RSpec { ), Multipart.FormData.BodyPart( "xml", - HttpEntity.fromPath(MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`), xmlFileToSend.toPath), + HttpEntity.fromPath(MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`), xmlFileToSend), Map("filename" -> "brokenMapping.xml") ) ) @@ -125,7 +125,7 @@ class StandoffRouteV2R2RSpec extends R2RSpec { "creation of a mapping returned a non successful HTTP status code: " + responseAs[String]) val expectedAnswerJSONLD = - FileUtil.readTextFile(new File("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/standoffR2RV2/mappingCreationResponse.jsonld")) compareJSONLDForMappingCreationResponse(expectedJSONLD = expectedAnswerJSONLD, receivedJSONLD = responseAs[String]) diff --git a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesRouteV2E2ESpec.scala b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesRouteV2E2ESpec.scala index 6f2eb8f8a0..bffa6eb072 100644 --- a/webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesRouteV2E2ESpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/e2e/v2/ValuesRouteV2E2ESpec.scala @@ -19,8 +19,8 @@ package org.knora.webapi.e2e.v2 -import java.io.File import java.net.URLEncoder +import java.nio.file.Paths import java.time.Instant import java.util.UUID @@ -668,7 +668,7 @@ class ValuesRouteV2E2ESpec extends E2ESpec { val responseStr = responseToString(response) assert(response.status == StatusCodes.OK, responseStr) val expectedResponseStr = - readOrWriteTextFile(responseStr, new File(s"test_data/valuesE2EV2/$fileBasename.jsonld"), writeTestDataFiles) + readOrWriteTextFile(responseStr, Paths.get(s"test_data/valuesE2EV2/$fileBasename.jsonld"), writeTestDataFiles) compareJSONLDForResourcesResponse(expectedJSONLD = expectedResponseStr, receivedJSONLD = responseStr) clientTestDataCollector.addFile( @@ -1980,7 +1980,7 @@ class ValuesRouteV2E2ESpec extends E2ESpec { "create a text value with standoff containing escaped text" in { val resourceIri = AThing.iri val maybeResourceLastModDate: Option[Instant] = getResourceLastModificationDate(resourceIri, anythingUserEmail) - val jsonLDEntity = FileUtil.readTextFile(new File("test_data/valuesE2EV2/CreateValueWithEscape.jsonld")) + val jsonLDEntity = FileUtil.readTextFile(Paths.get("test_data/valuesE2EV2/CreateValueWithEscape.jsonld")) val request = Post(baseApiUrl + "/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials( BasicHttpCredentials(anythingUserEmail, password)) val response: HttpResponse = singleAwaitingRequest(request) @@ -2012,7 +2012,7 @@ class ValuesRouteV2E2ESpec extends E2ESpec { "create a TextValue from XML representing HTML with an attribute containing escaped quotes" in { // Create the mapping. - val xmlFileToSend = new File("test_data/test_route/texts/mappingForHTML.xml") + val xmlFileToSend = Paths.get("test_data/test_route/texts/mappingForHTML.xml") val mappingParams = s"""{ @@ -2034,7 +2034,7 @@ class ValuesRouteV2E2ESpec extends E2ESpec { ), Multipart.FormData.BodyPart( "xml", - HttpEntity.fromPath(MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`), xmlFileToSend.toPath), + HttpEntity.fromPath(MediaTypes.`text/xml`.toContentType(HttpCharsets.`UTF-8`), xmlFileToSend), Map("filename" -> "HTMLMapping.xml") ) ) @@ -3809,7 +3809,7 @@ class ValuesRouteV2E2ESpec extends E2ESpec { "update a text value with standoff containing escaped text" in { val resourceIri = AThing.iri val maybeResourceLastModDate: Option[Instant] = getResourceLastModificationDate(resourceIri, anythingUserEmail) - val jsonLDEntity = FileUtil.readTextFile(new File("test_data/valuesE2EV2/UpdateValueWithEscape.jsonld")) + val jsonLDEntity = FileUtil.readTextFile(Paths.get("test_data/valuesE2EV2/UpdateValueWithEscape.jsonld")) val jsonLDEntityWithResourceValueIri = jsonLDEntity.replace("VALUE_IRI", textValueWithEscapeIri.get) val request = Put( baseApiUrl + "/v2/values", diff --git a/webapi/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2Spec.scala b/webapi/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2Spec.scala index ae19dd22f1..ec77e1c818 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2Spec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2Spec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.util -import java.io.File +import java.nio.file.Paths import akka.testkit.ImplicitSender import akka.util.Timeout @@ -52,7 +52,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response into a resource" in { val resourceIri: IRI = "http://rdfh.ch/0803/c5058f3a" - val turtleStr: String = FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/Zeitglocklein.ttl")) + val turtleStr: String = FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/Zeitglocklein.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -87,7 +87,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response with hidden values into a resource with the anything admin user" in { val resourceIri: IRI = "http://rdfh.ch/0001/F8L7zPp7TI-4MGJQlCO4Zg" val turtleStr: String = - FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/visibleThingWithHiddenIntValues.ttl")) + FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/visibleThingWithHiddenIntValues.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -123,7 +123,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response with hidden values into a resource with the incunabula user" in { val resourceIri: IRI = "http://rdfh.ch/0001/F8L7zPp7TI-4MGJQlCO4Zg" val turtleStr: String = - FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/visibleThingWithHiddenIntValues.ttl")) + FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/visibleThingWithHiddenIntValues.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -159,7 +159,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response with a hidden thing into a resource with the anything admin user" in { val resourceIri: IRI = "http://rdfh.ch/0001/0JhgKcqoRIeRRG6ownArSw" val turtleStr: String = - FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/thingWithOneHiddenThing.ttl")) + FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/thingWithOneHiddenThing.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -195,7 +195,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response with a hidden thing into a resource with an unknown user" in { val resourceIri: IRI = "http://rdfh.ch/0001/0JhgKcqoRIeRRG6ownArSw" val turtleStr: String = - FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/thingWithOneHiddenThing.ttl")) + FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/thingWithOneHiddenThing.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -230,7 +230,8 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { "convert a resource Turtle response with standoff into a resource with anything admin user" in { val resourceIri: IRI = "http://rdfh.ch/0001/a-thing-with-text-values" - val turtleStr: String = FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/thingWithStandoff.ttl")) + val turtleStr: String = + FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/thingWithStandoff.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -296,7 +297,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { */ val resourceIris: Seq[IRI] = Seq("http://rdfh.ch/0803/76570a749901", "http://rdfh.ch/0803/773f258402") - val turtleStr: String = FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/mainQuery1.ttl")) + val turtleStr: String = FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/mainQuery1.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = @@ -363,7 +364,7 @@ class ConstructResponseUtilV2Spec extends CoreSpec() with ImplicitSender { */ val resourceIris: Seq[IRI] = Seq("http://rdfh.ch/0803/c5058f3a", "http://rdfh.ch/0803/ff17e5ef9601") - val turtleStr: String = FileUtil.readTextFile(new File("test_data/constructResponseUtilV2/mainQuery2.ttl")) + val turtleStr: String = FileUtil.readTextFile(Paths.get("test_data/constructResponseUtilV2/mainQuery2.ttl")) val resourceRequestResponse: SparqlExtendedConstructResponse = SparqlExtendedConstructResponse.parseTurtleResponse(turtleStr, rdfFormatUtil, log).get val mainResourcesAndValueRdfData: ConstructResponseUtilV2.MainResourcesAndValueRdfData = diff --git a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/JsonLDUtilSpec.scala b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/JsonLDUtilSpec.scala index d7fb1846d8..e56d720916 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/JsonLDUtilSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/JsonLDUtilSpec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.util.rdf -import java.io.File +import java.nio.file.Paths import org.knora.webapi.CoreSpec import org.knora.webapi.feature._ @@ -127,7 +127,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { "convert JSON-LD representing an ontology to an RDF4J Model" in { // Read a JSON-LD file. val inputJsonLD: String = - FileUtil.readTextFile(new File("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.jsonld")) // Parse it to a JsonLDDocument. val jsonLDDocument: JsonLDDocument = JsonLDUtil.parseJsonLD(inputJsonLD) @@ -137,7 +137,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { // Read an isomorphic Turtle file. val expectedTurtle: String = - FileUtil.readTextFile(new File("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl")) + FileUtil.readTextFile(Paths.get("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl")) // Parse the Turtle to an RDF4J Model. val expectedModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = expectedTurtle, rdfFormat = Turtle) @@ -148,7 +148,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { "convert an RDF4J Model representing an ontology to JSON-LD" in { // Read a Turtle file. - val turtle = FileUtil.readTextFile(new File("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl")) + val turtle = FileUtil.readTextFile(Paths.get("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl")) // Parse it to an RDF4J Model. val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = turtle, rdfFormat = Turtle) @@ -164,7 +164,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { // Read an isomorphic JSON-LD file. val expectedJsonLD = - FileUtil.readTextFile(new File("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/ontologyR2RV2/anythingOntologyWithValueObjects.jsonld")) // Parse it to an RDF4J Model. val jsonLDExpectedModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = expectedJsonLD, rdfFormat = JsonLD) @@ -176,7 +176,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { "convert JSON-LD representing a resource to an RDF4J Model" in { // Read a JSON-LD file. val inputJsonLD: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) // Parse it to a JsonLDDocument. val jsonLDDocument: JsonLDDocument = JsonLDUtil.parseJsonLD(inputJsonLD) @@ -191,7 +191,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { outputModelAsJsonLDDocument should ===(jsonLDDocument) // Read an isomorphic Turtle file. - val expectedTurtle = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + val expectedTurtle = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) // Parse it to an RDF4J Model. val expectedModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = expectedTurtle, rdfFormat = Turtle) @@ -202,7 +202,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { "convert an RDF4J Model representing a resource to JSON-LD" in { // Read a Turtle file. - val turtle = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + val turtle = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) // Parse it to an RDF4J Model. val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = turtle, rdfFormat = Turtle) @@ -217,7 +217,7 @@ abstract class JsonLDUtilSpec(featureToggle: FeatureToggle) extends CoreSpec { jsonLDOutputModel should ===(inputModel) // Read an isomorphic JSON-LD file. - val expectedJsonLD = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + val expectedJsonLD = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) // Parse it to a JsonLDDocument and compare it with the generated one. val expectedJsonLDDocument: JsonLDDocument = JsonLDUtil.parseJsonLD(expectedJsonLD) diff --git a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/KnoraResponseV2Spec.scala b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/KnoraResponseV2Spec.scala index fe0f452c82..2301da04b6 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/KnoraResponseV2Spec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/KnoraResponseV2Spec.scala @@ -19,7 +19,7 @@ package org.knora.webapi.util.rdf -import java.io.File +import java.nio.file.Paths import org.knora.webapi._ import org.knora.webapi.feature._ @@ -123,7 +123,7 @@ abstract class KnoraResponseV2Spec(featureToggle: FeatureToggle) extends CoreSpe "KnoraResponseV2" should { "convert Turtle to JSON-LD" in { // Read a Turtle file representing a resource. TODO: Use sample project metadata for this test. - val turtle: String = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + val turtle: String = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) // Wrap it in a KnoraTurtleResponseV2. val turtleTestResponse = TurtleTestResponse(turtle) @@ -142,7 +142,7 @@ abstract class KnoraResponseV2Spec(featureToggle: FeatureToggle) extends CoreSpe // Read an isomorphic JSON-LD file and parse it to a JsonLDDocument. val expectedJsonLD: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) val parsedExpectedJsonLD: JsonLDDocument = JsonLDUtil.parseJsonLD(expectedJsonLD) // Compare the two documents. @@ -151,7 +151,7 @@ abstract class KnoraResponseV2Spec(featureToggle: FeatureToggle) extends CoreSpe "convert JSON-LD to Turtle" in { // Read a JSON-LD file representing a resource. - val jsonLD: String = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + val jsonLD: String = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) // Wrap it in a KnoraJsonLDResponseV2. val jsonLDTestResponse = JsonLDTestResponse(JsonLDUtil.parseJsonLD(jsonLD)) @@ -170,7 +170,7 @@ abstract class KnoraResponseV2Spec(featureToggle: FeatureToggle) extends CoreSpe // Read an isomorphic Turtle file and parse it to an RDF4J Model. val expectedTurtle: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) val parsedExpectedTurtle: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = expectedTurtle, rdfFormat = Turtle) // Compare the two models. diff --git a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtilSpec.scala b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtilSpec.scala index beaf639646..b0b4e78caa 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtilSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/util/rdf/RdfFormatUtilSpec.scala @@ -19,15 +19,10 @@ package org.knora.webapi.util.rdf -import java.io._ -import java.nio.file.Files - -import org.knora.webapi.feature.{ - FeatureFactoryConfig, - FeatureToggle, - KnoraSettingsFeatureFactoryConfig, - TestFeatureFactoryConfig -} +import java.io.{BufferedInputStream, ByteArrayInputStream, ByteArrayOutputStream} +import java.nio.file.{Files, Path, Paths} + +import org.knora.webapi.feature._ import org.knora.webapi.messages.OntologyConstants import org.knora.webapi.messages.util.rdf._ import org.knora.webapi.util.FileUtil @@ -109,7 +104,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "RdfFormatUtil" should { "parse RDF in Turtle format, producing an RdfModel, then format it as Turtle again" in { - val inputTurtle: String = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + val inputTurtle: String = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputTurtle, rdfFormat = Turtle) checkModelForRdfTypeBook(inputModel) @@ -121,7 +116,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "parse RDF in JSON-LD format, producing an RdfModel, then format it as JSON-LD again" in { val inputTurtle: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputTurtle, rdfFormat = JsonLD) checkModelForRdfTypeBook(inputModel) @@ -132,7 +127,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec } "parse RDF in Turtle format, producing a JsonLDDocument, then format it as Turtle again" in { - val inputTurtle: String = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) + val inputTurtle: String = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputTurtle, rdfFormat = Turtle) val inputJsonLDDocument: JsonLDDocument = rdfFormatUtil.parseToJsonLDDocument(rdfStr = inputTurtle, rdfFormat = Turtle) @@ -149,7 +144,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec } "parse RDF in RDF/XML format, producing a JsonLDDocument, then format it as RDF/XML again" in { - val inputRdfXml: String = FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.rdf")) + val inputRdfXml: String = FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.rdf")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputRdfXml, rdfFormat = RdfXml) val inputJsonLDDocument: JsonLDDocument = rdfFormatUtil.parseToJsonLDDocument(rdfStr = inputRdfXml, rdfFormat = RdfXml) @@ -167,14 +162,14 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "parse RDF in TriG format" in { val graphIri = "http://example.org/data#" - val inputTrig = FileUtil.readTextFile(new File("test_data/rdfFormatUtil/BookReiseInsHeiligeLand.trig")) + val inputTrig = FileUtil.readTextFile(Paths.get("test_data/rdfFormatUtil/BookReiseInsHeiligeLand.trig")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputTrig, rdfFormat = TriG) checkModelForRdfTypeBook(rdfModel = inputModel, context = Some(graphIri)) } "parse RDF in N-Quads format" in { val graphIri = "http://example.org/data#" - val inputTrig = FileUtil.readTextFile(new File("test_data/rdfFormatUtil/BookReiseInsHeiligeLand.nq")) + val inputTrig = FileUtil.readTextFile(Paths.get("test_data/rdfFormatUtil/BookReiseInsHeiligeLand.nq")) val inputModel: RdfModel = rdfFormatUtil.parseToRdfModel(rdfStr = inputTrig, rdfFormat = NQuads) checkModelForRdfTypeBook(rdfModel = inputModel, context = Some(graphIri)) } @@ -182,8 +177,9 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "read Turtle, add a graph IRI to it, write it to a TriG file, and read back the TriG file" in { val graphIri = "http://example.org/data#" val rdfSource = RdfInputStreamSource( - new BufferedInputStream(new FileInputStream(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")))) - val outputFile: File = Files.createTempFile("test", ".trig").toFile + new BufferedInputStream( + Files.newInputStream(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")))) + val outputFile: Path = Files.createTempFile("test", ".trig") rdfFormatUtil.turtleToQuadsFile( rdfSource = rdfSource, @@ -199,8 +195,9 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "read Turtle, add a graph IRI to it, write it to an N-Quads file, and read back the N-Quads file" in { val graphIri = "http://example.org/data#" val rdfSource = RdfInputStreamSource( - new BufferedInputStream(new FileInputStream(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")))) - val outputFile: File = Files.createTempFile("test", ".trig").toFile + new BufferedInputStream( + Files.newInputStream(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.ttl")))) + val outputFile: Path = Files.createTempFile("test", ".trig") rdfFormatUtil.turtleToQuadsFile( rdfSource = rdfSource, @@ -215,7 +212,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "parse RDF in JSON-LD format, producing a JsonLDDocument, then format it as JSON-LD again" in { val inputTurtle: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLand.jsonld")) val inputJsonLDDocument: JsonLDDocument = rdfFormatUtil.parseToJsonLDDocument(rdfStr = inputTurtle, rdfFormat = JsonLD) checkJsonLDDocumentForRdfTypeBook(inputJsonLDDocument) @@ -229,7 +226,7 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec "use prefixes and custom datatypes" in { val inputJsonLD: String = - FileUtil.readTextFile(new File("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld")) + FileUtil.readTextFile(Paths.get("test_data/resourcesR2RV2/BookReiseInsHeiligeLandSimple.jsonld")) val inputJsonLDDocument: JsonLDDocument = JsonLDUtil.parseJsonLD(inputJsonLD) val outputModel: RdfModel = inputJsonLDDocument.toRdfModel(rdfModelFactory) @@ -252,7 +249,8 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec } "parse RDF from a stream and process it using an RdfStreamProcessor" in { - val inputStream = new BufferedInputStream(new FileInputStream("test_data/ontologies/anything-onto.ttl")) + val inputStream = + new BufferedInputStream(Files.newInputStream(Paths.get("test_data/ontologies/anything-onto.ttl"))) val testStreamProcessor = new TestStreamProcessor rdfFormatUtil.parseWithStreamProcessor( @@ -268,7 +266,8 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec // Read the file, process it with an RdfStreamProcessor, and write the result // to a ByteArrayOutputStream. - val fileInputStream = new BufferedInputStream(new FileInputStream("test_data/ontologies/anything-onto.ttl")) + val fileInputStream = + new BufferedInputStream(Files.newInputStream(Paths.get("test_data/ontologies/anything-onto.ttl"))) val byteArrayOutputStream = new ByteArrayOutputStream() val formattingStreamProcessor = rdfFormatUtil.makeFormattingStreamProcessor( @@ -299,7 +298,8 @@ abstract class RdfFormatUtilSpec(featureToggle: FeatureToggle) extends CoreSpec } "stream RDF data from an InputStream into an RdfModel, then into an OutputStream, then back into an RdfModel" in { - val fileInputStream = new BufferedInputStream(new FileInputStream("test_data/ontologies/anything-onto.ttl")) + val fileInputStream = + new BufferedInputStream(Files.newInputStream(Paths.get("test_data/ontologies/anything-onto.ttl"))) val rdfModel: RdfModel = rdfFormatUtil.inputStreamToRdfModel(inputStream = fileInputStream, rdfFormat = Turtle) fileInputStream.close() assert(rdfModel.contains(expectedThingLabelStatement)) diff --git a/webapi/src/test/scala/org/knora/webapi/messages/util/standoff/XMLUtilSpec.scala b/webapi/src/test/scala/org/knora/webapi/messages/util/standoff/XMLUtilSpec.scala index f2dc95b59f..22e49ee878 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/util/standoff/XMLUtilSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/util/standoff/XMLUtilSpec.scala @@ -19,17 +19,17 @@ package org.knora.webapi.util.standoff -import java.io.File +import java.nio.file.Paths import org.knora.webapi.CoreSpec import org.knora.webapi.exceptions.StandoffConversionException -import org.knora.webapi.messages.util.standoff.{XMLToStandoffUtil, XMLUtil} +import org.knora.webapi.messages.util.standoff.XMLUtil import org.knora.webapi.util.FileUtil import org.xmlunit.builder.{DiffBuilder, Input} import org.xmlunit.diff.Diff /** - * Tests [[XMLToStandoffUtil]]. + * Tests [[org.knora.webapi.messages.util.standoff.XMLToStandoffUtil]]. */ class XMLUtilSpec extends CoreSpec { @@ -91,17 +91,17 @@ class XMLUtilSpec extends CoreSpec { """.stripMargin assertThrows[StandoffConversionException] { - val transformed: String = XMLUtil.applyXSLTransformation(xml, xsltInvalid) + val _: String = XMLUtil.applyXSLTransformation(xml, xsltInvalid) } } "demonstrate how to handle resources that may or may not be embedded" in { val xmlWithNestedResource = - FileUtil.readTextFile(new File("test_data/test_route/texts/beol/xml-with-nested-resources.xml")) + FileUtil.readTextFile(Paths.get("test_data/test_route/texts/beol/xml-with-nested-resources.xml")) val xmlWithNonNestedResource = - FileUtil.readTextFile(new File("test_data/test_route/texts/beol/xml-with-non-nested-resources.xml")) - val xslt = FileUtil.readTextFile(new File("test_data/test_route/texts/beol/header.xsl")) + FileUtil.readTextFile(Paths.get("test_data/test_route/texts/beol/xml-with-non-nested-resources.xml")) + val xslt = FileUtil.readTextFile(Paths.get("test_data/test_route/texts/beol/header.xsl")) val transformedXmlWithNestedResource: String = XMLUtil.applyXSLTransformation(xmlWithNestedResource, xslt) val transformedXmlWithNonNestedResource: String = XMLUtil.applyXSLTransformation(xmlWithNonNestedResource, xslt) diff --git a/webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1SpecContextData.scala b/webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1SpecContextData.scala index 09c722960b..473124667a 100644 --- a/webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1SpecContextData.scala +++ b/webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1SpecContextData.scala @@ -19,7 +19,7 @@ package org.knora.webapi.responders.v1 -import java.io.File +import java.nio.file.Paths import akka.actor.ActorSystem import org.knora.webapi.messages.v1.responder.resourcemessages._ @@ -42,7 +42,7 @@ object ResourcesResponderV1SpecContextData { */ private val expectedBookResourceContextResponseStr = FileUtil .readTextFile( - new File("test_data/v1/expectedBookContextResponse.json") + Paths.get("test_data/v1/expectedBookContextResponse.json") ) .replaceAll("IIIF_BASE_URL", settings.externalSipiIIIFGetUrl)