Search in sources :

Example 96 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class VmwareCollectorComplianceTest method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(anyInt())).thenReturn(node);
    when(node.getAssetRecord().getVmwareManagementServer()).thenReturn("mdx");
    when(node.getAssetRecord().getVmwareManagedEntityType()).thenReturn("tsx");
    when(node.getForeignId()).thenReturn("rsx");
    VmwareCollection collection = new VmwareCollection();
    VmwareDatacollectionConfigDao vmwareDatacollectionConfigDao = mock(VmwareDatacollectionConfigDao.class);
    when(vmwareDatacollectionConfigDao.getVmwareCollection(COLLECTION)).thenReturn(collection);
    when(vmwareDatacollectionConfigDao.getRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
    VmwareServer vmwareServer = new VmwareServer();
    vmwareServer.setHostname(InetAddrUtils.getLocalHostAddress().getCanonicalHostName());
    Map<String, VmwareServer> serverMap = new ImmutableMap.Builder<String, VmwareServer>().put("mdx", vmwareServer).build();
    VmwareConfigDao vmwareConfigDao = mock(VmwareConfigDao.class);
    when(vmwareConfigDao.getServerMap()).thenReturn(serverMap);
    return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("vmwareDatacollectionConfigDao", vmwareDatacollectionConfigDao).put("vmwareConfigDao", vmwareConfigDao).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) VmwareConfigDao(org.opennms.netmgt.dao.VmwareConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection) VmwareDatacollectionConfigDao(org.opennms.netmgt.dao.VmwareDatacollectionConfigDao) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Example 97 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NodeDaoIT method simulateScan.

private void simulateScan(Date timestamp) {
    OnmsNode n = getNodeDao().get(getNode1().getId());
    assertEquals(4, n.getIpInterfaces().size());
    assertEquals(4, n.getSnmpInterfaces().size());
    OnmsIpInterface iface = n.getIpInterfaceByIpAddress("192.168.1.1");
    assertNotNull(iface);
    iface.setIpLastCapsdPoll(timestamp);
    OnmsSnmpInterface snmpIface = n.getSnmpInterfaceWithIfIndex(1);
    assertNotNull(snmpIface);
    snmpIface.setLastCapsdPoll(timestamp);
    getNodeDao().saveOrUpdate(n);
    getNodeDao().flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 98 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NodeDaoIT method testQueryWithHierarchy.

@Test
@Transactional
public void testQueryWithHierarchy() throws Exception {
    OnmsNode n = getNodeDao().getHierarchy(getNode1().getId());
    validateNode(n);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 99 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NodeDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "MyFirstNode");
    getNodeDao().save(node);
    getNodeDao().flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NodeDaoIT method testLldpSaveAndUpdate.

@Test
@Transactional
public void testLldpSaveAndUpdate() throws InterruptedException {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "MyFirstLldpNode");
    getNodeDao().save(node);
    getNodeDao().flush();
    Collection<OnmsNode> nodes = getNodeDao().findAll();
    assertEquals(7, nodes.size());
    Integer nodeid = null;
    for (OnmsNode retrieved : nodes) {
        if (retrieved.getLabel().equals("MyFirstLldpNode")) {
            nodeid = retrieved.getId();
            System.out.println("nodeid: " + nodeid);
        }
    }
    OnmsNode dbnode1 = getNodeDao().get(nodeid);
    assertNotNull(dbnode1);
    if (dbnode1.getLldpElement() == null) {
        LldpElement lldpElement = new LldpElement();
        lldpElement.setLldpChassisId("abc123456");
        lldpElement.setLldpChassisIdSubType(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS);
        lldpElement.setLldpSysname("prova");
        lldpElement.setNode(node);
        lldpElement.setLldpNodeLastPollTime(lldpElement.getLldpNodeCreateTime());
        dbnode1.setLldpElement(lldpElement);
    }
    getNodeDao().save(dbnode1);
    getNodeDao().flush();
    OnmsNode dbnode2 = getNodeDao().get(nodeid);
    assertNotNull(dbnode2);
    assertNotNull(dbnode2.getLldpElement());
    System.out.println("lldp element id: " + dbnode2.getLldpElement().getId());
    System.out.println("lldp element create time: " + dbnode2.getLldpElement().getLldpNodeCreateTime());
    System.out.println("lldp element last poll time: " + dbnode2.getLldpElement().getLldpNodeLastPollTime());
    assertEquals("abc123456", dbnode2.getLldpElement().getLldpChassisId());
    assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, dbnode2.getLldpElement().getLldpChassisIdSubType());
    assertEquals("prova", dbnode2.getLldpElement().getLldpSysname());
    assertNotNull(dbnode2.getLldpElement().getLldpNodeCreateTime());
    assertNotNull(dbnode2.getLldpElement().getLldpNodeLastPollTime());
    System.out.println("---------");
    Thread.sleep(1000);
    System.out.println("---------");
    LldpElement lldpUpdateElement = new LldpElement();
    lldpUpdateElement.setLldpChassisId("abc012345");
    lldpUpdateElement.setLldpChassisIdSubType(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS);
    lldpUpdateElement.setLldpSysname("prova");
    LldpElement dbLldpElement = dbnode2.getLldpElement();
    dbLldpElement.merge(lldpUpdateElement);
    dbnode2.setLldpElement(dbLldpElement);
    getNodeDao().save(dbnode2);
    getNodeDao().flush();
    OnmsNode dbnode3 = getNodeDao().get(nodeid);
    assertNotNull(dbnode3);
    assertNotNull(dbnode3.getLldpElement());
    System.out.println("lldp element id: " + dbnode3.getLldpElement().getId());
    System.out.println("lldp element create time: " + dbnode3.getLldpElement().getLldpNodeCreateTime());
    System.out.println("lldp element last poll time: " + dbnode3.getLldpElement().getLldpNodeLastPollTime());
    assertEquals("abc012345", dbnode3.getLldpElement().getLldpChassisId());
    assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, dbnode3.getLldpElement().getLldpChassisIdSubType());
    assertEquals("prova", dbnode3.getLldpElement().getLldpSysname());
    assertNotNull(dbnode3.getLldpElement().getLldpNodeCreateTime());
    assertNotNull(dbnode3.getLldpElement().getLldpNodeLastPollTime());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) LldpElement(org.opennms.netmgt.model.LldpElement) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23