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

refactor: add missing client test data (DEV-979) #2072

Merged
merged 5 commits into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions webapi/scripts/expected-client-test-data.txt
Expand Up @@ -18,6 +18,7 @@ test-data/admin/lists/add-child-to-second-child-request.json
test-data/admin/lists/add-child-to-second-child-response.json
test-data/admin/lists/add-second-child-to-root-request.json
test-data/admin/lists/add-second-child-to-root-response.json
test-data/admin/lists/candeletelist-response.json
test-data/admin/lists/create-child-node-request.json
test-data/admin/lists/create-child-node-response.json
test-data/admin/lists/create-child-node-with-custom-IRI-request.json
Expand All @@ -26,6 +27,7 @@ test-data/admin/lists/create-list-request.json
test-data/admin/lists/create-list-response.json
test-data/admin/lists/create-list-with-custom-IRI-request.json
test-data/admin/lists/create-list-with-custom-IRI-response.json
test-data/admin/lists/delete-list-node-comments-response.json
test-data/admin/lists/delete-list-node-response.json
test-data/admin/lists/delete-list-response.json
test-data/admin/lists/get-anything-project-lists-response.json
Expand Down Expand Up @@ -194,7 +196,9 @@ test-data/v2/ontologies/create-ontology-with-comment-request.json
test-data/v2/ontologies/create-ontology-with-comment-response.json
test-data/v2/ontologies/create-value-property-request.json
test-data/v2/ontologies/create-value-property-response.json
test-data/v2/ontologies/delete-class-comment-response.json
test-data/v2/ontologies/delete-ontology-response.json
test-data/v2/ontologies/delete-property-comment-response.json
test-data/v2/ontologies/get-class-anything-thing-with-allLanguages-response.json
test-data/v2/ontologies/get-class-image-bild-response.json
test-data/v2/ontologies/get-class-incunabula-book-response.json
Expand Down
Expand Up @@ -51,6 +51,19 @@ class DeleteListItemsRouteADME2ESpec
// Collects client test data
private val clientTestDataCollector = new ClientTestDataCollector(settings)

// Collects client test data
private def collectClientTestData(fileName: String, fileContent: String): Unit =
clientTestDataCollector.addFile(
TestDataFileContent(
filePath = TestDataFilePath(
directoryPath = clientTestDataPath,
filename = fileName,
fileExtension = "json"
),
text = fileContent
)
)

override lazy val rdfDataObjects = List(
RdfDataObject(path = "test_data/demo_data/images-demo-data.ttl", name = "http://www.knora.org/data/00FF/images"),
RdfDataObject(path = "test_data/all_data/anything-data.ttl", name = "http://www.knora.org/data/0001/anything")
Expand Down Expand Up @@ -125,16 +138,7 @@ class DeleteListItemsRouteADME2ESpec
val firstChild = children.head
firstChild.children.size should be(5)

clientTestDataCollector.addFile(
TestDataFileContent(
filePath = TestDataFilePath(
directoryPath = clientTestDataPath,
filename = "delete-list-node-response",
fileExtension = "json"
),
text = responseToString(response)
)
)
collectClientTestData("delete-list-node-response", responseToString(response))
}

"delete the single child of a node" in {
Expand All @@ -161,22 +165,13 @@ class DeleteListItemsRouteADME2ESpec
val deletedStatus = AkkaHttpUtils.httpResponseToJson(response).fields("deleted")
deletedStatus.convertTo[Boolean] should be(true)

clientTestDataCollector.addFile(
TestDataFileContent(
filePath = TestDataFilePath(
directoryPath = clientTestDataPath,
filename = "delete-list-response",
fileExtension = "json"
),
text = responseToString(response)
)
)
collectClientTestData("delete-list-response", responseToString(response))
}
}

