| 1 package org.jbpm.bpel.data.exe; 2 3 import java.util.Calendar ; 4 import java.util.TimeZone ; 5 6 import javax.xml.namespace.QName ; 7 8 import junit.framework.TestCase; 9 10 import org.w3c.dom.Element ; 11 12 import org.jbpm.context.def.ContextDefinition; 13 import org.jbpm.graph.def.ProcessDefinition; 14 import org.jbpm.graph.exe.ProcessInstance; 15 import org.jbpm.graph.exe.Token; 16 17 import org.jbpm.bpel.data.def.ElementTypeInfo; 18 import org.jbpm.bpel.data.def.SchemaTypeInfo; 19 import org.jbpm.bpel.data.def.Snippet; 20 import org.jbpm.bpel.data.def.VariableDefinition; 21 import org.jbpm.bpel.xml.BpelConstants; 22 import org.jbpm.bpel.xml.BpelException; 23 import org.jbpm.bpel.xml.util.DatatypeUtil; 24 import org.jbpm.bpel.xml.util.NodeUtil; 25 26 30 public class DeadlineExpressionTest extends TestCase { 31 32 private Token token; 33 34 private static final String ELEM_TEXT = 35 "<a>" + 36 " <b date=\"1981-03-19+06:00\"/>" + 37 " <c>2002-10-10T14:35:10.567Z</c>" + 38 "</a>"; 39 40 public DeadlineExpressionTest(String name) { 41 super(name); 42 } 43 44 protected void setUp() throws Exception { 45 ProcessDefinition pd = new ProcessDefinition(); 47 pd.addDefinition(new ContextDefinition()); 48 ProcessInstance pi = new ProcessInstance(pd); 49 token = pi.getRootToken(); 50 Element elem1 = NodeUtil.parseElement(ELEM_TEXT); 52 VariableDefinition var1 = new VariableDefinition(); 53 var1.setName("var1"); 54 var1.setTypeInfo(new ElementTypeInfo(new QName (elem1.getNamespaceURI(), elem1.getLocalName()))); 55 var1.createInstance(token).setValue(elem1); 56 } 57 58 public void testSimpleExtraction() { 59 VariableDefinition simple = new VariableDefinition(); 61 simple.setName("simple"); 62 simple.setTypeInfo(new SchemaTypeInfo(new QName (BpelConstants.NS_XML_SCHEMA, "dateTime"))); 63 simple.createInstance(token).setValue(DatatypeUtil.parseDateTime("1999-12-31T23:59:45")); 64 Calendar calendar = Calendar.getInstance(); 66 calendar.setLenient(false); 67 calendar.clear(); 68 calendar.set(1999, Calendar.DECEMBER, 31, 23, 59, 45); 69 assertEquals(calendar, eval("$simple")); 71 } 72 73 public void testAttributeExtraction() { 74 Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+6")); 75 calendar.setLenient(false); 76 calendar.clear(); 77 calendar.set(1981, Calendar.MARCH, 19); 78 assertEquals(calendar, eval("$var1/b/@date")); 79 } 80 81 public void testContentExtraction() { 82 Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+0")); 83 calendar.setLenient(false); 84 calendar.set(2002, Calendar.OCTOBER, 10, 14, 35, 10); 85 calendar.set(Calendar.MILLISECOND, 567); 86 assertEquals(calendar, eval("$var1/c")); 87 } 88 89 private Calendar eval(String exprText) { 90 Calendar value = null; 91 try { 92 Snippet expr = new Snippet(); 93 expr.setText(exprText); 94 expr.setUse(Snippet.Use.EXPRESSION); 95 expr.parseScript(); 96 value = DatatypeUtil.toDateTime(expr.getScript().evaluate(token)); 97 } 98 catch (BpelException e) { 99 fail(e.getMessage()); 100 } 101 return value; 102 } 103 } 104 | Popular Tags |