1   /*
2    * Copyright 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  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              // expected
62          }
63          
64          AlertBean alterBean = (AlertBean) reader.parse(validIn);
65      }
66  }