01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: return new File(basedir, path).getAbsolutePath();
50: }
51:
52: public String getTestFileURL(String path)
53: throws MalformedURLException {
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",
62: "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",
72: "http://jakarta.apache.org/commons/");
73: projects.put("jakarta-taglibs",
74: "http://jakarta.apache.org/taglibs/");
75: bean.setProjectMap(projects);
76:
77: AddressBean address = new AddressBean();
78: address.setStreet("Near the park");
79: address.setCity("London");
80: address.setCountry("UK");
81: address.setCode("N5");
82:
83: bean.setAddress(address);
84:
85: bean.setDate((Date) ConvertUtils.convert("2002-03-17",
86: Date.class));
87: bean.setTime((Time) ConvertUtils
88: .convert("20:30:40", Time.class));
89: bean.setTimestamp((Timestamp) ConvertUtils.convert(
90: "2002-03-17 20:30:40.0", Timestamp.class));
91:
92: bean.setBigDecimal(new BigDecimal("1234567890.12345"));
93: bean.setBigInteger(new BigInteger("1234567890"));
94:
95: return bean;
96: }
97: }
|