Skip to content

Commit

Permalink
test(v2-ontology-cache): add test for isEditable property on link val…
Browse files Browse the repository at this point in the history
…ues (DSP-1840) (#1897)

* test(v2-ontology-cache): add basic test

* reproduce bug in e2e test

* add temp test

* add more temp tests

* work on unit test

* get unit test to work for now

* add example test for adding properties to ontology

* add books ontology for testing

* add cache test for link values

* improve cache test

* remove freetest ontology from cache test

* remove redundant test

* fix R2R test for isEditable property

* Update OntologyResponderV2.scala

* cleanup code

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
Co-authored-by: Balduin Landolt <balduin.landolt@hotmail.com>
  • Loading branch information
3 people committed Sep 13, 2021
1 parent 6caa18e commit b1c22c0
Show file tree
Hide file tree
Showing 6 changed files with 567 additions and 1 deletion.
57 changes: 57 additions & 0 deletions test_data/all_data/books-data.ttl
@@ -0,0 +1,57 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@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 foaf: <http://xmlns.com/foaf/0.1/> .
@prefix knora-base: <http://www.knora.org/ontology/knora-base#> .
@prefix knora-admin: <http://www.knora.org/ontology/knora-admin#> .
@prefix salsah-gui: <http://www.knora.org/ontology/salsah-gui#> .
@prefix books: <http://www.knora.org/ontology/0001/books#> .


<http://rdfh.ch/0001/book-instance-01/values/has-title-value-01>
a knora-base:TextValue ;
knora-base:valueHasUUID "OTAzYmIzOTktYzA4Ni00NmM0LWFlZGItYzIyNzcyN2FkNjFk"^^xsd:string ;
knora-base:isDeleted false ;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime ;
knora-base:valueHasOrder 0 ;
knora-base:valueHasString "Handbuch Projektmanagement" ;
knora-base:hasPermissions
"CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser" ;
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .


<http://rdfh.ch/0001/book-instance-01>
a books:Book ;
knora-base:attachedToUser <http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q> ;
knora-base:attachedToProject <http://rdfh.ch/projects/0001> ;
knora-base:hasPermissions "V knora-admin:UnknownUser|M knora-admin:ProjectMember" ;
knora-base:creationDate "2019-11-29T10:00:00.673298Z"^^xsd:dateTime ;
books:hasTitle <http://rdfh.ch/0001/book-instance-01/values/has-title-value-01> ;
rdfs:label "instance of a book" ;
knora-base:isDeleted false .


<http://rdfh.ch/0001/page-instance-01/values/has-page-number-value-01>
a knora-base:IntValue ;
knora-base:valueHasUUID "MmI4YTg1YTctZjM4Yy00MzE2LTkwNTgtYzdjODk1NjcwZmFm"^^xsd:string ;
knora-base:isDeleted false ;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime ;
knora-base:valueHasInteger 1 ;
knora-base:valueHasOrder 0 ;
knora-base:valueHasString "1" ;
knora-base:hasPermissions
"CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser" ;
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .


<http://rdfh.ch/0001/page-instance-01>
a books:Page ;
knora-base:attachedToUser <http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q> ;
knora-base:attachedToProject <http://rdfh.ch/projects/0001> ;
knora-base:hasPermissions "V knora-admin:UnknownUser|M knora-admin:ProjectMember" ;
knora-base:creationDate "2019-11-29T10:00:00.673298Z"^^xsd:dateTime ;
books:hasPageNumber <http://rdfh.ch/0001/page-instance-01/values/has-page-number-value-01> ;
rdfs:label "instance of a page" ;
knora-base:isDeleted false .
71 changes: 71 additions & 0 deletions test_data/ontologies/books-onto.ttl
@@ -0,0 +1,71 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@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 foaf: <http://xmlns.com/foaf/0.1/> .
@prefix knora-base: <http://www.knora.org/ontology/knora-base#> .
@prefix salsah-gui: <http://www.knora.org/ontology/salsah-gui#> .
@base <http://www.knora.org/ontology/0001/books#> .

# A bookish ontology, used only for testing Knora.

@prefix : <http://www.knora.org/ontology/0001/books#> .

<http://www.knora.org/ontology/0001/books>
rdf:type owl:Ontology ;
rdfs:label "An ontology about books" ;
knora-base:attachedToProject <http://rdfh.ch/projects/0001> ;
knora-base:lastModificationDate "2012-12-12T12:12:12.12Z"^^xsd:dateTime .



:hasTitle
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasValue ;
rdfs:label "Titel"@de, "title"@en ;
knora-base:subjectClassConstraint :Book ;
knora-base:objectClassConstraint knora-base:TextValue ;
salsah-gui:guiElement salsah-gui:SimpleText ;
salsah-gui:guiAttribute "size=80", "maxlength=255" .


#:hasPage
# rdf:type owl:ObjectProperty ;
# rdfs:subPropertyOf knora-base:hasLinkTo ;
# rdfs:label "Seite im Buch"@de, "Page in the book"@en ;
# knora-base:subjectClassConstraint :Book ;
# knora-base:objectClassConstraint :Page ;
# salsah-gui:guiElement salsah-gui:Searchbox .
#
#
#:hasPageValue
# rdf:type owl:ObjectProperty ;
# rdfs:subPropertyOf knora-base:hasLinkToValue ;
# rdfs:label "Seite im Buch"@de, "Page in the book"@en ;
# knora-base:objectClassConstraint knora-base:LinkValue .


:Book
rdf:type owl:Class ;
rdfs:subClassOf knora-base:Resource;
knora-base:resourceIcon "book.png" ;
rdfs:label "Buch"@de, "Book"@en ;
rdfs:comment """A resource describing a book."""@en .


:hasPageNumber
rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf knora-base:hasValue ;
rdfs:label "Seitenzahl"@de, "Page number"@en ;
knora-base:objectClassConstraint knora-base:IntValue ;
salsah-gui:guiElement salsah-gui:Spinbox ;
salsah-gui:guiAttribute "min=0", "max=-1" .


:Page
rdf:type owl:Class ;
rdfs:subClassOf knora-base:Resource;
knora-base:resourceIcon "page.png" ;
rdfs:label "Seite"@de, "Page"@en ;
rdfs:comment """A resource describing a page in a book."""@en .
Expand Up @@ -2640,6 +2640,7 @@ class OntologyResponderV2(responderData: ResponderData) extends Responder(respon
maybeUnescapedNewLinkValuePropertyDef.map { unescapedNewLinkPropertyDef =>
unescapedNewLinkPropertyDef.propertyIri -> ReadPropertyInfoV2(
entityInfoContent = unescapedNewLinkPropertyDef,
isEditable = true,
isResourceProp = true,
isLinkValueProp = true
)
Expand All @@ -2665,7 +2666,6 @@ class OntologyResponderV2(responderData: ResponderData) extends Responder(respon
)

// Read the data back from the cache.

response <- getPropertyDefinitionsFromOntologyV2(
propertyIris = Set(internalPropertyIri),
allLanguages = true,
Expand Down
Expand Up @@ -1678,6 +1678,46 @@ class OntologyV2R2RSpec extends R2RSpec {
}
}

"add all IRIs to newly created link value property again" in {
val url = URLEncoder.encode(s"${SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI_LocalHost}", "UTF-8")
Get(
s"/v2/ontologies/allentities/${url}"
) ~> ontologiesPath ~> check {
val responseStr: String = responseAs[String]
assert(status == StatusCodes.OK, response.toString)
val responseJsonDoc = JsonLDUtil.parseJsonLD(responseStr)

val graph = responseJsonDoc.body.requireArray("@graph").value

val hasOtherNothingValue = graph
.filter(
_.asInstanceOf[JsonLDObject]
.value("@id")
.asInstanceOf[JsonLDString]
.value == "http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherNothingValue"
)
.head
.asInstanceOf[JsonLDObject]

val iris = hasOtherNothingValue.value.keySet

val expectedIris = Set(
OntologyConstants.Rdfs.Comment,
OntologyConstants.Rdfs.Label,
OntologyConstants.Rdfs.SubPropertyOf,
OntologyConstants.KnoraApiV2Complex.IsEditable,
OntologyConstants.KnoraApiV2Complex.IsResourceProperty,
OntologyConstants.KnoraApiV2Complex.IsLinkValueProperty,
OntologyConstants.KnoraApiV2Complex.ObjectType,
OntologyConstants.KnoraApiV2Complex.SubjectType,
"@id",
"@type"
)

iris should equal(expectedIris)
}
}

"remove the cardinality for the property anything:hasOtherNothing from the class anything:Nothing" in {
val params =
s"""{
Expand Down
Expand Up @@ -3,6 +3,47 @@ package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test")
load("//third_party:dependencies.bzl", "ALL_WEBAPI_MAIN_DEPENDENCIES", "BASE_TEST_DEPENDENCIES", "BASE_TEST_DEPENDENCIES_WITH_JSON", "BASE_TEST_DEPENDENCIES_WITH_JSON_LD")


scala_test(
name = "CacheSpec",
size = "small", # 60s
srcs = [
"CacheSpec.scala",
],
data = [
"//knora-ontologies",
"//test_data",
],
jvm_flags = ["-Dconfig.resource=fuseki.conf"],
resources = [
"//webapi/scripts:fuseki_repository_config_ttl_template",
"//webapi/src/main/resources",
"//webapi/src/test/resources",
],
scalacopts = ["-deprecation"],
unused_dependency_checker_mode = "warn",
deps = [
"//webapi:test_library",
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/feature",
"//webapi/src/main/scala/org/knora/webapi/instrumentation",
"//webapi/src/main/scala/org/knora/webapi/messages",
"//webapi/src/main/scala/org/knora/webapi/responders/v2/ontology",
"//webapi/src/main/scala/org/knora/webapi/settings",
"//webapi/src/main/scala/org/knora/webapi/store",
"//webapi/src/main/scala/org/knora/webapi/util/cache",
"@maven//:com_typesafe_akka_akka_actor_2_13",
"@maven//:com_typesafe_config",
"@maven//:com_typesafe_scala_logging_scala_logging_2_13",
"@maven//:org_scalactic_scalactic_2_13",
"@maven//:org_scalatest_scalatest_compatible",
"@maven//:org_scalatest_scalatest_core_2_13",
"@maven//:org_scalatest_scalatest_matchers_core_2_13",
"@maven//:org_scalatest_scalatest_shouldmatchers_2_13",
"@maven//:org_scalatest_scalatest_wordspec_2_13",
],
)

scala_test(
name = "DeleteCardinalitiesFromClassSpec",
size = "small", # 60s
Expand Down

0 comments on commit b1c22c0

Please sign in to comment.