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.support;
18  
19  import java.lang.reflect.Method;
20  import javax.xml.XMLConstants;
21  import javax.xml.namespace.NamespaceContext;
22  
23  import org.springframework.ws.server.endpoint.annotation.Namespace;
24  import org.springframework.ws.server.endpoint.annotation.Namespaces;
25  
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertEquals;
29  
30  @Namespaces([email protected](prefix = "prefix1", uri = "class1"), @Namespace(uri = "class2")})
31  public class NamespaceUtilsTest {
32  
33      @Test
34      public void getNamespaceContextMethod() throws NoSuchMethodException {
35          Method method = getClass().getMethod("method");
36          NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method);
37          assertEquals("method1", namespaceContext.getNamespaceURI("prefix1"));
38          assertEquals("method2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
39  
40      }
41      
42      @Test
43      public void getNamespaceContextClass() throws NoSuchMethodException {
44          Method method = getClass().getMethod("getNamespaceContextClass");
45          NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method);
46          assertEquals("class1", namespaceContext.getNamespaceURI("prefix1"));
47          assertEquals("class2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
48  
49      }
50  
51      @Namespaces([email protected](prefix = "prefix1", uri = "method1"), @Namespace(uri = "method2")})
52      public void method() {
53  
54      }
55  
56  }