org.camunda.bpm.engine.history.HistoricVariableInstance Java Examples

The following examples show how to use org.camunda.bpm.engine.history.HistoricVariableInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadVariablePermissionOnStandaloneHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);
  processEngineConfiguration.setEnforceSpecificVariablePermission(true);

  String taskId = "aTaskId";
  createTask(taskId);
  disableAuthorization();
  taskService.setVariable(taskId, "foo", "bar");
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ_VARIABLE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());

  // clear
  deleteTask(taskId, true);
}
 
Example #2
Source File: HistoricVariableInstanceRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<HistoricVariableInstanceDto> queryHistoricVariableInstances(HistoricVariableInstanceQueryDto queryDto,
    Integer firstResult, Integer maxResults, boolean deserializeObjectValues) {
  queryDto.setObjectMapper(objectMapper);
  HistoricVariableInstanceQuery query = queryDto.toQuery(processEngine);
  query.disableBinaryFetching();

  if (!deserializeObjectValues) {
    query.disableCustomObjectDeserialization();
  }

  List<HistoricVariableInstance> matchingHistoricVariableInstances;
  if (firstResult != null || maxResults != null) {
    matchingHistoricVariableInstances = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingHistoricVariableInstances = query.list();
  }

  List<HistoricVariableInstanceDto> historicVariableInstanceDtoResults = new ArrayList<HistoricVariableInstanceDto>();
  for (HistoricVariableInstance historicVariableInstance : matchingHistoricVariableInstances) {
    HistoricVariableInstanceDto resultHistoricVariableInstance = HistoricVariableInstanceDto.fromHistoricVariableInstance(historicVariableInstance);
    historicVariableInstanceDtoResults.add(resultHistoricVariableInstance);
  }
  return historicVariableInstanceDtoResults;
}
 
Example #3
Source File: HistoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = {"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
public void testDeleteHistoricVariableAndDetailsFromCaseAndSetAgain() {
  // given
  String caseInstanceId = caseService.createCaseInstanceByKey("oneTaskCase").getId();
  caseService.setVariable(caseInstanceId, "myVariable", 1);
  caseService.setVariable(caseInstanceId, "myVariable", 2);
  caseService.setVariable(caseInstanceId, "myVariable", 3);

  HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery().singleResult();
  HistoricDetailQuery detailsQuery = historyService.createHistoricDetailQuery()
      .caseInstanceId(caseInstanceId)
      .variableInstanceId(variableInstance.getId());
  historyService.deleteHistoricVariableInstance(variableInstance.getId());
  assertEquals(0, historyService.createHistoricVariableInstanceQuery().count());
  assertEquals(0, detailsQuery.count());

  // when
  caseService.setVariable(caseInstanceId, "myVariable", 4);

  // then
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().count());
  assertEquals(1, detailsQuery.count());
}
 
Example #4
Source File: HistoryServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"})
public void testNativeHistoricVariableInstanceTest() {
  Date date = Calendar.getInstance().getTime();
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("stringVar", "abcdef");
  vars.put("dateVar", date);
  runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, vars);

  assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricVariableInstance.class)).count());
  assertEquals(1, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).listPage(0, 1).size());

  List<HistoricVariableInstance> variables = historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).list();
  assertEquals(2, variables.size());
  for (HistoricVariableInstance variable : variables) {
    assertTrue(vars.containsKey(variable.getName()));
    assertEquals(vars.get(variable.getName()), variable.getValue());
    vars.remove(variable.getName());
  }
}
 
Example #5
Source File: RemovalTimeStrategyStartTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldResolveVariableInstance() {
  // given
  testRule.deploy(CALLING_PROCESS);

  testRule.deploy(CALLED_PROCESS);

  ClockUtil.setCurrentTime(START_DATE);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CALLING_PROCESS_KEY,
    Variables.createVariables()
      .putValue("aVariableName", Variables.stringValue("aVariableValue")));

  // when
  runtimeService.setVariable(processInstance.getId(), "aVariableName", Variables.stringValue("anotherVariableValue"));

  HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().singleResult();

  Date removalTime = addDays(START_DATE, 5);

  // then
  assertThat(historicVariableInstance.getRemovalTime(), is(removalTime));
}
 
