Commit ceb87284 authored by Siebers, Michael's avatar Siebers, Michael
Browse files

test endpoint bg/show

add response schema and link in documentation
parent ad3e8304
......@@ -421,6 +421,10 @@ system_test:endpoint_bg@clear:
variables:
TEST_NAME: endpoint_bg@clear
system_test:endpoint_bg@show:
extends: .system_test:run_with_data_and_db
variables:
TEST_NAME: endpoint_bg@show
# If no FORCE_... variable is set to "yes", no pipeline is created for merge
# requests targetting a non-default branch. Thus, the MR cannot be merged. This
......
......@@ -97,7 +97,7 @@ None.
| --- | --- | --- | --- |
| Ok | `200`| Request successful | a JSON object with properties `item_count` and `list` |
The property `item_count` (_nonnegative integer_) contains the number of items stored in the background knowledge. All items in the background knowledge are listed in `list` (list of [item](<#json_types>)s).
The property `item_count` (_nonnegative integer_) contains the number of items stored in the background knowledge. All items in the background knowledge are listed in `list` (list of [item](<#json_types>)s). The response body follows this [JSON schema](</doc/schema/response-bg-show-schema.json>).
#### Example Call
......
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "response-bg-show-schema.json",
"type": "object",
"title": "response bg/show",
"description": "The response body when querying the server's background knowledge.",
"properties": {
"item_count": {
"type": "integer",
"minimum": 0,
"description": "number of items in the background knowledge"
},
"list": {
"description": "items in the background knowledge",
"type": "array",
"items": {
"$ref": "type-item-schema.json"
}
}
},
"required": [
"item_count",
"list"
]
}
[
{
"items": [
{
"type" : "directory",
"abs_path": "A/B",
"creation_time": 1604235509
},
{
"type":"file",
"abs_path": "testfile.ext",
"file_size": 1024,
"creation_time": 1604235569,
"modification_time": 1604235569,
"access_time": 1604235569,
"change_time": 1604235569,
"media_type": "other",
"filename_extension": "ext"
},
{
"type" : "directory",
"abs_path": "top",
"creation_time": 1604235209
},
{
"type":"file",
"abs_path": "top/topfile.txt",
"file_size": 17369,
"creation_time": 1604257109,
"modification_time": 1604258119,
"access_time": 1604268813,
"change_time": 1604258119,
"media_type": "text",
"filename_extension": "txt"
},
{
"type":"file",
"abs_path": "top/other.csv",
"file_size": 2342754,
"creation_time": 1604252069,
"modification_time": 1604520690,
"access_time": 1604530901,
"change_time": 1604520690,
"media_type": "other",
"filename_extension": "csv"
},
{
"type" : "directory",
"abs_path": "top/middle",
"creation_time": 1604235709
},
{
"type":"file",
"abs_path": "top/middle/middlefile.txt",
"file_size": 12038,
"creation_time": 1604357091,
"modification_time": 1604587091,
"access_time": 1605870913,
"change_time": 1605870913,
"media_type": "text",
"filename_extension": "txt"
},
{
"type":"file",
"abs_path": "top/middle/other.pdf",
"file_size": 12479123,
"creation_time": 1604370912,
"modification_time": 1604379192,
"access_time": 1604379922,
"change_time": 1604379192,
"media_type": "pdf",
"filename_extension": "pdf"
},
{
"type" : "directory",
"abs_path": "top/middle/bottom",
"creation_time": 1604245209
},
{
"type":"file",
"abs_path": "top/middle/bottom/bottomfile.txt",
"file_size": 623,
"creation_time": 1605252092,
"modification_time": 1605520257,
"access_time": 1606202578,
"change_time": 1605520257,
"media_type": "text",
"filename_extension": "txt"
},
{
"type":"file",
"abs_path": "top/middle/bottom/other.png",
"file_size": 6543672,
"creation_time": 1604245090,
"modification_time": 1604450903,
"access_time": 1604459037,
"change_time": 1604450903,
"media_type": "image",
"filename_extension": "other"
},
{
"type" : "directory",
"abs_path": "top/also_middle",
"creation_time": 1604257037
},
{
"type":"file",
"abs_path": "top/also_middle/another.jpg",
"file_size": 823243,
"creation_time": 1604457371,
"modification_time": 1604457371,
"access_time": 1604457371,
"change_time": 1604457371,
"media_type": "image",
"filename_extension": "jpg"
}
],
"item_count": 13
}
]
{
"info": {
"_postman_id": "4fc9d6a9-0efd-416c-8d96-b128f4d8d1a9",
"name": "Endpoint bg/show",
"description": "This collection tests the direct responses of the API Endpoint bg/add of the [Reasoning WebAPI for Dare2Del](https://gitlab.rz.uni-bamberg.de/cogsys/dare2del/demonstrator) (Version 1.0.0). It is not checked, whether the correct information is stored on the server. This is part of the user stories.\n\nThe collection assumes that the background knowledge is empty.\n\nThe collection is to be run with the data file `endpoint_bg@add-data.json`.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Load File Schema",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Response is JSON object\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" const jsonData = pm.response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" pm.collectionVariables.set(\"json_schema:file\", JSON.stringify(jsonData));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}{{SCHEMA_PATH}}/type-file-schema.json",
"protocol": "http",
"host": [
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path": [
"type-file-schema.json"
]
}
},
"response": []
},
{
"name": "Load Directory Schema",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Response is JSON object\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" const jsonData = pm.response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" pm.collectionVariables.set(\"json_schema:directory\", JSON.stringify(jsonData));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}{{SCHEMA_PATH}}/type-directory-schema.json",
"protocol": "http",
"host": [
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path": [
"type-directory-schema.json"
]
}
},
"response": []
},
{
"name": "Load Item Schema",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Response is JSON object\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" const jsonData = pm.response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" pm.collectionVariables.set(\"json_schema:item\", JSON.stringify(jsonData));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}{{SCHEMA_PATH}}/type-item-schema.json",
"protocol": "http",
"host": [
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path": [
"type-item-schema.json"
]
}
},
"response": []
},
{
"name": "Load Show Response Schema",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Response is JSON object\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" const jsonData = pm.response.json();",
" pm.expect(jsonData).is.an(\"object\");",
"",
" pm.collectionVariables.set(\"json_schema:response\", JSON.stringify(jsonData));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}{{SCHEMA_PATH}}/response-bg-show-schema.json",
"protocol": "http",
"host": [
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path": [
"response-bg-show-schema.json"
]
}
},
"response": []
},
{
"name": "Get Items",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(pm.variables.get(\"test_prefix\") + \"Case: OK\", function () {",
" pm.expect(pm.response.code).to.eql(200);",
"});",
"",
"var jsonData;",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"Response JSON schema valid\", function() {",
" pm.response.to.be.withBody;",
" pm.response.to.be.json;",
"",
" var Ajv = require('ajv');",
" ajv = new Ajv();",
"",
" // prepare schemas",
" ajv.addSchema(JSON.parse(pm.variables.get(\"json_schema:item\")));",
" ajv.addSchema(JSON.parse(pm.variables.get(\"json_schema:file\")));",
" ajv.addSchema(JSON.parse(pm.variables.get(\"json_schema:directory\"))); ",
" const schema = JSON.parse(pm.variables.get(\"json_schema:response\"));",
"",
" jsonData = pm.response.json();",
"",
" const validate = ajv.compile(schema);",
" pm.expect(validate(jsonData)).to.be.true;",
"});",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"All received\", function () {",
" var expected_item_count = pm.iterationData.get(\"item_count\");",
" var expected_items = pm.iterationData.get(\"items\");",
"",
" pm.expect(jsonData.item_count, \"Transmitted item_count unexpected.\").to.eql(expected_item_count);",
" pm.expect(jsonData.list, \"Number of items in list does not match item_count.\").to.have.lengthOf(expected_item_count);",
" pm.expect(jsonData.list).to.have.deep.members(expected_items);",
"",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}/bg/show",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"bg",
"show"
]
},
"description": "Add a single, previously unknown file (good case)."
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"pm.variables.set(\"test_prefix\", pm.info.requestName + \": \");"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
\ No newline at end of file
assert(item_('testfile.ext',file{abs_path:'testfile.ext',access_time:1604235569,change_time:1604235569,creation_time:1604235569,file_size:1024,filename_extension:ext,media_type:other,modification_time:1604235569})).
assert(item_('A/B',directory{abs_path:'A/B',creation_time:1604235509})).
assert(item_(top,directory{abs_path:top,creation_time:1604235209})).
assert(item_('top/topfile.txt',file{abs_path:'top/topfile.txt',access_time:1604268813,change_time:1604258119,creation_time:1604257109,file_size:17369,filename_extension:txt,media_type:text,modification_time:1604258119})).
assert(item_('top/other.csv',file{abs_path:'top/other.csv',access_time:1604530901,change_time:1604520690,creation_time:1604252069,file_size:2342754,filename_extension:csv,media_type:other,modification_time:1604520690})).
assert(item_('top/middle',directory{abs_path:'top/middle',creation_time:1604235709})).
assert(item_('top/middle/middlefile.txt',file{abs_path:'top/middle/middlefile.txt',access_time:1605870913,change_time:1605870913,creation_time:1604357091,file_size:12038,filename_extension:txt,media_type:text,modification_time:1604587091})).
assert(item_('top/middle/other.pdf',file{abs_path:'top/middle/other.pdf',access_time:1604379922,change_time:1604379192,creation_time:1604370912,file_size:12479123,filename_extension:pdf,media_type:pdf,modification_time:1604379192})).
assert(item_('top/middle/bottom',directory{abs_path:'top/middle/bottom',creation_time:1604245209})).
assert(item_('top/middle/bottom/bottomfile.txt',file{abs_path:'top/middle/bottom/bottomfile.txt',access_time:1606202578,change_time:1605520257,creation_time:1605252092,file_size:623,filename_extension:txt,media_type:text,modification_time:1605520257})).
assert(item_('top/middle/bottom/other.png',file{abs_path:'top/middle/bottom/other.png',access_time:1604459037,change_time:1604450903,creation_time:1604245090,file_size:6543672,filename_extension:other,media_type:image,modification_time:1604450903})).
assert(item_('top/also_middle',directory{abs_path:'top/also_middle',creation_time:1604257037})).
assert(item_('top/also_middle/another.jpg',file{abs_path:'top/also_middle/another.jpg',access_time:1604457371,change_time:1604457371,creation_time:1604457371,file_size:823243,filename_extension:jpg,media_type:image,modification_time:1604457371})).
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment