BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [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 producer stub container |
| 21 | |
| 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 |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 33 | PORT=8992 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 34 | # Set http protocol |
| 35 | HTTPX="http" |
| 36 | else |
| 37 | #Default https port for the simulator |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 38 | PORT=8993 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 39 | # Set https protocol |
| 40 | HTTPX="https" |
| 41 | fi |
| 42 | |
| 43 | # source function to do curl and check result |
| 44 | . ../common/do_curl_function.sh |
| 45 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 46 | echo "=== hello world ===" |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 47 | RESULT="OK" |
| 48 | do_curl GET / 200 |
| 49 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 50 | echo "=== reset ===" |
| 51 | RESULT="" |
| 52 | do_curl GET /reset 200 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 53 | |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 54 | echo "=== status ===" |
| 55 | RESULT="json:{}" |
| 56 | do_curl GET /status 200 |
| 57 | |
| 58 | # Basic admin |
| 59 | |
| 60 | echo "=== check supervision counter ===" |
| 61 | RESULT="-1" |
| 62 | do_curl GET /counter/supervision/prod-x 200 |
| 63 | |
| 64 | echo "=== check create counter ===" |
| 65 | RESULT="-1" |
| 66 | do_curl GET /counter/create/prod-x/job-x 200 |
| 67 | |
| 68 | echo "=== check delete counter ===" |
| 69 | RESULT="-1" |
| 70 | do_curl GET /counter/delete/prod-x/job-x 200 |
| 71 | |
| 72 | ## Create/update a producer |
| 73 | |
| 74 | echo "=== create producer ===" |
| 75 | RESULT="Unknown query parameter(s)" |
| 76 | do_curl PUT /arm/supervision/prod-x?test=201 400 |
| 77 | |
| 78 | echo "=== create producer ===" |
| 79 | RESULT="" |
| 80 | do_curl PUT /arm/supervision/prod-x?response=201 200 |
| 81 | |
| 82 | echo "=== update producer ===" |
| 83 | RESULT="" |
| 84 | do_curl PUT /arm/supervision/prod-x?response=400 200 |
| 85 | |
| 86 | echo "=== update producer ===" |
| 87 | RESULT="" |
| 88 | do_curl PUT /arm/supervision/prod-x 200 |
| 89 | |
| 90 | ## Add types to a producere |
| 91 | |
| 92 | echo "=== add type 10 ===" |
| 93 | RESULT="" |
| 94 | do_curl PUT /arm/type/prod-x/10 200 |
| 95 | |
| 96 | echo "=== add type 15 ===" |
| 97 | RESULT="" |
| 98 | do_curl PUT /arm/type/prod-x/15 200 |
| 99 | |
| 100 | ## check the db |
| 101 | |
| 102 | echo "=== status ===" |
| 103 | RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}" |
| 104 | do_curl GET /status 200 |
| 105 | |
| 106 | ## Add type |
| 107 | echo "=== add type 20 ===" |
| 108 | RESULT="" |
| 109 | do_curl PUT /arm/type/prod-x/20 200 |
| 110 | |
| 111 | echo "=== status ===" |
| 112 | RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\", \"20\"]}}" |
| 113 | do_curl GET /status 200 |
| 114 | |
| 115 | ## remove type |
| 116 | echo "=== remove type 20 ===" |
| 117 | RESULT="" |
| 118 | do_curl DELETE /arm/type/prod-x/20 200 |
| 119 | |
| 120 | echo "=== status ===" |
| 121 | RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}" |
| 122 | do_curl GET /status 200 |
| 123 | |
| 124 | ## producer supervision |
| 125 | echo "=== check supervision counter ===" |
| 126 | RESULT="0" |
| 127 | do_curl GET /counter/supervision/prod-x 200 |
| 128 | |
| 129 | echo "=== supervision producer ===" |
| 130 | RESULT="" |
| 131 | do_curl GET /callbacks/supervision/prod-x 200 |
| 132 | |
| 133 | echo "=== update producer ===" |
| 134 | RESULT="" |
| 135 | do_curl PUT /arm/supervision/prod-x?response=400 200 |
| 136 | |
| 137 | echo "=== callback supervision producer ===" |
| 138 | RESULT="returning configured response code" |
| 139 | do_curl GET /callbacks/supervision/prod-x 400 |
| 140 | |
| 141 | ## check the db |
| 142 | |
| 143 | echo "=== status ===" |
| 144 | RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"]}}" |
| 145 | do_curl GET /status 200 |
| 146 | |
| 147 | ## create/update job |
| 148 | |
| 149 | echo "=== add job ===" |
| 150 | RESULT="" |
| 151 | do_curl PUT /arm/create/prod-x/job-y 200 |
| 152 | |
| 153 | echo "=== update job ===" |
| 154 | RESULT="" |
| 155 | do_curl PUT /arm/create/prod-x/job-y?response=405 200 |
| 156 | |
| 157 | ## check the db |
| 158 | |
| 159 | echo "=== status ===" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 160 | RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 404, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 161 | do_curl GET /status 200 |
| 162 | |
| 163 | ## add delete response for job |
| 164 | |
| 165 | echo "=== update job ===" |
| 166 | RESULT="" |
| 167 | do_curl PUT /arm/delete/prod-x/job-y?response=407 200 |
| 168 | |
| 169 | ## check the db |
| 170 | |
| 171 | echo "=== status ===" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 172 | RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 173 | do_curl GET /status 200 |
| 174 | |
| 175 | ## Get jobdata |
| 176 | echo "=== job data ===" |
| 177 | RESULT="" |
| 178 | do_curl GET /jobdata/prod-x/job-y 204 |
| 179 | |
| 180 | ## callback create |
| 181 | |
| 182 | echo "=== add job ===" |
| 183 | RESULT="" |
| 184 | do_curl PUT /arm/create/prod-x/job-1 200 |
| 185 | RESULT="" |
| 186 | do_curl PUT /arm/delete/prod-x/job-1 200 |
| 187 | |
| 188 | echo "=== callback create job ===" |
| 189 | RESULT="" |
| 190 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 191 | do_curl POST /callbacks/job/prod-x 201 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 192 | |
| 193 | echo "=== callback create job -update ===" |
| 194 | RESULT="" |
| 195 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 196 | do_curl POST /callbacks/job/prod-x 200 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 197 | |
| 198 | ## Get jobdata |
| 199 | echo "=== job data ===" |
| 200 | RESULT="json:{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}" |
| 201 | do_curl GET /jobdata/prod-x/job-1 200 |
| 202 | |
| 203 | ## check the db |
| 204 | |
| 205 | echo "=== status ===" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 206 | RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 200, \"delete_response\": 204, \"json\": {\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}, \"create_counter\": 2, \"delete_counter\": 0, \"delivering\": \"delivering\", \"delivery_attempts\": 0}}}" |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 207 | do_curl GET /status 200 |
| 208 | |
| 209 | # create and delete job tests |
| 210 | echo "=== set job create response ===" |
| 211 | RESULT="" |
| 212 | do_curl PUT /arm/create/prod-x/job-1?response=404 200 |
| 213 | |
| 214 | echo "=== callback create job -update ===" |
| 215 | RESULT="returning configured response code" |
| 216 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 217 | do_curl POST /callbacks/job/prod-x 404 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 218 | |
| 219 | echo "=== set job delete response ===" |
| 220 | RESULT="" |
| 221 | do_curl PUT /arm/delete/prod-x/job-1?response=404 200 |
| 222 | |
| 223 | echo "=== callback delete job===" |
| 224 | RESULT="returning configured response code" |
| 225 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 226 | do_curl DELETE /callbacks/job/prod-x/job-1 404 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 227 | |
| 228 | echo "=== set job delete response ===" |
| 229 | RESULT="" |
| 230 | do_curl PUT /arm/delete/prod-x/job-1 200 |
| 231 | |
| 232 | echo "=== callback delete job===" |
| 233 | RESULT="" |
| 234 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 235 | do_curl DELETE /callbacks/job/prod-x/job-1 204 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 236 | |
| 237 | ## check the db |
| 238 | |
| 239 | echo "=== status ===" |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 240 | RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 404, \"delete_response\": 404, \"json\": null, \"create_counter\": 3, \"delete_counter\": 2, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}" |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 241 | do_curl GET /status 200 |
| 242 | |
| 243 | |
| 244 | ## data delivery |
| 245 | |
| 246 | echo "=== update producer ===" |
| 247 | RESULT="" |
| 248 | do_curl PUT /arm/create/prod-x/job-1 200 |
| 249 | |
| 250 | echo "=== callback create job ===" |
| 251 | RESULT="" |
| 252 | echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json |
BjornMagnussonXA | 7b36db6 | 2020-11-23 10:57:57 +0100 | [diff] [blame] | 253 | do_curl POST /callbacks/job/prod-x 201 .p.json |
BjornMagnussonXA | 39ad50e | 2020-10-22 09:55:25 +0200 | [diff] [blame] | 254 | |
| 255 | echo "=== data delivery start ===" |
| 256 | RESULT="job not found" |
| 257 | do_curl POST /jobdata/prod-x/job-x?action=START 404 |
| 258 | |
| 259 | echo "=== data delivery start ===" |
| 260 | RESULT="" |
| 261 | do_curl POST /jobdata/prod-x/job-1?action=START 200 |
| 262 | |
| 263 | echo "sleep 5" |
| 264 | sleep 5 |
| 265 | |
| 266 | echo "=== data delivery stop ===" |
| 267 | RESULT="" |
| 268 | do_curl POST /jobdata/prod-x/job-1?action=STOP 200 |
BjornMagnussonXA | f38e1e8 | 2020-10-11 23:05:02 +0200 | [diff] [blame] | 269 | |
| 270 | echo "********************" |
| 271 | echo "*** All tests ok ***" |
| 272 | echo "********************" |