View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.ws.construct;
8   
9   import org.mule.MessageExchangePattern;
10  import org.mule.api.construct.FlowConstructInvalidException;
11  import org.mule.tck.MuleTestUtils;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  
14  import java.net.URI;
15  import java.util.concurrent.Callable;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertTrue;
20  import static org.junit.Assert.fail;
21  
22  public class WsProxyConfigurationIssuesTestCase extends AbstractMuleContextTestCase
23  {
24      @Test
25      public void testNullMessageSource()
26      {
27          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
28          {
29              public WSProxy call() throws Exception
30              {
31                  return new WSProxy("testNullMessageSource", muleContext, null,
32                      MuleTestUtils.getTestOutboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE,
33                          muleContext));
34              }
35          });
36      }
37  
38      @Test
39      public void testNullOutboundEndpoint()
40      {
41          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
42          {
43              public WSProxy call() throws Exception
44              {
45                  return new WSProxy("testNullOutboundEndpoint", muleContext,
46                      getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE), null);
47              }
48          });
49      }
50  
51      @Test
52      public void testNullOutboundEndpointWithWsdl()
53      {
54          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
55          {
56              public WSProxy call() throws Exception
57              {
58                  return new WSProxy("testNullOutboundEndpointWithWsdl", muleContext,
59                      getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE), null, "fake_wsdl");
60              }
61          });
62      }
63  
64      @Test
65      public void testBlankWsdlContents()
66      {
67          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
68          {
69              public WSProxy call() throws Exception
70              {
71                  return new WSProxy("testBlankWsdlContents", muleContext,
72                      getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE),
73                      MuleTestUtils.getTestOutboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE,
74                          muleContext), "");
75              }
76          });
77      }
78  
79      @Test
80      public void testNullWsdlUri()
81      {
82          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
83          {
84              public WSProxy call() throws Exception
85              {
86                  return new WSProxy("testNullWsdlUrl", muleContext,
87                      getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE),
88                      MuleTestUtils.getTestOutboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE,
89                          muleContext), (URI) null);
90              }
91          });
92      }
93  
94      @Test
95      public void testOneWayInboundEndpoint()
96      {
97          runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
98          {
99              public WSProxy call() throws Exception
100             {
101                 return new WSProxy("testOneWayInboundEndpoint", muleContext,
102                     getTestInboundEndpoint(MessageExchangePattern.ONE_WAY),
103                     MuleTestUtils.getTestOutboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE,
104                         muleContext));
105             }
106         });
107     }
108 
109     @Test
110     public void testOneWayOutboundEndpoint()
111     {
112         runTestFailingWithExpectedFlowConstructInvalidException(new Callable<WSProxy>()
113         {
114             public WSProxy call() throws Exception
115             {
116                 return new WSProxy("testOneWayOutboundEndpoint", muleContext,
117                     getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE),
118                     MuleTestUtils.getTestOutboundEndpoint(MessageExchangePattern.ONE_WAY, muleContext));
119             }
120         });
121     }
122 
123     private void runTestFailingWithExpectedFlowConstructInvalidException(Callable<WSProxy> failingStatement)
124     {
125         try
126         {
127             failingStatement.call().validateConstruct();
128             fail("should have got a FlowConstructInvalidException");
129         }
130         catch (final Exception e)
131         {
132             assertTrue(e instanceof FlowConstructInvalidException);
133         }
134     }
135 }