001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxb;
019:
020: import org.junit.Assert;
021: import org.junit.Test;
022:
023: public class JAXBUtilsTest extends Assert {
024:
025: @Test
026: public void testBuiltInTypeToJavaType() {
027: assertEquals("boolean", JAXBUtils
028: .builtInTypeToJavaType("boolean"));
029: assertEquals("javax.xml.datatype.XMLGregorianCalendar",
030: JAXBUtils.builtInTypeToJavaType("gYear"));
031: assertNull(JAXBUtils.builtInTypeToJavaType("other"));
032: }
033:
034: @Test
035: public void testPackageNames() {
036: assertEquals(
037: "org.apache.cxf.configuration.types",
038: JAXBUtils
039: .namespaceURIToPackage("http://cxf.apache.org/configuration/types"));
040: assertEquals(
041: "org.apache.cxf.configuration.types",
042: JAXBUtils
043: .namespaceURIToPackage("http://cxf.apache.org/configuration/types.xsd"));
044: assertEquals(
045: "org.apache.cxf.config_types",
046: JAXBUtils
047: .namespaceURIToPackage("http://cxf.apache.org/config-types"));
048: assertEquals(
049: "org.apache.cxf._default.types",
050: JAXBUtils
051: .namespaceURIToPackage("http://cxf.apache.org/default/types"));
052: assertEquals(
053: "org.apache.cxf.config._4types",
054: JAXBUtils
055: .namespaceURIToPackage("http://cxf.apache.org/config/4types."));
056: assertEquals(
057: "com.iona.configuration.types",
058: JAXBUtils
059: .namespaceURIToPackage("http://www.iona.com/configuration/types"));
060: assertEquals(
061: "org.apache.cxf.config.types",
062: JAXBUtils
063: .namespaceURIToPackage("urn://cxf-apache-org/config/types"));
064: assertEquals("types", JAXBUtils.namespaceURIToPackage("types"));
065: }
066:
067: @Test
068: public void testNameToIdentifier() {
069: assertEquals("_return", JAXBUtils.nameToIdentifier("return",
070: JAXBUtils.IdentifierType.VARIABLE));
071: assertEquals("getReturn", JAXBUtils.nameToIdentifier("return",
072: JAXBUtils.IdentifierType.GETTER));
073: assertEquals("setReturn", JAXBUtils.nameToIdentifier("return",
074: JAXBUtils.IdentifierType.SETTER));
075:
076: assertEquals("_public", JAXBUtils.nameToIdentifier("public",
077: JAXBUtils.IdentifierType.VARIABLE));
078: assertEquals("getPublic", JAXBUtils.nameToIdentifier("public",
079: JAXBUtils.IdentifierType.GETTER));
080: assertEquals("setPublic", JAXBUtils.nameToIdentifier("public",
081: JAXBUtils.IdentifierType.SETTER));
082:
083: assertEquals("arg0", JAXBUtils.nameToIdentifier("arg0",
084: JAXBUtils.IdentifierType.VARIABLE));
085: assertEquals("getArg0", JAXBUtils.nameToIdentifier("arg0",
086: JAXBUtils.IdentifierType.GETTER));
087: assertEquals("setArg0", JAXBUtils.nameToIdentifier("arg0",
088: JAXBUtils.IdentifierType.SETTER));
089:
090: assertEquals("mixedCaseName", JAXBUtils.nameToIdentifier(
091: "mixedCaseName", JAXBUtils.IdentifierType.VARIABLE));
092: assertEquals("MixedCaseName", JAXBUtils.nameToIdentifier(
093: "mixedCaseName", JAXBUtils.IdentifierType.CLASS));
094: assertEquals("setMixedCaseName", JAXBUtils.nameToIdentifier(
095: "mixedCaseName", JAXBUtils.IdentifierType.SETTER));
096: assertEquals("MIXED_CASE_NAME", JAXBUtils.nameToIdentifier(
097: "mixedCaseName", JAXBUtils.IdentifierType.CONSTANT));
098:
099: assertEquals("answer42", JAXBUtils.nameToIdentifier("Answer42",
100: JAXBUtils.IdentifierType.VARIABLE));
101: assertEquals("Answer42", JAXBUtils.nameToIdentifier("Answer42",
102: JAXBUtils.IdentifierType.CLASS));
103: assertEquals("getAnswer42", JAXBUtils.nameToIdentifier(
104: "Answer42", JAXBUtils.IdentifierType.GETTER));
105: assertEquals("ANSWER_42", JAXBUtils.nameToIdentifier(
106: "Answer42", JAXBUtils.IdentifierType.CONSTANT));
107:
108: assertEquals("nameWithDashes", JAXBUtils.nameToIdentifier(
109: "name-with-dashes", JAXBUtils.IdentifierType.VARIABLE));
110: assertEquals("NameWithDashes", JAXBUtils.nameToIdentifier(
111: "name-with-dashes", JAXBUtils.IdentifierType.CLASS));
112: assertEquals("setNameWithDashes", JAXBUtils.nameToIdentifier(
113: "name-with-dashes", JAXBUtils.IdentifierType.SETTER));
114: assertEquals("NAME_WITH_DASHES", JAXBUtils.nameToIdentifier(
115: "name-with-dashes", JAXBUtils.IdentifierType.CONSTANT));
116:
117: assertEquals("otherPunctChars", JAXBUtils.nameToIdentifier(
118: "other_punct-chars", JAXBUtils.IdentifierType.VARIABLE));
119: assertEquals("OtherPunctChars", JAXBUtils.nameToIdentifier(
120: "other_punct-chars", JAXBUtils.IdentifierType.CLASS));
121: assertEquals("getOtherPunctChars", JAXBUtils.nameToIdentifier(
122: "other_punct-chars", JAXBUtils.IdentifierType.GETTER));
123: assertEquals("OTHER_PUNCT_CHARS", JAXBUtils.nameToIdentifier(
124: "other_punct-chars", JAXBUtils.IdentifierType.CONSTANT));
125: }
126:
127: @Test
128: public void testNsToPkg() {
129: String urn = "urn:cxf.apache.org";
130: String pkg = JAXBUtils.namespaceURIToPackage(urn);
131: assertEquals("org.apache.cxf", pkg);
132:
133: urn = "urn:cxf.apache.org:test.v4.6.4";
134: pkg = JAXBUtils.namespaceURIToPackage(urn);
135: assertEquals("org.apache.cxf.test_v4_6_4", pkg);
136: }
137: }
|