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);
}
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);
}
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();
}
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();
}
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);
}
Aggregations