Search in sources :

Example 1 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 2 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 3 with UrlResource

use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.

the class PathResourceResolverTests method checkRelativeLocation.

// SPR-12624
@Test
public void checkRelativeLocation() throws Exception {
    String locationUrl = new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
    Resource location = new UrlResource(locationUrl.replace("/springframework", "/../org/springframework"));
    List<Resource> locations = singletonList(location);
    assertNotNull(this.resolver.resolveResource(null, "main.css", locations, null).block(Duration.ofMillis(5000)));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Test(org.junit.Test)

Example 4 with UrlResource

use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.

the class ResourceWebHandlerTests method testInvalidPath.

private void testInvalidPath(HttpMethod httpMethod) throws Exception {
    Resource location = new ClassPathResource("test/", getClass());
    this.handler.setLocations(Collections.singletonList(location));
    testInvalidPath(httpMethod, "../testsecret/secret.txt", location);
    testInvalidPath(httpMethod, "test/../../testsecret/secret.txt", location);
    testInvalidPath(httpMethod, ":/../../testsecret/secret.txt", location);
    location = new UrlResource(getClass().getResource("./test/"));
    this.handler.setLocations(Collections.singletonList(location));
    Resource secretResource = new UrlResource(getClass().getResource("testsecret/secret.txt"));
    String secretPath = secretResource.getURL().getPath();
    testInvalidPath(httpMethod, "file:" + secretPath, location);
    testInvalidPath(httpMethod, "/file:" + secretPath, location);
    testInvalidPath(httpMethod, "url:" + secretPath, location);
    testInvalidPath(httpMethod, "/url:" + secretPath, location);
    testInvalidPath(httpMethod, "////../.." + secretPath, location);
    testInvalidPath(httpMethod, "/%2E%2E/testsecret/secret.txt", location);
    testInvalidPath(httpMethod, "url:" + secretPath, location);
// The following tests fail with a MalformedURLException on Windows
// testInvalidPath(location, "/" + secretPath);
// testInvalidPath(location, "/  " + secretPath);
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 5 with UrlResource

use of org.springframework.core.io.UrlResource in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testDoubleArrayConstructorWithAutowiring.

@Test
public void testDoubleArrayConstructorWithAutowiring() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerSingleton("integer1", new Integer(4));
    bf.registerSingleton("integer2", new Integer(5));
    bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
    bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
    RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
    rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    bf.registerBeanDefinition("arrayBean", rbd);
    ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
    assertEquals(new Integer(4), ab.getIntegerArray()[0]);
    assertEquals(new Integer(5), ab.getIntegerArray()[1]);
    assertEquals(new UrlResource("http://localhost:8080"), ab.getResourceArray()[0]);
    assertEquals(new UrlResource("http://localhost:9090"), ab.getResourceArray()[1]);
}
Also used : UrlResource(org.springframework.core.io.UrlResource) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

UrlResource (org.springframework.core.io.UrlResource)100 Resource (org.springframework.core.io.Resource)41 URL (java.net.URL)33 Test (org.junit.jupiter.api.Test)30 Test (org.junit.Test)24 ClassPathResource (org.springframework.core.io.ClassPathResource)19 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)14 FileSystemResource (org.springframework.core.io.FileSystemResource)13 MalformedURLException (java.net.MalformedURLException)11 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)10 lombok.val (lombok.val)9 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)9 GenericBean (org.springframework.beans.testfixture.beans.GenericBean)9 File (java.io.File)8 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)8 InputStream (java.io.InputStream)6 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 Properties (java.util.Properties)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5