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: */
019: package org.apache.axis2.databinding.utils;
020:
021: import junit.framework.TestCase;
022:
023: import java.math.BigInteger;
024: import java.text.SimpleDateFormat;
025: import java.util.ArrayList;
026: import java.util.Calendar;
027: import java.util.Date;
028: import java.util.List;
029: import java.util.TimeZone;
030:
031: public class ConverterUtilTest extends TestCase {
032:
033: /** Test conversion of Big Integer */
034: public void testBigInteger() {
035: List l = new ArrayList();
036: l.add("23445");
037: l.add("23446");
038: l.add("23456646");
039: l.add("1113646");
040:
041: Object convertedObj = ConverterUtil.convertToArray(
042: BigInteger.class, l);
043:
044: assertTrue(convertedObj.getClass().isArray());
045: assertTrue(convertedObj.getClass().equals(BigInteger[].class));
046:
047: }
048:
049: /** integer arrays */
050: public void testInt() {
051: List l = new ArrayList();
052: l.add("23445");
053: l.add("23446");
054: l.add("23456646");
055: l.add("1113646");
056:
057: Object convertedObj = ConverterUtil
058: .convertToArray(int.class, l);
059:
060: assertTrue(convertedObj.getClass().isArray());
061: assertTrue(convertedObj.getClass().equals(int[].class));
062:
063: }
064:
065: /** boolean arrays */
066: public void testBool() {
067: List l = new ArrayList();
068: l.add("true");
069: l.add("false");
070: l.add("true");
071: l.add("false");
072:
073: Object convertedObj = ConverterUtil.convertToArray(
074: boolean.class, l);
075:
076: assertTrue(convertedObj.getClass().isArray());
077: assertTrue(convertedObj.getClass().equals(boolean[].class));
078:
079: }
080:
081: public void testConvertToDateTime() {
082:
083: SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
084: "yyyy-MM-dd HH:mm:ss.SSS Z");
085: Calendar calendar;
086: calendar = ConverterUtil
087: .convertToDateTime("2007-02-15T14:54:29");
088: System.out.println("String ==> " + "2007-02-15T14:54:29");
089: System.out.println("calendar ==> "
090: + simpleDateFormat.format(calendar.getTime()));
091:
092: calendar = ConverterUtil
093: .convertToDateTime("2007-02-15T14:54:29.399");
094: System.out.println("String ==> " + "2007-02-15T14:54:29.399");
095: System.out.println("calendar ==> "
096: + simpleDateFormat.format(calendar.getTime()));
097:
098: calendar = ConverterUtil
099: .convertToDateTime("2007-02-15T14:54:29+05:30");
100: System.out.println("String ==> "
101: + "2007-02-15T14:54:29+05:30");
102: System.out.println("calendar ==> "
103: + simpleDateFormat.format(calendar.getTime()));
104:
105: calendar = ConverterUtil
106: .convertToDateTime("2007-02-15T14:54:29.399+05:30");
107: System.out.println("String ==> "
108: + "2007-02-15T14:54:29.399+05:30");
109: System.out.println("calendar ==> "
110: + simpleDateFormat.format(calendar.getTime()));
111:
112: calendar = ConverterUtil
113: .convertToDateTime("2007-02-15T14:54:29Z");
114: System.out.println("String ==> " + "2007-02-15T14:54:29Z");
115: System.out.println("calendar ==> "
116: + simpleDateFormat.format(calendar.getTime()));
117:
118: calendar = ConverterUtil
119: .convertToDateTime("2007-02-15T14:54:29.399Z");
120: System.out
121: .println("String ==> " + "2007-02-15T14:54:29.399Z");
122: System.out.println("calendar ==> "
123: + simpleDateFormat.format(calendar.getTime()));
124:
125: calendar = ConverterUtil
126: .convertToDateTime("2007-02-15T14:54:29.399-05:30");
127: System.out.println("String ==> "
128: + "2007-02-15T14:54:29.399-05:30");
129: System.out.println("calendar ==> "
130: + simpleDateFormat.format(calendar.getTime()));
131:
132: calendar = ConverterUtil
133: .convertToDateTime("2006-12-11T23:57:16.625Z");
134: System.out
135: .println("String ==> " + "2006-12-11T23:57:16.625Z");
136: simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
137: System.out.println("calendar ==> "
138: + simpleDateFormat.format(calendar.getTime()));
139:
140: }
141:
142: public void testConvertToDateString() {
143: Date date = new Date();
144: String dateString = ConverterUtil.convertToString(date);
145: System.out.println("Date ==> " + dateString);
146: }
147:
148: public void testConvertToDate() {
149:
150: Date date;
151: SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
152: "yyyy-MM-dd Z");
153: // date = ConverterUtil.convertToDate("2007-02-15");
154: // System.out.println("String ==> " + "2007-02-15");
155: // System.out.println("calendar ==> " + simpleDateFormat.format(date));
156: //
157: // date = ConverterUtil.convertToDate("2007-02-15Z");
158: // System.out.println("String ==> " + "2007-02-15Z");
159: // System.out.println("calendar ==> " + simpleDateFormat.format(date));
160: //
161: // date = ConverterUtil.convertToDate("2007-02-15+0530");
162: // System.out.println("String ==> " + "2007-02-15+0530");
163: // System.out.println("calendar ==> " + simpleDateFormat.format(date));
164:
165: date = ConverterUtil.convertToDate("2007-02-15-12:30");
166: System.out.println("String ==> " + "2007-02-15-12:30");
167: System.out.println("calendar ==> "
168: + simpleDateFormat.format(date));
169: }
170:
171: }
|