"Candeletelist route (/admin/lists/candelete)" when {
"used to query if list can be deleted" should {
"return TRUE for unused list" in {
"return positive response for unused list" in {
val unusedList = "http://rdfh.ch/lists/0001/notUsedList"
val unusedListEncoded = java.net.URLEncoder.encode(unusedList, "utf-8")
val request = Get(baseApiUrl + s"/admin/lists/candelete/" + unusedListEncoded) ~> addCredentials(
Expand All @@ -190,9 +185,11 @@ class DeleteListItemsRouteADME2ESpec
canDelete.convertTo[Boolean] should be(true)
val listIri = AkkaHttpUtils.httpResponseToJson(response).fields("listIri")
listIri.convertTo[String] should be(unusedList)

collectClientTestData("candeletelist-response", responseToString(response))
}

"return FALSE for used list" in {
"return negative response for used list" in {
val usedList = "http://rdfh.ch/lists/0001/treeList01"
val usedListEncoded = java.net.URLEncoder.encode(usedList, "utf-8")
val request = Get(baseApiUrl + s"/admin/lists/candelete/" + usedListEncoded) ~> addCredentials(
Expand Down Expand Up @@ -220,4 +217,40 @@ class DeleteListItemsRouteADME2ESpec
}
}
}

"DeleteListNodeComments route (/admin/lists/comments)" when {
"deleting comments" should {
"delete child node comments" in {
val childNodeIri = "http://rdfh.ch/lists/0001/testList01"
val childNodeIriEncoded = java.net.URLEncoder.encode(childNodeIri, "utf-8")
val request = Delete(s"$baseApiUrl/admin/lists/comments/$childNodeIriEncoded") ~> addCredentials(
BasicHttpCredentials(rootCreds.email, rootCreds.password)
)

val response: HttpResponse = singleAwaitingRequest(request)
val responseStr = responseToString(response)

response.status should be(StatusCodes.OK)
val commentsDeleted = AkkaHttpUtils.httpResponseToJson(response).fields("commentsDeleted")
commentsDeleted.convertTo[Boolean] should be(true)
val nodeIri = AkkaHttpUtils.httpResponseToJson(response).fields("nodeIri")
nodeIri.convertTo[String] should be(childNodeIri)

collectClientTestData("delete-list-node-comments-response", responseStr)
}

"return exception for root node comments" in {
val childNodeIri = "http://rdfh.ch/lists/0001/testList"
val childNodeIriEncoded = java.net.URLEncoder.encode(childNodeIri, "utf-8")
val request = Delete(s"$baseApiUrl/admin/lists/comments/$childNodeIriEncoded") ~> addCredentials(
BasicHttpCredentials(rootCreds.email, rootCreds.password)
)

val response: HttpResponse = singleAwaitingRequest(request)
val responseStr = responseToString(response)

response.status should be(StatusCodes.BadRequest)
}
}
}
}
Expand Up @@ -983,8 +983,9 @@ class OntologyV2R2RSpec extends R2RSpec {
Delete(
s"/v2/ontologies/properties/comment/$propertySegment?lastModificationDate=$lastModificationDate"
) ~> addCredentials(BasicHttpCredentials(anythingUsername, password)) ~> ontologiesPath ~> check {
assert(status == StatusCodes.OK, response.toString)
val responseJsonDoc: JsonLDDocument = responseToJsonLDDocument(response)
val responseStr = responseAs[String]
assert(status == StatusCodes.OK, responseStr)
val responseJsonDoc = JsonLDUtil.parseJsonLD(responseStr)
val newFreetestLastModDate = responseJsonDoc.requireDatatypeValueInObject(
key = OntologyConstants.KnoraApiV2Complex.LastModificationDate,
expectedDatatype = OntologyConstants.Xsd.DateTimeStamp.toSmartIri,
Expand Down Expand Up @@ -1047,9 +1048,12 @@ class OntologyV2R2RSpec extends R2RSpec {

val responseFromJsonLD: InputOntologyV2 =
InputOntologyV2.fromJsonLD(responseJsonDoc, parsingMode = TestResponseParsingModeV2).unescape

responseFromJsonLD.properties.head._2.predicates.toSet should ===(
expectedResponseToCompare.properties.head._2.predicates.toSet
)

CollectClientTestData("delete-property-comment-response", responseStr)
}
}

Expand All @@ -1061,8 +1065,9 @@ class OntologyV2R2RSpec extends R2RSpec {
Delete(
s"/v2/ontologies/classes/comment/$classSegment?lastModificationDate=$lastModificationDate"
) ~> addCredentials(BasicHttpCredentials(anythingUsername, password)) ~> ontologiesPath ~> check {
assert(status == StatusCodes.OK, response.toString)
val responseJsonDoc: JsonLDDocument = responseToJsonLDDocument(response)
val responseStr = responseAs[String]
assert(status == StatusCodes.OK, responseStr)
val responseJsonDoc: JsonLDDocument = JsonLDUtil.parseJsonLD(responseStr)
val newFreetestLastModDate = responseJsonDoc.requireDatatypeValueInObject(
key = OntologyConstants.KnoraApiV2Complex.LastModificationDate,
expectedDatatype = OntologyConstants.Xsd.DateTimeStamp.toSmartIri,
Expand Down Expand Up @@ -1125,6 +1130,8 @@ class OntologyV2R2RSpec extends R2RSpec {
responseFromJsonLD.classes.head._2.predicates.toSet should ===(
expectedResponseToCompare.classes.head._2.predicates.toSet
)

CollectClientTestData("delete-class-comment-response", responseStr)
}
}

Expand Down