Test to read XML logs
[gnucomo.git] / test / read_xml_log
1 #!/bin/bash
2
3 #
4 #  Create an object 'kithira.andromeda.nl' in the database and
5 #  parse a piece of a XML file.
6
7 rm -f gcm_input.log
8
9 createdb gnucomo_test
10 result=1
11
12 if psql gnucomo_test -q <../src/database/create.sql >/dev/null
13 then
14    psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
15
16    # read logs from an XML file. 2 log entries are expected
17    echo "Read a good XML file"
18    ../src/gcm_input/gcm_input -v -c gnucomo_test <log.xml
19    NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
20    echo $NR_LOGS log entries in the datebase
21
22    # read a bad XML file, resulting in a parse error
23    psql gnucomo_test -q -t -c "delete from log"
24    echo "Read a bad XML file"
25    ../src/gcm_input/gcm_input -v -c gnucomo_test <log_bad.xml
26    result=$?
27    echo "gcm_input returned $result"
28
29    if [[ $result -eq 1 ]]
30    then
31       # check if nothing was stored in the (existing) database
32       NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
33       if [[ $NR_LOGS -eq 0 ]]
34       then
35          echo "No log entries in database"
36          result=0
37       fi
38       # check if the saved XML file exists
39       SAVEDFILE=`grep 'XML content stored' gcm_input.log |cut -d ' ' -f 12`
40       echo "Saved file is $SAVEDFILE"
41       if [[ ! -e $SAVEDFILE ]]
42       then
43          echo $SAVEDFILE does not exist.
44          result=2
45       fi
46       rm $SAVEDFILE   # cleanup
47    else
48       echo "gcm_input did not return an error"
49       result=1
50    fi
51
52    psql gnucomo_test -f ../src/database/destroy.sql -q
53 else
54    echo Can not create test database
55    result=1
56 fi
57
58 dropdb gnucomo_test
59 exit $result