001: /*
002: * $Id: ProcessControllerImplTest.java,v 1.15 2004/12/06 07:53:41 fornp1 Exp $
003: *
004: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
005: * Berne University of Applied Sciences
006: * School of Engineering and Information Technology
007: * All rights reserved.
008: */
009: package bexee.core;
010:
011: import java.io.FileNotFoundException;
012: import java.io.InputStream;
013:
014: import javax.xml.namespace.QName;
015: import javax.xml.rpc.encoding.XMLType;
016:
017: import bexee.BexeeTestCase;
018: import bexee.model.BPELDocumentException;
019: import bexee.model.BPELProcessFactory;
020: import bexee.model.activity.Invoke;
021: import bexee.model.activity.Receive;
022: import bexee.model.activity.Reply;
023: import bexee.model.activity.Sequence;
024: import bexee.model.activity.impl.InvokeImpl;
025: import bexee.model.activity.impl.ReceiveImpl;
026: import bexee.model.activity.impl.ReplyImpl;
027: import bexee.model.activity.impl.SequenceImpl;
028: import bexee.model.elements.Variable;
029: import bexee.model.elements.Variables;
030: import bexee.model.elements.impl.VariableImpl;
031: import bexee.model.elements.impl.VariablesImpl;
032: import bexee.model.process.BPELProcess;
033: import bexee.model.process.Process;
034: import bexee.model.process.impl.BPELProcessImpl;
035: import bexee.model.process.impl.ProcessImpl;
036:
037: /**
038: * @version $Revision: 1.15 $, $Date: 2004/12/06 07:53:41 $
039: * @author Patric Fornasier
040: */
041: public class ProcessControllerImplTest extends BexeeTestCase {
042:
043: private ProcessInstance instance;
044:
045: private ProcessController controller;
046:
047: private BPELProcessFactory factory;
048:
049: protected void setUp() throws Exception {
050: super .setUp();
051:
052: // create process instance
053: factory = BPELProcessFactory.getInstance();
054:
055: // create process controller
056: controller = ProcessControllerFactory.createProcessController();
057: }
058:
059: protected void tearDown() throws Exception {
060: super .tearDown();
061: }
062:
063: public void testProcessMessage() throws Exception {
064:
065: BPELProcess bpelProcess = createReceiveReplyProcess();
066: ProcessContext ctx = new ProcessContext();
067:
068: instance = new ProcessInstance(bpelProcess, ctx);
069:
070: // create BexeeMessage
071: BexeeMessage message = new BexeeMessage();
072: message.setOperation("process");
073: String partValue = "inputvalue";
074: message.putPart("value", partValue);
075:
076: controller.processMessage(instance, message);
077:
078: Object result = instance.getContext().getResult();
079:
080: assertEquals(partValue, result);
081: }
082:
083: private BPELProcess createReceiveReplyProcess()
084: throws FileNotFoundException, BPELDocumentException {
085: InputStream inputStream = getLoader().getResourceAsStream(
086: "outAndInProcess.xml");
087: BPELProcess bpelProcess = factory
088: .createBPELProcess(inputStream);
089: return bpelProcess;
090: }
091:
092: private BPELProcess createBPELProcess() {
093:
094: BPELProcess bpelProcess = null;
095: Receive receiveInput = null;
096: Reply replyOutput = null;
097:
098: // create Variables
099: //
100: Variables variables = new VariablesImpl();
101:
102: // create input Variable
103: //
104: Variable inputVariable = new VariableImpl();
105: inputVariable.setName("input");
106: inputVariable.setMessageType(XMLType.XSD_STRING);
107:
108: // create output Variable
109: //
110: Variable outputVariable = new VariableImpl();
111: outputVariable.setName("output");
112: outputVariable.setMessageType(XMLType.XSD_STRING);
113:
114: // create sequence
115: //
116: Sequence sequence = new SequenceImpl();
117:
118: // create creation receive
119: //
120: receiveInput = new ReceiveImpl();
121: receiveInput.setName("receiveInput");
122: receiveInput.setOperation("process");
123: receiveInput.setVariable(inputVariable);
124: receiveInput.setCreateInstance(true);
125:
126: // create invoke
127: //
128: Invoke invoke = new InvokeImpl();
129: invoke.setName("versionInvoke");
130: invoke.setPortType(new QName("Version"));
131: invoke.setOperation("getVersion");
132: invoke.setOutputVariable(outputVariable);
133:
134: // create reply
135: //
136: replyOutput = new ReplyImpl();
137: replyOutput.setName("replyOutput");
138: replyOutput.setOperation("process");
139: replyOutput.setVariable(outputVariable);
140:
141: // compose the sequence
142: //
143: sequence.addActivity(receiveInput);
144: sequence.addActivity(invoke);
145: sequence.addActivity(replyOutput);
146:
147: // create the process
148: //
149: Process process = new ProcessImpl();
150: process.setName("bexeeExample");
151:
152: // compose variables
153: //
154: variables.addVariable(inputVariable);
155: variables.addVariable(outputVariable);
156:
157: // add variables
158: //
159: process.setVariables(variables);
160:
161: // add activity
162: //
163: process.setActivity(sequence);
164:
165: // create the BPELProcess and set the process element
166: //
167: bpelProcess = new BPELProcessImpl();
168: bpelProcess.setProcess(process);
169:
170: return bpelProcess;
171: }
172:
173: }
|