KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > assign > ToPropertyTest


1 package org.jbpm.bpel.def.assign;
2
3 import javax.wsdl.Definition;
4 import javax.xml.namespace.QName JavaDoc;
5
6 import junit.framework.TestCase;
7
8 import org.w3c.dom.Element JavaDoc;
9
10 import org.jbpm.graph.exe.ProcessInstance;
11 import org.jbpm.graph.exe.Token;
12
13 import org.jbpm.bpel.data.def.VariableDefinition;
14 import org.jbpm.bpel.data.exe.MessageVariableInstance;
15 import org.jbpm.bpel.def.BpelDefinition;
16 import org.jbpm.bpel.def.ImportsDefinition;
17 import org.jbpm.bpel.wsdl.util.WsdlUtil;
18 import org.jbpm.bpel.xml.BpelConstants;
19 import org.jbpm.bpel.xml.BpelReader;
20 /**
21  * @author Alejandro Guízar
22  * @version $Revision: 1.10 $ $Date: 2005/06/23 02:17:26 $
23  */

24 public class ToPropertyTest extends TestCase {
25   
26   private Token token;
27   private MessageVariableInstance messageInstance;
28   private ToProperty to = new ToProperty();
29   
30   private static final String JavaDoc WSDL_TEXT =
31     "<definitions targetNamespace='http://jbpm.org/bpel/examples'" +
32     " xmlns:tns='http://jbpm.org/bpel/examples'" +
33     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
34     " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" +
35     " xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
36     " <message name='request'>" +
37     " <part name='simplePart' type='xsd:string'/>" +
38     " <part name='elementPart' element='tns:surpriseElement'/>" +
39     " </message>" +
40     " <bpws:property name='nameProperty' type='xsd:string'/>" +
41     " <bpws:property name='idProperty' type='xsd:int'/>" +
42     " <bpws:propertyAlias propertyName='tns:nameProperty' messageType='tns:request'>" +
43     " <bpws:query>elementPart/tns:surpriseElement/c/@name</bpws:query>" +
44     " </bpws:propertyAlias>" +
45     " <bpws:propertyAlias propertyName='tns:idProperty' messageType='tns:request'>" +
46     " <bpws:query>elementPart/tns:surpriseElement/e</bpws:query>" +
47     " </bpws:propertyAlias>" +
48     "</definitions>";
49   private static final QName JavaDoc Q_NAME_PROP = new QName JavaDoc(BpelConstants.NS_EXAMPLES, "nameProperty");
50
51   public ToPropertyTest(String JavaDoc name) {
52     super(name);
53   }
54   
55   protected void setUp() throws Exception JavaDoc {
56     // process and context
57
BpelDefinition pd = new BpelDefinition();
58     token = new ProcessInstance(pd).getRootToken();
59     // read wsdl
60
Definition def = WsdlUtil.readText(WSDL_TEXT);
61     ImportsDefinition imports = pd.getImports();
62     imports.addImport(WsdlUtil.createImport(def));
63     BpelReader.getInstance().registerPropertyAliases(imports);
64     // message variable
65
VariableDefinition messageDefinition = new VariableDefinition();
66     messageDefinition.setName("msg");
67     messageDefinition.setTypeInfo(imports.getMessageTypeInfo(new QName JavaDoc(BpelConstants.NS_EXAMPLES, "request")));
68     messageInstance = (MessageVariableInstance) messageDefinition.createInstance(token);
69   }
70   
71   public void testAssign() throws Exception JavaDoc {
72     Element JavaDoc elementPart = messageInstance.getOrCreatePart("elementPart");
73     Element JavaDoc elemC = (Element JavaDoc) elementPart.appendChild(elementPart.getOwnerDocument().createElementNS(null, "c"));
74     elemC.setAttribute("name", "wazabi");
75     
76     to.setVariable(messageInstance.getDefinition());
77     to.setProperty(Q_NAME_PROP);
78     to.assign(token, "foo");
79     assertEquals("foo", elemC.getAttribute("name"));
80   }
81 }
82
Popular Tags