blob: 18b7735838340518df2e157a10b1bcf7ac347c2d [file] [log] [blame]
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001#!/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
22if [ $# -ne 1 ]; then
23 echo "Usage: ./basic_test.sh nonsecure|secure"
24 exit 1
25fi
26if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27 echo "Usage: ./basic_test.sh nonsecure|secure"
28 exit 1
29fi
30
31if [ $1 == "nonsecure" ]; then
32 #Default http port for the simulator
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020033 PORT=8992
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020034 # Set http protocol
35 HTTPX="http"
36else
37 #Default https port for the simulator
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020038 PORT=8993
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020039 # Set https protocol
40 HTTPX="https"
41fi
42
43# source function to do curl and check result
44. ../common/do_curl_function.sh
45
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020046echo "=== hello world ==="
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020047RESULT="OK"
48do_curl GET / 200
49
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020050echo "=== reset ==="
51RESULT=""
52do_curl GET /reset 200
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020053
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +020054echo "=== status ==="
55RESULT="json:{}"
56do_curl GET /status 200
57
58# Basic admin
59
60echo "=== check supervision counter ==="
61RESULT="-1"
62do_curl GET /counter/supervision/prod-x 200
63
64echo "=== check create counter ==="
65RESULT="-1"
66do_curl GET /counter/create/prod-x/job-x 200
67
68echo "=== check delete counter ==="
69RESULT="-1"
70do_curl GET /counter/delete/prod-x/job-x 200
71
72## Create/update a producer
73
74echo "=== create producer ==="
75RESULT="Unknown query parameter(s)"
76do_curl PUT /arm/supervision/prod-x?test=201 400
77
78echo "=== create producer ==="
79RESULT=""
80do_curl PUT /arm/supervision/prod-x?response=201 200
81
82echo "=== update producer ==="
83RESULT=""
84do_curl PUT /arm/supervision/prod-x?response=400 200
85
86echo "=== update producer ==="
87RESULT=""
88do_curl PUT /arm/supervision/prod-x 200
89
90## Add types to a producere
91
92echo "=== add type 10 ==="
93RESULT=""
94do_curl PUT /arm/type/prod-x/10 200
95
96echo "=== add type 15 ==="
97RESULT=""
98do_curl PUT /arm/type/prod-x/15 200
99
100## check the db
101
102echo "=== status ==="
103RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
104do_curl GET /status 200
105
106## Add type
107echo "=== add type 20 ==="
108RESULT=""
109do_curl PUT /arm/type/prod-x/20 200
110
111echo "=== status ==="
112RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\", \"20\"]}}"
113do_curl GET /status 200
114
115## remove type
116echo "=== remove type 20 ==="
117RESULT=""
118do_curl DELETE /arm/type/prod-x/20 200
119
120echo "=== status ==="
121RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
122do_curl GET /status 200
123
124## producer supervision
125echo "=== check supervision counter ==="
126RESULT="0"
127do_curl GET /counter/supervision/prod-x 200
128
129echo "=== supervision producer ==="
130RESULT=""
131do_curl GET /callbacks/supervision/prod-x 200
132
133echo "=== update producer ==="
134RESULT=""
135do_curl PUT /arm/supervision/prod-x?response=400 200
136
137echo "=== callback supervision producer ==="
138RESULT="returning configured response code"
139do_curl GET /callbacks/supervision/prod-x 400
140
141## check the db
142
143echo "=== status ==="
144RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"]}}"
145do_curl GET /status 200
146
147## create/update job
148
149echo "=== add job ==="
150RESULT=""
151do_curl PUT /arm/create/prod-x/job-y 200
152
153echo "=== update job ==="
154RESULT=""
155do_curl PUT /arm/create/prod-x/job-y?response=405 200
156
157## check the db
158
159echo "=== status ==="
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100160RESULT="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}}}"
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200161do_curl GET /status 200
162
163## add delete response for job
164
165echo "=== update job ==="
166RESULT=""
167do_curl PUT /arm/delete/prod-x/job-y?response=407 200
168
169## check the db
170
171echo "=== status ==="
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100172RESULT="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}}}"
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200173do_curl GET /status 200
174
175## Get jobdata
176echo "=== job data ==="
177RESULT=""
178do_curl GET /jobdata/prod-x/job-y 204
179
180## callback create
181
182echo "=== add job ==="
183RESULT=""
184do_curl PUT /arm/create/prod-x/job-1 200
185RESULT=""
186do_curl PUT /arm/delete/prod-x/job-1 200
187
188echo "=== callback create job ==="
189RESULT=""
190echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100191do_curl POST /callbacks/job/prod-x 201 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200192
193echo "=== callback create job -update ==="
194RESULT=""
195echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100196do_curl POST /callbacks/job/prod-x 200 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200197
198## Get jobdata
199echo "=== job data ==="
200RESULT="json:{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}"
201do_curl GET /jobdata/prod-x/job-1 200
202
203## check the db
204
205echo "=== status ==="
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100206RESULT="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}}}"
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200207do_curl GET /status 200
208
209# create and delete job tests
210echo "=== set job create response ==="
211RESULT=""
212do_curl PUT /arm/create/prod-x/job-1?response=404 200
213
214echo "=== callback create job -update ==="
215RESULT="returning configured response code"
216echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100217do_curl POST /callbacks/job/prod-x 404 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200218
219echo "=== set job delete response ==="
220RESULT=""
221do_curl PUT /arm/delete/prod-x/job-1?response=404 200
222
223echo "=== callback delete job==="
224RESULT="returning configured response code"
225echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100226do_curl DELETE /callbacks/job/prod-x/job-1 404 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200227
228echo "=== set job delete response ==="
229RESULT=""
230do_curl PUT /arm/delete/prod-x/job-1 200
231
232echo "=== callback delete job==="
233RESULT=""
234echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100235do_curl DELETE /callbacks/job/prod-x/job-1 204 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200236
237## check the db
238
239echo "=== status ==="
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100240RESULT="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}}}"
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200241do_curl GET /status 200
242
243
244## data delivery
245
246echo "=== update producer ==="
247RESULT=""
248do_curl PUT /arm/create/prod-x/job-1 200
249
250echo "=== callback create job ==="
251RESULT=""
252echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100253do_curl POST /callbacks/job/prod-x 201 .p.json
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200254
255echo "=== data delivery start ==="
256RESULT="job not found"
257do_curl POST /jobdata/prod-x/job-x?action=START 404
258
259echo "=== data delivery start ==="
260RESULT=""
261do_curl POST /jobdata/prod-x/job-1?action=START 200
262
263echo "sleep 5"
264sleep 5
265
266echo "=== data delivery stop ==="
267RESULT=""
268do_curl POST /jobdata/prod-x/job-1?action=STOP 200
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200269
270echo "********************"
271echo "*** All tests ok ***"
272echo "********************"