ef7014daa2718ba0f04e92f9fd8b9bb1f47fa7b0
[sim/a1-interface.git] / near-rt-ric-simulator / test / KAFKA_DISPATCHER_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 Kafka message dispatcher.
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=7075
38     # Set http protocol
39     HTTPX="http"
40 else
41     #Default https port for the simulator
42     PORT=7175
43     # Set https protocol
44     HTTPX="https"
45 fi
46
47 . ../common/test_common.sh
48 . ../common/elapse_time_curl.sh
49
50 echo "=== Kafka message dispatcher hello world ==="
51 RESULT="OK"
52 do_curl GET / 200
53
54 echo "=== Reset force delay ==="
55 RESULT="Force delay has been resetted for all dispatcher responses"
56 do_curl POST /dispatcheradmin/forcedelay 200
57
58 echo "=== API: Get policy type to topic mapping of type: ANR ==="
59 res=$(cat jsonfiles/ANR_to_topic_map.json)
60 RESULT="json:$res"
61 do_curl GET /policytypetotopicmapping/ANR 200
62
63 echo "=== Put policy: shall publish and consume for put policy operation ==="
64 RESULT=""
65 do_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
66
67 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
68 RESULT=""
69 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json
70
71 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
72 RESULT=""
73 do_curl PUT  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
74
75 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
76 RESULT=""
77 do_curl DELETE  /policytypes/STD_1/kafkadispatcher/alpha 200
78
79 echo "=== Set force delay 5 sec ==="
80 RESULT="Force delay: 5 sec set for all dispatcher responses until it is resetted"
81 do_curl POST '/dispatcheradmin/forcedelay?delay=5' 200
82
83 echo "=== Put policy: shall wait at least <delay-time> sec and then respond while publishing and consuming ==="
84 RESULT=""
85 do_elapsetime_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json 5
86
87 echo "=== Reset force delay ==="
88 RESULT="Force delay has been resetted for all dispatcher responses"
89 do_curl POST /dispatcheradmin/forcedelay 200
90
91 echo "=== Put policy: shall publish and consume for put policy operation for beta ==="
92 RESULT=""
93 do_curl PUT  /policytypes/STD_1/kafkadispatcher/beta 200 jsonfiles/beta_policy.json
94
95 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
96 RESULT=""
97 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/beta_policy.json
98
99 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
100 RESULT=""
101 do_curl PUT  /policytypes/STD_2/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
102
103 echo "=== Set force response code: 500 ==="
104 RESULT="Force response code: 500 set for all dispatcher response until it is resetted"
105 do_curl POST  '/dispatcheradmin/forceresponse?code=500' 200
106
107 echo "=== Put policy: shall not publish and consume for put policy operation for alpha ==="
108 res=$(cat jsonfiles/forced_response.json)
109 RESULT="json:$res"
110 do_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 500 jsonfiles/alpha_policy.json
111
112 echo "=== Reset force response code ==="
113 RESULT="Force response code has been resetted for dispatcher responses"
114 do_curl POST  /dispatcheradmin/forceresponse 200
115
116 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
117 RESULT=""
118 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json
119
120 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
121 RESULT=""
122 do_curl DELETE  /policytypes/STD_1/kafkadispatcher/alpha 200
123
124 echo "********************"
125 echo "*** All tests ok ***"
126 echo "********************"