]> granicus.if.org Git - icinga2/blob - test/icinga-notification.cpp
Merge pull request #7591 from Icinga/feature/docs-api-joins
[icinga2] / test / icinga-notification.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/notification.hpp"
4 #include <BoostTestTargetConfig.h>
5 #include <iostream>
6
7 using namespace icinga;
8
9 BOOST_AUTO_TEST_SUITE(icinga_notification)
10
11 BOOST_AUTO_TEST_CASE(strings)
12 {
13         // States
14         BOOST_CHECK("OK" == Notification::NotificationServiceStateToString(ServiceOK));
15         BOOST_CHECK("Critical" == Notification::NotificationServiceStateToString(ServiceCritical));
16         BOOST_CHECK("Up" == Notification::NotificationHostStateToString(HostUp));
17
18         // Types
19         BOOST_CHECK("DowntimeStart" == Notification::NotificationTypeToString(NotificationDowntimeStart));
20         BOOST_CHECK("Problem" == Notification::NotificationTypeToString(NotificationProblem));
21
22         // Compat
23         BOOST_CHECK("DOWNTIMECANCELLED" == Notification::NotificationTypeToStringCompat(NotificationDowntimeRemoved));
24 }
25
26 BOOST_AUTO_TEST_CASE(state_filter)
27 {
28         unsigned long fstate;
29
30         Array::Ptr states = new Array();
31         states->Add("OK");
32         states->Add("Warning");
33
34         Notification::Ptr notification = new Notification();
35
36         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
37         notification->Activate();
38         notification->SetAuthority(true);
39
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);
44
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));
49
50         /* Test unset states filter configuration */
51         notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
52
53         fstate = StateFilterOK;
54         std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
55         BOOST_CHECK(notification->GetStateFilter() & fstate);
56
57         /* Test empty states filter configuration */
58         states->Clear();
59         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
60
61         fstate = StateFilterCritical;
62         std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
63         BOOST_CHECK(!(notification->GetStateFilter() & fstate));
64 }
65 BOOST_AUTO_TEST_CASE(type_filter)
66 {
67         unsigned long ftype;
68
69         Array::Ptr types = new Array();
70         types->Add("Problem");
71         types->Add("DowntimeStart");
72         types->Add("DowntimeEnd");
73
74         Notification::Ptr notification = new Notification();
75
76         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
77         notification->Activate();
78         notification->SetAuthority(true);
79
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);
84
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));
89
90         /* Test unset types filter configuration */
91         notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
92
93         ftype = NotificationRecovery;
94         std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
95         BOOST_CHECK(notification->GetTypeFilter() & ftype);
96
97         /* Test empty types filter configuration */
98         types->Clear();
99         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
100
101         ftype = NotificationProblem;
102         std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
103         BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
104 }
105 BOOST_AUTO_TEST_SUITE_END()