01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.soap.axiom.support;
18:
19: import junit.framework.TestCase;
20: import org.apache.axiom.om.OMAbstractFactory;
21: import org.apache.axiom.om.OMElement;
22: import org.apache.axiom.om.OMFactory;
23: import org.apache.axiom.om.OMNamespace;
24:
25: import javax.xml.namespace.QName;
26: import java.util.Locale;
27:
28: public class AxiomUtilsTest extends TestCase {
29:
30: private OMElement element;
31:
32: protected void setUp() throws Exception {
33: OMFactory factory = OMAbstractFactory.getOMFactory();
34: OMNamespace namespace = factory.createOMNamespace(
35: "http://www.springframework.org", "prefix");
36: element = factory.createOMElement("element", namespace);
37: }
38:
39: public void testToNamespaceDeclared() throws Exception {
40: QName qName = new QName(element.getNamespace()
41: .getNamespaceURI(), "localPart");
42: OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
43: assertNotNull("Invalid namespace", namespace);
44: assertEquals("Invalid namespace", qName.getNamespaceURI(),
45: namespace.getNamespaceURI());
46: }
47:
48: public void testToNamespaceUndeclared() throws Exception {
49: QName qName = new QName("http://www.example.com", "localPart");
50: OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
51: assertNotNull("Invalid namespace", namespace);
52: assertEquals("Invalid namespace", qName.getNamespaceURI(),
53: namespace.getNamespaceURI());
54: assertFalse("Invalid prefix", "prefix".equals(namespace
55: .getPrefix()));
56: }
57:
58: public void testToNamespacePrefixDeclared() throws Exception {
59: QName qName = new QName(element.getNamespace()
60: .getNamespaceURI(), "localPart", "prefix");
61: OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
62: assertNotNull("Invalid namespace", namespace);
63: assertEquals("Invalid namespace", qName.getNamespaceURI(),
64: namespace.getNamespaceURI());
65: assertEquals("Invalid prefix", "prefix", namespace.getPrefix());
66: }
67:
68: public void testToNamespacePrefixUndeclared() throws Exception {
69: QName qName = new QName("http://www.example.com", "localPart",
70: "otherPrefix");
71: OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
72: assertNotNull("Invalid namespace", namespace);
73: assertEquals("Invalid namespace", qName.getNamespaceURI(),
74: namespace.getNamespaceURI());
75: assertEquals("Invalid prefix", qName.getPrefix(), namespace
76: .getPrefix());
77: }
78:
79: public void testToLanguage() throws Exception {
80: assertEquals("Invalid conversion", "fr-CA", AxiomUtils
81: .toLanguage(Locale.CANADA_FRENCH));
82: assertEquals("Invalid conversion", "en", AxiomUtils
83: .toLanguage(Locale.ENGLISH));
84: }
85:
86: public void testToLocale() throws Exception {
87: assertEquals("Invalid conversion", Locale.CANADA_FRENCH,
88: AxiomUtils.toLocale("fr-CA"));
89: assertEquals("Invalid conversion", Locale.ENGLISH, AxiomUtils
90: .toLocale("en"));
91: }
92: }
|