Search in sources :

Example 66 with Requisition

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

the class MockForeignSourceRepositoryTest method testBeanWrapperAccess.

/**
 * This test ensures that the Spring Bean accessor classes work properly
 * since our REST implementation uses bean access to update the values.
 */
@Test
public void testBeanWrapperAccess() throws Exception {
    createRequisition();
    Requisition r = m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName);
    BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(r);
    assertEquals("AC", wrapper.getPropertyValue("node[0].category[0].name"));
    assertEquals("UK", wrapper.getPropertyValue("node[0].category[1].name"));
    assertEquals("low", wrapper.getPropertyValue("node[0].category[2].name"));
    try {
        wrapper.getPropertyValue("node[1].category[0].name");
        fail("Did not catch expected InvalidPropertyException exception");
    } catch (InvalidPropertyException e) {
    // Expected failure
    }
    assertEquals(0, ((RequisitionCategory[]) wrapper.getPropertyValue("node[1].category")).length);
    wrapper.setPropertyValue("node[1].categories[0]", new RequisitionCategory("Hello world"));
    wrapper.setPropertyValue("node[1].categories[1]", new RequisitionCategory("Hello again"));
    assertEquals(2, ((RequisitionCategory[]) wrapper.getPropertyValue("node[1].category")).length);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 67 with Requisition

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

the class ProvisionServiceIT method dwLoadRequisition.

/**
 * This test should be set to Ignore until a DNS server can be integrated into unit tests
 *
 * @throws MalformedURLException
 */
@Test
@Ignore
public void dwLoadRequisition() throws MalformedURLException {
    String nodeLabel = "localhost";
    int nhash = nodeLabel.hashCode();
    int chash = "localhost".hashCode();
    Assert.assertEquals(nhash, chash);
    Resource resource = new UrlResource("dns://localhost/localhost");
    Requisition r = m_provService.loadRequisition(resource);
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.getNodeCount());
    String foreignId = String.valueOf("localhost".hashCode());
    RequisitionNode node = r.getNode(foreignId);
    Assert.assertNotNull(node);
    RequisitionInterface inf = node.getInterface("127.0.0.1");
    Assert.assertNotNull(inf);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 68 with Requisition

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

the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingMatchingExpression.

@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99"), @DNSEntry(hostname = "monkey", data = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingMatchingExpression() throws IOException, JAXBException {
    String urlString = "dns://localhost:9153/example.com/?expression=[Ww]ww.*";
    Resource resource = new UrlResource(urlString);
    Assert.assertEquals(urlString, resource.getURL().toString());
    Requisition req = null;
    Assert.assertNotNull(resource);
    InputStream resourceStream = resource.getInputStream();
    JAXBContext context = JAXBContext.newInstance(Requisition.class);
    Unmarshaller um = context.createUnmarshaller();
    um.setSchema(null);
    req = (Requisition) um.unmarshal(resourceStream);
    Assert.assertEquals(1, req.getNodeCount());
    resourceStream.close();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 69 with Requisition

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

the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingComplexMatchingExpression.

@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingComplexMatchingExpression() throws IOException, JAXBException {
    String urlString = "dns://localhost:9153/example.com/?expression=(%3Fi)^WWW.EXAM.*";
    Resource resource = new UrlResource(urlString);
    Assert.assertEquals(urlString, resource.getURL().toString());
    Requisition req = null;
    Assert.assertNotNull(resource);
    InputStream resourceStream = resource.getInputStream();
    JAXBContext context = JAXBContext.newInstance(Requisition.class);
    Unmarshaller um = context.createUnmarshaller();
    um.setSchema(null);
    req = (Requisition) um.unmarshal(resourceStream);
    Assert.assertEquals(1, req.getNodeCount());
    resourceStream.close();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 70 with Requisition

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

the class CsvRequisitionParser method createOrUpdateRequistion.

private static void createOrUpdateRequistion(RequisitionData rd) throws UnknownHostException {
    Requisition r = null;
    RequisitionNode rn = new RequisitionNode();
    String foreignSource = rd.getForeignSource();
    r = m_fsr.getRequisition(foreignSource);
    if (r == null) {
        r = new Requisition(foreignSource);
    }
    System.err.println("Creating/Updating requistion: " + foreignSource);
    r.updateDateStamp();
    RequisitionMonitoredServiceCollection services = new RequisitionMonitoredServiceCollection();
    for (String svc : m_serviceList) {
        services.add(new RequisitionMonitoredService(svc));
    }
    RequisitionInterface iface = new RequisitionInterface();
    iface.setDescr("mgmt-if");
    iface.setIpAddr(rd.getPrimaryIp());
    iface.setManaged(true);
    iface.setSnmpPrimary(PrimaryType.PRIMARY);
    iface.setStatus(Integer.valueOf(1));
    iface.setMonitoredServices(services.getObjects());
    RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
    ric.add(iface);
    // add categories requisition level categories
    RequisitionCategoryCollection rcc = new RequisitionCategoryCollection();
    if (m_categoryList != null && m_categoryList.size() > 0) {
        for (String cat : m_categoryList) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    // add categories already on the node to the requisition
    if (rd.getCategories() != null) {
        for (String cat : rd.getCategories()) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    rn.setBuilding(foreignSource);
    if (rcc.size() >= 1) {
        rn.setCategories(rcc.getObjects());
    }
    rn.setForeignId(rd.getForeignId());
    rn.setInterfaces(ric.getObjects());
    String nodeLabel = rd.getNodeLabel();
    if (m_resolveIps) {
        InetAddress addr = InetAddress.getByName(rd.getPrimaryIp());
        nodeLabel = addr.getCanonicalHostName();
    }
    rn.setNodeLabel(nodeLabel);
    // r.insertNode(rn);
    r.putNode(rn);
    m_fsr.save(r);
}
Also used : RequisitionCategoryCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionCategoryCollection) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionMonitoredServiceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredServiceCollection) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) InetAddress(java.net.InetAddress) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

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