1 /******************************************************************************
3 * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "icinga/notification.hpp"
21 #include <BoostTestTargetConfig.h>
23 using namespace icinga;
25 BOOST_AUTO_TEST_SUITE(icinga_notification)
27 BOOST_AUTO_TEST_CASE(state_filter)
31 Array::Ptr states = new Array();
33 states->Add("Warning");
35 Notification::Ptr notification = new Notification();
37 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
38 notification->Activate();
39 notification->SetAuthority(true);
41 /* Test passing notification state */
42 fstate = StateFilterWarning;
43 std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
44 BOOST_CHECK(notification->GetStateFilter() & fstate);
46 /* Test filtered notification state */
47 fstate = StateFilterUnknown;
48 std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
49 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
51 /* Test unset states filter configuration */
52 notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
54 fstate = StateFilterOK;
55 std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
56 BOOST_CHECK(notification->GetStateFilter() & fstate);
58 /* Test empty states filter configuration */
60 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
62 fstate = StateFilterCritical;
63 std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
64 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
66 BOOST_AUTO_TEST_CASE(type_filter)
70 Array::Ptr types = new Array();
71 types->Add("Problem");
72 types->Add("DowntimeStart");
73 types->Add("DowntimeEnd");
75 Notification::Ptr notification = new Notification();
77 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
78 notification->Activate();
79 notification->SetAuthority(true);
81 /* Test passing notification type */
82 ftype = NotificationProblem;
83 std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
84 BOOST_CHECK(notification->GetTypeFilter() & ftype);
86 /* Test filtered notification type */
87 ftype = NotificationCustom;
88 std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
89 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
91 /* Test unset types filter configuration */
92 notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
94 ftype = NotificationRecovery;
95 std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
96 BOOST_CHECK(notification->GetTypeFilter() & ftype);
98 /* Test empty types filter configuration */
100 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
102 ftype = NotificationProblem;
103 std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
104 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
106 BOOST_AUTO_TEST_SUITE_END()