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