Example #6
Source File: HistoricVariableInstanceQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public List<HistoricVariableInstance> executeList(CommandContext commandContext, Page page) {
  checkQueryOk();
  ensureVariablesInitialized();
  List<HistoricVariableInstance> historicVariableInstances = commandContext
          .getHistoricVariableInstanceManager()
          .findHistoricVariableInstancesByQueryCriteria(this, page);

  if (historicVariableInstances!=null) {
    for (HistoricVariableInstance historicVariableInstance: historicVariableInstances) {

      HistoricVariableInstanceEntity variableInstanceEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
      if (shouldFetchValue(variableInstanceEntity)) {
        try {
          variableInstanceEntity.getTypedValue(isCustomObjectDeserializationEnabled);

        } catch(Exception t) {
          // do not fail if one of the variables fails to load
          LOG.exceptionWhileGettingValueForVariable(t);
        }
      }

    }
  }
  return historicVariableInstances;
}
 
Example #7
Source File: HistoricVariableInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBinaryDataForNullFileVariable() {
  String filename = "test.txt";
  byte[] byteContent = null;
  FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create();

  HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance()
      .typedValue(variableValue)
      .build();

  when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);

  given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
  .then().expect().statusCode(Status.OK.getStatusCode())
  .and().contentType(ContentType.TEXT)
  .and().body(is(equalTo(new String())))
  .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
}
 
Example #8
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/executionlistener/ExecutionListenerTest.testScriptResourceListener.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/executionlistener/executionListener.groovy"
})
public void testScriptResourceListener() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
  assertTrue(processInstance.isEnded());

  if (processEngineRule.getProcessEngineConfiguration().getHistoryLevel().getId() >= HISTORYLEVEL_AUDIT) {
    HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
    long count = query.count();
    assertEquals(5, count);

    HistoricVariableInstance variableInstance = null;
    String[] variableNames = new String[]{"start-start", "start-end", "start-take", "end-start", "end-end"};
    for (String variableName : variableNames) {
      variableInstance = query.variableName(variableName).singleResult();
      assertNotNull("Unable ot find variable with name '" + variableName + "'", variableInstance);
      assertTrue("Variable '" + variableName + "' should be set to true", (Boolean) variableInstance.getValue());
    }
  }
}
 
Example #9
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadPermissionOnHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

  startProcessInstanceByKey(PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.setVariable(taskId, "foo", "bar");
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #10
Source File: CustomHistoryLevelWithoutUserOperationLogTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryDeleteVariableHistoryOperationOnStandaloneTask() {
  // given
  Task task = taskService.newTask();
  taskService.saveTask(task);
  taskService.setVariable(task.getId(), "testVariable", "testValue");
  taskService.setVariable(task.getId(), "testVariable", "testValue2");
  HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery().singleResult();

  // when
  historyService.deleteHistoricVariableInstance(variableInstance.getId());

  // then
  verifyVariableOperationAsserts(UserOperationLogEntry.OPERATION_TYPE_DELETE_HISTORY);

  taskService.deleteTask(task.getId(), true);
}
 
Example #11
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadPermissionOnCompletedHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

  startProcessInstanceByKey(PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.setVariable(taskId, "foo", "bar");
  taskService.complete(taskId);
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #12
Source File: HistoricVariableInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBinaryDataForFileVariable() {
  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();
  HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance().typedValue(variableValue).build();

  when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);

  Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
  .then().expect()
    .statusCode(Status.OK.getStatusCode())
  .and()
    .body(is(equalTo(new String(byteContent))))
    .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(variableInstanceQueryMock, never()).disableBinaryFetching();
}
 
Example #13
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadPermissionOnHistoricTaskAndNonePermissionOnProcessDefinition() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

  startProcessInstanceByKey(PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.setVariable(taskId, "foo", "bar");
  taskService.complete(taskId);
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId,
      ProcessDefinitionPermissions.NONE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #14
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadVariablePermissionOnHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);
  processEngineConfiguration.setEnforceSpecificVariablePermission(true);

  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = selectSingleTask().getId();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ_VARIABLE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #15
Source File: FullHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/history/oneTaskProcess.bpmn20.xml"})
public void testHistoricDetailQueryByVariableInstanceId() throws Exception {
  Map<String, Object> params = new HashMap<String, Object>();
  params.put("testVar", "testValue");
  runtimeService.startProcessInstanceByKey("oneTaskProcess", params);

  HistoricVariableInstance testVariable = historyService.createHistoricVariableInstanceQuery()
    .variableName("testVar")
    .singleResult();

  HistoricDetailQuery query = historyService.createHistoricDetailQuery();

  query.variableInstanceId(testVariable.getId());

  assertEquals(1, query.count());
  assertEquals(1, query.list().size());
}
 
Example #16
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckNonePermissionOnStandaloneHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

  String taskId = "aTaskId";
  createTask(taskId);
  disableAuthorization();
  taskService.setVariable(taskId, "foo", "bar");
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.NONE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(0, result.size());

  // clear
  deleteTask(taskId, true);
}
 
