01: package CustomDNS.Tests;
02:
03: import junit.framework.*;
04:
05: import net.espeak.infra.cci.exception.*;
06: import net.espeak.jesi.*;
07:
08: /*************************************************************************
09: * A subclass of TestCase with special support for testing CustomDNS.
10: *************************************************************************
11: */
12:
13: public class CustomDNSTestCase extends TestCase {
14:
15: // Configuration constants.
16: private static final String dataDir = "../../tests/";
17:
18: // Class variables.
19: private static ESConnection sESConnection = null;
20:
21: /*********************************************************************
22: * Create a new test case.
23: *********************************************************************
24: * @param name The name of the test case.
25: */
26:
27: public CustomDNSTestCase(String name) {
28: super (name);
29: }
30:
31: /*********************************************************************
32: * Find a specific test file.
33: *********************************************************************
34: * XXX - Do we need a better name?
35: * @param filename The name of a file containing test data.
36: * @return A path to the specified test file.
37: */
38:
39: public static String fullPath(String filename) {
40: return dataDir + filename;
41: }
42:
43: /*********************************************************************
44: * Get a connection to the E-Speak core.
45: *********************************************************************
46: * These connections are very expensive to set up, so we only do
47: * this once for an entire test run.
48: * @return A connection to the test core.
49: * @exception ESInvocationException An error occured while trying
50: * to connect to the E-Speak core.
51: * @exception ESLibException Cause unknown.
52: * @see ESConnection
53: */
54:
55: protected static synchronized ESConnection getESConnection()
56: throws ESInvocationException, ESLibException {
57: if (sESConnection == null) {
58: sESConnection = new ESConnection(fullPath("espeak.prop"));
59: }
60: return sESConnection;
61: }
62:
63: /*********************************************************************
64: * Find an E-speak service.
65: *********************************************************************
66: * @param core A connection to an e-speak core.
67: * @param intf The interface type to find.
68: * @param query A query object specifying the interface's properties.
69: * @return A service object matching the query.
70: * @exception ESInvocationException An error occured while trying
71: * to connect to the E-Speak core.
72: * @exception LookupFailedException The specified object could not
73: * be found.
74: */
75:
76: public static Object findService(ESConnection core, Class intf,
77: ESQuery query) throws ESInvocationException,
78: LookupFailedException {
79: String intfName = intf.getName();
80: ESServiceFinder finder = new ESServiceFinder(core, intfName);
81: return finder.find(query);
82: }
83: }
|