001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: */
019: package org.enhydra.zeus.util;
020:
021: // JUnit classes
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: /**
027: * <p>
028: * This is a test case for the <code>{@link DTDUtils}</code> class.
029: * </p>
030: *
031: * @author Robert Sese
032: * @author Brett McLaughlin
033: */
034: public class NamingUtilsTest extends TestCase {
035:
036: /**
037: * <p>
038: * This constructs a new <code>NamingUtilsTest</code>.
039: * </p>
040: *
041: * @param name the name of the test case.
042: */
043: public NamingUtilsTest(String name) {
044: super (name);
045: }
046:
047: /**
048: * <p>
049: * This method maeks it easier to call these
050: * tests dynamically.
051: * </p>
052: *
053: * @return <code>TestSuite</code> - corresponds to this
054: * <code>TestCase</code>.
055: */
056: public static Test suite() {
057: return new TestSuite(NamingUtilsTest.class);
058: }
059:
060: /**
061: * <p>
062: * This tests the <code>{@link NamingUtils#getCharMapping}</code>
063: * method.
064: * </p>
065: */
066: public void testGetCharMapping() {
067: Character ch = new Character('.');
068: String replaceString = "DOT";
069: NamingUtils.setCharMapping(ch, replaceString);
070: assertEquals(replaceString, NamingUtils.getCharMapping(ch));
071: }
072:
073: /**
074: * <p>
075: * This tests the <code>{@link NamingUtils#setCharMapping}</code>
076: * method.
077: * </p>
078: */
079: public void testSetCharMapping() {
080: Character ch = new Character('.');
081: String replaceString = "DOT";
082: NamingUtils.setCharMapping(ch, replaceString);
083: assertEquals(replaceString, NamingUtils.getCharMapping(ch));
084:
085: replaceString = "OTHER_DOT";
086: NamingUtils.setCharMapping(ch, replaceString);
087: assertEquals(replaceString, NamingUtils.getCharMapping(ch));
088: }
089:
090: /**
091: * <p>
092: * This tests the <code>{@link NamingUtils#isLegalJavaClassName}</code>
093: * method.
094: * </p>
095: */
096: public void testIsLegalJavaClassName() {
097: String className = "LegalClassName";
098: assertTrue(NamingUtils.isLegalJavaClassName(className));
099:
100: className = "#illegalClassName";
101: assertTrue(!NamingUtils.isLegalJavaClassName(className));
102:
103: className = "9illegalClassName";
104: assertTrue(!NamingUtils.isLegalJavaClassName(className));
105: }
106:
107: /**
108: * <p>
109: * This tests the <code>{@link NamingUtils#isLegalJavaPackageName}</code>
110: * method.
111: * </p>
112: */
113: public void testIsLegalJavaPackageName() {
114: String packageName = "packageName";
115: assertTrue(NamingUtils.isLegalJavaPackageName(packageName));
116:
117: packageName = "legal.package.name";
118: assertTrue(NamingUtils.isLegalJavaPackageName(packageName));
119:
120: packageName = "9illegal.package";
121: assertTrue(!NamingUtils.isLegalJavaPackageName(packageName));
122:
123: packageName = "#987654";
124: assertTrue(!NamingUtils.isLegalJavaPackageName(packageName));
125: }
126:
127: /**
128: * <p>
129: * This tests the <code>{@link NamingUtils#getJavaName}</code> method.
130: * </p>
131: */
132: public void testGetJavaName() {
133: String name = "my-element";
134: String expected = "myElement";
135: String actual = NamingUtils.getJavaName(name);
136:
137: assertEquals(expected, actual);
138: }
139:
140: /**
141: * <p>
142: * This tests the <code>{@link NamingUtils#getJavaVariableName}</code>
143: * method.
144: * </p>
145: */
146: public void testGetJavaVariableName() {
147: String name = "My-class";
148: String expected = "myClass";
149: String actual = NamingUtils.getJavaVariableName(name);
150: assertEquals(expected, actual);
151:
152: name = "import";
153: expected = "xmlimport";
154: actual = NamingUtils.getJavaVariableName(name);
155: assertEquals(expected, actual);
156: }
157:
158: /**
159: * <p>
160: * This tests the
161: * <code>{@link NamingUtils#getJavaCollectionVariableName}</code>
162: * method.
163: * </p>
164: */
165: public void testGetJavaCollectionVariableName() {
166: String name = "My-class";
167: String expected = "myClass";
168: String actual = NamingUtils.getJavaCollectionVariableName(name);
169:
170: assertEquals(expected, actual);
171: }
172:
173: /**
174: * <p>
175: * This tests the <code>{@link NamingUtils#getJavaClassName}</code> method.
176: * </p>
177: */
178: public void testGetJavaClassName() {
179: String name = "my-element";
180: String expected = "MyElement";
181: String actual = NamingUtils.getJavaClassName(name);
182:
183: assertEquals(expected, actual);
184: }
185:
186: /**
187: * <p>
188: * This tests the <code>{@link NamingUtils#getJavaType}</code>
189: * method.
190: * </p>
191: */
192: public void testGetJavaType() {
193: String name = "string";
194: String expected = "String";
195: String actual = NamingUtils.getJavaType(name);
196:
197: assertEquals(expected, actual);
198: }
199:
200: /**
201: * <p>
202: * This tests the
203: * <code>{@link NamingUtils#getXMLElementNameFromAccessor}</code>
204: * method.
205: * </p>
206: */
207: public void testGetXMLElementNameFromAccessor() {
208: String name = "getMyElement";
209: String expected = "myElement";
210: String actual = NamingUtils.getXMLElementNameFromAccessor(name);
211:
212: assertEquals(expected, actual);
213: }
214:
215: /**
216: * <p>
217: * This tests the <code>{@link NamingUtils#removePackage}</code> method.
218: * </p>
219: */
220: public void testRemovePackage() {
221: String name = "java.util.List";
222: String expected = "List";
223: assertEquals(expected, NamingUtils.removePackage(name));
224:
225: name = "SomeClass";
226: expected = name;
227: assertEquals(expected, NamingUtils.removePackage(name));
228: }
229: }
|