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
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 # Script for basic test of the simulator.
21 # Run the build_and_start with the same arg, except arg 'nonsecure|secure', as this script
24 echo "Usage: ./basic_test.sh nonsecure|secure "
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
35 if [ $1 == "nonsecure" ]; then
36 #Default http port for the simulator
41 #Default https port for the simulator
47 . ../common/test_common.sh
48 . ../common/elapse_time_curl.sh
50 echo "=== External server hello world ==="
54 echo "=== Reset external server a1policy instances ==="
55 RESULT="All a1 policy instances deleted"
56 do_curl POST /serveradmin/deleteinstances 200
58 echo "=== Reset force delay ==="
59 RESULT="Force delay has been resetted for all external server responses"
60 do_curl POST /serveradmin/forcedelay 200
62 echo "=== Put an a1 policy: alpha ==="
63 res=$(cat jsonfiles/alpha_policy.json)
65 do_curl PUT /a1policy/alpha 201 jsonfiles/alpha_policy.json
67 echo "=== Get an a1 policy: alpha ==="
68 res=$(cat jsonfiles/alpha_policy.json)
70 do_curl GET /a1policy/alpha 200
72 echo "=== Put an a1 policy alpha to update ==="
73 res=$(cat jsonfiles/alpha_policy.json)
75 do_curl PUT /a1policy/alpha 200 jsonfiles/alpha_policy.json
77 echo "=== API: Get a1 policy ids, shall contain a1policy alpha ==="
78 RESULT="json:[\"alpha\"]"
79 do_curl GET /a1policies 200
81 echo "=== Delete an a1 policy: alpha ==="
83 do_curl DELETE /a1policy/alpha 204
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
89 echo "=== API: Get a1 policies, shall be empty ==="
91 do_curl GET /a1policies 200
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
97 echo "=== API: Get a1 policies, should respond after 5 seconds later ==="
99 do_curl GET /a1policies 200
101 echo "=== API: Get A1 policy ids, shall wait at least <delay-time> sec and then respond ==="
103 do_elapsetime_curl GET /a1policies 200 5
105 echo "=== Reset force delay ==="
106 RESULT="Force delay has been resetted for all external server responses"
107 do_curl POST /serveradmin/forcedelay 200
109 echo "=== Put an a1 policy: beta ==="
110 res=$(cat jsonfiles/beta_policy.json)
112 do_curl PUT /a1policy/beta 201 jsonfiles/beta_policy.json
114 echo "=== Put an a1 policy: alpha ==="
115 res=$(cat jsonfiles/alpha_policy.json)
117 do_curl PUT /a1policy/alpha 201 jsonfiles/alpha_policy.json
119 echo "=== API: Get a1 policy ids, shall contain a1policy beta and alpha ==="
120 RESULT="json:[\"beta\", \"alpha\"]"
121 do_curl GET /a1policies 200
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
127 echo "=== API: Get a1 policies, shall return reponse code 500 =="
128 res=$(cat jsonfiles/forced_response.json)
130 do_curl GET /a1policies 500
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
136 echo "=== Delete an a1policy: alpha ==="
138 do_curl DELETE /a1policy/alpha 204
140 echo "=== API: Get a1policy ids, shall contain a1 policy beta ==="
141 RESULT="json:[\"beta\"]"
142 do_curl GET /a1policies 200
144 echo "********************"
145 echo "*** All tests ok ***"
146 echo "********************"