Jenkins job testing
[nonrtric.git] / near-rt-ric-simulator / nearric-simulator / nearric-service / test / test-api.sh
1 #!/bin/bash
2
3 #Script for basic testing of the A1 simulator API
4 #Note: policy is reset before test
5
6 HOST_PORT="localhost:8080"
7
8 echo "Usage: populate.sh [<host:port>]"
9
10 HOST_PORT="localhost:8080"
11
12 if [ $# == 1 ]; then
13         echo "Setting host and port from cmd line: "$1
14         HOST_PORT=$1
15 fi
16
17 echo "======================================="
18 echo "Using host and port:" $HOST_PORT
19 echo "======================================="
20
21 echo "======================================="
22 echo "Resetting db"
23 curl 'http://'$HOST_PORT'/reset'
24 echo "======================================="
25
26 #Create a policy type
27 create_pt() {
28     PATTERN="s/XXXX/${1}/g"
29     sed $PATTERN pt-template.json > .tmp.json
30     res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
31         http_code="${res:${#res}-3}"
32     echo "Response code: " $http_code
33 }
34
35 get_pt() {
36     res=$(curl -sw "%{http_code}" --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
37     http_code="${res:${#res}-3}"
38     echo "Response code: " $http_code
39     echo "Response: " ${res:0:${#res}-3}
40 }
41
42 get_pts() {
43     res=$(curl -sw "%{http_code}" --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/')
44     http_code="${res:${#res}-3}"
45     echo "Response code: " $http_code
46     echo "Response: " ${res:0:${#res}-3}
47 }
48
49 del_pt() {
50     res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: */*'  'http://'${HOST_PORT}'/a1-p/policytypes/'$1)
51     http_code="${res:${#res}-3}"
52     echo "Response code: " $http_code  
53 }
54
55 get_pis() {
56     res=$(curl -sw "%{http_code}" --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies')
57     http_code="${res:${#res}-3}"
58     echo "Response code: " $http_code
59     echo "Response: " ${res:0:${#res}-3}
60 }
61
62 create_pi() {
63     PATTERN="s/XXXX/${2}/g"
64     sed $PATTERN pi-template.json > .tmp.json
65     res=$(curl -sw "%{http_code}" -X PUT --header 'Content-Type: application/json' --header 'Accept: */*' -d @.tmp.json 'http://'${HOST_PORT}'/a1-p/policytypes/'$1'/policies/'$2)
66     http_code="${res:${#res}-3}"
67     echo "Response code: " $http_code
68 }
69
70 get_pi() {
71     res=$(curl -sw "%{http_code}" --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
72     http_code="${res:${#res}-3}"
73     echo "Response code: " $http_code
74     echo "Response: " ${res:0:${#res}-3}
75 }
76
77 del_pi() {
78     res=$(curl -sw "%{http_code}" -X DELETE --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2)
79     http_code="${res:${#res}-3}"
80     echo "Response code: " $http_code 
81 }
82
83 stat_pi() {
84     res=$(curl -sw "%{http_code}" --header 'Accept: application/json'  'http://'${HOST_PORT}'/a1-p/policytypes/'${1}'/policies/'$2'/status')
85     http_code="${res:${#res}-3}"
86     echo "Response code: " $http_code
87     echo "Response: " ${res:0:${#res}-3}
88 }
89
90
91 echo "== Create policy type 23"
92 create_pt 23
93 echo "== Get policy type 23"
94 get_pt 23
95 echo "== Create policy type 23 again"
96 create_pt 23
97 echo "== Create policy type 24"
98 create_pt 24
99 echo "== Get all policy types"
100 get_pts
101 echo "== Delete policy type 24"
102 del_pt 24
103 echo "== Delete policy type 24 again"
104 del_pt 24
105 echo "== Get all policy types"
106 get_pts
107 echo "== Get all policy instancess for type 23"
108 get_pis 23
109 echo "== Create policy instance 16 for type 23"
110 create_pi 23 16
111 echo "== Create policy instance 16 for type 23 again"
112 create_pi 23 16
113 echo "== Get policy instance 16 for type 23"
114 get_pi 23 16
115 echo "== Get missing policy instance 17 for type 23"
116 get_pi 23 17
117 echo "== Create policy instance 18 for type 23"
118 create_pi 23 18
119 echo "== Get all policy instances for type 23"
120 get_pis 23
121 echo "== Delete policy instance 18 for type 23"
122 del_pi 23 18
123 echo "== Get all policy instances for type 23"
124 get_pis 23
125 echo "== Get status for policy instance 16 for type 23"
126 stat_pi 23 16