001: /*
002: * $Id: ActivityImplFactoryTest.java,v 1.6 2004/12/06 07:53:34 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.model.xmltobpel;
010:
011: import java.io.InputStream;
012: import java.util.List;
013:
014: import org.apache.commons.digester.Digester;
015: import org.xml.sax.helpers.AttributesImpl;
016:
017: import bexee.BexeeTestCase;
018: import bexee.model.AttributeNames;
019: import bexee.model.BPELProcessFactory;
020: import bexee.model.activity.Invoke;
021: import bexee.model.activity.Receive;
022: import bexee.model.activity.Sequence;
023: import bexee.model.activity.impl.SwitchImpl;
024: import bexee.model.process.BPELProcess;
025: import bexee.model.process.Process;
026: import bexee.model.process.impl.BPELProcessImpl;
027:
028: /**
029: * @version $Revision: 1.6 $, $Date: 2004/12/06 07:53:34 $
030: * @author Pawel Kowalski
031: */
032: public class ActivityImplFactoryTest extends BexeeTestCase implements
033: AttributeNames {
034:
035: private BPELProcessFactory factory;
036:
037: /*
038: * @see TestCase#setUp()
039: */
040: protected void setUp() throws Exception {
041: super .setUp();
042: factory = BPELProcessFactory.getInstance();
043: }
044:
045: /*
046: * @see TestCase#tearDown()
047: */
048: protected void tearDown() throws Exception {
049: super .tearDown();
050: factory = null;
051: }
052:
053: public void testReceiveImplFactory() {
054:
055: Digester digester = new Digester();
056: BPELProcess process = new BPELProcessImpl();
057: digester.push(process);
058:
059: ReceiveImplFactory factory = new ReceiveImplFactory();
060: factory.setDigester(digester);
061:
062: String name = "receiveInput";
063: String pLinkName = "client";
064: String portType = "tns:FlowSample";
065: String operation = "initiate";
066: String variable = "input";
067: String createInstance = "YES";
068:
069: AttributesImpl rcvAttributes = new AttributesImpl();
070: rcvAttributes.addAttribute("", "", NAME, "", name);
071: rcvAttributes.addAttribute("", "", PARTNER_LINK, "", pLinkName);
072: rcvAttributes.addAttribute("", "", PORT_TYPE, "", portType);
073: rcvAttributes.addAttribute("", "", OPERATION, "", operation);
074: rcvAttributes.addAttribute("", "", VARIABLE, "", variable);
075: rcvAttributes.addAttribute("", "", CREATE_INSTANCE, "",
076: createInstance);
077:
078: try {
079: Receive receive = (Receive) factory
080: .createObject(rcvAttributes);
081: assertEquals(name, receive.getName());
082: } catch (Exception e) {
083: e.printStackTrace();
084: }
085: }
086:
087: public void testInvokeImplFactory() {
088:
089: Digester digester = new Digester();
090: BPELProcess process = new BPELProcessImpl();
091: digester.push(process);
092:
093: InvokeImplFactory factory = new InvokeImplFactory();
094: factory.setDigester(digester);
095:
096: String name = "receiveInput";
097: String pLinkName = "client";
098: String portType = "tns:FlowSample";
099: String operation = "initiate";
100: String variable = "input";
101: String createInstance = "YES";
102:
103: AttributesImpl invAttributes = new AttributesImpl();
104: invAttributes.addAttribute("", "", NAME, "", name);
105: invAttributes.addAttribute("", "", PARTNER_LINK, "", pLinkName);
106: invAttributes.addAttribute("", "", PORT_TYPE, "", portType);
107: invAttributes.addAttribute("", "", OPERATION, "", operation);
108: invAttributes.addAttribute("", "", VARIABLE, "", variable);
109: invAttributes.addAttribute("", "", CREATE_INSTANCE, "",
110: createInstance);
111:
112: try {
113: Invoke receive = (Invoke) factory
114: .createObject(invAttributes);
115: assertEquals(name, receive.getName());
116: } catch (Exception e) {
117: e.printStackTrace();
118: fail("Should not throw exception");
119: }
120: }
121:
122: public void testSwitch() {
123:
124: try {
125: InputStream inputStream = getLoader().getResourceAsStream(
126: "switch.xml");
127: BPELProcess bpelProcess = factory
128: .createBPELProcess(inputStream);
129: Process process = bpelProcess.getProcess();
130:
131: Sequence rootActivity = (Sequence) process.getActivity();
132: List activities = rootActivity.getActivities();
133: assertEquals(SwitchImpl.class, activities.get(1).getClass());
134:
135: } catch (Exception e) {
136: e.printStackTrace();
137: fail("Should create a \"switch\" process without throwing Exception");
138: }
139:
140: }
141:
142: }
|