Example #17
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadVariablePermissionOnCompletedHistoricTask() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);
  processEngineConfiguration.setEnforceSpecificVariablePermission(true);

  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.complete(taskId);
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ_VARIABLE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #18
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadVariablePermissionOnHistoricTaskAndNonePermissionOnProcessDefinition() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);
  processEngineConfiguration.setEnforceSpecificVariablePermission(true);

  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.complete(taskId);
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.READ_VARIABLE);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId,
      ProcessDefinitionPermissions.NONE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #19
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckNonePermissionOnHistoricTaskAndReadHistoryVariablePermissionOnProcessDefinition() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);
  processEngineConfiguration.setEnforceSpecificVariablePermission(true);

  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = selectSingleTask().getId();
  disableAuthorization();
  taskService.complete(taskId);
  enableAuthorization();

  createGrantAuthorization(HISTORIC_TASK, taskId, userId, HistoricTaskPermissions.NONE);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY_VARIABLE);

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery()
      .list();

  // then
  assertEquals(1, result.size());
}
 
Example #20
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testHistoricTaskPermissionsAuthorizationDisabled() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

  startProcessInstanceByKey(PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  disableAuthorization();

  taskService.setVariable(taskId, "foo", "bar");

  // when
  List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery().list();

  // then
  assertEquals(1, result.size());
}
 
Example #21
Source File: DeserializableVariableTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@OperateOnDeployment("clientDeployment")
public void testVariableDeserializationOnProcessApplicationRestart() {
  // given
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testDeserializeVariable");

  // when
  Assert.assertNull(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult());
  runtimeService.restartProcessInstances(pi.getProcessDefinitionId())
    .startAfterActivity("servicetask1")
    .processInstanceIds(pi.getId())
    .execute();

  // then

  // Since the variable retrieval is done outside the Process Application Context as well,
  // custom object deserialization is disabled and a null check is performed
  List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery().disableCustomObjectDeserialization().list();
  for (HistoricVariableInstance variable : variableInstances) {
    if (variable.getProcessInstanceId() != pi.getId() && variable instanceof HistoricVariableInstanceEntity) {
      Assert.assertNotNull(((HistoricVariableInstanceEntity) variable).getByteArrayValue());
    }
  }
}
 
Example #22
Source File: HistoricVariableInstanceScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSetVariableLocalOnTaskInsideParallelBranch() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);

  taskService.setVariableLocal(task.getId(), "testVar", "testValue");
  ExecutionEntity taskExecution = (ExecutionEntity) runtimeService.createExecutionQuery()
      .executionId(task.getExecutionId())
      .singleResult();
  assertNotNull(taskExecution);

  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
  assertEquals(1, query.count());

  HistoricVariableInstance variable = query.singleResult();
  // the variable is in the user task scope
  assertEquals(taskExecution.getActivityInstanceId(), variable.getActivityInstanceId());

  taskService.complete(task.getId());

  assertProcessEnded(pi.getId());
}
 
Example #23
Source File: ProcessInstanceModificationInTransactionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBeAbleToPerformModification() {

  // given
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("TestProcess")
    .startEvent()
    .intermediateCatchEvent("TimerEvent")
      .timerWithDate("${calculateTimerDate.execute(execution)}")
      .camundaExecutionListenerDelegateExpression("end", "${deleteVariableListener}")
    .endEvent()
    .done();

  deployModelInstance(modelInstance);
  final ProcessInstance procInst = runtimeService.startProcessInstanceByKey("TestProcess");

  // when
  userBean.completeUserTaskAndModifyInstanceInOneTransaction(procInst);

  // then
  VariableInstance variable = rule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(procInst.getId()).variableName("createDate").singleResult();
  assertNotNull(variable);
  HistoricVariableInstance historicVariable = rule.getHistoryService().createHistoricVariableInstanceQuery().singleResult();
  assertEquals(variable.getName(), historicVariable.getName());
  assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
}
 
