Search in sources :

Example 41 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class RequisitionFrom18Test method test18Requisitions.

@Test
public void test18Requisitions() {
    final Set<Requisition> requisitions = m_foreignSourceRepository.getRequisitions();
    assertEquals(11, requisitions.size());
    int nodeCount = 0;
    int interfaceCount = 0;
    for (final Requisition r : requisitions) {
        LOG.debug("got requisition: {}", r);
        nodeCount += r.getNodeCount();
        for (RequisitionNode node : r.getNode()) {
            interfaceCount += node.getInterfaceCount();
            if ("pgvip-master.somemediathing.net".equals(node.getNodeLabel())) {
                // Make sure that parent-foreign-source and parent-foreign-id work
                assertEquals("postgres", node.getParentForeignSource());
                assertEquals("1241674181872", node.getParentForeignId());
                assertEquals("barbacoa.somemediathing.net", node.getParentNodeLabel());
            }
        }
    }
    assertEquals("There is an unexpected number of nodes in the test requisitions", 49, nodeCount);
    assertEquals("There is an unexpected number of interfaces in the test requisitions", 60, interfaceCount);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 42 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method createRequisition.

private Requisition createRequisition() throws Exception {
    FileSystemResource resource = new FileSystemResource(getRequisitionFile());
    Requisition r = m_foreignSourceRepository.importResourceRequisition(resource);
    m_foreignSourceRepository.save(r);
    m_foreignSourceRepository.flush();
    // Give enough time to watcher's thread to cache the requisition
    Thread.sleep(2000);
    return r;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 43 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method testRequisition.

@Test
public void testRequisition() throws Exception {
    createRequisition();
    Requisition r = m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName);
    TestVisitor v = new TestVisitor();
    r.visit(v);
    assertEquals("number of nodes visited", 2, v.getNodeReqs().size());
    assertEquals("node name matches", "apknd", v.getNodeReqs().get(0).getNodeLabel());
    // Modifying the requisition outside the repository and verifying that the repository cache was updated.
    modifyRequisition();
    r = m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName);
    v = new TestVisitor();
    r.visit(v);
    assertEquals("number of nodes visited", 3, v.getNodeReqs().size());
    assertEquals("node name matches", "apknd_2", v.getNodeReqs().get(0).getNodeLabel());
    assertEquals("node name matches", "wan0", v.getNodeReqs().get(1).getNodeLabel());
    assertEquals("node name matches", "utility-robot", v.getNodeReqs().get(2).getNodeLabel());
    // Removing the requisition outside the repository and verifying that the repository cache was updated.
    deleteRequisition();
    r = m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName);
    Assert.assertNull(r);
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 44 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method modifyRequisition.

private void modifyRequisition() throws Exception {
    Requisition r = JaxbUtils.unmarshal(Requisition.class, getRequisitionFile());
    Assert.assertNotNull(r);
    // Modify existing node
    r.getNode("4243").setNodeLabel("apknd_2");
    RequisitionNode n = new RequisitionNode();
    n.setForeignId("R2D2");
    n.setNodeLabel("utility-robot");
    n.getCategories().add(new RequisitionCategory("StarWars"));
    n.getCategories().add(new RequisitionCategory("Rebels"));
    // Add a new node
    r.getNodes().add(n);
    JaxbUtils.marshal(r, new FileWriter(getRequisitionFile()));
    // Give enough time to watcher's thread to cache the requisition
    Thread.sleep(2000);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) FileWriter(java.io.FileWriter) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 45 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class FasterFilesystemForeignSourceRepositoryTest method testImportHttpSource.

@Test
@JUnitHttpServer(port = 9162)
public void testImportHttpSource() throws Exception {
    FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource");
    File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop();
    File reqDir = bldr.dir("requisitions").file("test.xml", req("test")).file("pending.xml", req("pending")).pop();
    FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir);
    Resource resource = new UrlResource("http://localhost:9162/requisition-test.xml");
    Requisition req = repo.importResourceRequisition(resource);
    assertNotNull(req);
    System.err.println(JaxbUtils.marshal(req));
    assertNotNull(req.getNode("4243"));
    assertNotNull(req.getNode("4244"));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)70 Test (org.junit.Test)31 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)16 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)11 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)11 UrlResource (org.springframework.core.io.UrlResource)10 File (java.io.File)9 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)8 Resource (org.springframework.core.io.Resource)8 IOException (java.io.IOException)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 InetAddress (java.net.InetAddress)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3