Sonar corrections. Unit tests and code coverage added
[sim/a1-interface.git] / near-rt-ric-simulator / test / OSC_2.1.0 / 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 # Script for basic test of the simulator.
21 # Run the build_and_start with the same arg as this script
22 if [ $# -ne 1 ]; then
23     echo "Usage: ./basic_test.sh nonsecure|secure"
24     exit 1
25 fi
26 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27     echo "Usage: ./basic_test.sh nonsecure|secure"
28     exit 1
29 fi
30
31 if [ $1 == "nonsecure" ]; then
32     #Default http port for the simulator
33     PORT=8085
34     # Set http protocol
35     HTTPX="http"
36 else
37     #Default https port for the simulator
38     PORT=8185
39     # Set https protocol
40     HTTPX="https"
41 fi
42
43 . ../common/test_common.sh
44
45 echo "=== Simulator hello world ==="
46 RESULT="OK"
47 do_curl GET / 200
48
49 echo "=== Check used and implemented interfaces ==="
50 RESULT="Current interface: OSC_2.1.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3']"
51 do_curl GET /container_interfaces 200
52
53 echo "=== Reset simulator instances ==="
54 RESULT="All policy instances deleted"
55 do_curl POST /deleteinstances 200
56
57 echo "=== Reset simulator, all ==="
58 RESULT="All policy instances and types deleted"
59 do_curl POST /deleteall 200
60
61 echo "=== API: Healthcheck ==="
62 RESULT=""
63 do_curl GET /a1-p/healthcheck 200
64
65 echo "=== API: Get policy types, shall be empty array =="
66 RESULT="json:[]"
67 do_curl GET /a1-p/policytypes 200
68
69 echo "=== API: Delete a policy type, shall fail =="
70 RESULT=""
71 do_curl DELETE /a1-p/policytypes/1 404
72
73 echo "=== API: Get policy instances for type 1, shall fail =="
74 RESULT=""
75 do_curl GET /a1-p/policytypes/1/policies 404
76
77 echo "=== API: Put a policy type: 1 ==="
78 RESULT=""
79 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
80
81 echo "=== API: Put a policy type: 1, again ==="
82 RESULT=""
83 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
84
85 echo "=== API: Delete a policy type: 1 ==="
86 RESULT=""
87 do_curl DELETE /a1-p/policytypes/1 204
88
89 echo "=== API: Get policy type ids, shall be empty =="
90 RESULT="json:[]"
91 do_curl GET /a1-p/policytypes 200
92
93 echo "=== API: Load a policy type: 1 ==="
94 RESULT=""
95 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
96
97 echo "=== API: Get policy type ids, shall contain type 1 =="
98 RESULT="json:[ 1 ]"
99 do_curl GET /a1-p/policytypes 200
100
101 echo "=== API: Get instances for type 1, shall be empty ==="
102 RESULT="json:[]"
103 do_curl GET '/a1-p/policytypes/1/policies' 200
104
105 echo "=== API: Create policy instance pi1 of type: 1 ==="
106 RESULT=""
107 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
108
109 echo "=== API: Update policy instance pi1 of type: 1 ==="
110 RESULT=""
111 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
112
113 echo "=== API: Load a policy type: 1, shall fail ==="
114 RESULT=""
115 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
116
117 echo "=== API: Get instances for type 1, shall contain pi1 ==="
118 RESULT="json:[ \"pi1\" ]"
119 do_curl GET '/a1-p/policytypes/1/policies' 200
120
121 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
122 RESULT=""
123 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
124
125 echo "=== Set force response code 401. ==="
126 RESULT="*"
127 do_curl POST '/forceresponse?code=401' 200
128
129 echo "=== API: Get policy type 1. Shall fail with forced code ==="
130 RESULT=""
131 do_curl GET '/a1-p/policytypes/1' 401
132
133 echo "=== API: Get policy status ==="
134 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
135 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
136
137 echo "=== Load a policy type: 2 ==="
138 RESULT="Policy type 2 is OK."
139 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
140
141 echo "=== Load a policy type: 2 again. ==="
142 RESULT="Policy type 2 is OK."
143 do_curl PUT '/policytype?id=2' 200 jsonfiles/pt2.json
144
145 echo "=== API: Get policy type ids, shall contain type 1 and 2 =="
146 RESULT="json:[ 1, 2 ]"
147 do_curl GET /a1-p/policytypes 200
148
149 echo "=== Get policy type ids, shall contain type 1 and 2 =="
150 RESULT="json:[\"1\", \"2\"]"
151 do_curl GET /policytypes 200
152
153 echo "=== API: Get policy type 2 =="
154 RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}"
155 do_curl GET /a1-p/policytypes/2 200
156
157 echo "=== Delete policy type: 2 ==="
158 RESULT=""
159 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
160
161 echo "=== API: Get policy type ids, shall contain type 1 =="
162 RESULT="json:[ 1 ]"
163 do_curl GET /a1-p/policytypes 200
164
165 echo "=== Load a policy type: 2 ==="
166 RESULT="Policy type 2 is OK."
167 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
168
169 echo "=== API: Get policy type 2 =="
170 RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}"
171 do_curl GET /a1-p/policytypes/2 200
172
173 echo "=== API: Get instances for type 2, shall be empty ==="
174 RESULT="json:[]"
175 do_curl GET '/a1-p/policytypes/2/policies' 200
176
177 echo "=== API: Create policy instance pi1 of type: 2, shall fail==="
178 RESULT=""
179 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
180
181 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
182 RESULT=""
183 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
184
185 echo "=== API: Create policy instance pi2 of type: 2 ==="
186 RESULT=""
187 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
188
189 echo "=== API: Update policy instance pi2 of type: 2 ==="
190 RESULT=""
191 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
192
193 echo "=== API: Get instances for type 1, shall contain pi1 ==="
194 RESULT="json:[ \"pi1\" ]"
195 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
196
197 echo "=== API: Get instances for type 2, shall contain pi2 ==="
198 RESULT="json:[ \"pi2\" ]"
199 do_curl GET '/a1-p/policytypes/2/policies' 200
200
201 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
202 RESULT=""
203 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
204
205 echo "=== Set force response code 401. ==="
206 RESULT="*"
207 do_curl POST '/forceresponse?code=401' 200
208
209 echo "=== API: Get policy status for pi1, shall fail ==="
210 RESULT=""
211 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
212
213 echo "=== Set force delay 10. ==="
214 RESULT="Force delay: 10 sec set for all A1 responses"
215 do_curl POST '/forcedelay?delay=10' 200
216
217 echo "=== API: Get policy status for pi1. Shall delay 10 sec ==="
218 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
219 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
220
221 echo "=== Reset force delay. ==="
222 RESULT="Force delay: None sec set for all A1 responses"
223 do_curl POST '/forcedelay' 200
224
225 echo "=== Set status for pi1 ==="
226 RESULT="Status set to IN EFFECT for policy: pi1"
227 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT' 200
228
229 echo "=== API: Get policy status for pi1 ==="
230 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
231 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
232
233 echo "=== Set status for pi1 ==="
234 RESULT="Status set to IN EFFECT and has_been_deleted set to true and created_at set to 2020-03-30 12:00:00 for policy: pi1"
235 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT&deleted=true&created_at=2020-03-30%2012:00:00' 200
236
237 echo "=== API: Get policy status for pi1 ==="
238 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"true\", \"created_at\": \"2020-03-30 12:00:00\"}"
239 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
240
241 echo "=== Get counter: instances ==="
242 RESULT="2"
243 do_curl GET '/counter/num_instances' 200
244
245 echo "=== Get counter: types ==="
246 RESULT="2"
247 do_curl GET '/counter/num_types' 200
248
249 echo "=== Get counter: interface ==="
250 RESULT="OSC_2.1.0"
251 do_curl GET '/counter/interface' 200
252
253 echo "=== Get counter: remote hosts ==="
254 RESULT="*"
255 do_curl GET '/counter/remote_hosts' 200
256
257 echo "=== DELETE policy pi1 ==="
258 RESULT=""
259 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
260
261 echo "=== API: Get instances for type 1, shall be empty ==="
262 RESULT="[]"
263 do_curl GET /a1-p/policytypes/1/policies 200
264
265 echo "=== API: Get instances for type 2, shall contain pi2 ==="
266 RESULT="[ \"pi2\" ]"
267 do_curl GET /a1-p/policytypes/2/policies 200
268
269 echo "=== Get counter: instances ==="
270 RESULT="1"
271 do_curl GET /counter/num_instances 200
272
273 echo "********************"
274 echo "*** All tests ok ***"
275 echo "********************"