-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use dsp ingest to get the metadata in case of AssetIngested
- Loading branch information
Showing
7 changed files
with
147 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
.../test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright © 2021 - 2023 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.knora.webapi.messages.v2.responder.valuemessages | ||
|
||
import zio.* | ||
import zio.nio.file.Path | ||
import zio.test.* | ||
|
||
import dsp.errors.AssertionException | ||
import org.knora.webapi.messages.admin.responder.usersmessages.UserADM | ||
import org.knora.webapi.messages.store.sipimessages.* | ||
import org.knora.webapi.messages.util.rdf.JsonLDUtil | ||
import org.knora.webapi.messages.v2.responder.SuccessResponseV2 | ||
import org.knora.webapi.messages.v2.responder.resourcemessages.CreateResourceRequestV2.AssetIngestState | ||
import org.knora.webapi.messages.v2.responder.resourcemessages.CreateResourceRequestV2.AssetIngestState.AssetInTemp | ||
import org.knora.webapi.messages.v2.responder.resourcemessages.CreateResourceRequestV2.AssetIngestState.AssetIngested | ||
import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId | ||
import org.knora.webapi.slice.admin.domain.model.KnoraProject | ||
import org.knora.webapi.slice.admin.domain.service.Asset | ||
import org.knora.webapi.store.iiif.api.FileMetadataSipiResponse | ||
import org.knora.webapi.store.iiif.api.SipiService | ||
|
||
object ValueContentV2Spec extends ZIOSpecDefault { | ||
|
||
private val assetId = AssetId.unsafeFrom("4sAf4AmPeeg-ZjDn3Tot1Zt") | ||
|
||
private val jsonLd = JsonLDUtil | ||
.parseJsonLD(s"{\"http://api.knora.org/ontology/knora-api/v2#fileValueHasFilename\" : \"$assetId.txt\"}") | ||
.body | ||
|
||
private val expected: FileMetadataSipiResponse = | ||
FileMetadataSipiResponse(Some("originalFilename"), None, "", None, None, None, None, None) | ||
|
||
override def spec: Spec[Any, Throwable] = | ||
suite("ValueContentV2.getFileInfo")( | ||
suite("Given the asset is present in the tmp folder of Sipi")( | ||
test("When getting file metadata with AssetInTemp from Sipi, then it should succeed") { | ||
for { | ||
temp <- ValueContentV2.getFileInfo("0001", AssetInTemp, jsonLd) | ||
} yield assertTrue(temp.metadata == expected) | ||
}, | ||
test("When getting file metadata with AssetIngested from dsp-ingest, then it should fail") { | ||
for { | ||
ingested <- ValueContentV2.getFileInfo("0001", AssetIngested, jsonLd).exit | ||
} yield assertTrue(ingested.isFailure) | ||
} | ||
).provide(mockSipi(AssetInTemp)), | ||
suite("Given the asset is ingested")( | ||
test("When getting file metadata with AssetInTemp from Sipi, then it should fail") { | ||
for { | ||
temp <- ValueContentV2.getFileInfo("0001", AssetInTemp, jsonLd).exit | ||
} yield assertTrue(temp.isFailure) | ||
}, | ||
test("When getting file metadata with AssetIngested from dsp-ingest, then it should succeed") { | ||
for { | ||
ingested <- ValueContentV2.getFileInfo("0001", AssetIngested, jsonLd) | ||
} yield assertTrue(ingested.metadata == expected) | ||
} | ||
).provide(mockSipi(AssetIngested)) | ||
) | ||
|
||
private def mockSipi(flag: AssetIngestState) = ZLayer.succeed(new SipiService { | ||
|
||
override def getFileMetadataFromSipiTemp(filename: String): Task[FileMetadataSipiResponse] = | ||
if (flag == AssetInTemp) { ZIO.succeed(expected) } | ||
else { ZIO.fail(AssertionException("fail")) } | ||
|
||
override def getFileMetadataFromDspIngestApi( | ||
shortcode: KnoraProject.Shortcode, | ||
assetId: AssetId | ||
): Task[FileMetadataSipiResponse] = | ||
if (flag == AssetIngested) { ZIO.succeed(expected) } | ||
else { ZIO.fail(AssertionException("fail")) } | ||
|
||
// The following are unsupported operations because they are not used in the test | ||
def moveTemporaryFileToPermanentStorage( | ||
moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest | ||
): Task[SuccessResponseV2] = | ||
ZIO.dieMessage("unsupported operation") | ||
def deleteTemporaryFile( | ||
deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest | ||
): Task[SuccessResponseV2] = | ||
ZIO.dieMessage("unsupported operation") | ||
def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = | ||
ZIO.dieMessage("unsupported operation") | ||
def getStatus(): Task[IIIFServiceStatusResponse] = | ||
ZIO.dieMessage("unsupported operation") | ||
def downloadAsset(asset: Asset, targetDir: Path, user: UserADM): Task[Option[Path]] = | ||
ZIO.dieMessage("unsupported operation") | ||
}) | ||
} |
89 changes: 0 additions & 89 deletions
89
...pi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValuesV2Spec.scala
This file was deleted.
Oops, something went wrong.