Callout hooks towards external server for create and delete operations
[sim/a1-interface.git] / near-rt-ric-simulator / test / EXT_SRV_TEST / basic_test.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2022 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, except arg 'nonsecure|secure', as this script
22
23 print_usage() {
24     echo "Usage: ./basic_test.sh nonsecure|secure "
25     exit 1
26 }
27
28 if [ $# -ne 1 ]; then
29     print_usage
30 fi
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
32     print_usage
33 fi
34
35 if [ $1 == "nonsecure" ]; then
36     #Default http port for the simulator
37     PORT=9095
38     # Set http protocol
39     HTTPX="http"
40 else
41     #Default https port for the simulator
42     PORT=9195
43     # Set https protocol
44     HTTPX="https"
45 fi
46
47 . ../common/test_common.sh
48 . ../common/elapse_time_curl.sh
49
50 echo "=== External server hello world ==="
51 RESULT="OK"
52 do_curl GET / 200
53
54 echo "=== Reset external server a1policy instances ==="
55 RESULT="All a1 policy instances deleted"
56 do_curl POST /serveradmin/deleteinstances 200
57
58 echo "=== Reset force delay ==="
59 RESULT="Force delay has been resetted for all external server responses"
60 do_curl POST /serveradmin/forcedelay 200
61
62 echo "=== Put an a1 policy: alpha ==="
63 res=$(cat jsonfiles/alpha_policy.json)
64 RESULT="json:$res"
65 do_curl PUT  /a1policy/alpha 201 jsonfiles/alpha_policy.json
66
67 echo "=== Get an a1 policy: alpha ==="
68 res=$(cat jsonfiles/alpha_policy.json)
69 RESULT="json:$res"
70 do_curl GET /a1policy/alpha 200
71
72 echo "=== Put an a1 policy alpha to update ==="
73 res=$(cat jsonfiles/alpha_policy.json)
74 RESULT="json:$res"
75 do_curl PUT  /a1policy/alpha 200 jsonfiles/alpha_policy.json
76
77 echo "=== API: Get a1 policy ids, shall contain a1policy alpha ==="
78 RESULT="json:[\"alpha\"]"
79 do_curl GET /a1policies 200
80
81 echo "=== Delete an a1 policy: alpha ==="
82 RESULT=""
83 do_curl DELETE  /a1policy/alpha 204
84
85 echo "=== Get an a1 policy: alpha, A1 policy instance not found ==="
86 RESULT="json:{\"title\": \"The A1 policy requested does not exist.\", \"status\": 404, \"instance\": \"alpha\"}"
87 do_curl GET /a1policy/alpha 404
88
89 echo "=== API: Get a1 policies, shall be empty ==="
90 RESULT="json:[]"
91 do_curl GET  /a1policies 200
92
93 echo "=== Set force delay 5 sec ==="
94 RESULT="Force delay: 5 sec set for all external server responses until it is resetted"
95 do_curl POST '/serveradmin/forcedelay?delay=5' 200
96
97 echo "=== API: Get a1 policies, should respond after 5 seconds later ==="
98 RESULT="json:[]"
99 do_curl GET  /a1policies 200
100
101 echo "=== API: Get A1 policy ids, shall wait at least <delay-time> sec and then respond ==="
102 RESULT="json:[]"
103 do_elapsetime_curl GET  /a1policies 200 5
104
105 echo "=== Reset force delay ==="
106 RESULT="Force delay has been resetted for all external server responses"
107 do_curl POST /serveradmin/forcedelay 200
108
109 echo "=== Put an a1 policy: beta ==="
110 res=$(cat jsonfiles/beta_policy.json)
111 RESULT="json:$res"
112 do_curl PUT  /a1policy/beta 201 jsonfiles/beta_policy.json
113
114 echo "=== Put an a1 policy: alpha ==="
115 res=$(cat jsonfiles/alpha_policy.json)
116 RESULT="json:$res"
117 do_curl PUT  /a1policy/alpha 201 jsonfiles/alpha_policy.json
118
119 echo "=== API: Get a1 policy ids, shall contain a1policy beta and alpha ==="
120 RESULT="json:[\"beta\", \"alpha\"]"
121 do_curl GET /a1policies 200
122
123 echo "=== Set force response code: 500 ==="
124 RESULT="Force response code: 500 set for all external server response until it is resetted"
125 do_curl POST  '/serveradmin/forceresponse?code=500' 200
126
127 echo "=== API: Get a1 policies, shall return reponse code 500 =="
128 res=$(cat jsonfiles/forced_response.json)
129 RESULT="json:$res"
130 do_curl GET  /a1policies 500
131
132 echo "=== Reset force response code ==="
133 RESULT="Force response code has been resetted for all external server responses"
134 do_curl POST  /serveradmin/forceresponse 200
135
136 echo "=== Delete an a1policy: alpha ==="
137 RESULT=""
138 do_curl DELETE  /a1policy/alpha 204
139
140 echo "=== API: Get a1policy ids, shall contain a1 policy beta ==="
141 RESULT="json:[\"beta\"]"
142 do_curl GET /a1policies 200
143
144 echo "********************"
145 echo "*** All tests ok ***"
146 echo "********************"