1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.transport.support;
18  
19  import java.net.URI;
20  
21  import org.springframework.ws.MockWebServiceMessage;
22  import org.springframework.ws.MockWebServiceMessageFactory;
23  import org.springframework.ws.WebServiceMessage;
24  import org.springframework.ws.context.MessageContext;
25  import org.springframework.ws.transport.WebServiceConnection;
26  import org.springframework.ws.transport.WebServiceMessageReceiver;
27  
28  import org.junit.Assert;
29  import org.junit.Before;
30  import org.junit.Test;
31  
32  import static org.easymock.EasyMock.*;
33  public class WebServiceMessageReceiverObjectSupportTest {
34  
35      private WebServiceMessageReceiverObjectSupport receiverSupport;
36  
37      private WebServiceConnection connectionMock;
38  
39      private MockWebServiceMessageFactory messageFactory;
40  
41      private MockWebServiceMessage request;
42  
43      @Before
44      public void setUp() throws Exception {
45          receiverSupport = new MyReceiverSupport();
46          messageFactory = new MockWebServiceMessageFactory();
47          receiverSupport.setMessageFactory(messageFactory);
48          connectionMock = createStrictMock(WebServiceConnection.class);
49          request = new MockWebServiceMessage();
50      }
51  
52      @Test
53      public void testHandleConnectionResponse() throws Exception {
54          expect(connectionMock.getUri()).andReturn(new URI("http://example.com"));
55          expect(connectionMock.receive(messageFactory)).andReturn(request);
56          connectionMock.send(isA(WebServiceMessage.class));
57          connectionMock.close();
58  
59          replay(connectionMock);
60  
61          WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() {
62  
63              public void receive(MessageContext messageContext) throws Exception {
64                  Assert.assertNotNull("No message context", messageContext);
65                  messageContext.getResponse();
66              }
67          };
68  
69          receiverSupport.handleConnection(connectionMock, receiver);
70  
71          verify(connectionMock);
72      }
73  
74      @Test
75      public void testHandleConnectionNoResponse() throws Exception {
76          expect(connectionMock.getUri()).andReturn(new URI("http://example.com"));
77          expect(connectionMock.receive(messageFactory)).andReturn(request);
78          connectionMock.close();
79  
80          replay(connectionMock);
81  
82          WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() {
83  
84              public void receive(MessageContext messageContext) throws Exception {
85                  Assert.assertNotNull("No message context", messageContext);
86              }
87          };
88  
89          receiverSupport.handleConnection(connectionMock, receiver);
90  
91          verify(connectionMock);
92      }
93  
94      private static class MyReceiverSupport extends WebServiceMessageReceiverObjectSupport {
95  
96      }
97  }