1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.commons.validator;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import junit.framework.TestCase;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.xml.sax.SAXException;
31
32 /***
33 * Consolidates reading in XML config file into parent class.
34 */
35 abstract public class TestCommon extends TestCase {
36
37 /***
38 * Resources used for validation tests.
39 */
40 protected ValidatorResources resources = null;
41
42 /***
43 * Commons Logging instance.
44 */
45 protected Log log = LogFactory.getLog(this.getClass());
46
47 public TestCommon(String string) {
48 super(string);
49 }
50
51 /***
52 * Load <code>ValidatorResources</code> from
53 * validator-numeric.xml.
54 */
55 protected void loadResources(String file) throws IOException, SAXException {
56
57 InputStream in = null;
58
59 try {
60 in = this.getClass().getResourceAsStream(file);
61 resources = new ValidatorResources(in);
62
63 } catch (IOException e) {
64 log.error(e.getMessage(), e);
65 throw e;
66
67 } finally {
68 if (in != null) {
69 try {
70 in.close();
71 } catch (IOException e) {
72 log.error(e.getMessage(), e);
73 }
74 }
75 }
76 }
77 }