Search in sources :

Example 21 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class DaoWebOutageRepositoryIT method testGetOutagesByLocation.

@Test
// Relies on specific IDs so we need a fresh database
@JUnitTemporaryDatabase
public void testGetOutagesByLocation() {
    createNodeEventAndOutage("Pittsboro", "nodeA", "172.16.10.10", "ICMP");
    createNodeEventAndOutage("Pittsboro", "nodeB", "172.16.10.20", "ICMP");
    createNodeEventAndOutage("Minneapolis", "nodeC", "172.16.20.10", "ICMP");
    createNodeEventAndOutage("Minneapolis", "nodeD", "172.16.20.20", "ICMP");
    createNodeEventAndOutage("Minneapolis", "nodeE", "172.16.20.30", "ICMP");
    Outage[] outage1 = m_daoOutageRepo.getMatchingOutages(new OutageCriteria());
    assertEquals(8, outage1.length);
    Outage[] outage2 = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new LocationFilter("Minneapolis")));
    assertEquals(3, outage2.length);
    assertTrue(Arrays.stream(outage2).allMatch(o -> o.getLocation().equals("Minneapolis")));
    Outage[] outage3 = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new NegativeLocationFilter("Minneapolis")));
    assertEquals(5, outage3.length);
    assertTrue(Arrays.stream(outage3).allMatch(o -> !o.getLocation().equals("Minneapolis")));
}
Also used : OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) RegainedServiceDateBeforeFilter(org.opennms.web.outage.filter.RegainedServiceDateBeforeFilter) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Date(java.util.Date) OutageCriteria(org.opennms.web.outage.filter.OutageCriteria) RunWith(org.junit.runner.RunWith) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) InetAddressUtils.addr(org.opennms.core.utils.InetAddressUtils.addr) OutageSummary(org.opennms.netmgt.model.outage.OutageSummary) InitializingBean(org.springframework.beans.factory.InitializingBean) OutageIdFilter(org.opennms.web.outage.filter.OutageIdFilter) LocationFilter(org.opennms.web.outage.filter.LocationFilter) OnmsNode(org.opennms.netmgt.model.OnmsNode) NegativeNodeFilter(org.opennms.web.outage.filter.NegativeNodeFilter) Before(org.junit.Before) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Properties(java.util.Properties) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) JUnitConfigurationEnvironment(org.opennms.test.JUnitConfigurationEnvironment) Assert.assertNotNull(org.junit.Assert.assertNotNull) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) NegativeLocationFilter(org.opennms.web.outage.filter.NegativeLocationFilter) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) NegativeForeignSourceFilter(org.opennms.web.outage.filter.NegativeForeignSourceFilter) MockLogAppender(org.opennms.core.test.MockLogAppender) BeanUtils(org.opennms.core.spring.BeanUtils) List(java.util.List) OpenNMSJUnit4ClassRunner(org.opennms.core.test.OpenNMSJUnit4ClassRunner) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) ForeignSourceFilter(org.opennms.web.outage.filter.ForeignSourceFilter) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NodeFilter(org.opennms.web.outage.filter.NodeFilter) Assert.assertEquals(org.junit.Assert.assertEquals) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) Transactional(org.springframework.transaction.annotation.Transactional) NegativeLocationFilter(org.opennms.web.outage.filter.NegativeLocationFilter) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) LocationFilter(org.opennms.web.outage.filter.LocationFilter) NegativeLocationFilter(org.opennms.web.outage.filter.NegativeLocationFilter) OutageCriteria(org.opennms.web.outage.filter.OutageCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 22 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class WebOutageRepositoryFilterIT method testRegainedServiceDateBeforeFilter.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testRegainedServiceDateBeforeFilter() {
    RegainedServiceDateBeforeFilter filter = new RegainedServiceDateBeforeFilter(new Date());
    OutageCriteria criteria = new OutageCriteria(filter);
    Outage[] outages = m_daoOutageRepo.getMatchingOutages(criteria);
    assertEquals(1, outages.length);
}
Also used : Outage(org.opennms.web.outage.Outage) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 23 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class WebOutageRepositoryFilterIT method testLostServiceDateBeforeFilter.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testLostServiceDateBeforeFilter() {
    LostServiceDateBeforeFilter filter = new LostServiceDateBeforeFilter(new Date());
    OutageCriteria criteria = new OutageCriteria(filter);
    Outage[] outages = m_daoOutageRepo.getMatchingOutages(criteria);
    assertEquals(3, outages.length);
}
Also used : Outage(org.opennms.web.outage.Outage) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 24 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NetworkElementFactoryIT method testGetNodesWithIpLikeOneInterface.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testGetNodesWithIpLikeOneInterface() throws Exception {
    // setUp() creates nodes by default, start with a clean slate
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    m_nodeDao.flush();
    m_jdbcTemplate.update("INSERT INTO node (location, nodeId, nodeCreateTime, nodeType) VALUES ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 12, now(), 'A')");
    m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.1', 'M')");
    final List<OnmsNode> nodes = NetworkElementFactory.getInstance(m_appContext).getNodesWithIpLike("*.*.*.*");
    assertEquals("node count", 1, nodes.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class NetworkElementFactoryIT method testGetNodesWithIpLikeTwoInterfaces.

// bug introduced in revision 2932
@Test
@JUnitTemporaryDatabase
public void testGetNodesWithIpLikeTwoInterfaces() throws Exception {
    // setUp() creates nodes by default, start with a clean slate
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    m_nodeDao.flush();
    m_jdbcTemplate.update("INSERT INTO node (location, nodeId, nodeCreateTime, nodeType) VALUES ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 12, now(), 'A')");
    m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.1', 'M')");
    m_jdbcTemplate.update("INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.2', 'M')");
    final List<OnmsNode> nodes = NetworkElementFactory.getInstance(m_appContext).getNodesWithIpLike("*.*.*.*");
    assertEquals("node count", 1, nodes.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)109 Test (org.junit.Test)105 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Date (java.util.Date)20 JSONObject (org.json.JSONObject)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 Transactional (org.springframework.transaction.annotation.Transactional)14 FileInputStream (java.io.FileInputStream)10 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)10 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)7 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)4