Search in sources :

Example 16 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.

@Test
@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");
    ClockUtil.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
    assertEquals(9, details.size());
    // Since we order by varName, first entry should be aVariable update from startTask
    HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
    assertEquals("aVariable", startVarUpdate.getVariableName());
    assertEquals("initial value", startVarUpdate.getValue());
    assertEquals(0, startVarUpdate.getRevision());
    assertEquals(processInstance.getId(), startVarUpdate.getProcessInstanceId());
    // Date should the the one set when starting
    assertEquals(startedDate, startVarUpdate.getTime());
    HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
    assertEquals("aVariable", updatedStringVariable.getVariableName());
    assertEquals("updated value", updatedStringVariable.getValue());
    assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId());
    // Date should be the updated date
    assertEquals(updatedDate, updatedStringVariable.getTime());
    HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
    assertEquals("bVariable", intVariable.getVariableName());
    assertEquals(123, intVariable.getValue());
    assertEquals(processInstance.getId(), intVariable.getProcessInstanceId());
    assertEquals(updatedDate, intVariable.getTime());
    HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
    assertEquals("cVariable", longVariable.getVariableName());
    assertEquals(12345L, longVariable.getValue());
    assertEquals(processInstance.getId(), longVariable.getProcessInstanceId());
    assertEquals(updatedDate, longVariable.getTime());
    HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
    assertEquals("dVariable", doubleVariable.getVariableName());
    assertEquals(1234.567, doubleVariable.getValue());
    assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId());
    assertEquals(updatedDate, doubleVariable.getTime());
    HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
    assertEquals("eVariable", shortVariable.getVariableName());
    assertEquals((short) 12, shortVariable.getValue());
    assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId());
    assertEquals(updatedDate, shortVariable.getTime());
    HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
    assertEquals("fVariable", dateVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue());
    assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId());
    assertEquals(updatedDate, dateVariable.getTime());
    HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
    assertEquals("gVariable", serializableVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), serializableVariable.getValue());
    assertEquals(processInstance.getId(), serializableVariable.getProcessInstanceId());
    assertEquals(updatedDate, serializableVariable.getTime());
    HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
    assertEquals("hVariable", byteArrayVariable.getVariableName());
    assertEquals(";-)", new String((byte[]) byteArrayVariable.getValue()));
    assertEquals(processInstance.getId(), byteArrayVariable.getProcessInstanceId());
    assertEquals(updatedDate, byteArrayVariable.getTime());
    // end process instance
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    taskService.complete(tasks.get(0).getId());
    testHelper.assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertEquals(8, historicProcessVariableQuery.count());
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertEquals("aVariable", historicVariable.getVariableName());
    assertEquals("updated value", historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(1);
    assertEquals("bVariable", historicVariable.getVariableName());
    assertEquals(123, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(2);
    assertEquals("cVariable", historicVariable.getVariableName());
    assertEquals(12345L, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(3);
    assertEquals("dVariable", historicVariable.getVariableName());
    assertEquals(1234.567, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(4);
    assertEquals("eVariable", historicVariable.getVariableName());
    assertEquals((short) 12, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(5);
    assertEquals("fVariable", historicVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(6);
    assertEquals("gVariable", historicVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(7);
    assertEquals("hVariable", historicVariable.getVariableName());
    assertEquals(";-)", ";-)", new String((byte[]) historicVariable.getValue()));
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) Date(java.util.Date) SerializableVariable(org.camunda.bpm.engine.test.history.SerializableVariable) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 17 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testBinaryDataForNonBinaryVariable.

@Test
public void testBinaryDataForNonBinaryVariable() {
    HistoricVariableUpdate detailMock = MockProvider.createMockHistoricVariableUpdate();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body(containsString("Value of variable with id aHistoricVariableUpdateId is not a binary value")).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
    verify(historicDetailQueryMock, never()).disableBinaryFetching();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 18 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testGetSingleVariableUpdateDeserialized.

@Test
public void testGetSingleVariableUpdateDeserialized() {
    ObjectValue serializedValue = MockObjectValue.fromObjectValue(Variables.objectValue("a value").serializationDataFormat("aDataFormat").create()).objectTypeName("aTypeName");
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate().typedValue(serializedValue);
    HistoricVariableUpdate variableInstanceMock = builder.build();
    when(historicDetailQueryMock.detailId(variableInstanceMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(variableInstanceMock);
    given().pathParam("id", builder.getId()).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("variableName", equalTo(builder.getName())).body("variableInstanceId", equalTo(builder.getVariableInstanceId())).body("variableType", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo("a value")).body("valueInfo.serializationDataFormat", equalTo("aDataFormat")).body("valueInfo.objectTypeName", equalTo("aTypeName")).body("processDefinitionKey", equalTo(builder.getProcessDefinitionKey())).body("processDefinitionId", equalTo(builder.getProcessDefinitionId())).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("errorMessage", equalTo(builder.getErrorMessage())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("revision", equalTo(builder.getRevision())).body("time", equalTo(builder.getTime())).body("taskId", equalTo(builder.getTaskId())).body("executionId", equalTo(builder.getExecutionId())).body("caseDefinitionKey", equalTo(builder.getCaseDefinitionKey())).body("caseDefinitionId", equalTo(builder.getCaseDefinitionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("tenantId", equalTo(builder.getTenantId())).when().get(HISTORIC_DETAIL_URL);
    verify(historicDetailQueryMock, times(1)).disableBinaryFetching();
    verify(historicDetailQueryMock, never()).disableCustomObjectDeserialization();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 19 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testGetSingleDetail.

@Test
public void testGetSingleDetail() {
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("variableName", equalTo(builder.getName())).body("variableInstanceId", equalTo(builder.getVariableInstanceId())).body("variableType", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo(builder.getValue())).body("processDefinitionKey", equalTo(builder.getProcessDefinitionKey())).body("processDefinitionId", equalTo(builder.getProcessDefinitionId())).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("errorMessage", equalTo(builder.getErrorMessage())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("revision", equalTo(builder.getRevision())).body("time", equalTo(builder.getTime())).body("taskId", equalTo(builder.getTaskId())).body("executionId", equalTo(builder.getExecutionId())).body("caseDefinitionKey", equalTo(builder.getCaseDefinitionKey())).body("caseDefinitionId", equalTo(builder.getCaseDefinitionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("tenantId", equalTo(builder.getTenantId())).when().get(HISTORIC_DETAIL_URL);
    verify(historicDetailQueryMock, times(1)).disableBinaryFetching();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 20 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class MockHistoricVariableUpdateBuilder method build.

public HistoricVariableUpdate build() {
    HistoricVariableUpdate mockVariable = mock(HistoricVariableUpdate.class);
    when(mockVariable.getId()).thenReturn(id);
    when(mockVariable.getVariableName()).thenReturn(name);
    when(mockVariable.getVariableInstanceId()).thenReturn(variableInstanceId);
    when(mockVariable.getVariableTypeName()).thenReturn(typedValue.getType().getName());
    if (ObjectValue.class.isAssignableFrom(typedValue.getClass())) {
        ObjectValue objectValue = (ObjectValue) typedValue;
        if (objectValue.isDeserialized()) {
            when(mockVariable.getValue()).thenReturn(typedValue.getValue());
        } else {
            when(mockVariable.getValue()).thenReturn(null);
        }
    } else {
        when(mockVariable.getValue()).thenReturn(typedValue.getValue());
    }
    when(mockVariable.getTypedValue()).thenReturn(typedValue);
    when(mockVariable.getProcessDefinitionKey()).thenReturn(processDefinitionKey);
    when(mockVariable.getProcessDefinitionId()).thenReturn(processDefinitionId);
    when(mockVariable.getProcessInstanceId()).thenReturn(processInstanceId);
    when(mockVariable.getErrorMessage()).thenReturn(errorMessage);
    when(mockVariable.getRevision()).thenReturn(revision);
    when(mockVariable.getTime()).thenReturn(DateTimeUtil.parseDate(time));
    when(mockVariable.getActivityInstanceId()).thenReturn(activityInstanceId);
    when(mockVariable.getTaskId()).thenReturn(taskId);
    when(mockVariable.getExecutionId()).thenReturn(executionId);
    when(mockVariable.getTypeName()).thenReturn(typedValue.getType().getName());
    when(mockVariable.getCaseDefinitionKey()).thenReturn(caseDefinitionKey);
    when(mockVariable.getCaseDefinitionId()).thenReturn(caseDefinitionId);
    when(mockVariable.getCaseInstanceId()).thenReturn(caseInstanceId);
    when(mockVariable.getCaseExecutionId()).thenReturn(caseExecutionId);
    when(mockVariable.getTenantId()).thenReturn(tenantId);
    when(mockVariable.getUserOperationId()).thenReturn(userOperationId);
    return mockVariable;
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue)

Aggregations

HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)29 Test (org.junit.Test)19 Deployment (org.camunda.bpm.engine.test.Deployment)13 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)8 MockHistoricVariableUpdateBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder)7 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)6 HashMap (java.util.HashMap)5 Task (org.camunda.bpm.engine.task.Task)5 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)5 FileValue (org.camunda.bpm.engine.variable.value.FileValue)4 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Response (com.jayway.restassured.response.Response)2 HistoryService (org.camunda.bpm.engine.HistoryService)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)2