1   /*
2    * $Id: BPELProcessImplTest.java,v 1.1 2004/12/15 14:18:23 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.model.process;
10  
11  import java.util.Collection;
12  
13  import javax.xml.namespace.QName;
14  
15  import org.jmock.MockObjectTestCase;
16  
17  import bexee.model.activity.*;
18  import bexee.model.activity.impl.*;
19  import bexee.model.elements.*;
20  import bexee.model.elements.impl.*;
21  import bexee.model.process.impl.*;
22  
23  /***
24   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:23 $
25   * @author Pawel Kowalski
26   */
27  public class BPELProcessImplTest extends MockObjectTestCase {
28  
29      private BPELProcess bpelProcess = null;
30  
31      private Receive receiveInput = null;
32  
33      /*
34       * @see TestCase#setUp()
35       */
36      protected void setUp() throws Exception {
37          super.setUp();
38  
39          // create client PartnerLink
40          //
41          String clientPartnerLinkName = "client";
42          PartnerLink clientPartnerLink = new PartnerLinkImpl();
43          clientPartnerLink.setName(clientPartnerLinkName);
44  
45          // create service PartnerLink
46          //
47          String servicePartnerLinkName = "service";
48          PartnerLink servicePartnerLink = new PartnerLinkImpl();
49          servicePartnerLink.setName(servicePartnerLinkName);
50  
51          // create input Variable
52          //
53          String inputVariableName = "input";
54          QName messageType = new QName("tns", "ReceiveRequestMessage");
55          Variable inputVariable = new VariableImpl();
56          inputVariable.setName(inputVariableName);
57          inputVariable.setMessageType(messageType);
58  
59          // create response Variable
60          //
61          String responseVariableName = "response";
62          messageType = new QName("tns", "ReceiveResultMessage");
63          Variable responseVariable = new VariableImpl();
64          responseVariable.setName(responseVariableName);
65          responseVariable.setMessageType(messageType);
66  
67          // create sequence
68          //
69          Sequence sequence = new SequenceImpl();
70  
71          // create creation receive
72          //
73          String receiveName = "receiveInput";
74          String operationName = "initiate";
75          boolean createInstance = true;
76          receiveInput = new ReceiveImpl();
77          receiveInput.setName(receiveName);
78          receiveInput.setPartnerLink(clientPartnerLink);
79          receiveInput.setOperation(operationName);
80          receiveInput.setVariable(inputVariable);
81          receiveInput.setCreateInstance(createInstance);
82  
83          // create invoke
84          //
85          String invokeName = "asynchInvoke";
86          QName invokePortType = new QName("services", "AsynchBPELService");
87          String invokeOperationName = "initiate";
88          Invoke invoke = new InvokeImpl();
89          invoke.setName(invokeName);
90          invoke.setPartnerLink(servicePartnerLink);
91          invoke.setPortType(invokePortType);
92          invoke.setOperation(invokeOperationName);
93          invoke.setInputVariable(inputVariable);
94  
95          // create result receive
96          //
97          receiveName = "receiveResult";
98          operationName = "onResult";
99          createInstance = false;
100         QName receiveResultPortType = new QName("services",
101                 "AsyncBPELServiceCallback");
102         Receive receiveResult = new ReceiveImpl();
103         receiveResult.setName(receiveName);
104         receiveResult.setPartnerLink(servicePartnerLink);
105         receiveResult.setOperation(operationName);
106         receiveResult.setVariable(responseVariable);
107 
108         // compose the sequence
109         //
110         sequence.addActivity(receiveInput);
111         sequence.addActivity(invoke);
112         sequence.addActivity(receiveResult);
113 
114         // create the process
115         //
116         String processName = "bexeeExample";
117         Process process = new ProcessImpl();
118         process.setName(processName);
119         process.setPartnerLinks(new PartnerLinksImpl());
120         process.getPartnerLinks().addPartnerLink(clientPartnerLink);
121         process.getPartnerLinks().addPartnerLink(servicePartnerLink);
122         process.setVariables(new VariablesImpl());
123         process.getVariables().addVariable(inputVariable);
124         process.getVariables().addVariable(responseVariable);
125 
126         process.setActivity(sequence);
127 
128         // create the BPELProcess and set the process element
129         //
130         bpelProcess = new BPELProcessImpl();
131         bpelProcess.setProcess(process);
132     }
133 
134     /*
135      * @see TestCase#tearDown()
136      */
137     protected void tearDown() throws Exception {
138         super.tearDown();
139 
140         bpelProcess = null;
141     }
142 
143     //***************************************************/
144     // test
145     //***************************************************/
146 
147     public final void testGetCreationReceives() {
148 
149         Collection creationReceives = bpelProcess.getCreationReceives();
150 
151         assertTrue("receiveInput is the only creation receive",
152                 creationReceives.contains(receiveInput));
153         assertEquals("only one creation receive must be contained", 1,
154                 creationReceives.size());
155 
156     }
157 }