Example #24
Source File: TransientVariableTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignalWithTransientVariables() {
  // given
  BpmnModelInstance instance = Bpmn.createExecutableProcess("Process")
  .startEvent()
  .intermediateCatchEvent("signalCatch")
    .signal("signal")
  .scriptTask("scriptTask")
    .scriptFormat("javascript")
    .camundaResultVariable("abc")
    .scriptText("execution.setVariable('abc', foo);")
  .endEvent()
  .done();

  testRule.deploy(instance);
  runtimeService.startProcessInstanceByKey("Process");

  // when
  runtimeService.signalEventReceived("signal",
      Variables.createVariables().putValue("foo", Variables.stringValue("bar", true)));

  // then
  List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
  assertEquals(1, variables.size());
  assertEquals("abc", variables.get(0).getName());
}
 
Example #25
Source File: HistoricVariableInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinaryDataForNonBinaryVariable() {
  HistoricVariableInstance variableInstanceMock = MockProvider.createMockHistoricVariableInstance();

  when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);

  given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
  .then().expect()
    .statusCode(Status.BAD_REQUEST.getStatusCode())
    .body(containsString("Value of variable with id "+variableInstanceMock.getId()+" is not a binary value"))
  .when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);

  verify(variableInstanceQueryMock, never()).disableBinaryFetching();

}
 
Example #26
Source File: HistoricVariableInstanceScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSetVariableLocalOnServiceTaskInsideParallelBranch() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  HistoricActivityInstance serviceTask = historyService.createHistoricActivityInstanceQuery()
      .activityId("serviceTask1")
      .singleResult();
  assertNotNull(serviceTask);

  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
  assertEquals(1, query.count());

  HistoricVariableInstance variable = query.singleResult();
  // the variable is in the service task scope
  assertEquals(serviceTask.getId(), variable.getActivityInstanceId());

  assertProcessEnded(pi.getId());
}
 
Example #27
Source File: TransientVariableTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void createVariablesUsingVariableMap() {
  // given
  BpmnModelInstance simpleInstanceWithListener = Bpmn.createExecutableProcess("Process")
      .startEvent()
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadTransientVariableExecutionListener.class)
      .userTask()
      .endEvent()
      .done();
  testRule.deploy(simpleInstanceWithListener);

  // when
  VariableMap variables = Variables.createVariables();
  variables.put(VARIABLE_NAME, Variables.untypedValue(true, true));
  runtimeService.startProcessInstanceByKey("Process",
     variables
      );

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());
  assertEquals(0, historicVariableInstances.size());
}
 
Example #28
Source File: TransientVariableTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void createTransientVariablesUsingFluentBuilder() {
  // given
  BpmnModelInstance simpleInstanceWithListener = Bpmn.createExecutableProcess("Process")
      .startEvent()
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadTransientVariableExecutionListener.class)
      .userTask()
      .endEvent()
      .done();
  testRule.deploy(simpleInstanceWithListener);

  // when
  runtimeService.createProcessInstanceByKey("Process")
    .setVariables(Variables.createVariables().putValue(VARIABLE_NAME, Variables.stringValue("dlsd", true)))
    .execute();

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());
  assertEquals(0, historicVariableInstances.size());
}
 
Example #29
Source File: ProcessInstanceModificationHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/history/oneAsyncTaskProcess.bpmn20.xml"})
public void testHistoricVariablesOnAsyncBefore() {
  // given
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("foo", "bar"));

  executeJob(managementService.createJobQuery().singleResult());

  // when
  runtimeService.createProcessInstanceModification(processInstance.getId())
    .startBeforeActivity("theStart")
    .execute(true, true);

  // then
  HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().singleResult();
  assertNotNull(variable);
  assertEquals(processInstance.getId(), variable.getProcessInstanceId());
}
 
Example #30
Source File: HistoricVariableInstanceScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/history/HistoricVariableInstanceScopeTest.testSetVariableLocalOnTaskInsideParallelBranch.bpmn"})
public void testSetVariableOnTaskInsideParallelBranch() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);

  taskService.setVariable(task.getId(), "testVar", "testValue");

  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
  assertEquals(1, query.count());

  HistoricVariableInstance variable = query.singleResult();
  // the variable is in the process instance scope
  assertEquals(pi.getId(), variable.getActivityInstanceId());

  taskService.complete(task.getId());

  assertProcessEnded(pi.getId());
}