<commit_before>//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2005 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
// OpenNMS Licensing       <<EMAIL>>
//     http://www.opennms.org/
//     http://www.opennms.com/
//
package org.opennms.netmgt.notifd;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.opennms.core.utils.TimeConverter;
import org.opennms.netmgt.config.DatabaseConnectionFactory;
import org.opennms.netmgt.config.NotificationCommandManager;
import org.opennms.netmgt.config.NotificationManager;
import org.opennms.netmgt.config.groups.Group;
import org.opennms.netmgt.config.users.Contact;
import org.opennms.netmgt.config.users.User;
import org.opennms.netmgt.mock.MockDatabase;
import org.opennms.netmgt.mock.MockEventIpcManager;
import org.opennms.netmgt.mock.MockLogAppender;
import org.opennms.netmgt.mock.MockNetwork;
import org.opennms.netmgt.mock.MockUtil;
import org.opennms.netmgt.notifd.mock.MockDestinationPathManager;
import org.opennms.netmgt.notifd.mock.MockGroupManager;
import org.opennms.netmgt.notifd.mock.MockNotifdConfigManager;
import org.opennms.netmgt.notifd.mock.MockNotification;
import org.opennms.netmgt.notifd.mock.MockNotificationCommandManager;
import org.opennms.netmgt.notifd.mock.MockNotificationManager;
import org.opennms.netmgt.notifd.mock.MockNotificationStrategy;
import org.opennms.netmgt.notifd.mock.MockUserManager;
import org.opennms.netmgt.notifd.mock.NotificationAnticipator;

import junit.framework.TestCase;

public class NotificationsTestCase extends TestCase {

