@After public void tearDown() { // Always reset the peer factory SnmpPeerFactory.setInstance(null); }
/** * Verifies that the SNMP agent configuration is retrieved using * the location name that is associated with the interface/node. */ @Test public void canGetLocationAwareAgentConfig() { // Mock the peer factory SnmpPeerFactory snmpPeerFactory = mock(SnmpPeerFactory.class); SnmpPeerFactory.setInstance(snmpPeerFactory); // Mock the other arguments required to create a DefaultCollectionAgent Integer ifaceId = 1; IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); OnmsIpInterface ipIface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS); when(ifaceDao.load(ifaceId)).thenReturn(ipIface); when(ipIface.getNode().getLocation().getLocationName()).thenReturn("Ocracoke"); // Retrieve the agent configuration SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ifaceId, ifaceDao, transMgr); agent.getAgentConfig(); // Verify verify(snmpPeerFactory, times(1)).getAgentConfig(any(), eq("Ocracoke")); }
@Before public void setup() { locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory()); snmpInterfaceMonitor = new SnmpPollInterfaceMonitor(locationAwareSnmpClient); SnmpPeerFactory.setInstance(snmpPeerFactory); // Set admin/operational status as unknown SnmpMinimalPollInterface iface = new SnmpMinimalPollInterface(6, SnmpMinimalPollInterface.IF_UNKNOWN, SnmpMinimalPollInterface.IF_UNKNOWN); interfacesResult.add(iface); }
private void initialize() throws IOException, Exception { System.setProperty("opennms.home", ConfigurationTestUtils.getDaemonEtcDirectory().getParentFile().getAbsolutePath()); DatabaseSchemaConfigFactory.init(); InputStream stream = null; stream = getInputStreamForFile("/org/opennms/netmgt/config/snmp-config.xml"); SnmpPeerFactory.setInstance(new SnmpPeerFactory(new InputStreamResource(stream))); stream.close(); stream = getInputStreamForFile("/org/opennms/netmgt/config/datacollection-config.xml"); DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao(); dataCollectionDao.setConfigResource(new InputStreamResource(stream)); dataCollectionDao.afterPropertiesSet(); DataCollectionConfigFactory.setInstance(dataCollectionDao); stream.close(); stream = getInputStreamForFile("/org/opennms/netmgt/config/collectd-testdata.xml"); try { new CollectdConfigFactory(stream); } finally { stream.close(); } } }
SnmpPeerFactory.setInstance(m_snmpPeerFactory); m_agentConfig = m_snmpPeerFactory.getAgentConfig(InetAddressUtils.addr(TEST_HOST_ADDRESS));
iface = ifaces.iterator().next(); SnmpPeerFactory.setInstance(m_snmpPeerFactory);
iface = ifaces.iterator().next(); SnmpPeerFactory.setInstance(m_snmpPeerFactory);
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));