OBEClientTest.java :  » Workflow-Engines » obe-1.0 » org » obe » test » Java Open Source

Java Open Source » Workflow Engines » obe 1.0 
obe 1.0 » org » obe » test » OBEClientTest.java
package org.obe.test;

import java.io.*;
import org.obe.client.api.WMClient;
import org.obe.client.api.WMClientFactory;
import org.obe.client.api.ClientConfig;
import org.obe.xpdl.model.pkg.XPDLPackage;
import org.obe.xpdl.parser.XPDLParser;
import org.obe.xpdl.parser.XPDLParserException;
import org.obe.xpdl.parser.dom4j.Dom4JXPDLParser;
import org.wfmc.wapi.WMConnectInfo;
import org.wfmc.wapi.WMWorkflowException;

/**
 * @author Adrian Price
 */
public abstract class OBEClientTest extends OBETestCase {
    protected static WMClient _client;
    protected String _protocol;
    protected String _host;

    protected OBEClientTest(String name, String protocol) {
        super(name);
        _protocol = protocol;
        _host = ClientConfig.getServerHostURL();
    }

    protected void connect() throws WMWorkflowException {
        _client = WMClientFactory.createClient(_protocol);
        WMConnectInfo connectInfo = _host == null || _principal == null
            ? null
            : new WMConnectInfo(_principal, _credentials, _host, "");
        _client.connect(connectInfo);
    }

    protected void disconnect() throws WMWorkflowException {
        _client.disconnect();
    }

    protected static String readFile(String fileName) throws IOException {
        InputStream in = WMClientTest.class.getResourceAsStream(fileName);
        Reader reader = new InputStreamReader(in);
        StringBuffer sbuf = new StringBuffer();
        char[] cbuf = new char[4096];
        int offset = 0, count;
        do {
            count = reader.read(cbuf, offset, cbuf.length);
            if (count > 0)
                sbuf.append(cbuf, 0, count);
        } while (count > 0);
        in.close();
        return sbuf.toString();
    }

    protected XPDLPackage readPackage(String content)
        throws XPDLParserException, IOException {

        assertNotNull("Package content is null;", content);
        XPDLParser parser = new Dom4JXPDLParser();
        return parser.parse(new StringReader(content));
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.