1
2
3
4
5
6
7
8
9 package bexee.core;
10
11 import java.io.FileNotFoundException;
12 import java.io.InputStream;
13
14 import javax.xml.namespace.QName;
15 import javax.xml.rpc.encoding.XMLType;
16
17 import bexee.BexeeTestCase;
18 import bexee.model.BPELDocumentException;
19 import bexee.model.BPELProcessFactory;
20 import bexee.model.activity.Invoke;
21 import bexee.model.activity.Receive;
22 import bexee.model.activity.Reply;
23 import bexee.model.activity.Sequence;
24 import bexee.model.activity.impl.InvokeImpl;
25 import bexee.model.activity.impl.ReceiveImpl;
26 import bexee.model.activity.impl.ReplyImpl;
27 import bexee.model.activity.impl.SequenceImpl;
28 import bexee.model.elements.Variable;
29 import bexee.model.elements.Variables;
30 import bexee.model.elements.impl.VariableImpl;
31 import bexee.model.elements.impl.VariablesImpl;
32 import bexee.model.process.BPELProcess;
33 import bexee.model.process.Process;
34 import bexee.model.process.impl.BPELProcessImpl;
35 import bexee.model.process.impl.ProcessImpl;
36
37 /***
38 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:12 $
39 * @author Patric Fornasier
40 */
41 public class ProcessControllerImplTest extends BexeeTestCase {
42
43 private ProcessInstance instance;
44
45 private ProcessController controller;
46
47 private BPELProcessFactory factory;
48
49 protected void setUp() throws Exception {
50 super.setUp();
51
52
53 factory = BPELProcessFactory.getInstance();
54
55
56 controller = ProcessControllerFactory.createProcessController();
57 }
58
59 protected void tearDown() throws Exception {
60 super.tearDown();
61 }
62
63 public void testProcessMessage() throws Exception {
64
65 BPELProcess bpelProcess = createReceiveReplyProcess();
66 ProcessContext ctx = new ProcessContext();
67
68 instance = new ProcessInstance(bpelProcess, ctx);
69
70
71 BexeeMessage message = new BexeeMessage();
72 message.setOperation("process");
73 String partValue = "inputvalue";
74 message.putPart("value", partValue);
75
76 controller.processMessage(instance, message);
77
78 Object result = instance.getContext().getResult();
79
80 assertEquals(partValue, result);
81 }
82
83 private BPELProcess createReceiveReplyProcess()
84 throws FileNotFoundException, BPELDocumentException {
85 InputStream inputStream = getLoader().getResourceAsStream(
86 "outAndInProcess.xml");
87 BPELProcess bpelProcess = factory.createBPELProcess(inputStream);
88 return bpelProcess;
89 }
90
91 private BPELProcess createBPELProcess() {
92
93 BPELProcess bpelProcess = null;
94 Receive receiveInput = null;
95 Reply replyOutput = null;
96
97
98
99 Variables variables = new VariablesImpl();
100
101
102
103 Variable inputVariable = new VariableImpl();
104 inputVariable.setName("input");
105 inputVariable.setMessageType(XMLType.XSD_STRING);
106
107
108
109 Variable outputVariable = new VariableImpl();
110 outputVariable.setName("output");
111 outputVariable.setMessageType(XMLType.XSD_STRING);
112
113
114
115 Sequence sequence = new SequenceImpl();
116
117
118
119 receiveInput = new ReceiveImpl();
120 receiveInput.setName("receiveInput");
121 receiveInput.setOperation("process");
122 receiveInput.setVariable(inputVariable);
123 receiveInput.setCreateInstance(true);
124
125
126
127 Invoke invoke = new InvokeImpl();
128 invoke.setName("versionInvoke");
129 invoke.setPortType(new QName("Version"));
130 invoke.setOperation("getVersion");
131 invoke.setOutputVariable(outputVariable);
132
133
134
135 replyOutput = new ReplyImpl();
136 replyOutput.setName("replyOutput");
137 replyOutput.setOperation("process");
138 replyOutput.setVariable(outputVariable);
139
140
141
142 sequence.addActivity(receiveInput);
143 sequence.addActivity(invoke);
144 sequence.addActivity(replyOutput);
145
146
147
148 Process process = new ProcessImpl();
149 process.setName("bexeeExample");
150
151
152
153 variables.addVariable(inputVariable);
154 variables.addVariable(outputVariable);
155
156
157
158 process.setVariables(variables);
159
160
161
162 process.setActivity(sequence);
163
164
165
166 bpelProcess = new BPELProcessImpl();
167 bpelProcess.setProcess(process);
168
169 return bpelProcess;
170 }
171
172 }