Search in sources :

Example 1 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterFullIT method testAddNodeDirectly.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterIT method testDelete.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@JUnitSnmpAgent(resource = "snmpAssetTestData.properties")
public void testDelete() throws Exception {
    AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
    m_adapter.getOperationQueue().addListener(verifyOperations);
    OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
    assertNotNull(n);
    m_adapter.deleteNode(n.getId());
    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(n.getId()).size());
// TODO: Add assertions to check that the deleteNode() adapter call updated the asset record
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 3 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterFullIT method testAddNode.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testAddNode() 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.addNode(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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 4 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterFullIT method testNodeConfigChanged.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 5 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterFullIT method testDeleteNode.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)109 Test (org.junit.Test)105 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Date (java.util.Date)20 JSONObject (org.json.JSONObject)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 Transactional (org.springframework.transaction.annotation.Transactional)14 FileInputStream (java.io.FileInputStream)10 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)10 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)7 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)4