1   /*
2    * Copyright 2006 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.soap.server.endpoint;
18  
19  import java.util.Locale;
20  
21  import junit.framework.TestCase;
22  import org.easymock.MockControl;
23  import org.springframework.ws.MockWebServiceMessage;
24  import org.springframework.ws.WebServiceMessageFactory;
25  import org.springframework.ws.context.DefaultMessageContext;
26  import org.springframework.ws.context.MessageContext;
27  import org.springframework.ws.soap.SoapMessage;
28  import org.springframework.ws.soap.soap11.Soap11Body;
29  
30  public class SimpleSoapExceptionResolverTest extends TestCase {
31  
32      private SimpleSoapExceptionResolver exceptionResolver;
33  
34      private MessageContext messageContext;
35  
36      private MockControl messageControl;
37  
38      private SoapMessage messageMock;
39  
40      private MockControl bodyControl;
41  
42      private Soap11Body bodyMock;
43  
44      private MockControl factoryControl;
45  
46      private WebServiceMessageFactory factoryMock;
47  
48      protected void setUp() throws Exception {
49          exceptionResolver = new SimpleSoapExceptionResolver();
50          factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
51          factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
52          messageContext = new DefaultMessageContext(new MockWebServiceMessage(), factoryMock);
53          messageControl = MockControl.createControl(SoapMessage.class);
54          messageMock = (SoapMessage) messageControl.getMock();
55          bodyControl = MockControl.createControl(Soap11Body.class);
56          bodyControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
57          bodyMock = (Soap11Body) bodyControl.getMock();
58      }
59  
60      public void testResolveExceptionInternal() throws Exception {
61          Exception exception = new Exception("message");
62          factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), messageMock);
63          messageControl.expectAndReturn(messageMock.getSoapBody(), bodyMock);
64          bodyControl.expectAndReturn(bodyMock.addServerOrReceiverFault(exception.getMessage(), Locale.ENGLISH), null);
65          factoryControl.replay();
66          messageControl.replay();
67          bodyControl.replay();
68          boolean result = exceptionResolver.resolveExceptionInternal(messageContext, null, exception);
69          assertTrue("Invalid result", result);
70          factoryControl.verify();
71          messageControl.verify();
72          bodyControl.verify();
73      }
74  }