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.soap.server.endpoint;
18  
19  import java.util.Locale;
20  
21  import org.springframework.ws.MockWebServiceMessage;
22  import org.springframework.ws.WebServiceMessageFactory;
23  import org.springframework.ws.context.DefaultMessageContext;
24  import org.springframework.ws.context.MessageContext;
25  import org.springframework.ws.soap.SoapMessage;
26  import org.springframework.ws.soap.soap11.Soap11Body;
27  
28  import org.junit.Assert;
29  import org.junit.Before;
30  import org.junit.Test;
31  
32  import static org.easymock.EasyMock.*;
33  
34  public class SimpleSoapExceptionResolverTest {
35  
36      private SimpleSoapExceptionResolver exceptionResolver;
37  
38      private MessageContext messageContext;
39  
40      private SoapMessage messageMock;
41  
42      private Soap11Body bodyMock;
43  
44      private WebServiceMessageFactory factoryMock;
45  
46      @Before
47      public void setUp() throws Exception {
48          exceptionResolver = new SimpleSoapExceptionResolver();
49          factoryMock = createMock(WebServiceMessageFactory.class);
50          messageContext = new DefaultMessageContext(new MockWebServiceMessage(), factoryMock);
51          messageMock = createMock(SoapMessage.class);
52          bodyMock = createMock(Soap11Body.class);
53      }
54  
55      @Test
56      public void testResolveExceptionInternal() throws Exception {
57          Exception exception = new Exception("message");
58          expect(factoryMock.createWebServiceMessage()).andReturn(messageMock);
59          expect(messageMock.getSoapBody()).andReturn(bodyMock);
60          expect(bodyMock.addServerOrReceiverFault(exception.getMessage(), Locale.ENGLISH)).andReturn(null);
61  
62          replay(factoryMock, messageMock, bodyMock);
63  
64          boolean result = exceptionResolver.resolveExceptionInternal(messageContext, null, exception);
65          Assert.assertTrue("Invalid result", result);
66  
67          verify(factoryMock, messageMock, bodyMock);
68      }
69  }