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

test endpoint bg/clear

add response schema and link in documentation
parent 528a231b
......@@ -387,12 +387,20 @@ system_test:prepare_container:
script:
- cp -f tests/api/${TEST_NAME}-theory_bg.db theory_bg.db
- chown webapi theory_bg.db
- swipl daemon.pl --user webapi --log access.log
- swipl daemon.pl --user webapi
- newman run tests/api/${TEST_NAME}-tests.json -e tests/api/env.json -d tests/api/${TEST_NAME}-data.json --reporters junit --reporter-junit-export="api-report.xml" --bail
- swipl daemon.pl --shutdown
after_script:
- cat access.log
.system_test:run_with_db:
extends: .system_test:run
script:
- cp -f tests/api/${TEST_NAME}-theory_bg.db theory_bg.db
- chown webapi theory_bg.db
- swipl daemon.pl --user webapi
- newman run tests/api/${TEST_NAME}-tests.json -e tests/api/env.json --reporters junit --reporter-junit-export="api-report.xml" --bail
- swipl daemon.pl --shutdown
system_test:up:
extends: .system_test:run
variables:
......@@ -408,6 +416,11 @@ system_test:endpoint_bg@remove:
variables:
TEST_NAME: endpoint_bg@remove
system_test:endpoint_bg@clear:
extends: .system_test:run_with_db
variables:
TEST_NAME: endpoint_bg@clear
# 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
......
......@@ -242,6 +242,8 @@ None.
- `removed` is the number of removed items
- `skipped` is the number of ot removed items. Should always be zero.
The response body follows this [JSON schema](</doc/schema/response-bg-clear-schema.json>).
#### Example Call
```bash
......@@ -431,7 +433,7 @@ status of the server.
| =status= | string | The status of the server. Currently, always =|"running"|=. |
| =version= | string | The [semantic version number](https://semver.org) of the WebAPI. |
Response follows this [JSON schema](</doc/schema/response-state-schema.json>).
The response body follows this [JSON schema](</doc/schema/response-state-schema.json>).
#### Example Call
......
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "dare2del/response/bg/clear",
"type": "object",
"title": "response bg/clear",
"description": "The response body after clearing the background knowledge",
"properties": {
"remove_all": {
"type": "boolean"
},
"removed": {
"type": "integer",
"minimum": 0
},
"skipped": {
"type": "integer",
"minimum": 0
}
},
"required": [
"remove_all",
"removed",
"skipped"
]
}
{
"info": {
"_postman_id": "a0198816-d9a9-4319-a884-0e00abbd7ffa",
"name": "Endpoint bg/clear",
"description": "This collection tests the direct responses of the API Endpoint bg/clear of the [Reasoning WebAPI for Dare2Del](https://gitlab.rz.uni-bamberg.de/cogsys/dare2del/demonstrator) (Version 1.0.0).\n\nThe collection assumes that server is started with background knowledge from `endpoint_bg@clear-theory_bg.db`.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Load Clear 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(\"expected_json_schema\", JSON.stringify(jsonData));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://{{SERVER}}{{SCHEMA_PATH}}/response-bg-clear-schema.json",
"protocol": "http",
"host": [
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path": [
"response-bg-clear-schema.json"
]
}
},
"response": []
},
{
"name": "Remove All 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;",
"",
" const schema_text = pm.variables.get(\"expected_json_schema\")",
" const schema = JSON.parse(schema_text)",
"",
" jsonData = pm.response.json();",
" pm.expect(tv4.validate(jsonData, schema)).to.be.true;",
"});",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"All removed\", function () {",
" pm.expect(jsonData.remove_all).to.be.true;",
" pm.expect(jsonData.removed).to.eql(13);",
" pm.expect(jsonData.skipped).to.eql(0);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"url": {
"raw": "http://{{SERVER}}/bg/clear",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"bg",
"clear"
]
},
"description": "Remove a single, previously known file (good case)."
},
"response": []
},
{
"name": "Remove Nol 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;",
"",
" const schema_text = pm.variables.get(\"expected_json_schema\")",
" const schema = JSON.parse(schema_text)",
"",
" jsonData = pm.response.json();",
" pm.expect(tv4.validate(jsonData, schema)).to.be.true;",
"});",
"",
"pm.test(pm.variables.get(\"test_prefix\") + \"All removed\", function () {",
" pm.expect(jsonData.remove_all).to.be.true;",
" pm.expect(jsonData.removed).to.eql(0);",
" pm.expect(jsonData.skipped).to.eql(0);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"url": {
"raw": "http://{{SERVER}}/bg/clear",
"protocol": "http",
"host": [
"{{SERVER}}"
],
"path": [
"bg",
"clear"
]
},
"description": "Remove a single, previously known 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": [
""
]
}
}
],
"variable": [
{
"key": "expected_json_schema",
"value": ""
}
]
}
\ 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