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