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.server.endpoint.mapping;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.springframework.ws.MockWebServiceMessage;
22  import org.springframework.ws.MockWebServiceMessageFactory;
23  import org.springframework.ws.context.DefaultMessageContext;
24  import org.springframework.ws.context.MessageContext;
25  
26  import org.junit.Assert;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  public class PayloadRootQNameEndpointMappingTest {
31  
32      private PayloadRootQNameEndpointMapping mapping;
33  
34      @Before
35      public void setUp() throws Exception {
36          mapping = new PayloadRootQNameEndpointMapping();
37      }
38  
39      @Test
40      public void testResolveQNames() throws Exception {
41          MockWebServiceMessage request = new MockWebServiceMessage("<root/>");
42          MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
43  
44          QName qName = mapping.resolveQName(context);
45          Assert.assertNotNull("mapping returns null", qName);
46          Assert.assertEquals("mapping returns invalid qualified name", new QName("root"), qName);
47      }
48  
49      @Test
50      public void testGetQNameNameNamespace() throws Exception {
51          MockWebServiceMessage request = new MockWebServiceMessage("<prefix:localname xmlns:prefix=\"namespace\"/>");
52          MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
53  
54          QName qName = mapping.resolveQName(context);
55          Assert.assertNotNull("mapping returns null", qName);
56          Assert.assertEquals("mapping returns invalid method name", new QName("namespace", "localname", "prefix"), qName);
57      }
58  }