📄 bpeltestabstract.java
字号:
try { for (QName procName : procs) { ProcessConfImpl conf = (ProcessConfImpl) store.getProcessConfiguration(procName); // Test processes always run with in-mem DAOs conf.setTransient(true); _server.register(conf); } } catch (Exception ex) { if (d.expectedException == null) failure(d, "REGISTER: Unexpected exception: " + ex, ex); else if (!d.expectedException.isAssignableFrom(ex.getClass())) failure(d, "REGISTER: Wrong exception; expected " + d.expectedException + " but got " + ex.getClass(), ex); } } protected void doUndeployments() { for (Deployment d : _deployments) { try { undeploy(d); } catch (Exception ex) { ex.printStackTrace(); failure(d, "Undeployment failed.", ex); } } _deployments.clear(); } protected void undeploy(Deployment d) { if (_deployed.contains(d)) { _deployed.remove(d); store.undeploy(d.deployDir); } } protected void doInvokes() throws Exception { ArrayList<Thread> testThreads = new ArrayList<Thread>(); for (Invocation i : _invocations) { InvokerThread t = new InvokerThread(i); testThreads.add(t); } for (Thread testThread : testThreads) { testThread.start(); if (testThreads.size() > 0) Thread.sleep(2000); } for (Thread testThread : testThreads) testThread.join(); } private void failure(Object where) { failure(where, "Failure", null); } private void failure(Object where, String message, Exception ex) { Failure f = new Failure(where, message, ex); _failures.add(f); Assert.fail(f.toString()); } private void failure(Object where, String message, Object expected, Object actual) { Failure f = new Failure(where, message, expected, actual, null); _failures.add(f); Assert.fail(f.toString()); } protected boolean isFailed() { return !_failures.isEmpty(); } protected File makeDeployDir(String deployDir) { String deployxml = deployDir + "/deploy.xml"; URL deployxmlurl = getClass().getResource(deployxml); if (deployxmlurl == null) { Assert.fail("Resource not found: " + deployxml); } try { return new File(deployxmlurl.toURI().getPath()).getParentFile(); } catch (URISyntaxException e) { e.printStackTrace(); Assert.fail(e.getMessage()); return null; } } /** * Override this to provide configuration properties for Ode extensions * like BpelEventListeners. * * @return */ protected Properties getConfigProperties() { // could also return null, returning an empty properties // object is more fail-safe. Properties p = new Properties(); p.setProperty("debugeventlistener.dumpToStdOut", SHOW_EVENTS_ON_CONSOLE); return p; } protected static class Failure { Object where; String msg; Object expected; Object actual; Exception ex; public Failure(Object where, String msg, Exception ex) { this(where, msg, null, null, ex); } public Failure(Object where, String msg, Object expected, Object actual, Exception ex) { this.actual = actual; this.expected = expected; this.where = where; this.msg = msg; this.ex = ex; } public String toString() { StringBuffer sbuf = new StringBuffer(where + ": " + msg); if (ex != null) { sbuf.append("; got exception msg: " + ex.getMessage()); } if (actual != null) sbuf.append("; got " + actual + ", expected " + expected); return sbuf.toString(); } } /** * Represents a test deployement. * * @author mszefler * */ public static class Deployment { /** The directory containing the deploy.xml and artefacts. */ public File deployDir; /** If non-null the type of exception we expect to get when we deploy. */ public Class expectedException = null; public Deployment(File deployDir) { this.deployDir = deployDir; } public String toString() { return "Deployment#" + deployDir; } } /** * Represents an test invocation of the BPEL engine. * * @author mszefler */ public static class Invocation { /** Identifier (for reporting). */ public String id; /** Name of the operation to invoke. */ public String operation; /** Name of service to invoke. */ public QName target; /** Expected RegExp pattern for the response, or null */ public Pattern expectedResponsePattern; /** The request message that should be sent to the server */ public Element request; /** Number of ms to wait (relative to other invokes) before invoking. */ public long invokeDelayMs = 0L; /** If non-null, expect an exception of this class (or subclass) on invoke. */ public Class expectedInvokeException = null; /** If non-null, expecte this status right after invoke. */ public MessageExchange.Status expectedStatus = null; /** If non-null, expect this status after response received. */ public MessageExchange.Status expectedFinalStatus = MessageExchange.Status.COMPLETED_OK; /** If non-null, expect this correlation status right after invoke. */ public CorrelationStatus expectedCorrelationStatus = null; /** If non-null, expect this correlation after response received. */ public CorrelationStatus expectedFinalCorrelationStatus = null; /** Maximum number of ms to wait for a response. */ public long maximumWaitMs = 60 * 1000; /** If non-null, minimum number of ms before a response should be available. */ public Long minimumWaitMs = null; long invokeTime; Exception invokeException; QName requestType; public Invocation(String id) { this.id = id; } public String toString() { return "Invocation#" + id; } } class InvokerThread extends Thread { Invocation _invocation; InvokerThread(Invocation invocation) { _invocation = invocation; } public void run() { final MyRoleMessageExchange mex; final Future<MessageExchange.Status> running; // Wait for it.... try { Thread.sleep(_invocation.invokeDelayMs); } catch (Exception ex) { } scheduler.begin(); try { mex = _server.getEngine().createMessageExchange(new GUID().toString(), _invocation.target, _invocation.operation); mexContext.clearCurrentResponse(); Message request = mex.createMessage(_invocation.requestType); request.setMessage(_invocation.request); _invocation.invokeTime = System.currentTimeMillis(); running = mex.invoke(request); Status status = mex.getStatus(); CorrelationStatus cstatus = mex.getCorrelationStatus(); if (_invocation.expectedStatus != null && !status.equals(_invocation.expectedStatus)) failure(_invocation, "Unexpected message exchange status", _invocation.expectedStatus, status); if (_invocation.expectedCorrelationStatus != null && !cstatus.equals(_invocation.expectedCorrelationStatus)) failure(_invocation, "Unexpected correlation status", _invocation.expectedCorrelationStatus, cstatus); } catch (Exception ex) { if (_invocation.expectedInvokeException == null) failure(_invocation, "Unexpected invocation exception.", ex); else if (_invocation.expectedInvokeException.isAssignableFrom(ex.getClass())) failure(_invocation, "Unexpected invocation exception.", _invocation.expectedInvokeException, ex.getClass()); return; } finally { scheduler.commit(); } if (isFailed()) return; try { running.get(_invocation.maximumWaitMs, TimeUnit.MILLISECONDS); } catch (Exception ex) { failure(_invocation, "Exception on future object.", ex); return; } long ctime = System.currentTimeMillis(); long itime = ctime - _invocation.invokeTime; if (_invocation.minimumWaitMs != null && _invocation.minimumWaitMs >= itime) failure(_invocation, "Response received too soon.", _invocation.minimumWaitMs, itime); if (_invocation.maximumWaitMs <= itime) failure(_invocation, "Response took too long.", _invocation.maximumWaitMs, itime); if (isFailed()) return; if (_invocation.expectedResponsePattern != null) { scheduler.begin(); try { Status finalstat = mex.getStatus(); if (_invocation.expectedFinalStatus != null && !_invocation.expectedFinalStatus.equals(finalstat)) if (finalstat.equals(Status.FAULT)) { failure(_invocation, "Unexpected final message exchange status", _invocation.expectedFinalStatus, "FAULT: " + mex.getFault() + " | " + mex.getFaultExplanation()); } else { failure(_invocation, "Unexpected final message exchange status", _invocation.expectedFinalStatus, finalstat); } if (_invocation.expectedFinalCorrelationStatus != null && !_invocation.expectedFinalCorrelationStatus.equals(mex.getCorrelationStatus())) { failure(_invocation, "Unexpected final correlation status", _invocation.expectedFinalCorrelationStatus, mex .getCorrelationStatus()); } if (mex.getResponse() == null) failure(_invocation, "Expected response, but got none.", null); String responseStr = DOMUtils.domToString(mex.getResponse().getMessage()); System.out.println("=>" + responseStr); Matcher matcher = _invocation.expectedResponsePattern.matcher(responseStr); if (!matcher.matches()) failure(_invocation, "Response does not match expected pattern", _invocation.expectedResponsePattern, responseStr); } finally { scheduler.commit(); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -