1
2
3
4
5
6
7 package org.mule.module.ws.construct;
8
9 import org.mule.MessageExchangePattern;
10 import org.mule.api.MuleEvent;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.endpoint.EndpointBuilder;
13 import org.mule.api.endpoint.InboundEndpoint;
14 import org.mule.api.endpoint.OutboundEndpoint;
15 import org.mule.api.transport.PropertyScope;
16 import org.mule.construct.AbstractFlowConstruct;
17 import org.mule.construct.AbstractFlowConstuctTestCase;
18 import org.mule.tck.MuleTestUtils;
19
20 import java.net.URI;
21
22 import org.junit.Test;
23 import org.mockito.Mock;
24 import org.mockito.MockitoAnnotations;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.mockito.Mockito.when;
28
29
30
31
32
33 public class WSProxyPathBugTestCase extends AbstractFlowConstuctTestCase
34 {
35 private static final String INBOUND_ADDRESS = "test://myhost:8090/weather-forecast";
36 private static final String OUTBOUND_ADDRESS = "test://ws.acme.com:6090/weather-forecast";
37 private static final String WSDL_LOCATION_SAME_PATH = OUTBOUND_ADDRESS;
38 private static final String WSDL_LOCATION_DIFFERENT_PATH = "test://ws.acme.com:6090/wsdl/weather-forecast";
39
40 private WSProxy proxy;
41 private MuleEvent inboundEvent;
42
43 @Mock
44 private EndpointBuilder mockEndpointBuilder;
45 @Mock
46 private InboundEndpoint mockWsdlEndpoint;
47 @Mock
48 private MuleMessage mockMuleMessage;
49
50 private OutboundEndpoint testOutboundEndpoint;
51
52 @Override
53 protected void doSetUp() throws Exception
54 {
55 super.doSetUp();
56 MockitoAnnotations.initMocks(this);
57 when(mockMuleMessage.getPayloadAsString()).thenReturn(OUTBOUND_ADDRESS);
58 inboundEvent = getTestEvent(null, getTestInboundEndpoint("test-inbound", INBOUND_ADDRESS));
59 when(mockWsdlEndpoint.request(inboundEvent.getTimeout())).thenReturn(mockMuleMessage);
60 inboundEvent.getMessage().setProperty("http.request", INBOUND_ADDRESS + "?wsdl", PropertyScope.INBOUND);
61 when(mockEndpointBuilder.buildInboundEndpoint()).thenReturn(mockWsdlEndpoint);
62 testOutboundEndpoint = MuleTestUtils.getTestOutboundEndpoint(
63 MessageExchangePattern.REQUEST_RESPONSE, muleContext, OUTBOUND_ADDRESS, null);
64 proxy = new WSProxy("test-proxy", muleContext, directInboundMessageSource, testOutboundEndpoint);
65
66 }
67
68 @Test
69 public void testWithSamePath() throws Exception
70 {
71 assertOnUriRewrite(WSDL_LOCATION_SAME_PATH);
72 }
73
74
75 @Test
76 public void testWithDifferentPath() throws Exception
77 {
78 assertOnUriRewrite(WSDL_LOCATION_DIFFERENT_PATH);
79 }
80
81 private void assertOnUriRewrite(String wsdlLocation) throws Exception
82 {
83 setUpProxy(wsdlLocation);
84 MuleEvent response = directInboundMessageSource.process(inboundEvent);
85 assertEquals(INBOUND_ADDRESS, response.getMessageAsString());
86 }
87
88 private void setUpProxy(String wsdlLocation) throws Exception
89 {
90 muleContext.getRegistry().registerEndpointBuilder(wsdlLocation, mockEndpointBuilder);
91 proxy = new WSProxy("test-proxy", muleContext, directInboundMessageSource,
92 testOutboundEndpoint, new URI(wsdlLocation));
93 proxy.initialise();
94 proxy.start();
95 }
96
97 @Override
98 protected AbstractFlowConstruct getFlowConstruct()
99 {
100 return proxy;
101 }
102 }