Skip to content

Commit

Permalink
test: Add test checking (link) properties for subclasses are created …
Browse files Browse the repository at this point in the history
…correctly (DEV-4025) (#3358)
  • Loading branch information
seakayone authored Sep 9, 2024
1 parent e95ffb2 commit 270b99e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|PREFIX owl: <http://www.w3.org/2002/07/owl#>
|PREFIX freetest: <http://www.knora.org/ontology/0001/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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 270b99e

Please sign in to comment.