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();
}
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();
}
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());
}
}
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());
}
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");
}
}
}
}
Aggregations