Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply new model to test data #2780

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
92fc993
remove demo ontology
BalduinLandolt Aug 9, 2023
06344fd
update ontologies
BalduinLandolt Aug 9, 2023
4bd04a4
update data
BalduinLandolt Aug 9, 2023
1a66f91
remove unused values from incunabula
BalduinLandolt Aug 9, 2023
8c52205
fix issue with previous values
BalduinLandolt Aug 9, 2023
c8e6e14
Update OntologyResponderV2Spec.scala
BalduinLandolt Aug 9, 2023
245b9b4
Update CreateValueWithEscape.jsonld
BalduinLandolt Aug 10, 2023
af8330e
Update anything-onto.ttl
BalduinLandolt Aug 10, 2023
c5f2cf3
fix test
BalduinLandolt Aug 17, 2023
c54cc3a
generate test data
BalduinLandolt Aug 17, 2023
f66561f
improve error messages
BalduinLandolt Aug 17, 2023
a30a4c6
update data
BalduinLandolt Aug 9, 2023
0293af9
remove unused values from incunabula
BalduinLandolt Aug 9, 2023
f6d5945
improve error reporting in tests
BalduinLandolt Aug 22, 2023
417ca00
fix some tests
BalduinLandolt Aug 22, 2023
e8cfff4
fix test and test data
BalduinLandolt Aug 22, 2023
53763ce
continue fixing tests
BalduinLandolt Aug 22, 2023
23f8c5a
fix tests
BalduinLandolt Aug 22, 2023
4441ecb
fix ValuesRoute E2E spec
BalduinLandolt Aug 22, 2023
ca288b2
update test data
BalduinLandolt Aug 22, 2023
a8800b5
update some test data
BalduinLandolt Aug 22, 2023
7166a07
fix test
BalduinLandolt Aug 22, 2023
8116b45
fix test
BalduinLandolt Aug 22, 2023
cef5634
Update CreateResourceWithEscape.jsonld
BalduinLandolt Aug 24, 2023
ee71204
Update ResourcesRouteV2E2ESpec.scala
BalduinLandolt Aug 24, 2023
2c9a249
Update ResourcesRouteV2E2ESpec.scala
BalduinLandolt Aug 24, 2023
b54b1ce
disallow custom formatted text values in simple schema
BalduinLandolt Aug 24, 2023
bcb8957
Update ResourcesRouteV2E2ESpec.scala
BalduinLandolt Aug 24, 2023
57963b3
Update ResourcesResponderV2.scala
BalduinLandolt Aug 24, 2023
f4ea6de
Update ValuesResponderV2.scala
BalduinLandolt Aug 24, 2023
9f37ba4
update some test data
BalduinLandolt Aug 24, 2023
d2afbee
Update NarrFulltextSearch.jsonld
BalduinLandolt Aug 24, 2023
55f735b
fix tests
BalduinLandolt Aug 24, 2023
ad26b03
hard code standard mapping
BalduinLandolt Aug 29, 2023
0ffbbdc
update test data
BalduinLandolt Aug 30, 2023
8429186
Revert "update test data"
BalduinLandolt Sep 20, 2023
d46a2e7
radically continue with test data (#2803)
BalduinLandolt Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,16 @@ lazy val integration: Project = Project(id = "integration", base = file("integra
"-Ymacro-annotations",
"-Wunused:imports",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s"
"-Wconf:src=target/.*:s",
// enable on demand
"-Wunused:privates",
"-Wunused:locals",
"-Wunused:explicits",
"-Wunused:implicits",
"-Wunused:params",
"-Wunused:patvars",
"-Wdead-code"
// "-Wvalue-discard"
),
logLevel := Level.Info,
javaAgents += Dependencies.aspectjweaver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ object InstanceCheckerSpec {
| "@type" : "anything:Thing",
| "anything:hasRichtext" : {
| "@id" : "http://rdfh.ch/0001/cUnhrC1DT821lwVWQSwEgg/values/VY4XodOeSaOdttZ6rEkFPg",
| "@type" : "knora-api:TextValue",
| "@type" : "knora-api:FormattedTextValue",
| "knora-api:attachedToUser" : {
| "@id" : "http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q"
| },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| "@id" : "anything:Thing"
| },
| "knora-api:objectType" : {
| "@id" : "knora-api:TextValue"
| "@id" : "knora-api:UnformattedTextValue"
| },
| "rdfs:comment" : [ {
| "@language" : "en",
Expand Down Expand Up @@ -1020,10 +1020,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| },
| "@type": "owl:ObjectProperty",
| "knora-api:objectType": {
| "@id": "knora-api:TextValue"
| },
| "salsah-gui:guiElement": {
| "@id": "salsah-gui:SimpleText"
| "@id": "knora-api:UnformattedTextValue"
| },
| "@id": "freetest:hasPropertyWithComment2"
| }
Expand Down Expand Up @@ -2590,7 +2587,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| "@id" : "useless:hasSharedName",
| "@type" : "owl:ObjectProperty",
| "knora-api:objectType" : {
| "@id" : "knora-api:TextValue"
| "@id" : "knora-api:UnformattedTextValue"
| },
| "rdfs:comment" : {
| "@language" : "en",
Expand Down Expand Up @@ -2706,7 +2703,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| "@id" : "anything:TestClass"
| },
| "knora-api:objectType" : {
| "@id" : "knora-api:TextValue"
| "@id" : "knora-api:UnformattedTextValue"
| },
| "rdfs:comment" : {
| "@language" : "en",
Expand Down Expand Up @@ -3012,7 +3009,7 @@ class OntologyV2R2RSpec extends R2RSpec {
lastModificationDate = freetestLastModDate,
propertyName = "hasBlueTestTextProp",
subjectClassName = Some("BlueFreeTestClass"),
propertyType = PropertyValueType.TextValue,
propertyType = PropertyValueType.UnformattedTextValue,
label = label1,
comment = comment1
)
Expand Down Expand Up @@ -3908,7 +3905,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| "@id" : "anything:Thing"
| },
| "knora-api:objectType" : {
| "@id" : "knora-api:TextValue"
| "@id" : "knora-api:IntValue"
| } ,
| "rdfs:label" : [ {
| "@language" : "en",
Expand Down Expand Up @@ -3959,7 +3956,7 @@ class OntologyV2R2RSpec extends R2RSpec {
| "@id" : "anything:Thing"
| },
| "knora-api:objectType" : {
| "@id" : "knora-api:TextValue"
| "@id" : "knora-api:IntValue"
| } ,
| "rdfs:label" : [ {
| "@language" : "en",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ import akka.http.scaladsl.model.headers.BasicHttpCredentials
import akka.http.scaladsl.unmarshalling.Unmarshal
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.Diff
import spray.json.JsValue
import spray.json.JsonParser
import zio.durationInt

import java.net.URLEncoder
import java.nio.file.Paths
import java.time.Instant
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Await
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration.SECONDS
Expand Down Expand Up @@ -769,14 +765,14 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
| }
| },
| "anything:hasRichtext" : {
| "@type" : "knora-api:TextValue",
| "@type" : "knora-api:FormattedTextValue",
| "knora-api:textValueAsXml" : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<text><p><strong>this is</strong> text</p> with standoff</text>",
| "knora-api:textValueHasMapping" : {
| "@id" : "http://rdfh.ch/standoff/mappings/StandardMapping"
| }
| },
| "anything:hasText" : {
| "@type" : "knora-api:TextValue",
| "anything:hasUnformattedText" : {
| "@type" : "knora-api:UnformattedTextValue",
| "knora-api:valueAsString" : "this is text without standoff"
| },
| "anything:hasUri" : {
Expand Down Expand Up @@ -806,7 +802,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
HttpEntity(RdfMediaTypes.`application/ld+json`, createResourceWithValues)
) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val response: HttpResponse = singleAwaitingRequest(request)
assert(response.status == StatusCodes.OK, response.toString)
assert(response.status == StatusCodes.OK, responseToString(response))
val responseJsonDoc: JsonLDDocument = responseToJsonLDDocument(response)
val validationFun: (String, => Nothing) => String = (s, e) => Iri.validateAndEscapeIri(s).getOrElse(e)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDKeywords.ID, validationFun)
Expand All @@ -832,6 +828,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
)
val resourceSimpleGetResponse: HttpResponse = singleAwaitingRequest(resourceSimpleGetRequest)
val resourceSimpleGetResponseAsString = responseToString(resourceSimpleGetResponse)
assert(resourceSimpleGetResponse.status == StatusCodes.OK, resourceSimpleGetResponseAsString)

instanceChecker.check(
instanceResponse = resourceSimpleGetResponseAsString,
Expand All @@ -851,7 +848,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"""{
| "@type" : "freetest:FreeTestSubClassOfFoafPerson",
| "freetest:hasFoafName" : {
| "@type" : "knora-api:TextValue",
| "@type" : "knora-api:UnformattedTextValue",
| "knora-api:valueAsString" : "this is a foaf name"
| },
| "knora-api:attachedToProject" : {
Expand Down Expand Up @@ -1645,148 +1642,6 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
responseDeleteDate should equal(deleteDate.toString)
}

"create a resource with a large text containing a lot of markup (32849 words, 6738 standoff tags)" ignore { // uses too much memory for GitHub CI
// Create a resource containing the text of Hamlet.

val hamletXml = FileUtil.readTextFile(Paths.get("..", "test_data/generated_test_data/resourcesR2RV2/hamlet.xml"))

val jsonLDEntity =
s"""{
| "@type" : "anything:Thing",
| "anything:hasRichtext" : {
| "@type" : "knora-api:TextValue",
| "knora-api:textValueAsXml" : ${stringFormatter.toJsonEncodedString(hamletXml)},
| "knora-api:textValueHasMapping" : {
| "@id" : "http://rdfh.ch/standoff/mappings/StandardMapping"
| }
| },
| "knora-api:attachedToProject" : {
| "@id" : "http://rdfh.ch/projects/0001"
| },
| "rdfs:label" : "test thing",
| "@context" : {
| "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
| "knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
| "rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
| "xsd" : "http://www.w3.org/2001/XMLSchema#",
| "anything" : "http://0.0.0.0:3333/ontology/0001/anything/v2#"
| }
|}""".stripMargin

val resourceCreateRequest = Post(
s"$baseApiUrl/v2/resources",
HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)
) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val resourceCreateResponseAsJsonLD: JsonLDDocument = getResponseAsJsonLD(resourceCreateRequest)
val validationFun: (String, => Nothing) => String = (s, e) => Iri.validateAndEscapeIri(s).getOrElse(e)
val resourceIri: IRI =
resourceCreateResponseAsJsonLD.body.requireStringWithValidation(JsonLDKeywords.ID, validationFun)
assert(resourceIri.toSmartIri.isKnoraDataIri)
hamletResourceIri.set(resourceIri)
}

"read the large text and its markup as XML, and check that it matches the original XML" ignore { // depends on previous test
val hamletXml = FileUtil.readTextFile(Paths.get("..", "test_data/generated_test_data/resourcesR2RV2/hamlet.xml"))

// Request the newly created resource.
val resourceGetRequest = Get(
s"$baseApiUrl/v2/resources/${URLEncoder.encode(hamletResourceIri.get, "UTF-8")}"
) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val resourceGetResponseAsString = getResponseAsString(resourceGetRequest)

// Check that the response matches the ontology.
instanceChecker.check(
instanceResponse = resourceGetResponseAsString,
expectedClassIri = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing".toSmartIri,
knoraRouteGet = doGetRequest
)

// Get the XML from the response.
val resourceGetResponseAsJsonLD = JsonLDUtil.parseJsonLD(resourceGetResponseAsString)
val xmlFromResponse: String = resourceGetResponseAsJsonLD.body
.requireObject("http://0.0.0.0:3333/ontology/0001/anything/v2#hasRichtext")
.requireString(OntologyConstants.KnoraApiV2Complex.TextValueAsXml)

// Compare it to the original XML.
val xmlDiff: Diff =
DiffBuilder.compare(Input.fromString(hamletXml)).withTest(Input.fromString(xmlFromResponse)).build()
xmlDiff.hasDifferences should be(false)
}

"read the large text without its markup, and get the markup separately as pages of standoff" ignore { // depends on previous test
// Get the resource without markup.
val resourceGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(hamletResourceIri.get, "UTF-8")}")
.addHeader(new MarkupHeader(RouteUtilV2.MARKUP_STANDOFF)) ~> addCredentials(
BasicHttpCredentials(anythingUserEmail, password)
)
val resourceGetResponse: HttpResponse = singleAwaitingRequest(resourceGetRequest)
val resourceGetResponseAsString = responseToString(resourceGetResponse)

// Check that the response matches the ontology.
instanceChecker.check(
instanceResponse = resourceGetResponseAsString,
expectedClassIri = "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing".toSmartIri,
knoraRouteGet = doGetRequest
)

// Get the standoff markup separately.
val resourceGetResponseAsJsonLD = JsonLDUtil.parseJsonLD(resourceGetResponseAsString)
val textValue: JsonLDObject =
resourceGetResponseAsJsonLD.body.requireObject("http://0.0.0.0:3333/ontology/0001/anything/v2#hasRichtext")
val maybeTextValueAsXml: Option[String] =
textValue.maybeString(OntologyConstants.KnoraApiV2Complex.TextValueAsXml)
assert(maybeTextValueAsXml.isEmpty)
val validationFun: (String, => Nothing) => String = (s, e) => Iri.validateAndEscapeIri(s).getOrElse(e)
val textValueIri: IRI = textValue.requireStringWithValidation(JsonLDKeywords.ID, validationFun)

val resourceIriEncoded: IRI = URLEncoder.encode(hamletResourceIri.get, "UTF-8")
val textValueIriEncoded: IRI = URLEncoder.encode(textValueIri, "UTF-8")

val standoffBuffer: ArrayBuffer[JsonLDObject] = ArrayBuffer.empty
var offset: Int = 0
var hasMoreStandoff: Boolean = true

while (hasMoreStandoff) {
// Get a page of standoff.

val standoffGetRequest = Get(
s"$baseApiUrl/v2/standoff/$resourceIriEncoded/$textValueIriEncoded/$offset"
) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val standoffGetResponse: HttpResponse = singleAwaitingRequest(standoffGetRequest)
val standoffGetResponseAsJsonLD: JsonLDObject = responseToJsonLDDocument(standoffGetResponse).body

val standoff: Seq[JsonLDValue] =
standoffGetResponseAsJsonLD.maybeArray(JsonLDKeywords.GRAPH).map(_.value).getOrElse(Seq.empty)

val standoffAsJsonLDObjects: Seq[JsonLDObject] = standoff.map {
case jsonLDObject: JsonLDObject => jsonLDObject
case other => throw AssertionException(s"Expected JsonLDObject, got $other")
}

standoffBuffer.appendAll(standoffAsJsonLDObjects)

standoffGetResponseAsJsonLD.maybeInt(OntologyConstants.KnoraApiV2Complex.NextStandoffStartIndex) match {
case Some(nextOffset) => offset = nextOffset
case None => hasMoreStandoff = false
}
}

assert(standoffBuffer.length == 6738)

// Check the standoff tags to make sure they match the ontology.

for (jsonLDObject <- standoffBuffer) {
val docForValidation = JsonLDDocument(body = jsonLDObject).toCompactString()

instanceChecker.check(
instanceResponse = docForValidation,
expectedClassIri =
jsonLDObject.requireStringWithValidation(JsonLDKeywords.TYPE, stringFormatter.toSmartIriWithErr),
knoraRouteGet = doGetRequest
)
}
}

"erase a resource" in {
val resourceLastModificationDate = Instant.parse("2019-02-13T09:05:10Z")

Expand Down Expand Up @@ -1829,8 +1684,8 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
val jsonLDEntity =
"""{
| "@type": "anything:Thing",
| "anything:hasText": {
| "@type": "knora-api:TextValue",
| "anything:hasRichtext": {
| "@type": "knora-api:FormattedTextValue",
| "knora-api:textValueAsXml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<text>\n This text links to another <a class=\"salsah-link\" href=\"http://rdfh.ch/0001/another-thing\">resource</a>.\n</text>",
| "knora-api:textValueHasMapping": {
| "@id": "http://rdfh.ch/standoff/mappings/StandardMapping"
Expand Down Expand Up @@ -1881,8 +1736,8 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
val jsonLDEntity =
"""{
| "@type": "anything:Thing",
| "anything:hasText": {
| "@type": "knora-api:TextValue",
| "anything:hasRichtext": {
| "@type": "knora-api:FormattedTextValue",
| "knora-api:textValueAsXml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<text>\n This text links to another <a class=\"salsah-link\" href=\"http://rdfh.ch/0001/another-thing\">thing</a> and a <a class=\"salsah-link\" href=\"http://rdfh.ch/0001/a-blue-thing\">blue thing</a>.\n</text>",
| "knora-api:textValueHasMapping": {
| "@id": "http://rdfh.ch/standoff/mappings/StandardMapping"
Expand Down Expand Up @@ -1998,7 +1853,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"""{
| "@type" : "freetest:NewClass",
| "freetest:hasName" : {
| "@type" : "knora-api:TextValue",
| "@type" : "knora-api:UnformattedTextValue",
| "knora-api:valueAsString" : "The new text value"
| },
| "knora-api:attachedToProject" : {
Expand All @@ -2020,7 +1875,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
) ~> addCredentials(auth)
val resourceResponse: HttpResponse = singleAwaitingRequest(resourceRequest)

assert(resourceResponse.status == StatusCodes.OK, resourceResponse.toString)
assert(resourceResponse.status == StatusCodes.OK, responseToString(resourceResponse))
val validationFun: (String, => Nothing) => String = (s, e) => Iri.validateAndEscapeIri(s).getOrElse(e)
val resourceIri: IRI =
responseToJsonLDDocument(resourceResponse).body.requireStringWithValidation(JsonLDKeywords.ID, validationFun)
Expand All @@ -2045,7 +1900,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
| "@type" : "freetest:NewClass",
| "freetest:hasName" : {
| "@id" : "$valueIri",
| "@type" : "knora-api:TextValue",
| "@type" : "knora-api:UnformattedTextValue",
| "knora-api:valueAsString" : "changed value"
| },
| "@context" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object ResponseCheckerV2 {
* @param receivedValue received value.
*/
private def compareValues(expectedValue: JsonLDValue, receivedValue: JsonLDValue): Unit =
assert(expectedValue == receivedValue, s"expected $expectedValue, received $receivedValue")
assert(expectedValue == receivedValue, s"\nexpected $expectedValue, \nreceived $receivedValue")

// TODO: recurse over target resource if it is a LinkValue

Expand Down Expand Up @@ -77,9 +77,12 @@ object ResponseCheckerV2 {
)

assert(
expectedResource.value.keySet -- noPropertyKeys == receivedResource.value.keySet -- noPropertyKeys,
s"property Iris are different for resource ${receivedResource
.value(JsonLDKeywords.ID)}: expected ${expectedResource.value.keySet -- noPropertyKeys}, received ${receivedResource.value.keySet -- noPropertyKeys}"
expectedResource.value.keySet -- noPropertyKeys == receivedResource.value.keySet -- noPropertyKeys, {
val exp = expectedResource.value.keySet -- noPropertyKeys
val rec = receivedResource.value.keySet -- noPropertyKeys
s"property Iris are different for resource ${receivedResource
.value(JsonLDKeywords.ID)}: \nexpected ${exp}, \nreceived ${rec}\nexpected has ${exp -- rec}\nreceived has ${rec -- exp}"
}
)

(expectedResource.value -- noPropertyKeys).foreach { case (propIri: IRI, expectedValuesForProp: JsonLDValue) =>
Expand Down
Loading