A1 simulator for STD 2.0.0
[sim/a1-interface.git] / near-rt-ric-simulator / test / STD_2.0.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
46 echo "=== Simulator hello world ==="
47 RESULT="OK"
48 do_curl GET / 200
49
50 echo "=== Check used and implemented interfaces ==="
51 RESULT="Current interface: STD_2.0.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']"
52 do_curl GET /container_interfaces 200
53
54 echo "=== Reset simulator instances ==="
55 RESULT="All policy instances deleted"
56 do_curl POST /deleteinstances 200
57
58 echo "=== Reset simulator, all ==="
59 RESULT="All policy instances and types deleted"
60 do_curl POST /deleteall 200
61
62 echo "=== Get counter: interface ==="
63 RESULT="STD_2.0.0"
64 do_curl GET /counter/interface 200
65
66 echo "=== Get counter: remote hosts ==="
67 RESULT="*"
68 do_curl GET /counter/remote_hosts 200
69
70 echo "=== Get counter: intstance ==="
71 RESULT="0"
72 do_curl GET /counter/num_instances 200
73
74 echo "=== Get counter: types (shall be 0)==="
75 RESULT="0"
76 do_curl GET /counter/num_types 200
77
78 echo "=== API: Get policy types, shall be empty array =="
79 RESULT="json:[]"
80 do_curl GET /A1-P/v2/policytypes 200
81
82 echo "=== API: Get policy instances for type 1, type not found=="
83 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}"
84 do_curl GET /A1-P/v2/policytypes/1/policies 404
85
86 echo "=== API: Get policy instances, type not found=="
87 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}"
88 do_curl GET /A1-P/v2/policytypes/test/policies 404
89
90 echo "=== Put a policy type: STD_1 ==="
91 RESULT="Policy type STD_1 is OK."
92 do_curl PUT  '/policytype?id=STD_1' 201 jsonfiles/std_1.json
93
94 echo "=== Put a policy type: STD_1, again ==="
95 RESULT="Policy type STD_1 is OK."
96 do_curl PUT  '/policytype?id=STD_1' 200 jsonfiles/std_1.json
97
98 echo "=== API: Get policy type ids, shall contain type STD_1 =="
99 RESULT="json:[ \"STD_1\" ]"
100 do_curl GET /A1-P/v2/policytypes 200
101
102 echo "=== Delete a policy type: STD_1 ==="
103 RESULT=""
104 do_curl DELETE  '/policytype?id=STD_1' 204
105
106 echo "=== API: Get policy type ids, shall be empty =="
107 RESULT="json:[]"
108 do_curl GET  /A1-P/v2/policytypes 200
109
110 echo "=== Put a policy type: STD_1 ==="
111 RESULT="Policy type STD_1 is OK."
112 do_curl PUT  '/policytype?id=STD_1' 201 jsonfiles/std_1.json
113
114 echo "=== API: Get policy type ids, shall contain type STD_1 =="
115 RESULT="json:[ \"STD_1\" ]"
116 do_curl GET /A1-P/v2/policytypes 200
117
118 echo "=== Get counter: types (shall be 1)==="
119 RESULT="1"
120 do_curl GET /counter/num_types 200
121
122 echo "=== API: Get policy type: STD_1 ==="
123 res=$(cat jsonfiles/std_1.json)
124 RESULT="json:$res"
125 do_curl GET /A1-P/v2/policytypes/STD_1 200
126
127 echo "=== API: Get policy instances, shall be empty=="
128 RESULT="json:[ ]"
129 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
130
131 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
132 res=$(cat jsonfiles/pi1.json)
133 RESULT="json:$res"
134 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
135
136 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
137 res=$(cat jsonfiles/pi1.json)
138 RESULT="json:$res"
139 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
140
141 echo "=== API: Update policy instance pi1 of type: STD_1==="
142 res=$(cat jsonfiles/pi1.json)
143 RESULT="json:$res"
144 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
145
146 echo "=== API: Update policy instance pi1 of type: STD_1==="
147 res=$(cat jsonfiles/pi1_updated.json)
148 RESULT="json:$res"
149 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
150
151 echo "=== API: Duplicate policy instance pi2 of type: STD_1==="
152 res=$(cat jsonfiles/pi1_updated.json)
153 RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
154 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json
155
156 echo "=== API: Get policy instances, shall contain pi1=="
157 RESULT="json:[ \"pi1\" ]"
158 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
159
160 echo "=== Get counter: types (shall be 1)==="
161 RESULT="1"
162 do_curl GET /counter/num_types 200
163
164 echo "=== Get counter: intstance ==="
165 RESULT="1"
166 do_curl GET /counter/num_instances 200
167
168
169 echo "=== Set force response code 409. ==="
170 RESULT="*"
171 do_curl POST '/forceresponse?code=409' 200
172
173 echo "=== API: Get policy instances, shall fail with 409 =="
174 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
175 do_curl GET /A1-P/v2/policytypes/STD_1/policies 409
176
177 echo "=== API: Get policy status ==="
178 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
179 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200
180
181 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
182 res=$(cat jsonfiles/pi2.json)
183 RESULT="json:$res"
184 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
185
186 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
187 res=$(cat jsonfiles/pi2.json)
188 RESULT="json:$res"
189 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
190
191 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
192 RESULT="json:[ \"pi1\", \"pi2\" ]"
193 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
194
195 echo "=== Get counter: types (shall be 1)==="
196 RESULT="1"
197 do_curl GET /counter/num_types 200
198
199 echo "=== Get counter: intstance ==="
200 RESULT="2"
201 do_curl GET /counter/num_instances 200
202
203 echo "=== Set force delay 10. ==="
204 RESULT="Force delay: 10 sec set for all A1 responses"
205 do_curl POST '/forcedelay?delay=10' 200
206
207 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
208 RESULT="json:[ \"pi1\", \"pi2\" ]"
209 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
210
211 echo "=== Reset force delay. ==="
212 RESULT="Force delay: None sec set for all A1 responses"
213 do_curl POST /forcedelay 200
214
215 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
216 res=$(cat jsonfiles/pi1_updated.json)
217 RESULT="json:$res"
218 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
219
220 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
221 res=$(cat jsonfiles/pi2.json)
222 RESULT="json:$res"
223 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
224
225 echo "=== API: DELETE policy instance pi1 ==="
226 RESULT=""
227 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
228
229 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
230 RESULT="json:[ \"pi2\" ]"
231 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
232
233 echo "=== API: Get policy status ==="
234 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
235 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
236
237 echo "=== Set status for policy instance pi2 ==="
238 RESULT="Status set to OK for policy: pi2"
239 do_curl PUT '/status?policyid=pi2&status=OK' 200
240
241 echo "=== API: Get policy status ==="
242 RESULT="json:{\"enforceStatus\": \"OK\"}"
243 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
244
245 echo "=== Set status for policy instance pi2 ==="
246 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
247 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
248
249 echo "=== API: Get policy status ==="
250 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}"
251 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
252
253 echo "=== Send status for pi2==="
254 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
255 do_curl POST '/sendstatus?policyid=pi2' 200
256
257 echo "=== Get counter: datadelivery ==="
258 RESULT="0"
259 do_curl GET /counter/datadelivery 200
260
261 echo "=== Send data ==="
262 echo "{}" > .p.json
263 RESULT=""
264 do_curl POST /datadelivery 200 .p.json
265
266 echo "=== Get counter: datadelivery ==="
267 RESULT="1"
268 do_curl GET /counter/datadelivery 200
269
270 echo "=== Get counter: intstance ==="
271 RESULT="1"
272 do_curl GET /counter/num_instances 200
273
274 echo "=== Get counter: types (shall be 0)==="
275 RESULT="1"
276 do_curl GET /counter/num_types 200
277
278 echo "=== Get counter: interface ==="
279 RESULT="STD_2.0.0"
280 do_curl GET /counter/interface 200
281
282 echo "=== Get counter: remote hosts ==="
283 RESULT="*"
284 do_curl GET /counter/remote_hosts 200
285
286 echo "********************"
287 echo "*** All tests ok ***"
288 echo "********************"