KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > TestConversion


1 /*
2  * Copyright 2004,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.betwixt;
18
19 import java.io.StringReader JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.commons.betwixt.io.BeanReader;
24
25 /**
26  * Tests conversions.
27  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
28  * @version $Revision: 1.3 $
29  */

30 public class TestConversion extends TestCase{
31
32     public TestConversion(String JavaDoc name) {
33         super(name);
34     }
35
36     /**
37      * Betwixt does not (by default) try to convert nulls and empty strings
38      * @throws Exception
39      */

40     public void testNullTimestampConversion() throws Exception JavaDoc {
41         String JavaDoc xml = "<?xml version='1.0'?>" +
42             "<EventBean>" +
43             "<type>WARNING</type>" +
44             "<start>2004-02-10 00:00:00.0</start>" +
45             "<end/>" +
46             "</EventBean>";
47             
48        StringReader JavaDoc in = new StringReader JavaDoc(xml);
49        BeanReader reader = new BeanReader();
50        reader.registerBeanClass(EventBean.class);
51        EventBean bean = (EventBean) reader.parse(in);
52        
53        assertNotNull("Parsing should work", bean);
54        assertEquals("Type property", "WARNING", bean.getType());
55        assertEquals("Start property", "2004-02-10 00:00:00.0", bean.getStart().toString());
56        assertNull("End property", bean.getEnd());
57     }
58    
59 }
60
Popular Tags