1   /*
2    * $Id: ActivityImplFactoryTest.java,v 1.1 2004/12/15 14:18:18 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.xmltobpel;
10  
11  import java.io.InputStream;
12  import java.util.List;
13  
14  import org.apache.commons.digester.Digester;
15  import org.xml.sax.helpers.AttributesImpl;
16  
17  import bexee.BexeeTestCase;
18  import bexee.model.AttributeNames;
19  import bexee.model.BPELProcessFactory;
20  import bexee.model.activity.Invoke;
21  import bexee.model.activity.Receive;
22  import bexee.model.activity.Sequence;
23  import bexee.model.activity.impl.SwitchImpl;
24  import bexee.model.process.BPELProcess;
25  import bexee.model.process.Process;
26  import bexee.model.process.impl.BPELProcessImpl;
27  
28  /***
29   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:18 $
30   * @author Pawel Kowalski
31   */
32  public class ActivityImplFactoryTest extends BexeeTestCase implements
33          AttributeNames {
34  
35      private BPELProcessFactory factory;
36  
37      /*
38       * @see TestCase#setUp()
39       */
40      protected void setUp() throws Exception {
41          super.setUp();
42          factory = BPELProcessFactory.getInstance();
43      }
44  
45      /*
46       * @see TestCase#tearDown()
47       */
48      protected void tearDown() throws Exception {
49          super.tearDown();
50          factory = null;
51      }
52  
53      public void testReceiveImplFactory() {
54  
55          Digester digester = new Digester();
56          BPELProcess process = new BPELProcessImpl();
57          digester.push(process);
58  
59          ReceiveImplFactory factory = new ReceiveImplFactory();
60          factory.setDigester(digester);
61  
62          String name = "receiveInput";
63          String pLinkName = "client";
64          String portType = "tns:FlowSample";
65          String operation = "initiate";
66          String variable = "input";
67          String createInstance = "YES";
68  
69          AttributesImpl rcvAttributes = new AttributesImpl();
70          rcvAttributes.addAttribute("", "", NAME, "", name);
71          rcvAttributes.addAttribute("", "", PARTNER_LINK, "", pLinkName);
72          rcvAttributes.addAttribute("", "", PORT_TYPE, "", portType);
73          rcvAttributes.addAttribute("", "", OPERATION, "", operation);
74          rcvAttributes.addAttribute("", "", VARIABLE, "", variable);
75          rcvAttributes.addAttribute("", "", CREATE_INSTANCE, "", createInstance);
76  
77          try {
78              Receive receive = (Receive) factory.createObject(rcvAttributes);
79              assertEquals(name, receive.getName());
80          } catch (Exception e) {
81              e.printStackTrace();
82          }
83      }
84  
85      public void testInvokeImplFactory() {
86  
87          Digester digester = new Digester();
88          BPELProcess process = new BPELProcessImpl();
89          digester.push(process);
90  
91          InvokeImplFactory factory = new InvokeImplFactory();
92          factory.setDigester(digester);
93  
94          String name = "receiveInput";
95          String pLinkName = "client";
96          String portType = "tns:FlowSample";
97          String operation = "initiate";
98          String variable = "input";
99          String createInstance = "YES";
100 
101         AttributesImpl invAttributes = new AttributesImpl();
102         invAttributes.addAttribute("", "", NAME, "", name);
103         invAttributes.addAttribute("", "", PARTNER_LINK, "", pLinkName);
104         invAttributes.addAttribute("", "", PORT_TYPE, "", portType);
105         invAttributes.addAttribute("", "", OPERATION, "", operation);
106         invAttributes.addAttribute("", "", VARIABLE, "", variable);
107         invAttributes.addAttribute("", "", CREATE_INSTANCE, "", createInstance);
108 
109         try {
110             Invoke receive = (Invoke) factory.createObject(invAttributes);
111             assertEquals(name, receive.getName());
112         } catch (Exception e) {
113             e.printStackTrace();
114             fail("Should not throw exception");
115         }
116     }
117 
118     public void testSwitch() {
119 
120         try {
121             InputStream inputStream = getLoader().getResourceAsStream(
122                     "switch.xml");
123             BPELProcess bpelProcess = factory.createBPELProcess(inputStream);
124             Process process = bpelProcess.getProcess();
125 
126             Sequence rootActivity = (Sequence)process.getActivity();
127             List activities = rootActivity.getActivities();
128             assertEquals(SwitchImpl.class, activities.get(1).getClass());
129 
130         } catch (Exception e) {
131             e.printStackTrace();
132             fail("Should create a \"switch\" process without throwing Exception");
133         }
134 
135     }
136 
137 }