1 package org.jbpm.context.log; 2 3 import java.util.Arrays ; 4 import java.util.Date ; 5 6 import junit.framework.TestCase; 7 8 import org.jbpm.bytes.ByteArray; 9 import org.jbpm.context.def.ContextDefinition; 10 import org.jbpm.context.exe.ContextInstance; 11 import org.jbpm.context.log.variableinstance.LongUpdateLog; 12 import org.jbpm.graph.def.ProcessDefinition; 13 import org.jbpm.graph.exe.ProcessInstance; 14 import org.jbpm.logging.exe.LoggingInstance; 15 16 public class VariableLogTest extends TestCase { 17 18 private ProcessDefinition processDefinition = null; 19 private ProcessInstance processInstance = null; 20 private ContextInstance contextInstance = null; 21 private LoggingInstance loggingInstance = null; 22 23 public void setUp() { 24 processDefinition = new ProcessDefinition(); 25 processDefinition.addDefinition(new ContextDefinition()); 26 processInstance = new ProcessInstance( processDefinition ); 27 contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class); 28 loggingInstance = (LoggingInstance) processInstance.getInstance(LoggingInstance.class); 29 } 30 31 public void testVariableCreateLogs() { 32 contextInstance.setVariable("a", new Integer (3)); 33 34 VariableCreateLog createLog = (VariableCreateLog)loggingInstance.getLogs(VariableCreateLog.class).get(0); 35 assertEquals("a", createLog.getVariableInstance().getName()); 36 37 LongUpdateLog updateLog = (LongUpdateLog)loggingInstance.getLogs(LongUpdateLog.class).get(0); 38 39 assertNull(updateLog.getOldValue()); 40 assertEquals(new Long (3), updateLog.getNewValue()); 41 } 42 43 public void testByteArrayUpdateLog() { 44 contextInstance.setVariable("a", "first value".getBytes()); 45 contextInstance.setVariable("a", "second value".getBytes()); 46 47 VariableUpdateLog variableLog = (VariableUpdateLog)loggingInstance.getLogs(VariableUpdateLog.class).get(1); 48 49 assertTrue(Arrays.equals("first value".getBytes(), ((ByteArray) variableLog.getOldValue()).getBytes())); 50 assertTrue(Arrays.equals("second value".getBytes(), ((ByteArray) variableLog.getNewValue()).getBytes())); 51 } 52 53 public void testDateUpdateLog() { 54 Date now = new Date (); 55 Date future = new Date (now.getTime()+5); 56 contextInstance.setVariable("a", now); 57 contextInstance.setVariable("a", future); 58 59 VariableUpdateLog variableLog = (VariableUpdateLog)loggingInstance.getLogs(VariableUpdateLog.class).get(1); 60 61 assertEquals(now, variableLog.getOldValue()); 62 assertEquals(future, variableLog.getNewValue()); 63 } 64 65 public void testDoubleUpdateLog() { 66 contextInstance.setVariable("a", new Double (3.3)); 67 contextInstance.setVariable("a", new Double (4.4)); 68 69 VariableUpdateLog variableLog = (VariableUpdateLog)loggingInstance.getLogs(VariableUpdateLog.class).get(1); 70 71 assertEquals(new Double (3.3), variableLog.getOldValue()); 72 assertEquals(new Double (4.4), variableLog.getNewValue()); 73 } 74 75 public void testLongUpdateLog() { 76 contextInstance.setVariable("a", new Integer (3)); 77 contextInstance.setVariable("a", new Integer (5)); 78 79 VariableUpdateLog variableLog = (VariableUpdateLog)loggingInstance.getLogs(VariableUpdateLog.class).get(1); 80 81 assertEquals(new Long (3), variableLog.getOldValue()); 82 assertEquals(new Long (5), variableLog.getNewValue()); 83 } 84 85 public void testStringUpdateLog() { 86 contextInstance.setVariable("a", "pope"); 87 contextInstance.setVariable("a", "me"); 88 89 VariableUpdateLog variableLog = (VariableUpdateLog)loggingInstance.getLogs(VariableUpdateLog.class).get(1); 90 91 assertEquals("pope", variableLog.getOldValue()); 92 assertEquals("me", variableLog.getNewValue()); 93 } 94 95 public void testVariableDeleteLog() { 96 contextInstance.setVariable("a", new Integer (3)); 97 contextInstance.deleteVariable("a"); 98 99 VariableDeleteLog deleteLog = (VariableDeleteLog)loggingInstance.getLogs(VariableDeleteLog.class).get(0); 100 101 assertEquals("a", deleteLog.getVariableInstance().getName()); 102 } 103 } 104 | Popular Tags |