1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17  package org.apache.commons.betwixt;
18  
19  import java.io.File;
20  import java.math.BigDecimal;
21  import java.math.BigInteger;
22  import java.net.MalformedURLException;
23  import java.sql.Date;
24  import java.sql.Time;
25  import java.sql.Timestamp;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.apache.commons.beanutils.ConvertUtils;
30  import org.apache.commons.betwixt.xmlunit.XmlTestCase;
31  
32  /** Abstract base class for test cases.
33    *
34    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
35    * @version $Revision: 438373 $
36    */
37  public abstract class AbstractTestCase extends XmlTestCase {
38      
39      /**
40       * Basedir for all i/o
41       */
42      public String basedir = System.getProperty("basedir");
43      
44      public AbstractTestCase(String testName) {
45          super(testName);
46      }
47  
48      public String getTestFile(String path)
49      {
50          return new File(basedir,path).getAbsolutePath();
51      }
52  
53      public String getTestFileURL(String path) throws MalformedURLException
54      {
55          return new File(basedir,path).toURL().toString();
56      }
57      
58      protected Object createBean() {
59          CustomerBean bean = new CustomerBean();
60          bean.setID( "1" );
61          bean.setName( "James" );
62          bean.setEmails( new String[] { "jstrachan@apache.org", "james_strachan@yahoo.co.uk" } );
63          bean.setNumbers( new int[] { 3, 4, 5 } );
64          bean.setLocation(0, "Highbury Barn" );
65          bean.setLocation(1, "Monument" );
66          bean.setLocation(2, "Leeds" );
67          
68          Map projects = new HashMap();
69          projects.put( "dom4j", "http://dom4j.org" );
70          projects.put( "jaxen", "http://jaxen.org" );
71          projects.put( "jakarta-commons", "http://jakarta.apache.org/commons/" );
72          projects.put( "jakarta-taglibs", "http://jakarta.apache.org/taglibs/" );
73          bean.setProjectMap( projects );
74          
75          AddressBean address = new AddressBean();
76          address.setStreet( "Near the park" );
77          address.setCity( "London" );
78          address.setCountry( "UK" );
79          address.setCode( "N5" );
80          
81          bean.setAddress( address );
82          
83          bean.setDate((Date) ConvertUtils.convert("2002-03-17", Date.class));
84          bean.setTime((Time) ConvertUtils.convert("20:30:40", Time.class));
85          bean.setTimestamp((Timestamp) ConvertUtils.convert("2002-03-17 20:30:40.0", Timestamp.class));
86          
87          bean.setBigDecimal(new BigDecimal("1234567890.12345"));
88          bean.setBigInteger(new BigInteger("1234567890"));
89          
90          return bean;
91      }
92  }
93