1   /*
2    * Copyright 2006 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 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  }