Search in sources :

Example 96 with UrlResource

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;
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) UrlResource(org.springframework.core.io.UrlResource) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL)

Example 97 with UrlResource

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);
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) PolicyException(org.apache.cxf.ws.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) Test(org.junit.Test)

Example 98 with UrlResource

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();
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) UrlResource(org.springframework.core.io.UrlResource) Element(org.w3c.dom.Element) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) URL(java.net.URL) Test(org.junit.Test)

Example 99 with UrlResource

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());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) URL(java.net.URL) Test(org.junit.Test)

Example 100 with UrlResource

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();
}
Also used : Bus(org.apache.cxf.Bus) PolicyException(org.apache.cxf.ws.policy.PolicyException) UrlResource(org.springframework.core.io.UrlResource) Element(org.w3c.dom.Element) PolicyException(org.apache.cxf.ws.policy.PolicyException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) 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