From bb521349bb9fbc21cb62b8854a729040217f72b7 Mon Sep 17 00:00:00 2001 From: Raitis Veinbahs Date: Thu, 7 Nov 2024 14:55:11 +0100 Subject: [PATCH] refactor.spec.kind --- .../knora/webapi/e2e/v2/ValuesV2R2RSpec.scala | 83 ++++++++----------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/integration/src/test/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala b/integration/src/test/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala index 15cc3dc5c22..dab3bc0a711 100644 --- a/integration/src/test/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/e2e/v2/ValuesV2R2RSpec.scala @@ -8,8 +8,6 @@ package org.knora.webapi.e2e.v2 import org.apache.pekko.http.scaladsl.model.HttpEntity import org.apache.pekko.http.scaladsl.model.StatusCodes import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials -import org.apache.pekko.http.scaladsl.server.RouteConcatenation.* -import zio.ZIO import scala.concurrent.ExecutionContextExecutor @@ -19,29 +17,23 @@ import dsp.valueobjects.Iri import org.knora.webapi.* import org.knora.webapi.messages.IriConversions.* import org.knora.webapi.messages.OntologyConstants +import org.knora.webapi.messages.OntologyConstants.{KnoraApiV2Complex => OntConsts} import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject import org.knora.webapi.messages.util.rdf.* import org.knora.webapi.messages.util.search.SparqlQueryConstants -import org.knora.webapi.routing.UnsafeZioRun -import org.knora.webapi.routing.v2.ValuesRouteV2 import org.knora.webapi.sharedtestdata.SharedTestDataADM -import org.knora.webapi.slice.search.api.SearchApiRoutes import org.knora.webapi.util.MutableTestIri +import org.apache.pekko.http.scaladsl.model.HttpResponse /** * Tests creating a still image file value using a mock Sipi. */ -class ValuesV2R2RSpec extends R2RSpec { +class ValuesV2R2RSpec extends E2ESpec { private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance - private val valuesPath = ValuesRouteV2().makeRoute - private val searchPath = UnsafeZioRun - .runOrThrow(ZIO.serviceWith[SearchApiRoutes](_.routes)) - .reduce(_ ~ _) - implicit val ec: ExecutionContextExecutor = system.dispatcher private val aThingPictureIri = "http://rdfh.ch/0001/a-thing-picture" @@ -70,14 +62,14 @@ class ValuesV2R2RSpec extends R2RSpec { .getResourceWithSpecifiedProperties(resourceIri, propertyIrisForGravsearch) .toString() - // Run the query. - Post( - "/v2/searchextended", + val request = Post( + baseApiUrl + "/v2/searchextended", HttpEntity(SparqlQueryConstants.`application/sparql-query`, gravsearchQuery), - ) ~> addCredentials(BasicHttpCredentials(userEmail, password)) ~> searchPath ~> check { - assert(status == StatusCodes.OK, response.toString) - responseToJsonLDDocument(response) - } + ) ~> addCredentials(BasicHttpCredentials(userEmail, password)) + + val response: HttpResponse = singleAwaitingRequest(request) + assert(response.status == StatusCodes.OK) + responseToJsonLDDocument(response) } private def getValuesFromResource(resource: JsonLDDocument, propertyIriInResult: SmartIri): JsonLDArray = @@ -141,7 +133,7 @@ class ValuesV2R2RSpec extends R2RSpec { "update a still image file value using a mock Sipi" in { val resourceIri: IRI = aThingPictureIri val internalFilename = "IQUO3t1AABm-FSLC0vNvVpr.jp2" - + // val internalFilename = "De6XyNL4H71-D9QxghOuOPJ.jp2" val jsonLDEntity = s"""{ | "@id" : "$resourceIri", @@ -157,36 +149,33 @@ class ValuesV2R2RSpec extends R2RSpec { | } |}""".stripMargin - Put("/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials( - BasicHttpCredentials(anythingUserEmail, password), - ) ~> valuesPath ~> check { - assert(status == StatusCodes.OK, response.toString) - val responseJsonDoc = responseToJsonLDDocument(response) - val valueIri: IRI = - responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, validationFun) - stillImageFileValueIri.set(valueIri) - val valueType: SmartIri = - responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.TYPE, stringFormatter.toSmartIriWithErr) - valueType should ===(OntologyConstants.KnoraApiV2Complex.StillImageFileValue.toSmartIri) - - val savedValue: JsonLDObject = getValue( - resourceIri = resourceIri, - propertyIriForGravsearch = OntologyConstants.KnoraApiV2Complex.HasStillImageFileValue.toSmartIri, - propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasStillImageFileValue.toSmartIri, - expectedValueIri = stillImageFileValueIri.get, - userEmail = anythingUserEmail, + val header = addHeader("X-Asset-Ingested", "true") + val request = + Put(baseApiUrl + "/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials( + BasicHttpCredentials(anythingUserEmail, password), ) - savedValue - .getRequiredString(OntologyConstants.KnoraApiV2Complex.FileValueHasFilename) - .fold(msg => throw BadRequestException(msg), identity) should ===(internalFilename) - savedValue - .getRequiredInt(OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimX) - .fold(e => throw BadRequestException(e), identity) should ===(512) - savedValue - .getRequiredInt(OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimY) - .fold(e => throw BadRequestException(e), identity) should ===(256) - } + val response: HttpResponse = singleAwaitingRequest(request) + assert(response.status == StatusCodes.OK) + val responseJsonDoc = responseToJsonLDDocument(response) + val valueIri: IRI = + responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, validationFun) + stillImageFileValueIri.set(valueIri) + val valueType: SmartIri = + responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.TYPE, stringFormatter.toSmartIriWithErr) + valueType should ===(OntConsts.StillImageFileValue.toSmartIri) + + val savedValue: JsonLDObject = getValue( + resourceIri = resourceIri, + propertyIriForGravsearch = OntConsts.HasStillImageFileValue.toSmartIri, + propertyIriInResult = OntConsts.HasStillImageFileValue.toSmartIri, + expectedValueIri = stillImageFileValueIri.get, + userEmail = anythingUserEmail, + ) + + savedValue.getRequiredString(OntConsts.FileValueHasFilename).toOption should contain(internalFilename) + savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimX).toOption should contain(512) + savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimY).toOption should contain(256) } } }