BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2020 Nordix Foundation. All rights reserved. |
| 5 | # ======================================================================== |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
| 20 | # Automated test script for mrstub container |
| 21 | |
| 22 | # mr-stub port |
| 23 | export PORT=3905 |
| 24 | |
| 25 | # source function to do curl and check result |
| 26 | . ../common/do_curl_function.sh |
| 27 | |
| 28 | echo "=== Stub hello world ===" |
| 29 | RESULT="OK" |
| 30 | do_curl GET / 200 |
| 31 | |
| 32 | echo "=== Stub reset ===" |
| 33 | RESULT="OK" |
| 34 | do_curl GET /reset 200 |
| 35 | |
| 36 | ## Test with json response |
| 37 | |
| 38 | echo "=== Send a request ===" |
| 39 | RESULT="*" |
| 40 | #create payload |
| 41 | echo "{\"data\": \"data-value\"}" > .tmp.json |
| 42 | |
| 43 | do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json |
| 44 | #Save id for later |
| 45 | CORRID=$body |
| 46 | |
| 47 | echo "=== Fetch a response, shall be empty ===" |
| 48 | RESULT="" |
| 49 | do_curl GET '/receive-response?correlationid='$CORRID 204 |
| 50 | |
| 51 | echo "=== Fetch a request ===" |
| 52 | RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]" |
| 53 | do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200 |
| 54 | |
| 55 | echo "=== Send a json response ===" |
| 56 | # Create minimal accepted response message |
| 57 | echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json |
| 58 | RESULT="OK" |
| 59 | do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json |
| 60 | |
| 61 | echo "=== Fetch a response ===" |
| 62 | RESULT="{\"test\": \"testresponse\"}200" |
| 63 | do_curl GET '/receive-response?correlationid='$CORRID 200 |
| 64 | |
| 65 | ### Test with plain text response |
| 66 | |
| 67 | echo "=== Send a request ===" |
| 68 | RESULT="*" |
| 69 | do_curl POST '/send-request?operation=GET&url=/test2' 200 |
| 70 | #Save id for later |
| 71 | CORRID=$body |
| 72 | |
| 73 | echo "=== Fetch a response, shall be empty ===" |
| 74 | RESULT="" |
| 75 | do_curl GET '/receive-response?correlationid='$CORRID 204 |
| 76 | |
| 77 | echo "=== Fetch a request ===" |
| 78 | RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]" |
| 79 | do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200 |
| 80 | |
| 81 | echo "=== Send a json response ===" |
| 82 | # Create minimal accepted response message |
| 83 | echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json |
| 84 | RESULT="OK" |
| 85 | do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json |
| 86 | |
| 87 | echo "=== Fetch a response ===" |
| 88 | RESULT="test2-response200" |
| 89 | do_curl GET '/receive-response?correlationid='$CORRID 200 |
| 90 | |
| 91 | echo "********************" |
| 92 | echo "*** All tests ok ***" |
| 93 | echo "********************" |