blob: 13ea3a60744e6fb432d8bcb22b7b7abe0fe22ef4 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/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 mrstub container
21
22# mr-stub port
23export PORT=3905
24
25# source function to do curl and check result
26. ../common/do_curl_function.sh
27
28echo "=== Stub hello world ==="
29RESULT="OK"
30do_curl GET / 200
31
32echo "=== Stub reset ==="
33RESULT="OK"
34do_curl GET /reset 200
35
36## Test with json response
37
38echo "=== Send a request ==="
39RESULT="*"
40#create payload
41echo "{\"data\": \"data-value\"}" > .tmp.json
42
43do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json
44#Save id for later
45CORRID=$body
46
47echo "=== Fetch a response, shall be empty ==="
48RESULT=""
49do_curl GET '/receive-response?correlationid='$CORRID 204
50
51echo "=== Fetch a request ==="
52RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]"
53do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
54
55echo "=== Send a json response ==="
56# Create minimal accepted response message
57echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json
58RESULT="OK"
59do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
60
61echo "=== Fetch a response ==="
62RESULT="{\"test\": \"testresponse\"}200"
63do_curl GET '/receive-response?correlationid='$CORRID 200
64
65### Test with plain text response
66
67echo "=== Send a request ==="
68RESULT="*"
69do_curl POST '/send-request?operation=GET&url=/test2' 200
70#Save id for later
71CORRID=$body
72
73echo "=== Fetch a response, shall be empty ==="
74RESULT=""
75do_curl GET '/receive-response?correlationid='$CORRID 204
76
77echo "=== Fetch a request ==="
78RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]"
79do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
80
81echo "=== Send a json response ==="
82# Create minimal accepted response message
83echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json
84RESULT="OK"
85do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
86
87echo "=== Fetch a response ==="
88RESULT="test2-response200"
89do_curl GET '/receive-response?correlationid='$CORRID 200
90
91echo "********************"
92echo "*** All tests ok ***"
93echo "********************"