01: package org.obe.test;
02:
03: import java.io.*;
04: import org.obe.client.api.WMClient;
05: import org.obe.client.api.WMClientFactory;
06: import org.obe.client.api.ClientConfig;
07: import org.obe.xpdl.model.pkg.XPDLPackage;
08: import org.obe.xpdl.parser.XPDLParser;
09: import org.obe.xpdl.parser.XPDLParserException;
10: import org.obe.xpdl.parser.dom4j.Dom4JXPDLParser;
11: import org.wfmc.wapi.WMConnectInfo;
12: import org.wfmc.wapi.WMWorkflowException;
13:
14: /**
15: * @author Adrian Price
16: */
17: public abstract class OBEClientTest extends OBETestCase {
18: protected static WMClient _client;
19: protected String _protocol;
20: protected String _host;
21:
22: protected OBEClientTest(String name, String protocol) {
23: super (name);
24: _protocol = protocol;
25: _host = ClientConfig.getServerHostURL();
26: }
27:
28: protected void connect() throws WMWorkflowException {
29: _client = WMClientFactory.createClient(_protocol);
30: WMConnectInfo connectInfo = _host == null || _principal == null ? null
31: : new WMConnectInfo(_principal, _credentials, _host, "");
32: _client.connect(connectInfo);
33: }
34:
35: protected void disconnect() throws WMWorkflowException {
36: _client.disconnect();
37: }
38:
39: protected static String readFile(String fileName)
40: throws IOException {
41: InputStream in = WMClientTest.class
42: .getResourceAsStream(fileName);
43: Reader reader = new InputStreamReader(in);
44: StringBuffer sbuf = new StringBuffer();
45: char[] cbuf = new char[4096];
46: int offset = 0, count;
47: do {
48: count = reader.read(cbuf, offset, cbuf.length);
49: if (count > 0)
50: sbuf.append(cbuf, 0, count);
51: } while (count > 0);
52: in.close();
53: return sbuf.toString();
54: }
55:
56: protected XPDLPackage readPackage(String content)
57: throws XPDLParserException, IOException {
58:
59: assertNotNull("Package content is null;", content);
60: XPDLParser parser = new Dom4JXPDLParser();
61: return parser.parse(new StringReader(content));
62: }
63: }
|