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