-
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.
fix: Allow creation of unformatted TextValues with language tags (DEV…
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 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
File renamed without changes.
96 changes: 96 additions & 0 deletions
96
...c/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/CreateValueV2Spec.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,96 @@ | ||
/* | ||
* Copyright © 2021 - 2024 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.ZIO | ||
import zio.test.Spec | ||
import zio.test.TestResult | ||
import zio.test.ZIOSpecDefault | ||
import zio.test.assertTrue | ||
|
||
import org.knora.webapi.ApiV2Complex | ||
import org.knora.webapi.IRI | ||
import org.knora.webapi.core.MessageRelay | ||
import org.knora.webapi.core.MessageRelayLive | ||
import org.knora.webapi.messages.StringFormatter | ||
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionADM | ||
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionsDataADM | ||
import org.knora.webapi.messages.v2.responder.valuemessages.TextValueType.UnformattedText | ||
import org.knora.webapi.routing.v2.AssetIngestState.AssetIngested | ||
import org.knora.webapi.slice.admin.api.model.Project | ||
import org.knora.webapi.slice.admin.domain.model.Group | ||
import org.knora.webapi.slice.admin.domain.model.User | ||
import org.knora.webapi.slice.admin.domain.service.KnoraGroupRepo | ||
import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo | ||
import org.knora.webapi.slice.resourceinfo.domain.IriConverter | ||
import org.knora.webapi.store.iiif.api.SipiService | ||
import org.knora.webapi.store.iiif.impl.SipiServiceMock | ||
|
||
object CreateValueV2Spec extends ZIOSpecDefault { | ||
|
||
private val unformattedTextValueWithLanguage = | ||
""" | ||
|{ | ||
| "@id": "http://rdfh.ch/0001/a-thing", | ||
| "@type": "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing", | ||
| "http://0.0.0.0:3333/ontology/0001/anything/v2#hasText":{ | ||
| "@type":"http://api.knora.org/ontology/knora-api/v2#TextValue", | ||
| "http://api.knora.org/ontology/knora-api/v2#valueAsString":"This is English", | ||
| "http://api.knora.org/ontology/knora-api/v2#textValueHasLanguage":"en" | ||
| } | ||
|}""".stripMargin | ||
|
||
private val rootUser = | ||
User( | ||
id = "http://rdfh.ch/users/root", | ||
username = "root", | ||
email = "[email protected]", | ||
givenName = "System", | ||
familyName = "Administrator", | ||
status = true, | ||
lang = "de", | ||
password = Option("$2a$12$7XEBehimXN1rbhmVgQsyve08.vtDmKK7VMin4AdgCEtE4DWgfQbTK"), | ||
groups = Seq.empty[Group], | ||
projects = Seq.empty[Project], | ||
permissions = PermissionsDataADM( | ||
groupsPerProject = Map( | ||
KnoraProjectRepo.builtIn.SystemProject.id.value -> List(KnoraGroupRepo.builtIn.SystemAdmin.id.value), | ||
), | ||
administrativePermissionsPerProject = Map.empty[IRI, Set[PermissionADM]], | ||
), | ||
) | ||
|
||
override def spec: Spec[Any, Throwable] = | ||
suite("CreateValueV2Spec")(test("UnformattedText TextValue fromJsonLd should contain the language") { | ||
for { | ||
sf <- ZIO.service[StringFormatter] | ||
value <- CreateValueV2.fromJsonLd(AssetIngested, unformattedTextValueWithLanguage, rootUser) | ||
} yield assertTrue( | ||
value == CreateValueV2( | ||
resourceIri = "http://rdfh.ch/0001/a-thing", | ||
resourceClassIri = sf.toSmartIri("http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"), | ||
propertyIri = sf.toSmartIri("http://0.0.0.0:3333/ontology/0001/anything/v2#hasText"), | ||
valueContent = TextValueContentV2( | ||
ontologySchema = ApiV2Complex, | ||
maybeValueHasString = Some("This is English"), | ||
textValueType = UnformattedText, | ||
valueHasLanguage = Some("en"), | ||
standoff = Nil, | ||
mappingIri = None, | ||
mapping = None, | ||
xslt = None, | ||
comment = None, | ||
), | ||
valueIri = None, | ||
valueUUID = None, | ||
valueCreationDate = None, | ||
permissions = None, | ||
ingestState = AssetIngested, | ||
), | ||
) | ||
}).provide(StringFormatter.test, MessageRelayLive.layer, IriConverter.layer, SipiServiceMock.layer) | ||
|
||
} |