Test FTC100 fails since A1-SIM update
[nonrtric.git] / test / mrstub / basic_test.sh
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 # Run the build_and_start with the same arg as this script
23 if [ $# -ne 1 ]; then
24     echo "Usage: ./basic_test nonsecure|secure"
25     exit 1
26 fi
27 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
28     echo "Usage: ./basic_test nonsecure|secure"
29     exit 1
30 fi
31
32 if [ $1 == "nonsecure" ]; then
33     #Default http port for the simulator
34     PORT=3904
35     # Set http protocol
36     HTTPX="http"
37 else
38     #Default https port for the mr-stub
39     PORT=3905
40     # Set https protocol
41     HTTPX="https"
42 fi
43
44 # source function to do curl and check result
45 . ../common/do_curl_function.sh
46
47 RESP_CONTENT='*' #Dont check resp content type
48
49 echo "=== Stub hello world ==="
50 RESULT="OK"
51 do_curl GET / 200
52
53 echo "=== Stub reset ==="
54 RESULT="OK"
55 do_curl GET /reset 200
56
57 ## Test with json response
58
59 echo "=== Send a request ==="
60 RESULT="*"
61 #create payload
62 echo "{\"data\": \"data-value\"}" > .tmp.json
63
64 do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json
65 #Save id for later
66 CORRID=$body
67
68 echo "=== Fetch a response, shall be empty ==="
69 RESULT=""
70 do_curl GET '/receive-response?correlationid='$CORRID 204
71
72 echo "=== Fetch a request ==="
73 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\"}]"
74 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
75
76 echo "=== Send a json response ==="
77 # Create minimal accepted response message, array
78 echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json
79 RESULT="{}"
80 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
81
82 echo "=== Fetch a response ==="
83 RESULT="{\"test\": \"testresponse\"}200"
84 do_curl GET '/receive-response?correlationid='$CORRID 200
85
86 echo "=== Send a json response ==="
87 # Create minimal accepted response message, single message - no array
88 echo "{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse2\"}, \"status\": \"200\"}" > .tmp.json
89 RESULT="{}"
90 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
91
92 echo "=== Fetch a response ==="
93 RESULT="{\"test\": \"testresponse2\"}200"
94 do_curl GET '/receive-response?correlationid='$CORRID 200
95
96 ### Test with plain text response
97
98 echo "=== Send a request ==="
99 RESULT="*"
100 do_curl POST '/send-request?operation=GET&url=/test2' 200
101 #Save id for later
102 CORRID=$body
103
104 echo "=== Fetch a response, shall be empty ==="
105 RESULT=""
106 do_curl GET '/receive-response?correlationid='$CORRID 204
107
108 echo "=== Fetch a request ==="
109 RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]"
110 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
111
112 echo "=== Fetch a request, empty. Shall delay 10 seconds ==="
113 T1=$SECONDS
114 RESULT="json:[]"
115 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
116 T2=$SECONDS
117 if [ $(($T2-$T1)) -lt 10 ] || [ $(($T2-$T1)) -gt 15 ]; then
118     echo "Delay to short or too long"$(($T2-$T1))". Should be default 10 sec"
119     exit 1
120 else
121     echo "  Delay ok:"$(($T2-$T1))
122 fi
123
124 echo "=== Fetch a request, empty. Shall delay 5 seconds ==="
125 T1=$SECONDS
126 RESULT="json:[]"
127 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=5000' 200
128 T2=$SECONDS
129 if [ $(($T2-$T1)) -lt 5 ] || [ $(($T2-$T1)) -gt 7 ]; then
130     echo "Delay too short or too long"$(($T2-$T1))". Should be 10 sec"
131     exit 1
132 else
133     echo "  Delay ok:"$(($T2-$T1))
134 fi
135
136 echo "=== Fetch a request with limit 25, shall be empty.  ==="
137 RESULT="json-array-size:0"
138 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=25' 200
139
140 echo "=== Send 5 request to test limit on MR GET==="
141 RESULT="*"
142 for i in {1..5}
143 do
144     do_curl POST '/send-request?operation=GET&url=/test2' 200
145 done
146
147 echo "=== Fetch a request with limit 3.  ==="
148 RESULT="json-array-size:3"
149 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
150
151 echo "=== Fetch a request with limit 3, shall return 2.  ==="
152 RESULT="json-array-size:2"
153 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
154
155 echo "=== Fetch a request with limit 3, shall return 0.  ==="
156 RESULT="json-array-size:0"
157 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
158
159 echo "=== Send a json response ==="
160 # Create minimal accepted response message
161 echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json
162 RESULT="{}"
163 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
164
165 echo "=== Fetch a response ==="
166 RESULT="test2-response200"
167 do_curl GET '/receive-response?correlationid='$CORRID 200
168
169
170 echo "=== Send a json response ==="
171 # Create minimal accepted response message, array
172 echo "{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}" > .tmp.json
173 RESULT="{}"
174 do_curl POST /events/generic-path 200 .tmp.json
175
176 echo "=== Fetch a request ==="
177 RESULT="json:[\"{\\\"correlationId\\\": \\\""$CORRID"\\\", \\\"message\\\": {\\\"test\\\": \\\"testresponse\\\"}, \\\"status\\\": \\\"200\\\"}\"]"
178 do_curl GET '/events/generic-path' 200
179
180 echo "********************"
181 echo "*** All tests ok ***"
182 echo "********************"