1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.betwixt.io.read;
17
18 import java.io.StringReader;
19
20 import org.apache.commons.betwixt.AbstractTestCase;
21 import org.apache.commons.betwixt.io.BeanReader;
22
23 /***
24 * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
25 */
26 public class TestReadData extends AbstractTestCase {
27
28 public TestReadData(String testName) {
29 super(testName);
30 }
31
32 public void testReadInvalidDate() throws Exception {
33
34 String xmlWithInvalidDate = "<?xml version='1.0'?>" +
35 "<AlertBean>" +
36 " <message>Whatever</message>" +
37 " <summary>Sometime</summary>" +
38 " <timestamp>2004-13-32 00:00:00.0</timestamp>" +
39 "</AlertBean>";
40 StringReader invalidIn = new StringReader(xmlWithInvalidDate);
41
42
43 String xmlWithValidDate = "<?xml version='1.0'?>" +
44 "<AlertBean>" +
45 " <message>Whatever</message>" +
46 " <summary>Sometime</summary>" +
47 " <timestamp>1999-12-31 00:00:00.0</timestamp>" +
48 "</AlertBean>";
49 StringReader validIn = new StringReader(xmlWithValidDate);
50
51
52 BeanReader reader = new BeanReader();
53 reader.registerBeanClass(AlertBean.class);
54 try
55 {
56 AlertBean alterBean = (AlertBean) reader.parse(invalidIn);
57 fail("Invalid date so expected exception");
58 }
59 catch (Exception e)
60 {
61
62 }
63
64 AlertBean alterBean = (AlertBean) reader.parse(validIn);
65 }
66 }