1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.createControl(WebServiceMessageFactory.class);
39 factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
40 request = new MockWebServiceMessage();
41 context = new DefaultMessageContext(request, factoryMock);
42 }
43
44 public void testRequest() throws Exception {
45 assertEquals("Invalid request returned", request, context.getRequest());
46 }
47
48 public void testResponse() throws Exception {
49 WebServiceMessage response = new MockWebServiceMessage();
50 factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), response);
51 factoryControl.replay();
52
53 WebServiceMessage result = context.getResponse();
54 assertEquals("Invalid response returned", response, result);
55 factoryControl.verify();
56 }
57
58 public void testProperties() throws Exception {
59 assertEquals("Invalid property names returned", 0, context.getPropertyNames().length);
60 String name = "name";
61 assertFalse("Property set", context.containsProperty(name));
62 String value = "value";
63 context.setProperty(name, value);
64 assertTrue("Property not set", context.containsProperty(name));
65 assertEquals("Invalid property names returned", Arrays.asList(new String[]{name}),
66 Arrays.asList(context.getPropertyNames()));
67 assertEquals("Invalid property value returned", value, context.getProperty(name));
68 context.removeProperty(name);
69 assertFalse("Property set", context.containsProperty(name));
70 assertEquals("Invalid property names returned", 0, context.getPropertyNames().length);
71 }
72
73 }