onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / message-router / dcae-startup-vm-message-router / docker_files / tests / regress.sh
1 #!/bin/ksh
2 #
3 # depends on jq - https://stedolan.github.io/jq/ 
4
5 PROTOCOL=http
6 FQDN=127.0.0.1
7 #vm1-message-router
8 #FQDN=10.208.128.229
9 PORT=3904
10 URL=$PROTOCOL://$FQDN:$PORT
11
12 rm -f out/*
13 mkdir -p out
14
15 results() {
16 #       echo "[debug] compare $1 to $2"
17         if [ $1 == $2 ]
18         then
19                 echo -n "SUCCESS    "
20         else
21                 echo -n "FAIL ($1) "
22         fi
23         echo " :TEST $3 ($4)"
24 }
25 SUITE=0
26 SUITE=$((SUITE + 1))
27 echo "SUITE $SUITE: List topics"
28 TN=0
29 TN=$((TN + 1))
30 TC=$SUITE.$TN
31 expect=200
32 rc=`curl -s -w "%{http_code}" -o out/$TC.out $URL/topics`
33 results $rc $expect $TC "list"
34 StartTopicCount=`cat out/$TC.out | wc -l`
35
36
37 SUITE=$((SUITE + 1))
38 echo
39 echo "SUITE $SUITE: APIKEY authenticated topic"
40 TOPIC=Topic-$$-$SUITE
41 TN=0
42 TN=$((TN + 1))
43 TC=$SUITE.$TN
44 OUT=out/$TC.out
45 echo '{ "email": "no.email", "description": "request for direct response KEY" }' > key.req
46 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X POST -H "Content-Type: application/json" -d @key.req $URL/apiKeys/create`
47 results $rc $expect $SUITE.$TN "gen apikey " 
48 TN=$((TN + 1))
49 TC=$SUITE.$TN
50 SECRET=$(jq ".secret" $OUT | cut -f 2 -d \")
51 KEY=$(jq ".key" $OUT | cut -f 2 -d \")
52 TIME=`date --iso-8601=seconds`
53 SIG=$(echo -n "$TIME" | openssl sha1 -hmac $SECRET -binary | openssl base64)
54 xAUTH=$KEY:$SIG
55 #echo "[debug] $SECRET  $KEY  $TIME $SIG $xAUTH"
56 DATA=data.$TC.json
57 echo "{ \"topicName\": \"$TOPIC\", \"topicDescription\": \"topic for test $TC\", \"partitionCount\": \"1\", \"replicationCount\": \"1\", \"transactionEnabled\": \"true\" }" > $DATA
58 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X POST -H "Content-Type: application/json" -H "X-CambriaAuth: $xAUTH" -H "X-CambriaDate: $TIME" -d @$DATA $URL/topics/create`
59 results $rc $expect $SUITE.$TN "create topic" 
60 TN=$((TN + 1))
61 TC=$SUITE.$TN
62 expect=200
63 rc=`curl -s -w "%{http_code}" -o out/$TC.out $URL/topics`
64 results $rc $expect $TC "list "
65 TopicCnt=`cat out/$TC.out | wc -l`
66 results $TopicCnt $((StartTopicCount + 1)) $TC "topic count"
67 TN=$((TN + 1))
68 TC=$SUITE.$TN
69 expect=200
70 rc=`curl -s -w "%{http_code}" -o out/$TC.out $URL/topics/$TOPIC`
71 results $rc $expect $TC "list $TOPIC"
72 TN=$((TN + 1))
73 TC=$SUITE.$TN
74 DATA=data.$TC.json
75 echo "{ \"datestamp\": \"`date`\", \"appkey\": \"x100\", \"appval\": \"some value\" }" > $DATA
76 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X POST -H "Content-Type: application/json" -H "X-CambriaAuth: $xAUTH" -H "X-CambriaDate: $TIME" -d @$DATA $URL/events/$TOPIC`
77 results $rc $expect $SUITE.$TN "pub APIKEY topic" 
78 TN=$((TN + 1))
79 TC=$SUITE.$TN
80 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X GET -H "Content-Type: application/json" -H "X-CambriaAuth: $xAUTH" -H "X-CambriaDate: $TIME" $URL/events/$TOPIC/g0/u1`
81 results $rc $expect $SUITE.$TN "sub APIKEY topic" 
82
83
84 SUITE=$((SUITE + 1))
85 echo
86 echo "SUITE $SUITE: anonymous topic"
87 TOPIC=$$.$SUITE
88 TN=0
89 TN=$((TN + 1))
90 TC=$SUITE.$TN
91 DATA=data.$TC.txt
92 echo "datestamp: `date`, key: $TC, value: this is a test " > $DATA
93 expect=200
94 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X POST -H "Content-Type: text/plain" -d @$DATA $URL/events/$TOPIC`
95 results $rc $expect $SUITE.$TN "pub text/plain" 
96 TN=$((TN + 1))
97 TC=$SUITE.$TN
98 expect=200
99 rc=`curl -s -w "%{http_code}" -o out/$TC.out $URL/events/$TOPIC/group1/u$$?timeout=1000`
100 results $rc $expect $SUITE.$TN "sub text/plain" 
101 TN=$((TN + 1))
102 TC=$SUITE.$TN
103 DATA=data.$TC.json
104 echo "{ \"datestamp\": \"`date`\", \"key\": \"$TC\", \"value\": \"this is a test\" }" > $DATA
105 expect=200
106 rc=`curl -s -w "%{http_code}" -o out/$TC.out -X POST -H "Content-Type: application/json" -d @$DATA $URL/events/$TOPIC`
107 results $rc $expect $SUITE.$TN "pub json" 
108 TN=$((TN + 1))
109 TC=$SUITE.$TN
110 expect=200
111 rc=`curl -s -w "%{http_code}" -o out/$TC.out $URL/events/$TOPIC/group1/u$$?timeout=1000`
112 results $rc $expect $SUITE.$TN "sub json" 
113