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();
}
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();
}
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);
}
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();
}
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());
}
Aggregations