1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.ws.construct.builder;
12
13 import java.io.File;
14 import java.net.URI;
15 import java.net.URISyntaxException;
16
17 import org.mule.api.MuleException;
18 import org.mule.api.config.ConfigurationException;
19 import org.mule.exception.DefaultServiceExceptionStrategy;
20 import org.mule.module.ws.construct.WSProxy;
21 import org.mule.tck.AbstractMuleTestCase;
22 import org.mule.transformer.compression.GZipCompressTransformer;
23 import org.mule.transformer.simple.ObjectToByteArray;
24 import org.mule.transformer.simple.StringAppendTransformer;
25
26 public class WSProxyBuilderTestCase extends AbstractMuleTestCase
27 {
28 public void testConfigurationInvalidFileWsdl()
29 {
30 try
31 {
32 new WSProxyBuilder().name("test-ws-proxy-invalid-file-wsdl")
33 .wsdlFile(new File("missing_file.foo"))
34 .inboundAddress("test://foo")
35 .outboundAddress("test://bar")
36 .build(muleContext);
37 fail("should have raised a MuleException");
38 }
39 catch (final MuleException me)
40 {
41 assertTrue(me instanceof ConfigurationException);
42 }
43 }
44
45 public void testFullConfigurationFileWsdl() throws Exception
46 {
47 final WSProxy wsProxy = new WSProxyBuilder().name("test-ws-proxy-full-file-wsdl")
48 .wsdlFile(new File(getTestWsdlUri()))
49 .inboundAddress("test://foo")
50 .outboundAddress("test://bar")
51 .outboundTransformers(new StringAppendTransformer("bar"))
52 .outboundResponseTransformers(new ObjectToByteArray(), new GZipCompressTransformer())
53 .exceptionStrategy(new DefaultServiceExceptionStrategy(muleContext))
54 .build(muleContext);
55
56 assertEquals("test-ws-proxy-full-file-wsdl", wsProxy.getName());
57 }
58
59 public void testConfigurationUriWsdl() throws Exception
60 {
61 final WSProxy wsProxy = new WSProxyBuilder().name("test-ws-proxy-uri-wsdl").wsldLocation(
62 getTestWsdlUri()).inboundAddress("test://foo").outboundAddress("test://bar").build(muleContext);
63
64 assertEquals("test-ws-proxy-uri-wsdl", wsProxy.getName());
65 }
66
67 public void testConfigurationNoWsdl() throws Exception
68 {
69 final WSProxy wsProxy = new WSProxyBuilder().name("test-ws-proxy-no-wsdl").inboundAddress(
70 "test://foo").outboundAddress("test://bar").build(muleContext);
71
72 assertEquals("test-ws-proxy-no-wsdl", wsProxy.getName());
73 }
74
75 private URI getTestWsdlUri() throws URISyntaxException
76 {
77 return Thread.currentThread().getContextClassLoader().getResource("weather-forecaster.wsdl").toURI();
78 }
79 }