Search in sources :

Example 16 with UrlResource

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);
}
Also used : OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) UrlResource(org.springframework.core.io.UrlResource) OnmsNodeCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsNodeCategoryRequisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) OnmsMonitoredServiceRequisition(org.opennms.netmgt.provision.persist.OnmsMonitoredServiceRequisition) OnmsServiceCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsServiceCategoryRequisition) OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) OnmsAssetRequisition(org.opennms.netmgt.provision.persist.OnmsAssetRequisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 17 with UrlResource

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());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) UrlResource(org.springframework.core.io.UrlResource) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 18 with UrlResource

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()));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) URL(java.net.URL) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with UrlResource

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();
}
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 20 with UrlResource

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

Aggregations

UrlResource (org.springframework.core.io.UrlResource)56 Test (org.junit.Test)31 Resource (org.springframework.core.io.Resource)26 URL (java.net.URL)17 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)10 ArrayList (java.util.ArrayList)9 ClassPathResource (org.springframework.core.io.ClassPathResource)9 GenericBean (org.springframework.tests.sample.beans.GenericBean)9 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 JUnitDNSServer (org.opennms.core.test.dns.annotations.JUnitDNSServer)5 BeansException (org.springframework.beans.BeansException)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 MalformedURLException (java.net.MalformedURLException)4 JAXBContext (javax.xml.bind.JAXBContext)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 File (java.io.File)3