Search in sources :

Example 6 with HistoricVariableUpdate

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

the class HistoricDetailRestServiceInteractionTest method testBinaryDataForFileVariable.

@Test
public void testBinaryDataForFileVariable() {
    String filename = "test.txt";
    byte[] byteContent = "test".getBytes();
    String encoding = "UTF-8";
    FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(variableValue).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).and().header("Content-Disposition", "attachment; filename=" + filename).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
    // due to some problems with wildfly we gotta check this separately
    String contentType = response.getContentType();
    assertThat(contentType, is(either(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + "; charset=UTF-8")).or(CoreMatchers.<Object>equalTo(ContentType.TEXT.toString() + ";charset=UTF-8"))));
    verify(historicDetailQueryMock, never()).disableBinaryFetching();
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Response(com.jayway.restassured.response.Response) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 7 with HistoricVariableUpdate

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

the class HistoricDetailRestServiceInteractionTest method testBinaryDataForBinaryVariable.

@Test
public void testBinaryDataForBinaryVariable() {
    final byte[] byteContent = "some bytes".getBytes();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(Variables.byteArrayValue(byteContent)).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).contentType(ContentType.BINARY.toString()).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
    byte[] responseBytes = response.getBody().asByteArray();
    Assert.assertEquals(new String(byteContent), new String(responseBytes));
    verify(historicDetailQueryMock, never()).disableBinaryFetching();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Response(com.jayway.restassured.response.Response) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 8 with HistoricVariableUpdate

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

the class HistoricVariableJsonSerializationTest method testSelectHistoricSerializedValuesUpdate.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricSerializedValuesUpdate() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, false);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));
    if (ProcessEngineConfiguration.HISTORY_FULL.equals(processEngineConfiguration.getHistory())) {
        HistoricVariableUpdate historicUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().singleResult();
        assertNotNull(historicUpdate.getValue());
        assertNull(historicUpdate.getErrorMessage());
        assertEquals(ValueType.OBJECT.getName(), historicUpdate.getTypeName());
        assertEquals(ValueType.OBJECT.getName(), historicUpdate.getVariableTypeName());
        JsonSerializable historyValue = (JsonSerializable) historicUpdate.getValue();
        assertEquals(bean.getStringProperty(), historyValue.getStringProperty());
        assertEquals(bean.getIntProperty(), historyValue.getIntProperty());
        assertEquals(bean.getBooleanProperty(), historyValue.getBooleanProperty());
        ObjectValue typedValue = (ObjectValue) historicUpdate.getTypedValue();
        assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
        JSONAssert.assertEquals(bean.toExpectedJsonString(), new String(typedValue.getValueSerialized()), true);
        assertEquals(JsonSerializable.class.getName(), typedValue.getObjectTypeName());
    }
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with HistoricVariableUpdate

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

the class ProcessInstantiationAtActivitiesHistoryTest method testHistoricProcessInstanceAsyncStartEvent.

@Deployment(resources = ASYNC_PROCESS)
public void testHistoricProcessInstanceAsyncStartEvent() {
    // when
    ProcessInstance instance = runtimeService.createProcessInstanceByKey("exclusiveGateway").startBeforeActivity("task2").setVariable("aVar", "aValue").execute();
    // then
    HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
    assertNotNull(historicInstance);
    assertEquals(instance.getId(), historicInstance.getId());
    assertNotNull(historicInstance.getStartTime());
    assertNull(historicInstance.getEndTime());
    // should be the first activity started
    assertEquals("task2", historicInstance.getStartActivityId());
    // task2 wasn't entered yet
    assertEquals(0, historyService.createHistoricActivityInstanceQuery().count());
    // history events for variables exist already
    ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId());
    HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableName("aVar").singleResult();
    assertNotNull(historicVariable);
    assertEquals(instance.getId(), historicVariable.getProcessInstanceId());
    assertEquals(activityInstance.getId(), historicVariable.getActivityInstanceId());
    assertEquals("aVar", historicVariable.getName());
    assertEquals("aValue", historicVariable.getValue());
    HistoricDetail historicDetail = historyService.createHistoricDetailQuery().variableInstanceId(historicVariable.getId()).singleResult();
    assertEquals(instance.getId(), historicDetail.getProcessInstanceId());
    assertNotNull(historicDetail);
    // TODO: fix if this is not ok due to CAM-3886
    assertNull(historicDetail.getActivityInstanceId());
    assertTrue(historicDetail instanceof HistoricVariableUpdate);
    assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName());
    assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with HistoricVariableUpdate

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

the class VariableListenerTest method FAILING_testListenerDoesNotInterfereWithHistory.

/**
 * TODO: add when history for case execution variables is implemented
 */
@Deployment
public void FAILING_testListenerDoesNotInterfereWithHistory() {
    CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
    // when i set a variable that causes the listener to be notified
    // and that listener sets the same variable to another value (here "value2")
    caseService.withCaseExecution(caseInstance.getId()).setVariableLocal("variable", "value1").execute();
    // then there should be two historic variable updates for both values
    if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_FULL.getId()) {
        List<HistoricDetail> variableUpdates = historyService.createHistoricDetailQuery().variableUpdates().list();
        assertEquals(2, variableUpdates.size());
        for (HistoricDetail detail : variableUpdates) {
            HistoricVariableUpdate update = (HistoricVariableUpdate) detail;
            boolean update1Processed = false;
            boolean update2Processed = false;
            if (!update1Processed && update.getValue().equals("value1")) {
                update1Processed = true;
            } else if (!update2Processed && update.getValue().equals("value2")) {
                update2Processed = true;
            } else {
                fail("unexpected variable update");
            }
        }
    }
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Deployment(org.camunda.bpm.engine.test.Deployment)

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