Skip to content

Commit

Permalink
fix.it
Browse files Browse the repository at this point in the history
  • Loading branch information
siers committed Nov 7, 2024
1 parent bb52134 commit ae1eddd
Showing 1 changed file with 15 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials

import scala.concurrent.ExecutionContextExecutor

import dsp.errors.AssertionException
import dsp.errors.BadRequestException
import dsp.valueobjects.Iri
import org.knora.webapi.*
Expand All @@ -30,7 +29,7 @@ import org.apache.pekko.http.scaladsl.model.HttpResponse
/**
* Tests creating a still image file value using a mock Sipi.
*/
class ValuesV2R2RSpec extends E2ESpec {
class ValuesV2R2RSpec extends ITKnoraLiveSpec {

private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

Expand Down Expand Up @@ -80,32 +79,14 @@ class ValuesV2R2RSpec extends E2ESpec {
propertyIriInResult: SmartIri,
expectedValueIri: IRI,
): JsonLDObject = {
val resourceIri: IRI =
resource.body.requireStringWithValidation(JsonLDKeywords.ID, validationFun)
val propertyValues: JsonLDArray =
getValuesFromResource(resource = resource, propertyIriInResult = propertyIriInResult)

val matchingValues: Seq[JsonLDObject] = propertyValues.value.collect {
case jsonLDObject: JsonLDObject
if jsonLDObject.requireStringWithValidation(
JsonLDKeywords.ID,
validationFun,
) == expectedValueIri =>
jsonLDObject
}

if (matchingValues.isEmpty) {
throw AssertionException(
s"Property <$propertyIriInResult> of resource <$resourceIri> does not have value <$expectedValueIri>",
)
}

if (matchingValues.size > 1) {
throw AssertionException(
s"Property <$propertyIriInResult> of resource <$resourceIri> has more than one value with the IRI <$expectedValueIri>",
)
}

val matchingValues: Seq[JsonLDObject] =
getValuesFromResource(resource = resource, propertyIriInResult = propertyIriInResult).value.collect {
case jsonLDObject: JsonLDObject
if jsonLDObject.requireStringWithValidation(JsonLDKeywords.ID, validationFun) == expectedValueIri =>
jsonLDObject
}

assert(matchingValues.size == 1)
matchingValues.head
}

Expand All @@ -132,8 +113,7 @@ class ValuesV2R2RSpec extends E2ESpec {
"The values v2 endpoint" should {
"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 internalFilename = "De6XyNL4H71-D9QxghOuOPJ.jp2"
val jsonLDEntity =
s"""{
| "@id" : "$resourceIri",
Expand All @@ -151,9 +131,9 @@ class ValuesV2R2RSpec extends E2ESpec {

val header = addHeader("X-Asset-Ingested", "true")
val request =
Put(baseApiUrl + "/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials(
BasicHttpCredentials(anythingUserEmail, password),
)
Put(baseApiUrl + "/v2/values", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity))
~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
~> header

val response: HttpResponse = singleAwaitingRequest(request)
assert(response.status == StatusCodes.OK)
Expand All @@ -174,8 +154,8 @@ class ValuesV2R2RSpec extends E2ESpec {
)

savedValue.getRequiredString(OntConsts.FileValueHasFilename).toOption should contain(internalFilename)
savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimX).toOption should contain(512)
savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimY).toOption should contain(256)
savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimX).toOption should contain(72)
savedValue.getRequiredInt(OntConsts.StillImageFileValueHasDimY).toOption should contain(72)
}
}
}

0 comments on commit ae1eddd

Please sign in to comment.