KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > AbstractTestCase


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 JavaDoc;
19 import java.math.BigDecimal JavaDoc;
20 import java.math.BigInteger JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.sql.Date JavaDoc;
23 import java.sql.Time JavaDoc;
24 import java.sql.Timestamp JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
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: 1.6 $
35   */

36 public abstract class AbstractTestCase extends XmlTestCase {
37     
38     /**
39      * Basedir for all i/o
40      */

41     public String JavaDoc basedir = System.getProperty("basedir");
42     
43     public AbstractTestCase(String JavaDoc testName) {
44         super(testName);
45     }
46
47     public String JavaDoc getTestFile(String JavaDoc path)
48     {
49         return new File JavaDoc(basedir,path).getAbsolutePath();
50     }
51
52     public String JavaDoc getTestFileURL(String JavaDoc path) throws MalformedURLException JavaDoc
53     {
54         return new File JavaDoc(basedir,path).toURL().toString();
55     }
56     
57     protected Object JavaDoc createBean() {
58         CustomerBean bean = new CustomerBean();
59         bean.setID( "1" );
60         bean.setName( "James" );
61         bean.setEmails( new String JavaDoc[] { "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 JavaDoc projects = new HashMap JavaDoc();
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 JavaDoc) ConvertUtils.convert("2002-03-17", Date JavaDoc.class));
83         bean.setTime((Time JavaDoc) ConvertUtils.convert("20:30:40", Time JavaDoc.class));
84         bean.setTimestamp((Timestamp JavaDoc) ConvertUtils.convert("2002-03-17 20:30:40.0", Timestamp JavaDoc.class));
85         
86         bean.setBigDecimal(new BigDecimal JavaDoc("1234567890.12345"));
87         bean.setBigInteger(new BigInteger JavaDoc("1234567890"));
88         
89         return bean;
90     }
91 }
92
93
Popular Tags