diff --git a/.github/workflows/postman.yml b/.github/workflows/postman.yml new file mode 100644 index 0000000..571e7fd --- /dev/null +++ b/.github/workflows/postman.yml @@ -0,0 +1,21 @@ +name: Automated API tests using Postman CLI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + automated-api-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - name: Install Postman CLI + run: | + curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh + - name: Login to Postman CLI + run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }} + - name: Run API tests + run: | + postman collection run "31208196-ebe740bc-2741-48ef-bdb6-e9ad85e8d39a" --reporters cli,junit --global-var api_url=http://localhost:8081 \ No newline at end of file diff --git a/.postman/api b/.postman/api new file mode 100644 index 0000000..a1d7485 --- /dev/null +++ b/.postman/api @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY +apis[] = {"apiId":"73c72b7f-85af-473f-ac2e-bbcd0e3bd2c2"} +configVersion = 1.0.0 +type = api diff --git a/.postman/api_73c72b7f-85af-473f-ac2e-bbcd0e3bd2c2 b/.postman/api_73c72b7f-85af-473f-ac2e-bbcd0e3bd2c2 new file mode 100644 index 0000000..2a62c81 --- /dev/null +++ b/.postman/api_73c72b7f-85af-473f-ac2e-bbcd0e3bd2c2 @@ -0,0 +1,20 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY +configVersion = 1.1.0 +type = apiEntityData + +[config] +id = 73c72b7f-85af-473f-ac2e-bbcd0e3bd2c2 + +[config.relations] + +[config.relations.collections] +rootDirectory = postman/collections + +[config.relations.collections.metaData] + +[config.relations.apiDefinition] +files[] = {"path":"index.json","metaData":{}} + +[config.relations.apiDefinition.metaData] +type = openapi:3 +rootFiles[] = index.json diff --git a/Postman Collections/SW7-API-Tests.json b/Postman Collections/SW7-API-Tests.json new file mode 100644 index 0000000..c198fef --- /dev/null +++ b/Postman Collections/SW7-API-Tests.json @@ -0,0 +1,171 @@ +{ + "info": { + "_postman_id": "ebe740bc-2741-48ef-bdb6-e9ad85e8d39a", + "name": "Test Setup", + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" + }, + "item": [ + { + "name": "Add Room", + "event": [ + { + "listen": "test", + "script": { + "id": "2e729a33-8d83-4858-8712-26fb7ce08576", + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.test(\"Response time is less than 1 s\", () => {", + " pm.expect(pm.response.responseTime).to.be.below(1000);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "id": "c4edb5a8-8719-49f6-bcd9-87a73f956cee", + "exec": [ + "let roomid = pm.environment.get(\"RoomId\")", + "roomid ++", + "pm.environment.set(\"RoomId\", roomid)" + ], + "type": "text/javascript" + } + } + ], + "id": "c2e1a61f-d755-43cc-8201-7fb289ef1c48", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"RoomId\": -1,\n \"Name\": \"Test room {{RoomId}}\",\n \"Description\": \"Postman Test Room\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": "http://127.0.0.1:8081/room/add" + }, + "response": [] + }, + { + "name": "Unregistered Trackers", + "event": [ + { + "listen": "prerequest", + "script": { + "id": "c1a422b3-cf2c-4c46-b21b-4faa7c4f7867", + "exec": [ + "let bluetoothMac = pm.environment.get(\"TrackerBluetoothMac\")", + "let wifiMac = pm.environment.get(\"TrackerWifiMac\")", + "", + "bluetoothMac ++", + "wifiMac ++", + "", + "pm.environment.set(\"TrackerBluetoothMac\", bluetoothMac)", + "pm.environment.set(\"TrackerWifiMac\", wifiMac)", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "id": "975300aa-dc06-4068-8d6b-6b388fe0ff09", + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.test(\"Response time is less than 1 s\", () => {", + " pm.expect(pm.response.responseTime).to.be.below(1000);", + "});" + ], + "type": "text/javascript" + } + } + ], + "id": "299f1464-fc5c-43ab-9e1e-1f0775ddf58e", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"unregisteredTrackers\": [\n {\n \"wifiMacAddress\": \"{{TrackerWifiMac}}\",\n \"bluetoothMacAddress\": \"{{TrackerBluetoothMac}}\"\n }\n ]\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": "http://127.0.0.1:8081/tracker/registration/unregistered" + }, + "response": [] + }, + { + "name": "Register Tracker", + "event": [ + { + "listen": "prerequest", + "script": { + "id": "17bcfeed-8473-43f7-8c52-d7209d650a54", + "exec": [ + "let trackerid = pm.environment.get(\"TrackerId\")", + "trackerid ++", + "pm.environment.set(\"TrackerId\", trackerid)" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "id": "30090c71-011c-4387-a08b-9ae5d5727388", + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.test(\"Response time is less than 1 s\", () => {", + " pm.expect(pm.response.responseTime).to.be.below(1000);", + "});" + ], + "type": "text/javascript" + } + } + ], + "id": "ac735894-40df-41ca-8109-0feeb5dd0156", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"roomId\": {{TrackerId}},\n \"name\": \"Tracker {{TrackerId}}\",\n \"description\": \"string\",\n \"wifiMacAddress\": \"{{TrackerBluetoothMac}}\",\n \"bluetoothMacAddress\": \"{{TrackerWifiMac}}\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": "http://127.0.0.1:8081/tracker/add" + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/index.json b/index.json new file mode 100644 index 0000000..771180c --- /dev/null +++ b/index.json @@ -0,0 +1,119 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Sample API", + "description": "Buy or rent spacecrafts" + }, + "paths": { + "/spacecrafts/{spacecraftId}": { + "parameters": [ + { + "name": "spacecraftId", + "description": "The unique identifier of the spacecraft", + "in": "path", + "required": true, + "schema": { + "$ref": "#/components/schemas/SpacecraftId" + } + } + ], + "get": { + "summary": "Read a spacecraft", + "responses": { + "200": { + "description": "The spacecraft corresponding to the provided `spacecraftId`", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Spacecraft" + } + } + } + }, + "404": { + "description": "No spacecraft found for the provided `spacecraftId`", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "500": { + "description": "Unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "SpacecraftId": { + "description": "The unique identifier of a spacecraft", + "type": "string" + }, + "Spacecraft": { + "type": "object", + "required": [ + "id", + "name", + "type" + ], + "properties": { + "id": { + "$ref": "#/components/schemas/SpacecraftId" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "capsule", + "probe", + "satellite", + "spaceplane", + "station" + ] + }, + "description": { + "type": "string" + } + } + }, + "Error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "description": "A human readable error message", + "type": "string" + } + } + } + }, + "securitySchemes": { + "ApiKey": { + "type": "apiKey", + "in": "header", + "name": "X-Api-Key" + } + } + }, + "security": [ + { + "ApiKey": [] + } + ] +} \ No newline at end of file