@Test
  @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database
  public void testUpdateNode() throws InterruptedException {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(2);
    m_adapter.getOperationQueue().addListener(verifyOperations);

    try {
      OnmsNode node = m_nodeDao.get(NODE_ID);
      assertNotNull(node);
      int firstNodeId = node.getId();

      assertNull(node.getAssetRecord().getComment());
      m_adapter.addNode(firstNodeId);
      m_adapter.updateNode(firstNodeId);

      assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
      assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
      assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
      assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size());

      node = m_nodeDao.get(firstNodeId);
      assertNotNull(node);
      System.out.println("ID: " + node.getAssetRecord().getId());
      System.out.println("Comment: " + node.getAssetRecord().getComment());
      assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment());
      assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment());
    } finally {
      m_adapter.getOperationQueue().removeListener(verifyOperations);
    }
  }
  @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);
  }
  @Test
  @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database
  public void testNodeConfigChanged() throws InterruptedException {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
    m_adapter.getOperationQueue().addListener(verifyOperations);

    try {
      OnmsNode node = m_nodeDao.get(NODE_ID);
      assertNotNull(node);
      int firstNodeId = node.getId();

      m_adapter.nodeConfigChanged(firstNodeId);
    } finally {
      m_adapter.getOperationQueue().removeListener(verifyOperations);
    }
  }
  @Test
  @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database
  public void testDeleteNode() throws InterruptedException {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
    m_adapter.getOperationQueue().addListener(verifyOperations);

    try {
      OnmsNode node = m_nodeDao.get(NODE_ID);
      assertNotNull(node);
      int firstNodeId = node.getId();

      m_adapter.deleteNode(firstNodeId);

      assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
      assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
      assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
      assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size());
    } finally {
      m_adapter.getOperationQueue().removeListener(verifyOperations);
    }
  }
  @Test
  @JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database
  @Transactional
  public void testAddNodeDirectly() throws InterruptedException {
    OnmsNode node = m_nodeDao.get(NODE_ID);
    assertNotNull(node);
    int firstNodeId = node.getId();

    m_adapter.doAddNode(firstNodeId);

    node = m_nodeDao.get(firstNodeId);
    assertNotNull(node);
    assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment());
    assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment());
  }