Search in sources :

Example 1 with SerializableVariable

use of org.activiti.engine.test.history.SerializableVariable in project Activiti by Activiti.

the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.

@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "initial value");
    Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
    // In the javaDelegate, the current time is manipulated
    Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
    processEngineConfiguration.getClock().setCurrentTime(startedDate);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
    // 8 variable updates should be present, one performed when starting process the other 7 are set in VariableSetter serviceTask
    assertThat(details).hasSize(9);
    // Since we order by varName, first entry should be aVariable update from startTask
    HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
    assertThat(startVarUpdate.getVariableName()).isEqualTo("aVariable");
    assertThat(startVarUpdate.getValue()).isEqualTo("initial value");
    assertThat(startVarUpdate.getRevision()).isEqualTo(0);
    assertThat(startVarUpdate.getProcessInstanceId()).isEqualTo(processInstance.getId());
    // Date should the the one set when starting
    assertThat(startVarUpdate.getTime()).isEqualTo(startedDate);
    HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
    assertThat(updatedStringVariable.getVariableName()).isEqualTo("aVariable");
    assertThat(updatedStringVariable.getValue()).isEqualTo("updated value");
    assertThat(updatedStringVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    // Date should be the updated date
    assertThat(updatedStringVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
    assertThat(intVariable.getVariableName()).isEqualTo("bVariable");
    assertThat(intVariable.getValue()).isEqualTo(123);
    assertThat(intVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(intVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
    assertThat(longVariable.getVariableName()).isEqualTo("cVariable");
    assertThat(longVariable.getValue()).isEqualTo(12345L);
    assertThat(longVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(longVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
    assertThat(doubleVariable.getVariableName()).isEqualTo("dVariable");
    assertThat(doubleVariable.getValue()).isEqualTo(1234.567);
    assertThat(doubleVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(doubleVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
    assertThat(shortVariable.getVariableName()).isEqualTo("eVariable");
    assertThat(shortVariable.getValue()).isEqualTo((short) 12);
    assertThat(shortVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(shortVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
    assertThat(dateVariable.getVariableName()).isEqualTo("fVariable");
    assertThat(dateVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
    assertThat(dateVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(dateVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
    assertThat(serializableVariable.getVariableName()).isEqualTo("gVariable");
    assertThat(serializableVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
    assertThat(serializableVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(serializableVariable.getTime()).isEqualTo(updatedDate);
    HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
    assertThat(byteArrayVariable.getVariableName()).isEqualTo("hVariable");
    assertThat(new String((byte[]) byteArrayVariable.getValue())).isEqualTo(";-)");
    assertThat(byteArrayVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(byteArrayVariable.getTime()).isEqualTo(updatedDate);
    // end process instance
    List<Task> tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(1);
    taskService.complete(tasks.get(0).getId());
    assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertThat(historicProcessVariableQuery.count()).isEqualTo(8);
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertThat(historicVariable.getVariableName()).isEqualTo("aVariable");
    assertThat(historicVariable.getValue()).isEqualTo("updated value");
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(1);
    assertThat(historicVariable.getVariableName()).isEqualTo("bVariable");
    assertThat(historicVariable.getValue()).isEqualTo(123);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(2);
    assertThat(historicVariable.getVariableName()).isEqualTo("cVariable");
    assertThat(historicVariable.getValue()).isEqualTo(12345L);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(3);
    assertThat(historicVariable.getVariableName()).isEqualTo("dVariable");
    assertThat(historicVariable.getValue()).isEqualTo(1234.567);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(4);
    assertThat(historicVariable.getVariableName()).isEqualTo("eVariable");
    assertThat(historicVariable.getValue()).isEqualTo((short) 12);
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(5);
    assertThat(historicVariable.getVariableName()).isEqualTo("fVariable");
    assertThat(historicVariable.getValue()).isEqualTo(sdf.parse("01/01/2001 01:23:45 678"));
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(6);
    assertThat(historicVariable.getVariableName()).isEqualTo("gVariable");
    assertThat(historicVariable.getValue()).isEqualTo(new SerializableVariable("hello hello"));
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
    historicVariable = historicVariables.get(7);
    assertThat(historicVariable.getVariableName()).isEqualTo("hVariable");
    assertThat(new String((byte[]) historicVariable.getValue())).isEqualTo(";-)");
    assertThat(historicVariable.getProcessInstanceId()).isEqualTo(processInstance.getId());
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Date(java.util.Date) SerializableVariable(org.activiti.engine.test.history.SerializableVariable) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.activiti.engine.test.Deployment)

Example 2 with SerializableVariable

use of org.activiti.engine.test.history.SerializableVariable in project Activiti by Activiti.

the class VariableSetter method execute.

public void execute(DelegateExecution execution) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
    // We set the time to check of the updated time is picked up in the
    // history
    Date updatedDate = null;
    try {
        updatedDate = sdf.parse("01/01/2001 01:23:46 000");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Context.getProcessEngineConfiguration().getClock().setCurrentTime(updatedDate);
    execution.setVariable("aVariable", "updated value");
    execution.setVariable("bVariable", 123);
    execution.setVariable("cVariable", 12345L);
    execution.setVariable("dVariable", 1234.567);
    execution.setVariable("eVariable", (short) 12);
    Date theDate = null;
    try {
        theDate = sdf.parse("01/01/2001 01:23:45 678");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    execution.setVariable("fVariable", theDate);
    execution.setVariable("gVariable", new SerializableVariable("hello hello"));
    execution.setVariable("hVariable", ";-)".getBytes());
}
Also used : SerializableVariable(org.activiti.engine.test.history.SerializableVariable) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 SerializableVariable (org.activiti.engine.test.history.SerializableVariable)2 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 HistoricDetail (org.activiti.engine.history.HistoricDetail)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)1 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Task (org.activiti.engine.task.Task)1 Deployment (org.activiti.engine.test.Deployment)1