BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 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 | # Automated test script for callback receiver container |
| 21 | |
| 22 | # callbackreciver port |
ecaiyanlinux | 113bf09 | 2020-08-01 14:05:17 +0000 | [diff] [blame] | 23 | # export PORT=8090 |
| 24 | if [ $# -ne 1 ]; then |
| 25 | echo "Usage: ./basic_test.sh nonsecure|secure" |
| 26 | exit 1 |
| 27 | fi |
| 28 | if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then |
| 29 | echo "Usage: ./basic_test.sh nonsecure|secure" |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | if [ $1 == "nonsecure" ]; then |
| 34 | #Default http port for the simulator |
| 35 | PORT=8090 |
| 36 | # Set http protocol |
| 37 | HTTPX="http" |
| 38 | else |
| 39 | #Default https port for the simulator |
| 40 | PORT=8091 |
| 41 | # Set https protocol |
| 42 | HTTPX="https" |
| 43 | fi |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 44 | |
| 45 | # source function to do curl and check result |
| 46 | . ../common/do_curl_function.sh |
| 47 | |
| 48 | echo "=== CR hello world ===" |
| 49 | RESULT="OK" |
| 50 | do_curl GET / 200 |
| 51 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 52 | echo "=== Reset ===" |
| 53 | RESULT="*" |
| 54 | do_curl POST /reset 200 |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 55 | |
| 56 | echo "=== Get counter - callbacks ===" |
| 57 | RESULT="0" |
| 58 | do_curl GET /counter/received_callbacks 200 |
| 59 | |
| 60 | echo "=== Get counter - fetched events ===" |
| 61 | RESULT="0" |
| 62 | do_curl GET /counter/fetched_callbacks 200 |
| 63 | |
| 64 | echo "=== Get counter - current events ===" |
| 65 | RESULT="0" |
| 66 | do_curl GET /counter/current_messages 200 |
| 67 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 68 | echo "=== Send a request non json ===" |
| 69 | RESULT="*" |
| 70 | #create payload |
| 71 | echo "DATA" > .tmp.json |
| 72 | do_curl POST '/callbacks/test' 200 .tmp.json |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 73 | |
| 74 | echo "=== Send a request ===" |
| 75 | RESULT="*" |
| 76 | #create payload |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 77 | echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 78 | do_curl POST '/callbacks/test' 200 .tmp.json |
| 79 | |
| 80 | |
| 81 | echo "=== Fetch an event, wrong id===" |
| 82 | RESULT="*" |
| 83 | do_curl GET '/get-event/wrongid' 204 |
| 84 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 85 | # Test counters for all ids |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 86 | echo "=== Get counter - callbacks ===" |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 87 | RESULT="2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 88 | do_curl GET /counter/received_callbacks 200 |
| 89 | |
| 90 | echo "=== Get counter - fetched events ===" |
| 91 | RESULT="0" |
| 92 | do_curl GET /counter/fetched_callbacks 200 |
| 93 | |
| 94 | echo "=== Get counter - current events ===" |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 95 | RESULT="2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 96 | do_curl GET /counter/current_messages 200 |
| 97 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 98 | # Test counter for one id |
| 99 | echo "=== Get counter - callbacks ===" |
| 100 | RESULT="2" |
| 101 | do_curl GET /counter/received_callbacks?id=test 200 |
| 102 | |
| 103 | echo "=== Get counter - fetched events ===" |
| 104 | RESULT="0" |
| 105 | do_curl GET /counter/fetched_callbacks?id=test 200 |
| 106 | |
| 107 | echo "=== Get counter - current events ===" |
| 108 | RESULT="2" |
| 109 | do_curl GET /counter/current_messages?id=test 200 |
| 110 | |
| 111 | # Test counter for dummy id |
| 112 | echo "=== Get counter - callbacks ===" |
| 113 | RESULT="0" |
| 114 | do_curl GET /counter/received_callbacks?id=dummy 200 |
| 115 | |
| 116 | echo "=== Get counter - fetched events ===" |
| 117 | RESULT="0" |
| 118 | do_curl GET /counter/fetched_callbacks?id=dummy 200 |
| 119 | |
| 120 | echo "=== Get counter - current events ===" |
| 121 | RESULT="0" |
| 122 | do_curl GET /counter/current_messages?id=dummy 200 |
| 123 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 124 | |
| 125 | echo "=== Fetch an event ===" |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 126 | RESULT="json:{}" |
| 127 | do_curl GET '/get-event/test' 200 |
| 128 | |
| 129 | echo "=== Fetch an event ===" |
| 130 | RESULT="json:{\"DATA-MSG\":\"msg\"}" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 131 | do_curl GET '/get-event/test' 200 |
| 132 | |
| 133 | echo "=== Fetch an event again ===" |
| 134 | RESULT="*" |
| 135 | do_curl GET '/get-event/test' 204 |
| 136 | |
| 137 | echo "=== Get counter - callbacks ===" |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 138 | RESULT="2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 139 | do_curl GET /counter/received_callbacks 200 |
| 140 | |
| 141 | echo "=== Get counter - fetched events ===" |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 142 | RESULT="2" |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 143 | do_curl GET /counter/fetched_callbacks 200 |
| 144 | |
| 145 | echo "=== Get counter - current events ===" |
| 146 | RESULT="0" |
| 147 | do_curl GET /counter/current_messages 200 |
| 148 | |
BjornMagnussonXA | 49f0e5a | 2020-11-08 22:41:39 +0100 | [diff] [blame] | 149 | # Test counter for one id |
| 150 | echo "=== Get counter - callbacks ===" |
| 151 | RESULT="2" |
| 152 | do_curl GET /counter/received_callbacks?id=test 200 |
| 153 | |
| 154 | echo "=== Get counter - fetched events ===" |
| 155 | RESULT="2" |
| 156 | do_curl GET /counter/fetched_callbacks?id=test 200 |
| 157 | |
| 158 | echo "=== Get counter - current events ===" |
| 159 | RESULT="0" |
| 160 | do_curl GET /counter/current_messages?id=test 200 |
| 161 | |
| 162 | echo "=== Send a request ===" |
| 163 | RESULT="*" |
| 164 | #create payload |
| 165 | echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json |
| 166 | do_curl POST '/callbacks/test' 200 .tmp.json |
| 167 | |
| 168 | echo "=== Send a request ===" |
| 169 | RESULT="*" |
| 170 | #create payload |
| 171 | echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json |
| 172 | do_curl POST '/callbacks/test' 200 .tmp.json |
| 173 | |
| 174 | echo "=== Send a request ===" |
| 175 | RESULT="*" |
| 176 | #create payload |
| 177 | echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json |
| 178 | do_curl POST '/callbacks/test1' 200 .tmp.json |
| 179 | |
| 180 | echo "=== Get counter - callbacks ===" |
| 181 | RESULT="5" |
| 182 | do_curl GET /counter/received_callbacks 200 |
| 183 | |
| 184 | echo "=== Get counter - fetched events ===" |
| 185 | RESULT="2" |
| 186 | do_curl GET /counter/fetched_callbacks 200 |
| 187 | |
| 188 | echo "=== Get counter - current events ===" |
| 189 | RESULT="3" |
| 190 | do_curl GET /counter/current_messages 200 |
| 191 | |
| 192 | # Test counter for one id, test1 |
| 193 | echo "=== Get counter - callbacks ===" |
| 194 | RESULT="1" |
| 195 | do_curl GET /counter/received_callbacks?id=test1 200 |
| 196 | |
| 197 | echo "=== Get counter - fetched events ===" |
| 198 | RESULT="0" |
| 199 | do_curl GET /counter/fetched_callbacks?id=test1 200 |
| 200 | |
| 201 | echo "=== Get counter - current events ===" |
| 202 | RESULT="1" |
| 203 | do_curl GET /counter/current_messages?id=test1 200 |
| 204 | |
| 205 | echo "=== Fetch all events ===" |
| 206 | RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]" |
| 207 | do_curl GET '/get-all-events/test' 200 |
| 208 | |
| 209 | echo "=== Get counter - callbacks ===" |
| 210 | RESULT="5" |
| 211 | do_curl GET /counter/received_callbacks 200 |
| 212 | |
| 213 | echo "=== Get counter - fetched events ===" |
| 214 | RESULT="4" |
| 215 | do_curl GET /counter/fetched_callbacks 200 |
| 216 | |
| 217 | echo "=== Get counter - current events ===" |
| 218 | RESULT="1" |
| 219 | do_curl GET /counter/current_messages 200 |
| 220 | |
BjornMagnussonXA | 80a9200 | 2020-03-19 14:31:06 +0100 | [diff] [blame] | 221 | echo "=== CR reset ===" |
| 222 | RESULT="OK" |
| 223 | do_curl GET /reset 200 |
| 224 | |
| 225 | echo "=== Get counter - callbacks ===" |
| 226 | RESULT="0" |
| 227 | do_curl GET /counter/received_callbacks 200 |
| 228 | |
| 229 | echo "=== Get counter - fetched events ===" |
| 230 | RESULT="0" |
| 231 | do_curl GET /counter/fetched_callbacks 200 |
| 232 | |
| 233 | echo "=== Get counter - current events ===" |
| 234 | RESULT="0" |
| 235 | do_curl GET /counter/current_messages 200 |
| 236 | |
| 237 | |
| 238 | echo "********************" |
| 239 | echo "*** All tests ok ***" |
| 240 | echo "********************" |