001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.datatypes;
051:
052: import junit.framework.*;
053: import org.jaffa.datatypes.ValidationException;
054:
055: public class FormatterTest extends TestCase {
056:
057: public FormatterTest(java.lang.String testName) {
058: super (testName);
059: }
060:
061: public static void main(java.lang.String[] args) {
062: junit.textui.TestRunner.run(suite());
063: }
064:
065: public static Test suite() {
066: TestSuite suite = new TestSuite(FormatterTest.class);
067:
068: return suite;
069: }
070:
071: public void setUp() {
072: }
073:
074: public void tearDown() {
075: }
076:
077: public void testFormatBoolean() {
078: Boolean input = null;
079: String layout = null;
080: String output = null;
081:
082: layout = null;
083: input = new Boolean(true);
084: output = Formatter.format(input, layout);
085: System.out.println("Formatting- Layout: " + layout + " Input: "
086: + input + " Output: " + output);
087: input = Parser.parseBoolean(output, layout);
088: System.out.println("Parsing- Layout: " + layout + " Input: "
089: + output + " Output: " + input);
090: System.out.println();
091:
092: layout = null;
093: input = new Boolean(false);
094: output = Formatter.format(input, layout);
095: System.out.println("Formatting- Layout: " + layout + " Input: "
096: + input + " Output: " + output);
097: input = Parser.parseBoolean(output, layout);
098: System.out.println("Parsing- Layout: " + layout + " Input: "
099: + output + " Output: " + input);
100: System.out.println();
101:
102: layout = "The Truth,The Bull-Shit";
103: input = new Boolean(true);
104: output = Formatter.format(input, layout);
105: System.out.println("Formatting- Layout: " + layout + " Input: "
106: + input + " Output: " + output);
107: input = Parser.parseBoolean(output, layout);
108: System.out.println("Parsing- Layout: " + layout + " Input: "
109: + output + " Output: " + input);
110: System.out.println();
111:
112: layout = "The Truth,The Bull-Shit";
113: input = new Boolean(false);
114: output = Formatter.format(input, layout);
115: System.out.println("Formatting- Layout: " + layout + " Input: "
116: + input + " Output: " + output);
117: input = Parser.parseBoolean(output, layout);
118: System.out.println("Parsing- Layout: " + layout + " Input: "
119: + output + " Output: " + input);
120: System.out.println();
121: }
122:
123: public void testFormatInteger() throws ValidationException {
124: Long input = null;
125: String layout = null;
126: String output = null;
127:
128: layout = null;
129: input = new Long(1234567890);
130: output = Formatter.format(input, layout);
131: System.out.println("Formatting- Layout: " + layout + " Input: "
132: + input + " Output: " + output);
133: input = Parser.parseInteger(output, layout);
134: System.out.println("Parsing- Layout: " + layout + " Input: "
135: + output + " Output: " + input);
136: System.out.println();
137:
138: layout = "0,00,00,00,00,00,00,00";
139: input = new Long(1234567890);
140: output = Formatter.format(input, layout);
141: System.out.println("Formatting- Layout: " + layout + " Input: "
142: + input + " Output: " + output);
143: input = Parser.parseInteger(output, layout);
144: System.out.println("Parsing- Layout: " + layout + " Input: "
145: + output + " Output: " + input);
146: System.out.println();
147: }
148:
149: public void testFormatDecimal() throws ValidationException {
150: Double input = null;
151: String layout = null;
152: String output = null;
153:
154: layout = null;
155: input = new Double(1234567890.6576);
156: output = Formatter.format(input, layout);
157: System.out.println("Formatting- Layout: " + layout + " Input: "
158: + input + " Output: " + output);
159: input = Parser.parseDecimal(output, layout);
160: System.out.println("Parsing- Layout: " + layout + " Input: "
161: + output + " Output: " + input);
162: System.out.println();
163:
164: layout = "0,00,00,00,00,00,00,00.000000";
165: input = new Double(1234567890.6576);
166: System.out.println("Formatting- Layout: " + layout + " Input: "
167: + input + " Output: " + output);
168: input = Parser.parseDecimal(output, layout);
169: System.out.println("Parsing- Layout: " + layout + " Input: "
170: + output + " Output: " + input);
171: System.out.println();
172: }
173:
174: public void testFormatCurrency() throws ValidationException {
175: Currency input = null;
176: String layout = null;
177: String output = null;
178:
179: layout = null;
180: input = new Currency(1234567890.6576);
181: output = Formatter.format(input, layout);
182: System.out.println("Formatting- Layout: " + layout + " Input: "
183: + input + " Output: " + output);
184: input = Parser.parseCurrency(output, layout);
185: System.out.println("Parsing- Layout: " + layout + " Input: "
186: + output + " Output: " + input);
187: System.out.println();
188:
189: layout = "$0,00,00,00,00,00,00,00.000000";
190: input = new Currency(1234567890.6576);
191: System.out.println("Formatting- Layout: " + layout + " Input: "
192: + input + " Output: " + output);
193: input = Parser.parseCurrency(output, layout);
194: System.out.println("Parsing- Layout: " + layout + " Input: "
195: + output + " Output: " + input);
196: System.out.println();
197: }
198:
199: public void testFormatDateTime() throws ValidationException {
200: DateTime input = null;
201: String layout = null;
202: String output = null;
203:
204: layout = null;
205: input = new DateTime();
206: output = Formatter.format(input, layout);
207: System.out.println("Formatting- Layout: " + layout + " Input: "
208: + input + " Output: " + output);
209: input = Parser.parseDateTime(output, layout);
210: System.out.println("Parsing- Layout: " + layout + " Input: "
211: + output + " Output: " + input);
212: System.out.println();
213:
214: layout = "dd/MMM/yyyy";
215: input = new DateTime();
216: output = Formatter.format(input, layout);
217: System.out.println("Formatting- Layout: " + layout + " Input: "
218: + input + " Output: " + output);
219: input = Parser.parseDateTime(output, layout);
220: System.out.println("Parsing- Layout: " + layout + " Input: "
221: + output + " Output: " + input);
222: System.out.println();
223: }
224:
225: public void testFormatDateOnly() throws ValidationException {
226: DateOnly input = null;
227: String layout = null;
228: String output = null;
229:
230: layout = null;
231: input = new DateOnly();
232: output = Formatter.format(input, layout);
233: System.out.println("Formatting- Layout: " + layout + " Input: "
234: + input + " Output: " + output);
235: input = Parser.parseDateOnly(output, layout);
236: System.out.println("Parsing- Layout: " + layout + " Input: "
237: + output + " Output: " + input);
238: System.out.println();
239:
240: layout = "dd/MMM/yyyy";
241: input = new DateOnly();
242: output = Formatter.format(input, layout);
243: System.out.println("Formatting- Layout: " + layout + " Input: "
244: + input + " Output: " + output);
245: input = Parser.parseDateOnly(output, layout);
246: System.out.println("Parsing- Layout: " + layout + " Input: "
247: + output + " Output: " + input);
248: System.out.println();
249:
250: layout = "dd/MMM/yyyy";
251: output = "n-10";
252: input = Parser.parseDateOnly(output, layout);
253: System.out.println("Parsing- Layout: " + layout + " Input: "
254: + output + " Output: " + input);
255: output = Formatter.format(input, layout);
256: System.out.println("Formatting- Layout: " + layout + " Input: "
257: + input + " Output: " + output);
258: System.out.println();
259: }
260:
261: public void testFormatRaw() throws ValidationException {
262: byte[] input = null;
263: String output = null;
264:
265: input = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
266: output = Formatter.format(input);
267: System.out.println("Formatting- Input: " + input + " Output: "
268: + output);
269: input = Parser.parseRaw(output);
270: System.out.println("Parsing- Input: " + output + " Output: "
271: + input);
272: System.out.println();
273:
274: output = "1234567890";
275: input = Parser.parseRaw(output);
276: System.out.println("Parsing- Input: " + output + " Output: "
277: + input);
278: output = Formatter.format(input);
279: System.out.println("Formatting- Input: " + input + " Output: "
280: + output);
281: System.out.println();
282: }
283:
284: }
|