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