Search in sources :

Example 51 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class ProvisionerIT method testRequisitionedCategoriesWithPolicies.

@Test(timeout = 300000)
public void testRequisitionedCategoriesWithPolicies() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    final ForeignSource fs = m_foreignSourceRepository.getForeignSource("empty");
    final PluginConfig policy = new PluginConfig("addDumbCategory", NodeCategorySettingPolicy.class.getName());
    policy.addParameter("category", "Dumb");
    policy.addParameter("label", "test");
    fs.addPolicy(policy);
    m_foreignSourceRepository.save(fs);
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    // after import, we should have 1 category, because policies haven't been applied yet
    OnmsNode n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertEquals("TotallyMadeUpCategoryName", n.getCategories().iterator().next().getName());
    assertEquals(0, n.getRequisitionedCategories().size());
    runPendingScans();
    // when the scan has completed, both categories should have been applied
    n = getNodeDao().get(nextNodeId);
    assertEquals(2, n.getCategories().size());
    assertTrue(n.hasCategory("TotallyMadeUpCategoryName"));
    assertTrue(n.hasCategory("Dumb"));
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) NodeCategorySettingPolicy(org.opennms.netmgt.provision.persist.policies.NodeCategorySettingPolicy) Test(org.junit.Test)

Example 52 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class ProvisionerIT method testRequisitionedCategoriesThenUpdateRequisitionToRemoveCategory.

@Test(timeout = 300000)
public void testRequisitionedCategoriesThenUpdateRequisitionToRemoveCategory() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    runPendingScans();
    // make sure we have the 1 category we expect
    OnmsNode n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertTrue(n.hasCategory("TotallyMadeUpCategoryName"));
    importFromResource("classpath:/provisioner-testCategories-noCategories.xml", Boolean.TRUE.toString());
    runPendingScans();
    // when the scan has completed, the category should be removed
    n = getNodeDao().get(nextNodeId);
    assertEquals(0, n.getCategories().size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test)

Example 53 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class InvalidRequisitionDataIT method testImportInvalidAsset.

@Test
public void testImportInvalidAsset() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    assertEquals(0, m_nodeDao.countAll());
    final Resource invalidAssetFieldResource = getResource("classpath:/import_invalidAssetFieldName.xml");
    m_eventManager.getEventAnticipator().anticipateEvent(getStarted(invalidAssetFieldResource));
    m_eventManager.getEventAnticipator().anticipateEvent(getSuccessful(invalidAssetFieldResource));
    m_eventManager.getEventAnticipator().anticipateEvent(getNodeAdded(nextNodeId));
    m_eventManager.getEventAnticipator().anticipateEvent(getNodeGainedInterface(nextNodeId));
    m_eventManager.getEventAnticipator().anticipateEvent(getNodeGainedService(nextNodeId));
    m_eventManager.getEventAnticipator().anticipateEvent(getNodeScanCompleted(nextNodeId));
    // This requisition has an asset on some nodes called "pollercategory".
    // Change it to "pollerCategory" (capital 'C') and the test passes...
    m_provisioner.doImport(invalidAssetFieldResource.getURL().toString(), Boolean.TRUE.toString());
    waitForEverything();
    m_eventManager.getEventAnticipator().verifyAnticipated();
    // should still import the node, just skip the asset field
    assertEquals(1, m_nodeDao.countAll());
    OnmsNode node = m_nodeDao.get(m_nodeDao.getNodeIds().iterator().next());
    assertEquals("yellow human", node.getAssetRecord().getDescription());
    assertNull(node.getAssetRecord().getPollerCategory());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Resource(org.springframework.core.io.Resource) Test(org.junit.Test)

Example 54 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class ProvisionerIT method testProvisionerAddNodeToSchedule.

@Test(timeout = 300000)
public void testProvisionerAddNodeToSchedule() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    m_provisioner.scheduleRescanForExistingNodes();
    assertEquals(0, m_provisioner.getScheduleLength());
    final OnmsNode node = createNode("empty");
    assertEquals(nextNodeId, node.getId().intValue());
    assertNotNull(m_nodeDao.get(nextNodeId));
    final EventBuilder bldr = new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Tests");
    bldr.setNodeid(nextNodeId);
    m_mockEventIpcManager.broadcastNow(bldr.getEvent());
    assertEquals(1, m_provisioner.getScheduleLength());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 55 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class ProvisionerIT method testNonSnmpImportAndScan.

@Test(timeout = 300000)
public void testNonSnmpImportAndScan() throws Exception {
    importFromResource("classpath:/import_localhost.xml", Boolean.TRUE.toString());
    runPendingScans();
    final OnmsNode scannedNode = getNodeDao().findAll().get(0);
    assertEquals("TestCategory", scannedNode.getCategories().iterator().next().getName());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23