1+ /*
2+ * Copyright 2007 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 junit .framework .TestCase ;
20+ import org .easymock .MockControl ;
21+ import org .springframework .ws .MockWebServiceMessage ;
22+ import org .springframework .ws .MockWebServiceMessageFactory ;
23+ import org .springframework .ws .context .MessageContext ;
24+ import org .springframework .ws .transport .WebServiceConnection ;
25+ import org .springframework .ws .transport .WebServiceMessageReceiver ;
26+
27+ public class WebServiceMessageReceiverObjectSupportTest extends TestCase {
28+
29+ private WebServiceMessageReceiverObjectSupport receiverSupport ;
30+
31+ private MockControl connectionControl ;
32+
33+ private WebServiceConnection connectionMock ;
34+
35+ private MockWebServiceMessageFactory messageFactory ;
36+
37+ private MockWebServiceMessage request ;
38+
39+ protected void setUp () throws Exception {
40+ receiverSupport = new MyReceiverSupport ();
41+ messageFactory = new MockWebServiceMessageFactory ();
42+ receiverSupport .setMessageFactory (messageFactory );
43+ connectionControl = MockControl .createStrictControl (WebServiceConnection .class );
44+ connectionMock = (WebServiceConnection ) connectionControl .getMock ();
45+ request = new MockWebServiceMessage ();
46+ }
47+
48+ public void testHandleConnectionResponse () throws Exception {
49+ connectionControl .expectAndReturn (connectionMock .receive (messageFactory ), request );
50+ connectionMock .send (new MockWebServiceMessage ());
51+ connectionControl .setMatcher (MockControl .ALWAYS_MATCHER );
52+ connectionMock .close ();
53+
54+ connectionControl .replay ();
55+
56+ WebServiceMessageReceiver receiver = new WebServiceMessageReceiver () {
57+
58+ public void receive (MessageContext messageContext ) throws Exception {
59+ assertNotNull ("No message context" , messageContext );
60+ messageContext .getResponse ();
61+ }
62+ };
63+
64+ receiverSupport .handleConnection (connectionMock , receiver );
65+
66+ connectionControl .verify ();
67+ }
68+
69+ public void testHandleConnectionNoResponse () throws Exception {
70+ connectionControl .expectAndReturn (connectionMock .receive (messageFactory ), request );
71+ connectionMock .close ();
72+
73+ connectionControl .replay ();
74+
75+ WebServiceMessageReceiver receiver = new WebServiceMessageReceiver () {
76+
77+ public void receive (MessageContext messageContext ) throws Exception {
78+ assertNotNull ("No message context" , messageContext );
79+ }
80+ };
81+
82+ receiverSupport .handleConnection (connectionMock , receiver );
83+
84+ connectionControl .verify ();
85+ }
86+
87+ private static class MyReceiverSupport extends WebServiceMessageReceiverObjectSupport {
88+
89+ }
90+ }
0 commit comments