KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > AssignDbTest


1 package org.jbpm.bpel.def;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List 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.db.AbstractDbTestCase;
13 import org.jbpm.bpel.def.Assign.Copy;
14 import org.jbpm.bpel.def.assign.*;
15 import org.jbpm.bpel.xml.util.NodeUtil;
16
17 public class AssignDbTest extends AbstractDbTestCase {
18
19   BpelDefinition processDefinition;
20   
21   public void testFromExpression() {
22     FromExpression from = new FromExpression();
23     Snippet expression = new Snippet();
24     expression.setUse(Snippet.Use.EXPRESSION);
25     from.setExpression(expression);
26     createCopy().setFrom(from);
27     
28     from = (FromExpression) getCopy().getFrom();
29     assertNotNull(from.getExpression());
30   }
31   
32   public void testFromLiteral() throws Exception JavaDoc {
33     FromLiteral from = new FromLiteral();
34     Element JavaDoc literal = NodeUtil.parseElement("<catalog><cd artist='kinky'/><cd artist='cafe tacuba'/></catalog>");
35     from.setLiteral(literal);
36     createCopy().setFrom(from);
37
38     processDefinition = saveAndReload(processDefinition);
39
40     from = (FromLiteral) getCopy().getFrom();
41     assertEquals(literal, from.getLiteral());
42   }
43   
44   public void testFromPartnerLink() throws Exception JavaDoc {
45     FromPartnerLink from = new FromPartnerLink();
46     from.setEndpointReference("http://www.yourservices.com");
47     from.setPartnerLink("flightScheduleService");
48     createCopy().setFrom(from);
49     
50     from = (FromPartnerLink) getCopy().getFrom();
51     assertEquals("http://www.yourservices.com", from.getEndpointReference());
52     assertEquals("flightScheduleService", from.getPartnerLink());
53   }
54   
55   public void testFromProperty() throws Exception JavaDoc {
56     FromProperty from = new FromProperty();
57     
58     VariableDefinition variable = new VariableDefinition();
59     variable.setName("RFQ");
60     from.setVariable(variable);
61     QName JavaDoc provider = new QName JavaDoc("providerId");
62     from.setProperty(provider);
63     createCopy().setFrom(from);
64     
65     Object JavaDoc fromObject = getCopy().getFrom();
66     assertEquals(FromProperty.class, fromObject.getClass());
67     from = (FromProperty) fromObject;
68     assertEquals(variable.getName(), from.getVariable().getName());
69     assertEquals(provider, from.getProperty());
70   }
71   
72   public void testToQuery() {
73     ToQuery to = new ToQuery();
74     Snippet query = new Snippet();
75     query.setUse(Snippet.Use.QUERY);
76     to.setQuery(query);
77     createCopy().setTo(to);
78     
79     to = (ToQuery) getCopy().getTo();
80     assertNotNull(to.getQuery());
81   }
82   
83   public void testToPartnerLink() throws Exception JavaDoc {
84     ToPartnerLink to = new ToPartnerLink();
85     to.setPartnerLink("flightScheduleService");
86     createCopy().setTo(to);
87     
88     to = (ToPartnerLink) getCopy().getTo();
89     assertEquals("flightScheduleService", to.getPartnerLink());
90   }
91   
92   public void testToProperty() throws Exception JavaDoc {
93     ToProperty to = new ToProperty();
94     
95     VariableDefinition variable = new VariableDefinition();
96     variable.setName("RFQ");
97     to.setVariable(variable);
98     QName JavaDoc provider = new QName JavaDoc("providerId");
99     to.setProperty(provider);
100     createCopy().setTo(to);
101     
102     Object JavaDoc toObject = getCopy().getTo();
103     assertEquals(ToProperty.class, toObject.getClass());
104     to = (ToProperty) toObject;
105     assertEquals(variable.getName(), to.getVariable().getName());
106     assertEquals(provider, to.getProperty());
107   }
108     
109   private Copy getCopy() {
110     processDefinition = saveAndReload(processDefinition);
111     Assign assign = (Assign) processDefinition.getNode("activity");
112     return ((Copy) assign.getCopies().get(0));
113   }
114   
115   private Copy createCopy() {
116     processDefinition = new BpelDefinition("process");
117     Assign assign = new Assign("activity");
118     List JavaDoc copies = new ArrayList JavaDoc();
119     Copy copy = new Copy();
120     copies.add(copy);
121     assign.setCopies(copies);
122     processDefinition.addNode(assign);
123     return copy;
124   }
125 }
126
Popular Tags