@Before
  public void setUp() {
    m_dbPopulator.populateDatabase();
    OnmsMonitoredService svc2 =
        m_dbPopulator
            .getMonitoredServiceDao()
            .get(m_dbPopulator.getNode2().getId(), InetAddressUtils.addr("192.168.2.1"), "ICMP");
    // This requires every test method to have a new database instance :/
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);

    OnmsOutage unresolved2 = new OnmsOutage(new Date(), event, svc2);
    m_dbPopulator.getOutageDao().save(unresolved2);
    m_dbPopulator.getOutageDao().flush();
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetDataLinksOnInterface() {
    List<LinkInterface> dlis =
        NetworkElementFactory.getInstance(m_appContext)
            .getDataLinksOnInterface(m_dbPopulator.getNode1().getId(), 1);
    assertEquals(4, dlis.size());

    List<LinkInterface> dlis2 =
        NetworkElementFactory.getInstance(m_appContext)
            .getDataLinksOnInterface(m_dbPopulator.getNode1().getId(), 9);
    assertEquals(0, dlis2.size());
  }
  @Test
  @Transactional
  public void testGetByCompositeId() {
    final OnmsMonitoredService monSvc =
        m_monitoredServiceDao.get(
            m_databasePopulator.getNode1().getId(), addr("192.168.1.1"), "SNMP");
    assertNotNull(monSvc);

    final OnmsMonitoredService monSvc2 =
        m_monitoredServiceDao.get(
            m_databasePopulator.getNode1().getId(),
            addr("192.168.1.1"),
            monSvc.getIfIndex(),
            monSvc.getServiceId());
    assertNotNull(monSvc2);
  }
  @Before
  public void setUp() throws Exception {
    // Use the mock.logLevel system property to control the log level
    MockLogAppender.setupLogging(true);

    // Set the operation delay to 1 second so that queued operations execute immediately
    m_adapter.setDelay(1);
    m_adapter.setTimeUnit(TimeUnit.SECONDS);

    Assert.notNull(m_nodeDao, "Autowiring failed, NodeDao is null");
    Assert.notNull(m_mockEventIpcManager, "Autowiring failed, IPC manager is null");
    Assert.notNull(m_populator, "Autowiring failed, DB populator is null");
    Assert.notNull(m_adapter, "Autowiring failed, adapter is null");

    // Make sure that the localhost SNMP connection config factory has overridden
    // the normal config factory
    assertTrue(m_adapter.getSnmpPeerFactory() instanceof ProxySnmpAgentConfigFactory);

    m_populator.populateDatabase();

    OnmsNode node = m_nodeDao.get(NODE_ID);
    assertNotNull(node);
    node.setSysObjectId(".1.3");
    m_nodeDao.saveOrUpdate(node);
  }
Exemple #5
0
  @Test
  @JUnitTemporaryDatabase
  public void testInsert() {
    String newIfName = "newIf0";
    assertEquals(0, countIfs(m_populator.getNode1().getId(), 1001, newIfName));

    // add non existent snmpiface
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface();
    snmpIface.setNode(m_populator.getNode1());
    snmpIface.setIfIndex(1001);
    snmpIface.setIfName(newIfName);

    m_upsertService.upsert(m_populator.getNode1().getId() /* nodeid */, snmpIface, 0);

    assertEquals(1, countIfs(m_populator.getNode1().getId(), 1001, newIfName));
  }
Exemple #6
0
  @Test
  @JUnitTemporaryDatabase
  public void testUpdate() {
    String oldIfName = "eth0";
    String newIfName = "newIf0";
    assertEquals(1, countIfs(m_populator.getNode1().getId(), 2, oldIfName));
    assertEquals(0, countIfs(m_populator.getNode1().getId(), 2, newIfName));

    // add non existent snmpiface
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface();
    snmpIface.setIfIndex(2);
    snmpIface.setIfName(newIfName);

    m_upsertService.upsert(m_populator.getNode1().getId(), snmpIface, 0);

    assertEquals(0, countIfs(m_populator.getNode1().getId(), 2, oldIfName));
    assertEquals(1, countIfs(m_populator.getNode1().getId(), 2, newIfName));
  }
 @Test
 @Transactional
 @JUnitTemporaryDatabase
 public void testGetActiveInterfacesOnNode() {
   Interface[] intfs =
       NetworkElementFactory.getInstance(m_appContext)
           .getActiveInterfacesOnNode(m_dbPopulator.getNode1().getId());
   assertEquals("active interfaces", 4, intfs.length);
 }
 @BeforeTransaction
 public void setUp() {
   try {
     if (!m_populated) {
       m_populator.populateDatabase();
     }
   } catch (Throwable e) {
     e.printStackTrace(System.err);
   } finally {
     m_populated = true;
   }
 }
  @Test
  @Transactional
  public void testLazy() {
    final List<OnmsMonitoredService> allSvcs = m_monitoredServiceDao.findAll();
    assertTrue(allSvcs.size() > 1);

    final OnmsMonitoredService svc = allSvcs.iterator().next();
    assertEquals(addr("192.168.1.1"), svc.getIpAddress());
    assertEquals(1, svc.getIfIndex().intValue());
    assertEquals(m_databasePopulator.getNode1().getId(), svc.getIpInterface().getNode().getId());
    assertEquals("M", svc.getIpInterface().getIsManaged());
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetAtInterfaces() throws Exception {
    AtInterface atif =
        NetworkElementFactory.getInstance(m_appContext)
            .getAtInterface(m_dbPopulator.getNode2().getId(), "192.168.2.1");
    assertEquals("AA:BB:CC:DD:EE:FF", atif.get_physaddr());

    List<OnmsNode> nodes =
        NetworkElementFactory.getInstance(m_appContext).getNodesFromPhysaddr("AA:BB:CC:DD:EE:FF");
    assertEquals(1, nodes.size());
  }
Exemple #11
0
  @Test
  @JUnitTemporaryDatabase
  public void testConcurrentInsert() throws InterruptedException {
    Inserter one = new Inserter(m_upsertService, m_populator.getNode1().getId(), 1001, "ifName1");
    Inserter two = new Inserter(m_upsertService, m_populator.getNode1().getId(), 1001, "ifName2");

    one.start();
    two.start();

    one.join();
    two.join();

    assertNull("Exception on upsert two " + two.getThrowable(), two.getThrowable());
    assertNull("Exception on upsert one " + one.getThrowable(), one.getThrowable());
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetInterfacesWithIpAddress() throws Exception {
    Interface[] interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5");
    assertEquals("interface count", 1, interfaces.length);
    assertEquals("node ID", m_dbPopulator.getNode1().getId().intValue(), interfaces[0].getNodeId());
    assertEquals("ifIndex", 4, interfaces[0].getIfIndex());

    interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:0001%5");
    assertEquals("interface count", 0, interfaces.length);

    interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4");
    assertEquals("interface count", 0, interfaces.length);
  }
Exemple #13
0
 @Before
 public void setUp() {
   m_populator.populateDatabase();
 }
 @Before
 public void setUp() {
   assertNotNull(m_outageRepo);
   m_dbPopulator.populateDatabase();
 }
 @Before
 public void setUp() {
   MockLogAppender.setupLogging();
   m_populator.populateDatabase();
   m_interfaces = m_ipInterfaceDao.findAll();
 }
 @AfterTransaction
 public void tearDown() {
   m_populator.resetDatabase();
 }
 @BeforeTransaction
 public void setUp() {
   m_populator.populateDatabase();
 }