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(strings)
14 BOOST_CHECK("OK" == Notification::NotificationServiceStateToString(ServiceOK));
15 BOOST_CHECK("Critical" == Notification::NotificationServiceStateToString(ServiceCritical));
16 BOOST_CHECK("Up" == Notification::NotificationHostStateToString(HostUp));
19 BOOST_CHECK("DowntimeStart" == Notification::NotificationTypeToString(NotificationDowntimeStart));
20 BOOST_CHECK("Problem" == Notification::NotificationTypeToString(NotificationProblem));
23 BOOST_CHECK("DOWNTIMECANCELLED" == Notification::NotificationTypeToStringCompat(NotificationDowntimeRemoved));
26 BOOST_AUTO_TEST_CASE(state_filter)
30 Array::Ptr states = new Array();
32 states->Add("Warning");
34 Notification::Ptr notification = new Notification();
36 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
37 notification->Activate();
38 notification->SetAuthority(true);
40 /* Test passing notification state */
41 fstate = StateFilterWarning;
42 std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
43 BOOST_CHECK(notification->GetStateFilter() & fstate);
45 /* Test filtered notification state */
46 fstate = StateFilterUnknown;
47 std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
48 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
50 /* Test unset states filter configuration */
51 notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
53 fstate = StateFilterOK;
54 std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
55 BOOST_CHECK(notification->GetStateFilter() & fstate);
57 /* Test empty states filter configuration */
59 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
61 fstate = StateFilterCritical;
62 std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
63 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
65 BOOST_AUTO_TEST_CASE(type_filter)
69 Array::Ptr types = new Array();
70 types->Add("Problem");
71 types->Add("DowntimeStart");
72 types->Add("DowntimeEnd");
74 Notification::Ptr notification = new Notification();
76 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
77 notification->Activate();
78 notification->SetAuthority(true);
80 /* Test passing notification type */
81 ftype = NotificationProblem;
82 std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
83 BOOST_CHECK(notification->GetTypeFilter() & ftype);
85 /* Test filtered notification type */
86 ftype = NotificationCustom;
87 std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
88 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
90 /* Test unset types filter configuration */
91 notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
93 ftype = NotificationRecovery;
94 std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
95 BOOST_CHECK(notification->GetTypeFilter() & ftype);
97 /* Test empty types filter configuration */
99 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
101 ftype = NotificationProblem;
102 std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
103 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
105 BOOST_AUTO_TEST_SUITE_END()