1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
33
34
35
36
37 public abstract class AbstractTestCase extends XmlTestCase {
38
39
40
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