01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
51: .createControl(WebServiceMessageFactory.class);
52: factoryMock = (WebServiceMessageFactory) factoryControl
53: .getMock();
54: messageContext = new DefaultMessageContext(
55: new MockWebServiceMessage(), factoryMock);
56: messageControl = MockControl.createControl(SoapMessage.class);
57: messageMock = (SoapMessage) messageControl.getMock();
58: bodyControl = MockControl.createControl(Soap11Body.class);
59: bodyControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
60: bodyMock = (Soap11Body) bodyControl.getMock();
61: }
62:
63: public void testResolveExceptionInternal() throws Exception {
64: Exception exception = new Exception("message");
65: factoryControl.expectAndReturn(factoryMock
66: .createWebServiceMessage(), messageMock);
67: messageControl.expectAndReturn(messageMock.getSoapBody(),
68: bodyMock);
69: bodyControl.expectAndReturn(bodyMock.addServerOrReceiverFault(
70: exception.getMessage(), Locale.ENGLISH), null);
71: factoryControl.replay();
72: messageControl.replay();
73: bodyControl.replay();
74: boolean result = exceptionResolver.resolveExceptionInternal(
75: messageContext, null, exception);
76: assertTrue("Invalid result", result);
77: factoryControl.verify();
78: messageControl.verify();
79: bodyControl.verify();
80: }
81: }
|