KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > AssignReaderTest


1 package org.jbpm.bpel.xml;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import javax.xml.namespace.QName JavaDoc;
7
8 import org.w3c.dom.Element JavaDoc;
9
10 import org.jbpm.bpel.data.def.Snippet;
11 import org.jbpm.bpel.data.def.VariableDefinition;
12 import org.jbpm.bpel.def.Assign;
13 import org.jbpm.bpel.def.assign.*;
14 import org.jbpm.bpel.service.def.PartnerLinkDefinition;
15
16 /**
17  * @author Juan Cantú
18  * @author Alejandro Guízar
19  * @version $Revision: 1.3 $ $Date: 2005/05/07 00:03:45 $
20  */

21 public class AssignReaderTest extends AbstractReaderTestCase {
22   
23   public void setUp() throws Exception JavaDoc {
24     super.setUp();
25     VariableDefinition variable = new VariableDefinition();
26     variable.setName("v");
27     scope.addVariable(variable);
28   }
29   
30   public void testFromExpression() throws Exception JavaDoc {
31     String JavaDoc xml =
32       "<assign xmlns:a='urn:a'>" +
33       "<copy xmlns:c='urn:c'>" +
34       "<from xmlns:f='urn:f'>$v/p/q</from>" +
35       "<to>$v/p</to>" +
36       "</copy>" +
37       "</assign>";
38     Assign assign = (Assign) readActivity(xml);
39     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
40     Snippet expr = ((FromExpression) copy.getFrom()).getExpression();
41     assertEquals("$v/p/q", expr.getText());
42     Map JavaDoc namespaces = expr.getNamespaces();
43     assertEquals("urn:a", namespaces.get("a"));
44     assertEquals("urn:c", namespaces.get("c"));
45     assertEquals("urn:f", namespaces.get("f"));
46   }
47   
48   public void testFromVariableProperty() throws Exception JavaDoc {
49     String JavaDoc xml =
50       "<assign>" +
51       "<copy>" +
52       "<from variable='v' property='p'/>" +
53       "<to>$v/p</to>" +
54       "</copy>" +
55       "</assign>";
56     Assign assign = (Assign) readActivity(xml);
57     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
58     FromProperty from = (FromProperty)copy.getFrom();
59     assertEquals("v", from.getVariable().getName());
60     assertEquals(new QName JavaDoc("p"), from.getProperty());
61   }
62   
63   public void testFromLiteralElement() throws Exception JavaDoc {
64     String JavaDoc xml =
65       "<assign>" +
66       "<copy>" +
67       "<from literal='yes'><order name='o'/></from>" +
68       "<to>$v/p</to>" +
69       "</copy>" +
70       "</assign>";
71     Assign assign = (Assign) readActivity(xml);
72     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
73     Element JavaDoc literal = (Element JavaDoc) ((FromLiteral) copy.getFrom()).getLiteral();
74     assertEquals("order", literal.getNodeName());
75   }
76   
77   public void testFromLiteralList() throws Exception JavaDoc {
78     String JavaDoc xml =
79       "<assign>" +
80       "<copy>" +
81       "<from literal='yes'><order name='o1'/><order name='o2'/></from>" +
82       "<to>$v/p</to>" +
83       "</copy>" +
84       "</assign>";
85     Assign assign = (Assign) readActivity(xml);
86     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
87     List JavaDoc literal = (List JavaDoc) ((FromLiteral) copy.getFrom()).getLiteral();
88     assertEquals(2, literal.size());
89     Element JavaDoc secondElement = (Element JavaDoc) literal.get(1);
90     assertEquals("o2", secondElement.getAttribute("name"));
91   }
92   
93   public void testFromLiteralText() throws Exception JavaDoc {
94     String JavaDoc xml =
95       "<assign>" +
96       "<copy>" +
97       "<from literal='yes'>2</from>" +
98       "<to>$v/p</to>" +
99       "</copy>" +
100       "</assign>";
101     Assign assign = (Assign) readActivity(xml);
102     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
103     assertEquals("2", ((FromLiteral) copy.getFrom()).getLiteral());
104   }
105   
106   public void testFromPartnerLink() throws Exception JavaDoc {
107     PartnerLinkDefinition pl = new PartnerLinkDefinition();
108     pl.setName("pl");
109     scope.addPartnerLink(pl);
110     String JavaDoc xml =
111       "<assign>" +
112       "<copy>" +
113       "<from partnerLink='pl' endpointReference='myRole'/>" +
114       "<to>$v/p</to>" +
115       "</copy>" +
116       "</assign>";
117     Assign assign = (Assign) readActivity(xml);
118     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
119     FromPartnerLink from = (FromPartnerLink)copy.getFrom();
120     assertEquals("pl", from.getPartnerLink());
121     assertEquals("myRole", from.getEndpointReference());
122   }
123   
124   public void testToQuery() throws Exception JavaDoc {
125     String JavaDoc xml =
126       "<assign>" +
127       "<copy>" +
128       "<from>$v/p</from>" +
129       "<to>$v/p/q</to>" +
130       "</copy>" +
131       "</assign>";
132     Assign assign = (Assign) readActivity(xml);
133     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
134     assertEquals("$v/p/q", ((ToQuery) copy.getTo()).getQuery().getText());
135   }
136   
137   public void testToVariableProperty() throws Exception JavaDoc {
138     String JavaDoc xml =
139       "<assign>" +
140       "<copy>" +
141       "<from>$v/p</from>" +
142       "<to variable='v' property='p'/>" +
143       "</copy>" +
144       "</assign>";
145     Assign assign = (Assign) readActivity(xml);
146     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
147     ToProperty to = (ToProperty)copy.getTo();
148     assertEquals("v", to.getVariable().getName());
149     assertEquals(new QName JavaDoc("p"), to.getProperty());
150   }
151   
152   public void testToPartnerLink() throws Exception JavaDoc {
153     PartnerLinkDefinition pl = new PartnerLinkDefinition();
154     pl.setName("pl");
155     scope.addPartnerLink(pl);
156     String JavaDoc xml =
157       "<assign>" +
158       "<copy>" +
159       "<from>$v/p</from>" +
160       "<to partnerLink='pl'/>" +
161       "</copy>" +
162       "</assign>";
163     Assign assign = (Assign) readActivity(xml);
164     Assign.Copy copy = (Assign.Copy) assign.getCopies().get(0);
165     ToPartnerLink to = (ToPartnerLink)copy.getTo();
166     assertEquals("pl", to.getPartnerLink());
167   }
168 }
Popular Tags