Search in sources :

Example 26 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 27 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 28 with OnmsNode

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

the class ProvisionerIT method testImportUtf8.

/**
     * This test first bulk imports 10 nodes then runs update with 1 node missing
     * from the import file.
     * 
     * @throws ModelImportException
     */
@Test(timeout = 300000)
public void testImportUtf8() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    m_provisioner.importModelFromResource(new ClassPathResource("/utf-8.xml"), Boolean.TRUE.toString());
    assertEquals(1, getNodeDao().countAll());
    // ñ is unicode for n~ 
    final OnmsNode onmsNode = getNodeDao().get(nextNodeId);
    LOG.debug("node = {}", onmsNode);
    assertEquals("ñode2", onmsNode.getLabel());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 29 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 30 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)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)438 Test (org.junit.Test)187 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)99 Transactional (org.springframework.transaction.annotation.Transactional)76 ArrayList (java.util.ArrayList)48 Date (java.util.Date)40 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)36 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)31 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)31 InetAddress (java.net.InetAddress)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 Before (org.junit.Before)27 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)26 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)26 File (java.io.File)24 HashMap (java.util.HashMap)23 List (java.util.List)21 Path (javax.ws.rs.Path)21 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)20