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