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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 #Default port for the simulator
23 . ../common/test_common.sh
25 echo "=== Simulator hello world ==="
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
33 echo "=== Reset simulator instances ==="
34 RESULT="All policy instances deleted"
35 do_curl POST /deleteinstances 200
37 echo "=== Reset simulator, all ==="
38 RESULT="All policy instances and types deleted"
39 do_curl POST /deleteall 200
41 echo "=== API: Healthcheck ==="
43 do_curl get /a1-p/healthcheck 200
45 echo "=== API: Get policy types, shall be empty array =="
47 do_curl GET /a1-p/policytypes 200
49 echo "=== API: Delete a policy type, shall fail =="
51 do_curl DELETE /a1-p/policytypes/1 404
53 echo "=== API: Get policy instances for type 1, shall fail =="
55 do_curl GET /a1-p/policytypes/1/policies 404
57 echo "=== API: Put a policy type: 1 ==="
59 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
61 echo "=== API: Put a policy type: 1, again ==="
63 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
65 echo "=== API: Delete a policy type: 1 ==="
67 do_curl DELETE /a1-p/policytypes/1 204
69 echo "=== API: Get policy type ids, shall be empty =="
71 do_curl GET /a1-p/policytypes 200
73 echo "=== API: Load a policy type: 1 ==="
75 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
77 echo "=== API: Get policy type ids, shall contain type 1 =="
78 RESULT="json:[ \"1\" ]"
79 do_curl GET /a1-p/policytypes 200
81 echo "=== API: Get instances for type 1, shall be empty ==="
83 do_curl GET '/a1-p/policytypes/1/policies' 200
85 echo "=== API: Create policy instance pi1 of type: 1 ==="
87 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
89 echo "=== API: Update policy instance pi1 of type: 1 ==="
91 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
93 echo "=== API: Load a policy type: 1, shall fail ==="
95 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
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
101 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
103 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
105 echo "=== Set force response code 401. ==="
107 do_curl POST '/forceresponse?code=401' 200
109 echo "=== API: Get policy type 1. Shall fail with forced code ==="
111 do_curl GET '/a1-p/policytypes/1' 401
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
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
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
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
129 echo "=== Get policy type ids, shall contain type 1 and 2 =="
130 RESULT="json:[\"1\", \"2\"]"
131 do_curl GET /policytypes 200
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
137 echo "=== Delete policy type: 2 ==="
139 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt1.json
141 echo "=== API: Get policy type ids, shall contain type 1 =="
142 RESULT="json:[ \"1\" ]"
143 do_curl GET /a1-p/policytypes 200
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
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
153 echo "=== API: Get instances for type 2, shall be empty ==="
155 do_curl GET '/a1-p/policytypes/2/policies' 200
157 echo "=== API: Create policy instance pi1 of type: 2, shall fail==="
159 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
161 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
163 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
165 echo "=== API: Create policy instance pi2 of type: 2 ==="
167 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
169 echo "=== API: Update policy instance pi2 of type: 2 ==="
171 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
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
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
181 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
183 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
185 echo "=== Set force response code 401. ==="
187 do_curl POST '/forceresponse?code=401' 200
189 echo "=== API: Get policy status for pi1, shall fail ==="
191 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
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
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
201 echo "=== Reset force delay. ==="
202 RESULT="Force delay: None sec set for all A1 responses"
203 do_curl POST '/forcedelay' 200
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
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
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
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
221 echo "=== Get counter: instances ==="
223 do_curl GET '/counter/num_instances' 200
225 echo "=== Get counter: types ==="
227 do_curl GET '/counter/num_types' 200
229 echo "=== Get counter: interface ==="
231 do_curl GET '/counter/interface' 200
233 echo "=== DELETE policy pi1 ==="
235 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
237 echo "=== API: Get instances for type 1, shall be empty ==="
239 do_curl GET /a1-p/policytypes/1/policies 200
241 echo "=== API: Get instances for type 2, shall contain pi2 ==="
243 do_curl GET /a1-p/policytypes/2/policies 200
245 echo "=== Get counter: instances ==="
247 do_curl GET /counter/num_instances 200
249 echo "********************"
250 echo "*** All tests ok ***"
251 echo "********************"