    protected Notifd m_notifd;
    protected MockEventIpcManager m_eventMgr;
    protected MockNotifdConfigManager m_notifdConfig;
    protected MockGroupManager m_groupManager;
    protected MockUserManager m_userManager;
    protected NotificationManager m_notificationManager;
    protected NotificationCommandManager m_notificationCommandManger;
    protected MockDestinationPathManager m_destinationPathManager;
    private static String NOTIFD_CONFIG_MANAGER = "<?xml version=\"1.0\"?>\n" + 
                "<notifd-configuration \n" + 
                "        status=\"on\"\n" + 
                "        pages-sent=\"SELECT * FROM notifications\"\n" + 
                "        next-notif-id=\"SELECT nextval(\'notifynxtid\')\"\n" + 
                "        next-group-id=\"SELECT nextval(\'notifygrpid\')\"\n" + 
                "        service-id-sql=\"SELECT serviceID from service where serviceName = ?\"\n" + 
                "        outstanding-notices-sql=\"SELECT notifyid FROM notifications where notifyId = ? AND respondTime is not null\"\n" + 
                "        acknowledge-id-sql=\"SELECT notifyid FROM notifications WHERE eventuei=? AND nodeid=? AND interfaceid=? AND serviceid=?\"\n" + 
                "        acknowledge-update-sql=\"UPDATE notifications SET answeredby=?, respondtime=? WHERE notifyId=?\"\n" + 
                "   match-all=\"false\">\n" + 
                "        \n" + 
                "   <auto-acknowledge notify = \"true\" uei=\"uei.opennms.org/nodes/serviceResponsive\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/serviceUnresponsive\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "                          <match>serviceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "   \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeRegainedService\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/nodeLostService\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "                          <match>serviceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/interfaceUp\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/interfaceDown\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeUp\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/nodeDown\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <queue>\n" + 
                "                <queue-id>default</queue-id>\n" + 
                "                <interval>100ms</interval>\n" + 
                "                <handler-class>\n" + 
                "                        <name>org.opennms.netmgt.notifd.DefaultQueueHandler</name>\n" + 
                "                </handler-class>\n" + 
                "        </queue>\n" + 
                "</notifd-configuration>";
    private static final String NOTIFICATIONS = "<?xml version=\"1.0\"?>\n" + 
                "<notifications xmlns=\"http://xmlns.opennms.org/xsd/notifications\">\n" + 
                "    <header>\n" + 
                "        <rev>1.2</rev>\n" + 
                "        <created>Wednesday, February 6, 2002 10:10:00 AM EST</created>\n" + 
                "        <mstation>localhost</mstation>\n" + 
                "    </header>\n" + 
                "    <notification name=\"snmpTrap\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>trapNotifier</destinationPath>\n" + 
                "        <text-message>All services are down on node %nodeid%.</text-message>\n" + 
                "        <subject>node %nodeid% down.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "        <parameter name=\"trapVersion\" value=\"v1\" />\n"+
                "        <parameter name=\"trapTransport\" value=\"UDP\" />\n"+
                "        <parameter name=\"trapHost\" value=\"localhost\" />\n"+
                "        <parameter name=\"trapPort\" value=\"161\" />\n"+
                "        <parameter name=\"trapCommunity\" value=\"public\" />\n"+
                "        <parameter name=\"trapEnterprise\" value=\"public\" />\n"+
                "        <parameter name=\"trapGeneric\" value=\"6\" />\n"+
                "        <parameter name=\"trapSpecific\" value=\"1\" />\n"+
                "        <parameter name=\"trapVarbind\" value=\"%uei%\" />\n"+
                "    </notification>\n" + 
                "    <notification name=\"nodeDown\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>NoEscalate</destinationPath>\n" + 
                "        <text-message>All services are down on node %nodeid%.</text-message>\n" + 
                "        <subject>node %nodeid% down.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "    </notification>\n" + 
                "    <notification name=\"nodeUp\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeUp</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>UpPath</destinationPath>\n" + 
                "        <text-message>The node which was previously down is now up.</text-message>\n" + 
                "        <subject>node %nodeid% up.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "    </notification>\n" + 
                "    <notification name=\"interfaceDown\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/interfaceDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>Escalate</destinationPath>\n" + 
                "        <text-message>All services are down on interface %interface%, %ifalias%.</text-message>\n" + <commit_msg>fixed bad enterprise id in testcase<commit_after>//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2005 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// For more information contact:
// OpenNMS Licensing       <<EMAIL>>
//     http://www.opennms.org/
//     http://www.opennms.com/
//
package org.opennms.netmgt.notifd;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.opennms.core.utils.TimeConverter;
import org.opennms.netmgt.config.DatabaseConnectionFactory;
import org.opennms.netmgt.config.NotificationCommandManager;
import org.opennms.netmgt.config.NotificationManager;
import org.opennms.netmgt.config.groups.Group;
import org.opennms.netmgt.config.users.Contact;
import org.opennms.netmgt.config.users.User;
import org.opennms.netmgt.mock.MockDatabase;
import org.opennms.netmgt.mock.MockEventIpcManager;
import org.opennms.netmgt.mock.MockLogAppender;
import org.opennms.netmgt.mock.MockNetwork;
import org.opennms.netmgt.mock.MockUtil;
import org.opennms.netmgt.notifd.mock.MockDestinationPathManager;
import org.opennms.netmgt.notifd.mock.MockGroupManager;
import org.opennms.netmgt.notifd.mock.MockNotifdConfigManager;
import org.opennms.netmgt.notifd.mock.MockNotification;
import org.opennms.netmgt.notifd.mock.MockNotificationCommandManager;
import org.opennms.netmgt.notifd.mock.MockNotificationManager;
import org.opennms.netmgt.notifd.mock.MockNotificationStrategy;
import org.opennms.netmgt.notifd.mock.MockUserManager;
import org.opennms.netmgt.notifd.mock.NotificationAnticipator;

import junit.framework.TestCase;

public class NotificationsTestCase extends TestCase {

