diff --git a/integration/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala b/integration/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala index ad373d73d9..33359d99c3 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala @@ -26,6 +26,7 @@ import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter import org.knora.webapi.messages.store.triplestoremessages.* import org.knora.webapi.messages.util.KnoraSystemInstances +import org.knora.webapi.messages.util.rdf.SparqlSelectResult import org.knora.webapi.messages.v2.responder.CanDoResponseV2 import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.messages.v2.responder.ontologymessages.* @@ -56,6 +57,7 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender { private val anythingNonAdminUser = SharedTestDataADM.anythingUser1 private val anythingProjectIri = SharedTestDataADM.anythingProjectIri.toSmartIri private val ontologyResponder = ZIO.serviceWithZIO[OntologyResponderV2] + private val triplestoreService = ZIO.serviceWithZIO[TriplestoreService] override lazy val rdfDataObjects: List[RdfDataObject] = List( @@ -950,13 +952,9 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender { } "create a subproperty of an existing custom link property and add it to a resource class, check if the correct link and link value properties were added to the class" in { - - appActor ! OntologyMetadataGetByProjectRequestV2( - projectIris = Set(anythingProjectIri), - requestingUser = anythingAdminUser, + val metadataResponse = UnsafeZioRun.runOrThrow( + ontologyResponder(_.getOntologyMetadataForProjectsV2(Set(anythingProjectIri))), ) - - val metadataResponse = expectMsgType[ReadOntologyMetadataV2](timeout) assert(metadataResponse.ontologies.size == 3) freetestLastModDate = metadataResponse .toOntologySchema(ApiV2Complex) @@ -1008,7 +1006,7 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender { freetestLastModDate = newFreetestLastModDate } - // Create class freetest:ComicAuthor which is a subclass of feetest:Author + // Create class freetest:ComicAuthor which is a subclass of freetest:Author val comicAuthorClassIri = FreeTestOntologyIri.makeEntityIri("ComicAuthor") @@ -1158,8 +1156,37 @@ class OntologyResponderV2Spec extends CoreSpec with ImplicitSender { .getOrElse(throw AssertionException(s"${msg.ontologyMetadata.ontologyIri} has no last modification date")) assert(newFreetestLastModDate.isAfter(freetestLastModDate)) freetestLastModDate = newFreetestLastModDate - } + // Verify the cardinality of the new property and its link value where created in the subclass + val queryResult: SparqlSelectResult = + UnsafeZioRun.runOrThrow( + triplestoreService(_.query(Select(""" + |PREFIX rdf: + |PREFIX rdfs: + |PREFIX owl: + |PREFIX freetest: + | + |SELECT ?property ?maxCardinality + |WHERE { + | freetest:ComicBook rdfs:subClassOf ?restriction . + | ?restriction rdf:type owl:Restriction . + | ?restriction owl:onProperty ?property . + | ?restriction owl:maxCardinality ?maxCardinality . + |}""".stripMargin))), + ) + assert( + queryResult.results.bindings.exists(row => + row.rowMap.get("property").contains("http://www.knora.org/ontology/0001/freetest#hasComicAuthor") + && row.rowMap.get("maxCardinality").contains("1"), + ), + ) + assert( + queryResult.results.bindings.exists(row => + row.rowMap.get("property").contains("http://www.knora.org/ontology/0001/freetest#hasComicAuthorValue") + && row.rowMap.get("maxCardinality").contains("1"), + ), + ) + } } "not create a property without an rdf:type" in { diff --git a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala index 7df746c2bb..d3852a4349 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala @@ -326,7 +326,7 @@ final case class OntologyResponderV2( * @param projectIris the IRIs of the projects selected, or an empty set if all projects are selected. * @return a [[ReadOntologyMetadataV2]]. */ - private def getOntologyMetadataForProjectsV2(projectIris: Set[SmartIri]): Task[ReadOntologyMetadataV2] = { + def getOntologyMetadataForProjectsV2(projectIris: Set[SmartIri]): Task[ReadOntologyMetadataV2] = { val returnAllOntologies = projectIris.isEmpty for { allOntologies <- ontologyCache.getCacheData.map(_.ontologies.values.map(_.ontologyMetadata).toSet)