1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "icinga/notification.hpp"
4 #include <BoostTestTargetConfig.h>
7 using namespace icinga;
9 BOOST_AUTO_TEST_SUITE(icinga_notification)
11 BOOST_AUTO_TEST_CASE(state_filter)
15 Array::Ptr states = new Array();
17 states->Add("Warning");
19 Notification::Ptr notification = new Notification();
21 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
22 notification->Activate();
23 notification->SetAuthority(true);
25 /* Test passing notification state */
26 fstate = StateFilterWarning;
27 std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
28 BOOST_CHECK(notification->GetStateFilter() & fstate);
30 /* Test filtered notification state */
31 fstate = StateFilterUnknown;
32 std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
33 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
35 /* Test unset states filter configuration */
36 notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
38 fstate = StateFilterOK;
39 std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
40 BOOST_CHECK(notification->GetStateFilter() & fstate);
42 /* Test empty states filter configuration */
44 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
46 fstate = StateFilterCritical;
47 std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
48 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
50 BOOST_AUTO_TEST_CASE(type_filter)
54 Array::Ptr types = new Array();
55 types->Add("Problem");
56 types->Add("DowntimeStart");
57 types->Add("DowntimeEnd");
59 Notification::Ptr notification = new Notification();
61 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
62 notification->Activate();
63 notification->SetAuthority(true);
65 /* Test passing notification type */
66 ftype = NotificationProblem;
67 std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
68 BOOST_CHECK(notification->GetTypeFilter() & ftype);
70 /* Test filtered notification type */
71 ftype = NotificationCustom;
72 std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
73 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
75 /* Test unset types filter configuration */
76 notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
78 ftype = NotificationRecovery;
79 std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
80 BOOST_CHECK(notification->GetTypeFilter() & ftype);
82 /* Test empty types filter configuration */
84 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
86 ftype = NotificationProblem;
87 std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
88 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
90 BOOST_AUTO_TEST_SUITE_END()