KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > setup > util > TestPropertyConverter


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.setup.util;
10
11 import junit.framework.TestCase;
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.framework.Assert;
15
16 import java.net.URL JavaDoc;
17
18
19 public class TestPropertyConverter extends TestCase
20 {
21
22
23    public static void main(String JavaDoc args[])
24    {
25       junit.textui.TestRunner.run(TestPropertyConverter.class);
26    }
27
28    public TestPropertyConverter(String JavaDoc name)
29    {
30       super(name);
31    }
32
33    public static Test suite()
34    {
35       return new TestSuite(TestPropertyConverter.class);
36    }
37
38
39    public void testChar()
40    {
41       Character JavaDoc etalon = new Character JavaDoc(Character.MIN_VALUE);
42       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
43       lBuffer.append(Character.MIN_VALUE);
44       String JavaDoc strValue = null;
45       Object JavaDoc value = null;
46       Object JavaDoc value1 = null;
47       strValue = PropertyConverter.convertToString(etalon);
48       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
49       value = PropertyConverter.convertToValue(strValue, Character JavaDoc.class);
50       Assert.assertEquals(etalon, value);
51       value1 = PropertyConverter.convertToValue(strValue, char.class);
52       Assert.assertEquals(etalon, value1);
53    }
54
55
56    public void testFloat()
57    {
58       Float JavaDoc etalon = new Float JavaDoc(Float.MAX_VALUE);
59       String JavaDoc strValue = null;
60       Object JavaDoc value, value1 = null;
61       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
62       lBuffer.append(Float.MAX_VALUE);
63       strValue = PropertyConverter.convertToString(etalon);
64       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
65       value = PropertyConverter.convertToValue(strValue, Float JavaDoc.class);
66       Assert.assertEquals(etalon, value);
67       value1 = PropertyConverter.convertToValue(strValue, float.class);
68       Assert.assertEquals(etalon, value1);
69    }
70
71    public void testLong()
72    {
73       Long JavaDoc etalon = new Long JavaDoc(Long.MAX_VALUE);
74       String JavaDoc strValue = null;
75       Object JavaDoc value, value1 = null;
76       strValue = PropertyConverter.convertToString(etalon);
77       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
78       lBuffer.append(Long.MAX_VALUE);
79       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
80       value = PropertyConverter.convertToValue(strValue, Long JavaDoc.class);
81       Assert.assertEquals(etalon, value);
82       value1 = PropertyConverter.convertToValue(strValue, long.class);
83       Assert.assertEquals(etalon, value1);
84    }
85
86    public void testShort()
87    {
88       Short JavaDoc etalon = new Short JavaDoc(Short.MAX_VALUE);
89       String JavaDoc strValue = null;
90       Object JavaDoc value, value1 = null;
91       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
92       lBuffer.append(Short.MAX_VALUE);
93       strValue = PropertyConverter.convertToString(etalon);
94       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
95       value = PropertyConverter.convertToValue(strValue, Short JavaDoc.class);
96       Assert.assertEquals(etalon, value);
97       value1 = PropertyConverter.convertToValue(strValue, short.class);
98       Assert.assertEquals(etalon, value1);
99    }
100
101    public void testByte()
102    {
103       Byte JavaDoc etalon = new Byte JavaDoc(Byte.MAX_VALUE);
104       String JavaDoc strValue = null;
105       Object JavaDoc value, value1 = null;
106       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
107       lBuffer.append(Byte.MAX_VALUE);
108       strValue = PropertyConverter.convertToString(etalon);
109       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
110       value = PropertyConverter.convertToValue(strValue, Byte JavaDoc.class);
111       Assert.assertEquals(etalon, value);
112       value1 = PropertyConverter.convertToValue(strValue, byte.class);
113       Assert.assertEquals(etalon, value1);
114    }
115
116    public void testDouble()
117    {
118       Double JavaDoc etalon = new Double JavaDoc(Double.MAX_VALUE);
119       String JavaDoc strValue = null;
120       Object JavaDoc value, value1 = null;
121       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
122       lBuffer.append(Double.MAX_VALUE);
123       strValue = PropertyConverter.convertToString(etalon);
124       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
125       value = PropertyConverter.convertToValue(strValue, Double JavaDoc.class);
126       Assert.assertEquals(etalon, value);
127       value1 = PropertyConverter.convertToValue(strValue, double.class);
128       Assert.assertEquals(etalon, value1);
129    }
130
131    public void testInteger()
132    {
133       Integer JavaDoc etalon = new Integer JavaDoc(Integer.MAX_VALUE);
134       String JavaDoc strValue = null;
135       Object JavaDoc value, value1 = null;
136       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
137       lBuffer.append(Integer.MAX_VALUE);
138       strValue = PropertyConverter.convertToString(etalon);
139       Assert.assertEquals(strValue, new String JavaDoc(lBuffer));
140       value = PropertyConverter.convertToValue(strValue, Integer JavaDoc.class);
141       Assert.assertEquals(etalon, value);
142       value1 = PropertyConverter.convertToValue(strValue, int.class);
143       Assert.assertEquals(etalon, value1);
144    }
145
146    public void testBoolean()
147    {
148       Boolean JavaDoc etalon = Boolean.FALSE;
149       String JavaDoc strValue = null;
150       Object JavaDoc value, value1 = null;
151       StringBuffer JavaDoc lBuffer = new StringBuffer JavaDoc();
152       lBuffer.append(Boolean.FALSE);
153       strValue = PropertyConverter.convertToString(Boolean.FALSE);
154       Assert.assertTrue(strValue.equalsIgnoreCase(new String JavaDoc(lBuffer)));
155       value = PropertyConverter.convertToValue(strValue, Boolean JavaDoc.class);
156       Assert.assertEquals(etalon, value);
157       value1 = PropertyConverter.convertToValue(strValue, boolean.class);
158       Assert.assertEquals(etalon, value1);
159    }
160
161    public void testString()
162    {
163       String JavaDoc initialValue = "my test, &*(^\"";
164       String JavaDoc strValue = null;
165       Object JavaDoc value = null;
166       strValue = PropertyConverter.convertToString(initialValue);
167       Assert.assertEquals(strValue, initialValue);
168       value = PropertyConverter.convertToValue(strValue, String JavaDoc.class);
169       Assert.assertEquals(initialValue, value);
170
171    }
172
173    public void testURL()
174    {
175       String JavaDoc initialValue = "http://localhost:80/index.jsp";
176       String JavaDoc strValue = null;
177       Object JavaDoc value = null;
178       value = PropertyConverter.convertToValue(initialValue, URL JavaDoc.class);
179       strValue = PropertyConverter.convertToString(value);
180       Assert.assertEquals(strValue, initialValue);
181    }
182
183 }
184
Popular Tags