use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class ProvisionerIT method testDnsVisit.
/**
* We have to ignore this test until there is a DNS service available in the test harness
*
* @throws ForeignSourceRepositoryException
* @throws MalformedURLException
*/
@Test(timeout = 300000)
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "opennms.com.", v4address = "1.2.3.4", entries = { @DNSEntry(hostname = "www", address = "1.2.3.4") }) })
public void testDnsVisit() throws ForeignSourceRepositoryException, MalformedURLException {
final Requisition requisition = m_foreignSourceRepository.importResourceRequisition(new UrlResource("dns://localhost:9153/opennms.com"));
final CountingVisitor visitor = new CountingVisitor() {
@Override
public void visitNode(final OnmsNodeRequisition req) {
LOG.debug("visitNode: {}/{} {}", req.getForeignSource(), req.getForeignId(), req.getNodeLabel());
m_nodes.add(req);
m_nodeCount++;
}
@Override
public void visitInterface(final OnmsIpInterfaceRequisition req) {
LOG.debug("visitInterface: {}", req.getIpAddr());
m_ifaces.add(req);
m_ifaceCount++;
}
};
requisition.visit(visitor);
verifyDnsImportCounts(visitor);
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class FusedForeignSourceRepositoryTest method integrationTest.
@Test
public void integrationTest() {
/*
* First, the user creates a requisition in the UI, or RESTful
* interface.
*/
Requisition pendingReq = new Requisition("test");
pendingReq.putNode(createNode("1"));
m_pending.save(pendingReq);
m_pending.flush();
/*
* Then, the user makes a foreign source configuration to go along
* with that requisition.
*/
ForeignSource pendingSource = m_repository.getForeignSource("test");
assertTrue(pendingSource.isDefault());
pendingSource.setDetectors(new ArrayList<PluginConfig>());
m_pending.save(pendingSource);
m_pending.flush();
/*
* Now we got an import event, so we import that requisition file,
* and save it. The ForeignSource in the pending repository should
* match the one in the active one, now.
*/
Requisition activeReq = m_repository.importResourceRequisition(new UrlResource(m_pending.getRequisitionURL("test")));
ForeignSource activeSource = m_active.getForeignSource("test");
// and the foreign source should be the same as the one we made earlier, only this time it's active
assertEquals(activeSource.getName(), pendingSource.getName());
assertEquals(activeSource.getDetectorNames(), pendingSource.getDetectorNames());
assertEquals(activeSource.getScanInterval(), pendingSource.getScanInterval());
assertRequisitionsMatch("active and pending requisitions should match", activeReq, pendingReq);
/*
* Since it's been officially deployed, the requisition and foreign
* source should no longer be in the pending repo.
*/
assertNull("the requisition should be null in the pending repo", m_pending.getRequisition("test"));
assertTrue("the foreign source should be default since there's no specific in the pending repo", m_pending.getForeignSource("test").isDefault());
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class HandlerTest method dwOpenConnectionURL.
@Test
@Ignore
public void dwOpenConnectionURL() throws IOException {
URL url = new URL(DNS_URL);
UrlResource resource = new UrlResource(url);
MockForeignSourceRepository fsr = new MockForeignSourceRepository();
Requisition r = fsr.importResourceRequisition(resource);
Assert.assertTrue("Number of nodes in Model Import > 1", 1 == r.getNodeCount());
Assert.assertTrue("NodeLabel isn't localhost", "localhost".equals(r.getNodes().get(0).getNodeLabel()));
Assert.assertTrue("127.0.0.1".equals(r.getNodes().get(0).getInterfaces().get(0).getIpAddr()));
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingNonMatchingExpression.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99"), @DNSEntry(hostname = "monkey", address = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingNonMatchingExpression() throws IOException, JAXBException {
String urlString = "dns://localhost:9153/example.com/?expression=Local.*";
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(0, req.getNodeCount());
resourceStream.close();
}
use of org.springframework.core.io.UrlResource in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResource.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99") }) })
public void dwoUrlAsResource() throws IOException, JAXBException {
Resource resource = new UrlResource(TEST_URL);
Assert.assertEquals(TEST_URL, 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("should have 2 A records: 1 for example.com, and 1 for www.example.com", 2, req.getNodeCount());
resourceStream.close();
}
Aggregations