Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XPath20ExpressionRuntime.java URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XPath20ExpressionRuntime.java?rev=693931&view=auto ============================================================================== --- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XPath20ExpressionRuntime.java (added) +++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XPath20ExpressionRuntime.java Wed Sep 10 12:06:59 2008 @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ode.bpel.rtrep.v1.xpath20; + +import net.sf.saxon.trans.DynamicError; +import net.sf.saxon.value.DurationValue; +import net.sf.saxon.xpath.XPathEvaluator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.ode.bpel.common.FaultException; +import org.apache.ode.bpel.rtrep.v1.OExpression; +import org.apache.ode.bpel.rtrep.v1.EvaluationContext; +import org.apache.ode.bpel.rtrep.v1.ExpressionLanguageRuntime; +import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression; +import org.apache.ode.bpel.rtrep.common.ConfigurationException; +import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.ISO8601DateParser; +import org.apache.ode.utils.xsd.Duration; +import org.apache.ode.utils.xsl.XslTransformHandler; +import org.w3c.dom.*; + +import javax.xml.namespace.QName; +import javax.xml.transform.TransformerFactory; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import java.util.*; + +/** + * XPath 2.0 Expression Language run-time subsytem. + * Saxon implementation. + */ +public class XPath20ExpressionRuntime implements ExpressionLanguageRuntime { + + static final short NODE_TYPE = 1; + static final short NODESET_TYPE = 2; + static final short STRING_TYPE = 3; + static final short BOOLEAN_TYPE = 4; + static final short NUMBER_TYPE = 5; + + /** Class-level logger. */ + private static final Log __log = LogFactory.getLog(XPath20ExpressionRuntime.class); + + public XPath20ExpressionRuntime(){ + } + + public void initialize(Map properties) throws ConfigurationException { + TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl(); + XslTransformHandler.getInstance().setTransformerFactory(trsf); + } + + /** + * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsString(org.apache.ode.bpel.rtrep.v1.OExpression, org.apache.ode.bpel.explang.EvaluationContext) + */ + public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException { + return (String)evaluate(cexp, ctx, XPathConstants.STRING); + } + + /** + * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsBoolean(org.apache.ode.bpel.rtrep.v1.OExpression, org.apache.ode.bpel.explang.EvaluationContext) + */ + public boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx) throws FaultException { + return (Boolean) evaluate(cexp, ctx, XPathConstants.BOOLEAN); + } + + public Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx) throws FaultException { + return (Number) evaluate(cexp, ctx, XPathConstants.NUMBER); + } + + /** + * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluate(org.apache.ode.bpel.rtrep.v1.OExpression, org.apache.ode.bpel.explang.EvaluationContext) + */ + public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException { + List result; + Object someRes = evaluate(cexp, ctx, XPathConstants.NODESET); + if (someRes instanceof List) { + result = (List) someRes; + __log.debug("Returned list of size " + result.size()); + if ((result.size() == 1) && !(result.get(0) instanceof Node)) { + // Dealing with a Java class + Object simpleType = result.get(0); + // Dates get a separate treatment as we don't want to call toString on them + String textVal; + if (simpleType instanceof Date) + textVal = ISO8601DateParser.format((Date) simpleType); + else if (simpleType instanceof DurationValue) + textVal = ((DurationValue)simpleType).getStringValue(); + else + textVal = simpleType.toString(); + + // Wrapping in a document + Document d = DOMUtils.newDocument(); + // Giving our node a parent just in case it's an LValue expression + Element wrapper = d.createElement("wrapper"); + Text text = d.createTextNode(textVal); + wrapper.appendChild(text); + d.appendChild(wrapper); + result = Collections.singletonList(text); + } + } else if (someRes instanceof NodeList) { + NodeList retVal = (NodeList) someRes; + __log.debug("Returned node list of size " + retVal.getLength()); + result = new ArrayList(retVal.getLength()); + for(int m = 0; m < retVal.getLength(); ++m) { + Node val = retVal.item(m); + if (val.getNodeType() == Node.DOCUMENT_NODE) val = ((Document)val).getDocumentElement(); + result.add(val); + } + } else { + result = null; + } + + return result; + } + + public Node evaluateNode(OExpression cexp, EvaluationContext ctx) throws FaultException { + List retVal = evaluate(cexp, ctx); + if (retVal.size() == 0) + throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp); + if (retVal.size() > 1) + throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "Multiple results for expression: " + cexp); + return (Node) retVal.get(0); + } + + public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException { + List literal = DOMUtils.toList(evaluate(cexp, context, XPathConstants.NODESET)); + if (literal.size() == 0) + throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp); + if (literal.size() > 1) + throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "Multiple results for expression: " + cexp); + + Object date =literal.get(0); + if (date instanceof Calendar) return (Calendar) date; + if (date instanceof Date) { + Calendar cal = Calendar.getInstance(); + cal.setTime((Date) date); + return cal; + } + if (date instanceof Element) date = ((Element)date).getTextContent(); + + try { + return ISO8601DateParser.parseCal(date.toString()); + } catch (Exception ex) { + String errmsg = "Invalid date: " + literal; + __log.error(errmsg, ex); + throw new FaultException(cexp.getOwner().constants.qnInvalidExpressionValue,errmsg); + } + } + + public Duration evaluateAsDuration(OExpression cexp, EvaluationContext context) throws FaultException { + String literal = this.evaluateAsString(cexp, context); + try { + return new Duration(literal); + } catch (Exception ex) { + String errmsg = "Invalid duration: " + literal; + __log.error(errmsg, ex); + throw new FaultException(cexp.getOwner().constants.qnInvalidExpressionValue,errmsg); + } + } + + private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException { + try { + net.sf.saxon.xpath.XPathFactoryImpl xpf = new net.sf.saxon.xpath.XPathFactoryImpl(); + + OXPath20ExpressionBPEL20 oxpath20 = ((OXPath20ExpressionBPEL20) cexp); + xpf.setXPathFunctionResolver(new JaxpFunctionResolver(ctx, oxpath20)); + xpf.setXPathVariableResolver(new JaxpVariableResolver(ctx, oxpath20)); + XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath(); + xpe.setNamespaceContext(oxpath20.namespaceCtx); + // Just checking that the expression is valid + XPathExpression expr = xpe.compile(((OXPath10Expression)cexp).xpath); + + Object evalResult = expr.evaluate(ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode(), type); + if (evalResult != null && __log.isDebugEnabled()) { + __log.debug("Expression " + cexp.toString() + " generated result " + evalResult + + " - type=" + evalResult.getClass().getName()); + if (ctx.getRootNode() != null) + __log.debug("Was using context node " + DOMUtils.domToString(ctx.getRootNode())); + } + return evalResult; + } catch (XPathExpressionException e) { + // Extracting the real cause from all this wrapping isn't a simple task + Throwable cause = e.getCause() != null ? e.getCause() : e; + if (cause instanceof DynamicError) { + Throwable th = ((DynamicError)cause).getException(); + if (th != null) { + cause = th; + if (cause.getCause() != null) cause = cause.getCause(); + } + } + throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, cause.getMessage(), cause); + } catch (WrappedFaultException wre) { + __log.debug("Could not evaluate expression because of ", wre); + throw (FaultException)wre.getCause(); + } catch (Throwable t) { + __log.debug("Could not evaluate expression because of ", t); + throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, t.getMessage(), t); + } + + } + +}
Added: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XslRuntimeUriResolver.java URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XslRuntimeUriResolver.java?rev=693931&view=auto ============================================================================== --- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XslRuntimeUriResolver.java (added) +++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v1/xpath20/XslRuntimeUriResolver.java Wed Sep 10 12:06:59 2008 @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ode.bpel.rtrep.v1.xpath20; + +import org.apache.ode.bpel.rtrep.v1.OXslSheet; +import org.apache.ode.bpel.rtrep.v1.xpath10.OXPath10Expression; +import org.apache.ode.utils.StreamUtils; +import org.apache.ode.utils.fs.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.xml.transform.URIResolver; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.stream.StreamSource; +import java.net.URI; +import java.net.URISyntaxException; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; + +/** + * Used to give the Xsl processor a way to access included XSL sheets + * by using the maps of sheets pre-processed at compilation time and + * stored in the OXPath10Expression. + */ +public class XslRuntimeUriResolver implements URIResolver { + + private static final Log __log = LogFactory.getLog(XslRuntimeUriResolver.class); + + private OXPath10Expression _expr; + private final URI _baseResourceURI; + + public XslRuntimeUriResolver(OXPath10Expression expr, URI baseResourceURI) { + _expr = expr; + _baseResourceURI= baseResourceURI; + } + + public Source resolve(String href, String base) throws TransformerException { + String result; + URI uri; + try { + uri = new URI(FileUtils.encodePath(href)); + } catch (URISyntaxException e) { + return null; + } + + OXslSheet sheet = _expr.xslSheets.get(uri); + if( sheet != null) { + result = sheet.sheetBody; + } else { + result = getResourceAsString(uri); + } + + if( result != null ) { + return new StreamSource(new StringReader(result)); + } else { + return null; + } + } + + /** + * Given a URI this function will attempt to retrieve the resource declared at that URI location + * as a string. (Hopefully everything's character encodings are all ok...) This URI can be + * defined as being relative to the executing process instance's physical file location. + * + * @param docUri - the URI to resolve + * @return String - the resource contents, or null if none found. + */ + private String getResourceAsString(URI docUri) { + URI resolvedURI= _baseResourceURI.resolve(docUri); + InputStream is = null; + try { + File f = new File(resolvedURI); + if (!f.exists()) return null; + is = new FileInputStream(f); + return new String(StreamUtils.read(is)); + } catch (IOException e) { + __log.info("Couldn't load XSL resource " + docUri); + } finally { + try { + if (is != null) is.close(); + } catch (Exception ex) { + // No worries. + } + } + return null; + } + + + +} Modified: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ACTIVITYGUARD.java URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ACTIVITYGUARD.java?rev=693931&r1=693930&r2=693931&view=diff ============================================================================== --- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ACTIVITYGUARD.java (original) +++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ACTIVITYGUARD.java Wed Sep 10 12:06:59 2008 @@ -128,8 +128,7 @@ private boolean evaluateTransitionCondition(OExpression transitionCondition) throws FaultException { - if (transitionCondition == null) - return true; + if (transitionCondition == null) return true; return getBpelRuntime().getExpLangRuntime().evaluateAsBoolean(transitionCondition, new ExprEvaluationContextImpl(_scopeFrame, getBpelRuntime())); Modified: ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ASSIGN.java URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ASSIGN.java?rev=693931&r1=693930&r2=693931&view=diff ============================================================================== --- ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ASSIGN.java (original) +++ ode/trunk/runtimes/src/main/java/org/apache/ode/bpel/rtrep/v2/ASSIGN.java Wed Sep 10 12:06:59 2008 @@ -199,9 +199,8 @@ + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { - List<Node> l; OExpression expr = ((OAssign.Expression) from).expression; - l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext()); + List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); Added: ode/trunk/runtimes/src/test/java/org/apache/ode/bpel/rtrep/v1/CoreBpelTest.java URL: http://svn.apache.org/viewvc/ode/trunk/runtimes/src/test/java/org/apache/ode/bpel/rtrep/v1/CoreBpelTest.java?rev=693931&view=auto ============================================================================== --- ode/trunk/runtimes/src/test/java/org/apache/ode/bpel/rtrep/v1/CoreBpelTest.java (added) +++ ode/trunk/runtimes/src/test/java/org/apache/ode/bpel/rtrep/v1/CoreBpelTest.java Wed Sep 10 12:06:59 2008 @@ -0,0 +1,459 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ode.bpel.rtrep.v1; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.net.URI; +import java.util.Date; +import java.util.HashMap; +import java.util.Collection; + +import javax.wsdl.Operation; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.ode.bpel.common.CorrelationKey; +import org.apache.ode.bpel.common.FaultException; +import org.apache.ode.bpel.evt.ScopeEvent; +import org.apache.ode.bpel.evt.ProcessInstanceStartedEvent; +import org.apache.ode.jacob.vpu.ExecutionQueueImpl; +import org.apache.ode.jacob.vpu.JacobVPU; +import org.apache.ode.bpel.evar.ExternalVariableModuleException; +import org.apache.ode.bpel.rapi.*; +import org.apache.ode.bpel.rtrep.v1.channels.*; +import org.apache.ode.bpel.extension.ExtensionOperation; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.junit.Assert; + +/** + * Test core BPEL processing capabilities. + */ +public class CoreBpelTest extends TestCase implements OdeInternalInstance { + private boolean _completedOk; + + private boolean _terminate; + + private FaultInfo _fault; + + private ExecutionQueueImpl _soup; + + private JacobVPU _vpu; + + private Long _pid; + + private long _seq; + + protected void setUp() throws Exception { + _completedOk = false; + _terminate = false; + _fault = null; + _soup = new ExecutionQueueImpl(CoreBpelTest.class.getClassLoader()); + _vpu = new JacobVPU(_soup); + _vpu.registerExtension(OdeRTInstanceContext.class, this); + _pid = (long) 19355; + } + + public Long getPid() { + return _pid; + } + + public Long createScopeInstance(Long parentScopeId, String scopename, int scopemodelid) { + return (long) (Math.random() * 1000L) + scopemodelid; + } + + public void completedOk() { + _completedOk = true; + } + + public void completedFault(FaultData faultData) { + _fault = faultData; + } + + public void terminate() { + _terminate = true; + } + + public boolean isCorrelationInitialized(CorrelationSetInstance correlationSet) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + public String readProperty(VariableInstance variable, OProcess.OProperty property) throws FaultException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void writeCorrelation(CorrelationSetInstance cset, CorrelationKey ckeyVal) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public Node initializeVariable(VariableInstance var, ScopeFrame scopeFrame, Node val) throws ExternalVariableModuleException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public Long createScopeInstance(Long scopeInstanceId, OScope scopedef) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void initializePartnerLinks(Long parentScopeId, Collection<OPartnerLink> partnerLinks) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public String invoke(String invokeId, PartnerLinkInstance instance, Operation operation, Element outboundMsg, Object object) throws FaultException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void registerTimer(TimerResponseChannel timerChannel, Date future) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void select(PickResponseChannel pickResponseChannel, Date timeout, boolean createInstance, Selector[] selectors) throws FaultException { + //To change body of implemented methods use File | Settings | File Templates. + } + + public CorrelationKey readCorrelation(CorrelationSetInstance cset) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public ExpressionLanguageRuntimeRegistry getExpLangRuntime() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void cancel(PickResponseChannel responseChannel) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void commitChanges(VariableInstance var, ScopeFrame scopeFrame, Node value) throws ExternalVariableModuleException { + //To change body of implemented methods use File | Settings | File Templates. + } + + public Node fetchVariableData(VariableInstance var, ScopeFrame scopeFrame, OMessageVarType.Part part, boolean forWriting) throws FaultException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void sendEvent(ScopeEvent event) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void sendEvent(ProcessInstanceStartedEvent evt) { + //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isVariableInitialized(VariableInstance var) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + public Node fetchVariableData(VariableInstance variable, ScopeFrame scopeFrame, boolean forWriting) throws FaultException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void reply(PartnerLinkInstance plink, String opName, String bpelmex, Element element, QName fault) throws FaultException { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void testEmptyProcess() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + proc.procesScope.activity = new OEmpty(proc, proc.procesScope); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testThrow() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OThrow othrow = new OThrow(proc, proc.procesScope); + othrow.faultName = new QName("foo", "bar"); + proc.procesScope.activity = othrow; + + run(proc); + + Assert.assertFalse(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertEquals(_fault.getFaultName(), othrow.faultName); + } + + public void testFaultHandling() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OThrow othrow = new OThrow(proc, proc.procesScope); + othrow.faultName = new QName("foo", "bar"); + proc.procesScope.activity = othrow; + proc.procesScope.faultHandler = new OFaultHandler(proc); + OCatch ocatch = new OCatch(proc, proc.procesScope); + proc.procesScope.faultHandler.catchBlocks.add(ocatch); + ocatch.activity = new OEmpty(proc, ocatch); + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testOneElementSequence() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OSequence sequence = new OSequence(proc, proc.procesScope); + proc.procesScope.activity = sequence; + sequence.sequence.add(new OEmpty(proc, sequence)); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testTwoElementSequence() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OSequence sequence = new OSequence(proc, proc.procesScope); + proc.procesScope.activity = sequence; + sequence.sequence.add(new OEmpty(proc, sequence)); + sequence.sequence.add(new OEmpty(proc, sequence)); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testEmptyFlow() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + proc.procesScope.activity = new OFlow(proc, proc.procesScope); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testSingleElementFlow() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OFlow flow = new OFlow(proc, proc.procesScope); + proc.procesScope.activity = flow; + flow.parallelActivities.add(new OEmpty(proc, flow)); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testTwoElementFlow() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OFlow flow = new OFlow(proc, proc.procesScope); + proc.procesScope.activity = flow; + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + + run(proc); + + Assert.assertTrue(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertNull(_fault); + } + + public void testFlowTermination() { + OProcess proc = new OProcess("2.0"); + proc.procesScope = new OScope(proc, null); + OFlow flow = new OFlow(proc, proc.procesScope); + proc.procesScope.activity = flow; + OThrow othrow = new OThrow(proc, flow); + othrow.faultName = new QName("foo", "bar"); + flow.parallelActivities.add(othrow); + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + flow.parallelActivities.add(new OEmpty(proc, flow)); + + run(proc); + + Assert.assertFalse(_completedOk); + Assert.assertFalse(_terminate); + Assert.assertEquals(_fault.getFaultName(), othrow.faultName); + } + + private void run(OProcess proc) { + _vpu.inject(new PROCESS(proc)); + for (int i = 0; i < 100000 && !_completedOk && _fault == null && !_terminate; ++i) { + _vpu.execute(); + } + + Assert.assertTrue(_soup.isComplete()); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + try { + _soup.write(bos); + _soup.read(new ByteArrayInputStream(bos.toByteArray())); + // check empty soup. + } catch (Exception ex) { + + } + } + + public long genId() { + return _seq++; + } + + public Element getPartnerResponse(String mexId) { + // TODO Auto-generated method stub + return null; + } + + public Element getMyRequest(String mexId) { + // TODO Auto-generated method stub + return null; + } + + public QName getPartnerFault(String mexId) { + // TODO Auto-generated method stub + return null; + } + + public QName getPartnerResponseType(String mexId) { + // TODO Auto-generated method stub + return null; + } + + public Node convertEndpointReference(Element epr, Node targetNode) { + return null; + } + + public Node getPartData(Element message, OMessageVarType.Part part) { + return null; + } + + public Element getSourceEPR(String mexId) { + return null; + } + + public void writeEndpointReference(PartnerLinkInstance variable, Element data) { + } + + public Element fetchMyRoleEndpointReferenceData(PartnerLinkInstance pLink) { + // TODO Auto-generated method stub + return null; + } + + public Element fetchPartnerRoleEndpointReferenceData(PartnerLinkInstance pLink) throws FaultException { + // TODO Auto-generated method stub + return null; + } + + public boolean isPartnerRoleEndpointInitialized(PartnerLinkInstance pLink) { + // TODO Auto-generated method stub + return false; + } + + public String fetchMySessionId(PartnerLinkInstance pLink) { + // TODO Auto-generated method stub + return null; + } + + public String fetchPartnersSessionId(PartnerLinkInstance pLink) { + // TODO Auto-generated method stub + return null; + } + + public void initializePartnersSessionId(PartnerLinkInstance pLink, String session) { + // TODO Auto-generated method stub + + } + + public String getSourceSessionId(String mexId) { + // TODO Auto-generated method stub + return null; + } + + public void registerActivityForRecovery(ActivityRecoveryChannel channel, long activityId, String reason, + Date dateTime, Element data, String[] actions, int retries) { + } + + public void unregisterActivityForRecovery(ActivityRecoveryChannel channel) { + } + + public void recoverActivity(String channel, long activityId, String action, FaultData fault) { + } + + public String getPartnerFaultExplanation(String mexid) { + return null; + } + + public void releasePartnerMex(String mexId) { + // TODO Auto-generated method stub + + } + + public void forceFlush() { + // TODO Auto-generated method stub + + } + + public ExtensionOperation createExtensionActivityImplementation(QName name) { + // TODO Auto-generated method stub + return null; + } + + public void initializeExternalVariable(VariableInstance instance, HashMap<String, String> keymap) { + // TODO Auto-generated method stub + + } + + public Node readExtVar(OScope.Variable variable, Node reference) throws ExternalVariableModuleException { + // TODO Auto-generated method stub + return null; + } + + public Node readVariable(Long scopeInstanceId, String varname, boolean forWriting) throws FaultException { + // TODO Auto-generated method stub + return null; + } + + public VariableContext.ValueReferencePair writeExtVar(OScope.Variable variable, Node reference, Node value) + throws ExternalVariableModuleException { + // TODO Auto-generated method stub + return null; + } + + public Node writeVariable(VariableInstance var, Node changes) { + // TODO Auto-generated method stub + return null; + } + + public URI getBaseResourceURI() { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file
