Test creating notifications
[gnucomo.git] / test / notifications
diff --git a/test/notifications b/test/notifications
new file mode 100755 (executable)
index 0000000..915553f
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+#
+#  Test the service and log check notifications.
+#  Create a database with two objects and no services. After reading two
+#  log file fragments for these two objects, gcm_daemon should create
+#  several notifications, three for each object.
+#
+#  This tests problem report nr. 23
+
+#LD_LIBRARY_PATH=/usr/local/pqxx/lib
+#export LD_LIBRARY_PATH
+
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+
+result=0
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+   #  Prepare the database
+
+   psql gnucomo_test -q -c "insert into object (objectname) values ('example1.gnucomo.test')"
+   psql gnucomo_test -q -c "insert into object (objectname) values ('example2.gnucomo.test')"
+   psql gnucomo_test -q -c "delete from service"
+
+   #  read logs for both objects
+
+   ../src/gcm_input/gcm_input -c gnucomo_test -h example1.gnucomo.test -d 'sep 5 2002 20:30:45' <messages.bad
+   ../src/gcm_input/gcm_input -c gnucomo_test -h example2.gnucomo.test -d 'sep 5 2002 20:30:45' <messages
+
+   # Make the notifications.
+   cd ../src/gcm_daemon; ./gcm_daemon.php -c gnucomo_test; cd ../../test
+
+   # Check the notifications, 3 for each object.
+
+   NR_NOTIF1=`psql gnucomo_test -q -t -c "select count(*) from notification where objectid=1"`
+   NR_NOTIF2=`psql gnucomo_test -q -t -c "select count(*) from notification where objectid=2"`
+
+   if [[ $NR_NOTIF1 -ne 3 ]]
+   then
+      echo "$NR_NOTIF1 notifications for object 1 (3 expected)."
+      result=2
+   fi
+
+   if [[ $NR_NOTIF2 -ne 3 ]]
+   then
+      echo "$NR_NOTIF2 notifications for object 2 (3 expected)."
+      result=3
+   fi
+
+   #  Clean up.
+
+   psql gnucomo_test -f ../src/database/destroy.sql -q
+   dropdb gnucomo_test
+
+   exit $result
+else
+   echo Can not create test database
+   dropdb gnucomo_test
+   exit 1
+fi