1   /*
2    * Copyright 2001-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;
17  
18  import java.io.File;
19  import java.math.BigDecimal;
20  import java.math.BigInteger;
21  import java.net.MalformedURLException;
22  import java.sql.Date;
23  import java.sql.Time;
24  import java.sql.Timestamp;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.apache.commons.beanutils.ConvertUtils;
29  import org.apache.commons.betwixt.xmlunit.XmlTestCase;
30  
31  /*** Abstract base class for test cases.
32    *
33    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
34    * @version $Revision: 155402 $
35    */
36  public abstract class AbstractTestCase extends XmlTestCase {
37      
38      /***
39       * Basedir for all i/o
40       */
41      public String basedir = System.getProperty("basedir");
42      
43      public AbstractTestCase(String testName) {
44          super(testName);
45      }
46  
47      public String getTestFile(String path)
48      {
49          return new File(basedir,path).getAbsolutePath();
50      }
51  
52      public String getTestFileURL(String path) throws MalformedURLException
53      {
54          return new File(basedir,path).toURL().toString();
55      }
56      
57      protected Object createBean() {
58          CustomerBean bean = new CustomerBean();
59          bean.setID( "1" );
60          bean.setName( "James" );
61          bean.setEmails( new String[] { "jstrachan@apache.org", "james_strachan@yahoo.co.uk" } );
62          bean.setNumbers( new int[] { 3, 4, 5 } );
63          bean.setLocation(0, "Highbury Barn" );
64          bean.setLocation(1, "Monument" );
65          bean.setLocation(2, "Leeds" );
66          
67          Map projects = new HashMap();
68          projects.put( "dom4j", "http://dom4j.org" );
69          projects.put( "jaxen", "http://jaxen.org" );
70          projects.put( "jakarta-commons", "http://jakarta.apache.org/commons/" );
71          projects.put( "jakarta-taglibs", "http://jakarta.apache.org/taglibs/" );
72          bean.setProjectMap( projects );
73          
74          AddressBean address = new AddressBean();
75          address.setStreet( "Near the park" );
76          address.setCity( "London" );
77          address.setCountry( "UK" );
78          address.setCode( "N5" );
79          
80          bean.setAddress( address );
81          
82          bean.setDate((Date) ConvertUtils.convert("2002-03-17", Date.class));
83          bean.setTime((Time) ConvertUtils.convert("20:30:40", Time.class));
84          bean.setTimestamp((Timestamp) ConvertUtils.convert("2002-03-17 20:30:40.0", Timestamp.class));
85          
86          bean.setBigDecimal(new BigDecimal("1234567890.12345"));
87          bean.setBigInteger(new BigInteger("1234567890"));
88          
89          return bean;
90      }
91  }
92