1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
Copyright (c) 2007, Dennis M. Sosnoski
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of JiBX nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jibx.binding.generator;
import org.jibx.custom.classes.CustomBase;
import org.jibx.custom.classes.GlobalCustom;
import org.jibx.custom.classes.NestingBase;
import org.jibx.custom.classes.PackageCustom;
/**
* Test code for nested property handling.
*/
public class NestingBaseTest extends CustomizationTestBase
{
public static final String SIMPLE_CUSTOM =
"<custom property-access='true' require='primitives'/>";
public static final String SIMPLE_PACKAGE =
"<custom property-access='true' force-classes='true'>\n" +
" <package property-access='false' name='org.jibx.binding'\n" +
" namespace='urn:binding'/>\n" +
"</custom>";
public static final String NESTED_PACKAGE =
"<custom property-access='true' force-classes='true'>\n" +
" <package property-access='false' name='org.jibx.binding'\n" +
" namespace='urn:binding'>\n" +
" <package property-access='true' name='generator'/>\n" +
" </package>\n" +
"</custom>";
public static final String MULTIPLE_PACKAGE =
"<custom property-access='true' force-classes='true'\n" +
" namespace-style='fixed'>\n" +
" <package property-access='false' name='org.jibx.binding'>\n" +
" <package property-access='true' name='generator'\n" +
" namespace='urn:binding.generator'/>\n" +
" </package>\n" +
" <package name='org.jibx.runtime' namespace='urn:runtime'/>\n" +
" <package property-access='false' name='org.jibx.extras'\n" +
" namespace-style='none'/>\n" +
"</custom>";
public static final String MULTIPLE_PACKAGE_HYPHENATED =
"<custom property-access='true' force-classes='true'>\n" +
" <package name-style='hyphenated' name='org.jibx.binding'>\n" +
" <package property-access='true' name='generator'\n" +
" namespace='urn:binding.generator'/>\n" +
" </package>\n" +
" <package name='org.jibx.runtime' namespace='urn:runtime'/>\n" +
" <package property-access='false' name='org.jibx.extras'/>\n" +
"</custom>";
public static final String MULTIPLE_PACKAGE_UPPERCAMELCASE =
"<custom property-access='true' force-classes='true'>\n" +
" <package name-style='upper-camel-case' name='org.jibx.binding'>\n" +
" <package property-access='true' name='generator'\n" +
" namespace='urn:binding.generator'/>\n" +
" </package>\n" +
" <package name='org.jibx.runtime' namespace='urn:runtime'/>\n" +
" <package property-access='false' name='org.jibx.extras'/>\n" +
"</custom>";
public static final String MULTIPLE_PACKAGE_DOTTED =
"<custom property-access='true' force-classes='true'>\n" +
" <package name-style='dotted' name='org.jibx.binding'>\n" +
" <package property-access='true' name='generator'\n" +
" namespace='urn:binding.generator'/>\n" +
" </package>\n" +
" <package name='org.jibx.runtime' namespace='urn:runtime'/>\n" +
" <package property-access='false' name='org.jibx.extras'/>\n" +
"</custom>";
public static final String MULTIPLE_PACKAGE_UNDERSCORED =
"<custom property-access='true' force-classes='true'>\n" +
" <package name-style='underscored' name='org.jibx.binding'>\n" +
" <package property-access='true' name='generator'\n" +
" namespace='urn:binding.generator'/>\n" +
" </package>\n" +
" <package name='org.jibx.runtime' namespace='urn:runtime'/>\n" +
" <package property-access='false' name='org.jibx.extras'/>\n" +
"</custom>";
public void testSimpleCustom() throws Exception {
GlobalCustom custom = readCustom(SIMPLE_CUSTOM);
assertFalse("add-constructors default", custom.isAddConstructors());
assertFalse("force-classes default", custom.isForceClasses());
assertTrue("input default", custom.isInput());
assertTrue("output default", custom.isOutput());
assertTrue("map-abstract default", custom.isMapAbstract());
assertEquals("name style default", CustomBase.CAMEL_CASE_NAMES, custom.getNameStyle());
assertEquals("value style default", NestingBase.ATTRIBUTE_VALUE_STYLE, custom.getValueStyle("int"));
assertFalse("require setting", custom.isObjectRequired("java.lang.String"));
assertTrue("require setting", custom.isPrimitiveRequired("int"));
assertTrue("property-access setting", custom.isPropertyAccess());
assertEquals("get root", custom, custom.getGlobal());
assertNull("empty namespace",custom.getNamespace());
}
public void testSimplePackage() throws Exception {
GlobalCustom custom = readCustom(SIMPLE_PACKAGE);
PackageCustom pack = custom.getPackage("org.jibx.binding");
assertTrue("map-abstract default", pack.isMapAbstract());
assertEquals("name style default", CustomBase.CAMEL_CASE_NAMES, pack.getNameStyle());
assertEquals("value style default", NestingBase.ATTRIBUTE_VALUE_STYLE, pack.getValueStyle("int"));
assertFalse("require setting", pack.isObjectRequired("java.lang.String"));
assertTrue("require setting", pack.isPrimitiveRequired("int"));
assertFalse("property-access setting", pack.isPropertyAccess());
assertEquals("get root", custom, pack.getGlobal());
assertEquals("package namespace", "urn:binding", pack.getNamespace());
}
public void testNestedPackage() throws Exception {
GlobalCustom custom = readCustom(NESTED_PACKAGE);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertTrue("map-abstract default", pack.isMapAbstract());
assertEquals("name style default", CustomBase.CAMEL_CASE_NAMES, pack.getNameStyle());
assertEquals("value style default", NestingBase.ATTRIBUTE_VALUE_STYLE, pack.getValueStyle("int"));
assertFalse("require setting", pack.isObjectRequired("java.lang.String"));
assertTrue("require setting", pack.isPrimitiveRequired("int"));
assertTrue("property-access setting", pack.isPropertyAccess());
assertEquals("get root", custom, pack.getGlobal());
assertEquals("package namespace", "urn:binding/generator", pack.getNamespace());
}
public void testMultiplePackage() throws Exception {
GlobalCustom custom = readCustom(MULTIPLE_PACKAGE);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertTrue("property-access setting", pack.isPropertyAccess());
assertEquals("package namespace", "urn:binding.generator", pack.getNamespace());
pack = custom.getPackage("org.jibx.runtime");
assertTrue("property-access setting", pack.isPropertyAccess());
assertEquals("package namespace", "urn:runtime", pack.getNamespace());
pack = custom.getPackage("org.jibx.extras");
assertFalse("property-access setting", pack.isPropertyAccess());
assertNull("package namespace", pack.getNamespace());
assertEquals("simple name", "a", pack.convertName("a"));
assertEquals("simple name", "a", pack.convertName("A"));
assertEquals("simple name", "aName", pack.convertName("aName"));
assertEquals("leading underscore name", "aName",
pack.convertName("__aName"));
assertEquals("embedded underscores name", "aName",
pack.convertName("a__Name"));
assertEquals("complex name", "aBCDefgH",
pack.convertName("aB_cDefgH"));
}
public void testHyphenated() throws Exception {
GlobalCustom custom = readCustom(MULTIPLE_PACKAGE_HYPHENATED);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertEquals("simple name", "a", pack.convertName("a"));
assertEquals("simple name", "a", pack.convertName("A"));
assertEquals("simple name", "a-name", pack.convertName("aName"));
assertEquals("leading underscore name", "a-name",
pack.convertName("__aName"));
assertEquals("embedded underscores name", "a-name",
pack.convertName("a__Name"));
assertEquals("complex name", "a-b-c-defg-h",
pack.convertName("aB_cDefgH"));
}
public void testUpperCamelCase() throws Exception {
GlobalCustom custom = readCustom(MULTIPLE_PACKAGE_UPPERCAMELCASE);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertEquals("simple name", "A", pack.convertName("a"));
assertEquals("simple name", "A", pack.convertName("A"));
assertEquals("simple name", "AName", pack.convertName("aName"));
assertEquals("leading underscore name", "AName",
pack.convertName("__aName"));
assertEquals("embedded underscores name", "AName",
pack.convertName("a__Name"));
assertEquals("complex name", "ABCDefgH",
pack.convertName("aB_cDefgH"));
}
public void testDotted() throws Exception {
GlobalCustom custom = readCustom(MULTIPLE_PACKAGE_DOTTED);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertEquals("simple name", "a", pack.convertName("a"));
assertEquals("simple name", "a", pack.convertName("A"));
assertEquals("simple name", "a.name", pack.convertName("aName"));
assertEquals("leading underscore name", "a.name",
pack.convertName("__aName"));
assertEquals("embedded underscores name", "a.name",
pack.convertName("a__Name"));
assertEquals("complex name", "a.b.c.defg.h",
pack.convertName("aB_cDefgH"));
}
public void testUnderscored() throws Exception {
GlobalCustom custom = readCustom(MULTIPLE_PACKAGE_UNDERSCORED);
PackageCustom pack = custom.getPackage("org.jibx.binding.generator");
assertEquals("simple name", "a", pack.convertName("a"));
assertEquals("simple name", "a", pack.convertName("A"));
assertEquals("simple name", "a_name", pack.convertName("aName"));
assertEquals("leading underscore name", "a_name",
pack.convertName("__aName"));
assertEquals("embedded underscores name", "a_name",
pack.convertName("a__Name"));
assertEquals("complex name", "a_b_c_defg_h",
pack.convertName("aB_cDefgH"));
}
}
|