use of org.springframework.core.io.UrlResource in project cxf by apache.
the class SpringServiceBuilderFactory method getApplicationContext.
/**
* This is factored out to permit use in a unit test.
*
* @param additionalFilePathnames
* @return
*/
public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames) {
BusApplicationContext busApplicationContext = BusFactory.getDefaultBus().getExtension(BusApplicationContext.class);
GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
List<URL> urls = ClassLoaderUtils.getResources("META-INF/cxf/java2wsbeans.xml", SpringServiceBuilderFactory.class);
for (URL url : urls) {
reader.loadBeanDefinitions(new UrlResource(url));
}
for (String pathname : additionalFilePathnames) {
try {
reader.loadBeanDefinitions(new FileSystemResource(pathname));
} catch (BeanDefinitionStoreException bdse) {
throw new ToolException("Unable to open bean definition file " + pathname, bdse.getCause());
}
}
appContext.refresh();
return appContext;
}
use of org.springframework.core.io.UrlResource in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentNotExisting.
@Test
public void testReadDocumentNotExisting() throws MalformedURLException {
ExternalAttachmentProvider eap = new ExternalAttachmentProvider();
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments1.xml");
String uri = url.toExternalForm();
uri = uri.replaceAll("attachments1.xml", "attachments0.xml");
eap.setLocation(new UrlResource(uri));
try {
eap.readDocument();
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
assertTrue(ex.getCause() instanceof FileNotFoundException);
}
}
use of org.springframework.core.io.UrlResource in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentEPRDomainExpression.
@Test
public void testReadDocumentEPRDomainExpression() throws MalformedURLException {
Bus bus = control.createMock(Bus.class);
DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
DomainExpression de = control.createMock(DomainExpression.class);
EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andReturn(de);
PolicyBuilder pb = control.createMock(PolicyBuilder.class);
EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(pb).anyTimes();
Policy p = control.createMock(Policy.class);
EasyMock.expect(pb.getPolicy(EasyMock.isA(Element.class))).andReturn(p);
control.replay();
ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus);
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments4.xml");
String uri = url.toExternalForm();
eap.setLocation(new UrlResource(uri));
eap.readDocument();
assertEquals(1, eap.getAttachments().size());
PolicyAttachment pa = eap.getAttachments().iterator().next();
assertSame(p, pa.getPolicy());
assertEquals(1, pa.getDomainExpressions().size());
assertSame(de, pa.getDomainExpressions().iterator().next());
control.verify();
}
use of org.springframework.core.io.UrlResource in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentWithoutAttachmentElements.
@Test
public void testReadDocumentWithoutAttachmentElements() throws MalformedURLException {
ExternalAttachmentProvider eap = new ExternalAttachmentProvider();
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments1.xml");
String uri = url.toExternalForm();
eap.setLocation(new UrlResource(uri));
eap.readDocument();
assertTrue(eap.getAttachments().isEmpty());
}
use of org.springframework.core.io.UrlResource in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentUnknownDomainExpression.
@Test
public void testReadDocumentUnknownDomainExpression() throws MalformedURLException {
Bus bus = control.createMock(Bus.class);
DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andThrow(new PolicyException(new Exception()));
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments3.xml");
String uri = url.toExternalForm();
control.replay();
ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus);
eap.setLocation(new UrlResource(uri));
try {
eap.readDocument();
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
control.verify();
}
Aggregations