    protected Notifd m_notifd;
    protected MockEventIpcManager m_eventMgr;
    protected MockNotifdConfigManager m_notifdConfig;
    protected MockGroupManager m_groupManager;
    protected MockUserManager m_userManager;
    protected NotificationManager m_notificationManager;
    protected NotificationCommandManager m_notificationCommandManger;
    protected MockDestinationPathManager m_destinationPathManager;
    private static String NOTIFD_CONFIG_MANAGER = "<?xml version=\"1.0\"?>\n" + 
                "<notifd-configuration \n" + 
                "        status=\"on\"\n" + 
                "        pages-sent=\"SELECT * FROM notifications\"\n" + 
                "        next-notif-id=\"SELECT nextval(\'notifynxtid\')\"\n" + 
                "        next-group-id=\"SELECT nextval(\'notifygrpid\')\"\n" + 
                "        service-id-sql=\"SELECT serviceID from service where serviceName = ?\"\n" + 
                "        outstanding-notices-sql=\"SELECT notifyid FROM notifications where notifyId = ? AND respondTime is not null\"\n" + 
                "        acknowledge-id-sql=\"SELECT notifyid FROM notifications WHERE eventuei=? AND nodeid=? AND interfaceid=? AND serviceid=?\"\n" + 
                "        acknowledge-update-sql=\"UPDATE notifications SET answeredby=?, respondtime=? WHERE notifyId=?\"\n" + 
                "   match-all=\"false\">\n" + 
                "        \n" + 
                "   <auto-acknowledge notify = \"true\" uei=\"uei.opennms.org/nodes/serviceResponsive\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/serviceUnresponsive\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "                          <match>serviceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "   \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeRegainedService\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/nodeLostService\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "                          <match>serviceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/interfaceUp\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/interfaceDown\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "                          <match>interfaceid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeUp\" \n" + 
                "                          acknowledge=\"uei.opennms.org/nodes/nodeDown\">\n" + 
                "                          <match>nodeid</match>\n" + 
                "        </auto-acknowledge>\n" + 
                "        \n" + 
                "        <queue>\n" + 
                "                <queue-id>default</queue-id>\n" + 
                "                <interval>100ms</interval>\n" + 
                "                <handler-class>\n" + 
                "                        <name>org.opennms.netmgt.notifd.DefaultQueueHandler</name>\n" + 
                "                </handler-class>\n" + 
                "        </queue>\n" + 
                "</notifd-configuration>";
    private static final String NOTIFICATIONS = "<?xml version=\"1.0\"?>\n" + 
                "<notifications xmlns=\"http://xmlns.opennms.org/xsd/notifications\">\n" + 
                "    <header>\n" + 
                "        <rev>1.2</rev>\n" + 
                "        <created>Wednesday, February 6, 2002 10:10:00 AM EST</created>\n" + 
                "        <mstation>localhost</mstation>\n" + 
                "    </header>\n" + 
                "    <notification name=\"snmpTrap\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>trapNotifier</destinationPath>\n" + 
                "        <text-message>All services are down on node %nodeid%.</text-message>\n" + 
                "        <subject>node %nodeid% down.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "        <parameter name=\"trapVersion\" value=\"v1\" />\n"+
                "        <parameter name=\"trapTransport\" value=\"UDP\" />\n"+
                "        <parameter name=\"trapHost\" value=\"localhost\" />\n"+
                "        <parameter name=\"trapPort\" value=\"161\" />\n"+
                "        <parameter name=\"trapCommunity\" value=\"public\" />\n"+
                "        <parameter name=\"trapEnterprise\" value=\".1.3.6.1.4.1.5813\" />\n"+
                "        <parameter name=\"trapGeneric\" value=\"6\" />\n"+
                "        <parameter name=\"trapSpecific\" value=\"1\" />\n"+
                "        <parameter name=\"trapVarbind\" value=\"%uei%\" />\n"+
                "    </notification>\n" + 
                "    <notification name=\"nodeDown\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>NoEscalate</destinationPath>\n" + 
                "        <text-message>All services are down on node %nodeid%.</text-message>\n" + 
                "        <subject>node %nodeid% down.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "    </notification>\n" + 
                "    <notification name=\"nodeUp\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/nodeUp</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>UpPath</destinationPath>\n" + 
                "        <text-message>The node which was previously down is now up.</text-message>\n" + 
                "        <subject>node %nodeid% up.</subject>\n" + 
                "        <numeric-message>111-%noticeid%</numeric-message>\n" + 
                "    </notification>\n" + 
                "    <notification name=\"interfaceDown\" status=\"on\">\n" + 
                "        <uei>uei.opennms.org/nodes/interfaceDown</uei>\n" + 
                "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" + 
                "        <destinationPath>Escalate</destinationPath>\n" + 
                "        <text-message>All services are down on interface %interface%, %ifalias%.</text-message>\n" + 
{'fraction_non_alphanumeric': 0.1377620611265471, 'fraction_numerical': 0.006769386208638545, 'mean_word_length': 1.692966943273024, 'pattern_counts': {'":': 0, '<': 225, '<?xml version=': 4, '>': 225, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 12}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417912', 'n_tokens_mistral': 6044, 'n_tokens_neox': 5597, 'n_words': 1033}