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.context;
18:
19: import java.util.Arrays;
20:
21: import junit.framework.TestCase;
22: import org.easymock.MockControl;
23: import org.springframework.ws.MockWebServiceMessage;
24: import org.springframework.ws.WebServiceMessage;
25: import org.springframework.ws.WebServiceMessageFactory;
26:
27: public class DefaultMessageContextTest extends TestCase {
28:
29: private DefaultMessageContext context;
30:
31: private MockControl factoryControl;
32:
33: private WebServiceMessageFactory factoryMock;
34:
35: private WebServiceMessage request;
36:
37: protected void setUp() throws Exception {
38: factoryControl = MockControl
39: .createControl(WebServiceMessageFactory.class);
40: factoryMock = (WebServiceMessageFactory) factoryControl
41: .getMock();
42: request = new MockWebServiceMessage();
43: context = new DefaultMessageContext(request, factoryMock);
44: }
45:
46: public void testRequest() throws Exception {
47: assertEquals("Invalid request returned", request, context
48: .getRequest());
49: }
50:
51: public void testResponse() throws Exception {
52: WebServiceMessage response = new MockWebServiceMessage();
53: factoryControl.expectAndReturn(factoryMock
54: .createWebServiceMessage(), response);
55: factoryControl.replay();
56:
57: WebServiceMessage result = context.getResponse();
58: assertEquals("Invalid response returned", response, result);
59: factoryControl.verify();
60: }
61:
62: public void testProperties() throws Exception {
63: assertEquals("Invalid property names returned", 0, context
64: .getPropertyNames().length);
65: String name = "name";
66: assertFalse("Property set", context.containsProperty(name));
67: String value = "value";
68: context.setProperty(name, value);
69: assertTrue("Property not set", context.containsProperty(name));
70: assertEquals("Invalid property names returned", Arrays
71: .asList(new String[] { name }), Arrays.asList(context
72: .getPropertyNames()));
73: assertEquals("Invalid property value returned", value, context
74: .getProperty(name));
75: context.removeProperty(name);
76: assertFalse("Property set", context.containsProperty(name));
77: assertEquals("Invalid property names returned", 0, context
78: .getPropertyNames().length);
79: }
80:
81: }
|