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

The following examples show how to use org.camunda.bpm.engine.history.HistoricVariableInstanceQuery. 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 testCheckNonePermissionOnHistoricProcessInstance() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

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

  createGrantAuthorization(HISTORIC_PROCESS_INSTANCE, processInstanceId, userId,
      HistoricProcessInstancePermissions.NONE);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  assertThat(query.list()).isEmpty();
}
 
Example #2
Source File: CompensateEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationTriggeredByEventSubProcessInSubProcessActivityRef.bpmn20.xml" })
public void testCompensateActivityRefTriggeredByEventSubprocessInSubProcess() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");
  assertProcessEnded(processInstance.getId());

  HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
      .processInstanceId(processInstance.getId()).variableName("undoBookHotel");

  if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
    assertEquals(1, historicVariableInstanceQuery.count());
    assertEquals("undoBookHotel", historicVariableInstanceQuery.list().get(0).getVariableName());
    assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue());

    assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count());
  }
}
 
Example #3
Source File: CompensateEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationTriggeredByEventSubProcessActivityRef.bpmn20.xml" })
public void testCompensateActivityRefTriggeredByEventSubprocess() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");
  assertProcessEnded(processInstance.getId());

  HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery()
      .processInstanceId(processInstance.getId()).variableName("undoBookHotel");

  if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
    assertEquals(1, historicVariableInstanceQuery.count());
    assertEquals("undoBookHotel", historicVariableInstanceQuery.list().get(0).getVariableName());
    assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue());

    assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count());
  }
}
 
Example #4
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());
}
 
Example #5
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 #6
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/oneTaskProcess.bpmn20.xml" })
public void testDeleteAllHistoricVariablesOnEmpty() {
  // given
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS);
  String executionId = processInstance.getId();
  assertEquals(1L, runtimeService.createProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());

  runtimeService.deleteProcessInstance(executionId, null);
  assertEquals(0L, runtimeService.createProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());
  assertEquals(1L, historyService.createHistoricProcessInstanceQuery().processDefinitionKey(ONE_TASK_PROCESS).count());

  HistoricVariableInstanceQuery histVariableQuery = historyService.createHistoricVariableInstanceQuery().processInstanceId(executionId);
  assertEquals(0L, histVariableQuery.count());

  HistoricDetailQuery detailsQuery = historyService.createHistoricDetailQuery().processInstanceId(executionId);
  assertEquals(0L, detailsQuery.count());

  // when
  historyService.deleteHistoricVariableInstancesByProcessInstanceId(executionId);

  // then
  assertEquals(0, histVariableQuery.count());
  assertEquals(0, detailsQuery.count());
}
 
Example #7
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testScriptListener() {
  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 #8
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/api/oneSubProcess.bpmn20.xml"})
public void testSetVariableOnUserTaskInsideSubProcess() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("startSimpleSubProcess");

  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());
}
 
Example #9
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/api/oneTaskProcess.bpmn20.xml"})
public void testSetVariableLocalOnUserTask() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  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();
  assertNotNull(variable);

  // the variable is in the task scope
  assertEquals(taskExecution.getActivityInstanceId(), variable.getActivityInstanceId());

  taskService.complete(task.getId());
  assertProcessEnded(pi.getId());
}
 
Example #10
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 #11
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadOnHistoricProcessInstanceAndNonePermissionOnProcessDefinition() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

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

  createGrantAuthorization(HISTORIC_PROCESS_INSTANCE, processInstanceId, userId,
      HistoricProcessInstancePermissions.READ);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId,
      ProcessDefinitionPermissions.NONE);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  assertThat(query.list())
      .extracting("processInstanceId")
      .containsExactly(processInstanceId);
}
 
Example #12
Source File: MultiTenancyHistoricVariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldQueryByTenantId() {
  // when
  HistoricVariableInstanceQuery queryTenantOne = historyService
      .createHistoricVariableInstanceQuery()
      .tenantIdIn(TENANT_ONE);

  HistoricVariableInstanceQuery queryTenantTwo = historyService
      .createHistoricVariableInstanceQuery()
      .tenantIdIn(TENANT_TWO);

  // then
  assertThat(queryTenantOne.count()).isEqualTo(1L);
  assertThat(queryTenantOne.list().get(0).getValue()).isEqualTo(TENANT_ONE_VAR);
  assertThat(queryTenantTwo.count()).isEqualTo(1L);
  assertThat(queryTenantTwo.list().get(0).getValue()).isEqualTo(TENANT_TWO_VAR);
}
 
Example #13
Source File: MultiTenancyHistoricDataCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteHistoricVariableInstanceWithAuthenticatedTenant() {
  testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS);
  String processInstanceId = startProcessInstance(null);
  runtimeService.setVariable(processInstanceId, "myVariable", "testValue");
  HistoricVariableInstanceQuery variableQuery = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId);
  
  assertThat(variableQuery.count(), is(1L));
  String variableInstanceId = variableQuery.singleResult().getId();

  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  historyService.deleteHistoricVariableInstance(variableInstanceId);
  assertThat(variableQuery.count(), is(0L));
  cleanUpAfterVariableInstanceTest(processInstanceId);
}
 
Example #14
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckNoneOnHistoricProcessInstanceAndReadHistoryPermissionOnProcessDefinition() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

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

  createGrantAuthorization(HISTORIC_PROCESS_INSTANCE, processInstanceId, userId,
      HistoricProcessInstancePermissions.NONE);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  assertThat(query.list())
      .extracting("processInstanceId")
      .containsExactly(processInstanceId);
}
 
Example #15
Source File: CompensateEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationInEventSubProcessActivityRef.bpmn20.xml" })
public void testCompensateActivityRefInEventSubprocess() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");
  assertProcessEnded(processInstance.getId());

  HistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createHistoricVariableInstanceQuery().variableName("undoBookSecondHotel");

  if (processEngineConfiguration.getHistoryLevel().getId() >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
    assertEquals(1, historicVariableInstanceQuery.count());
    assertEquals("undoBookSecondHotel", historicVariableInstanceQuery.list().get(0).getVariableName());
    assertEquals(5, historicVariableInstanceQuery.list().get(0).getValue());

    assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookFlight").count());

    assertEquals(0, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("undoBookHotel").count());
  }
}
 
Example #16
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryAfterDeletingDeployment() {
  // given
  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);

  disableAuthorization();
  List<Task> tasks = taskService.createTaskQuery().list();
  for (Task task : tasks) {
    taskService.complete(task.getId());
  }
  enableAuthorization();

  disableAuthorization();
  repositoryService.deleteDeployment(deploymentId);
  enableAuthorization();

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 3);

  cleanUpAfterDeploymentDeletion();
}
 
Example #17
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testMixedQueryWithReadHistoryVariablePermissionOnAnyProcessDefinition() {
  setReadHistoryVariableAsDefaultReadPermission();

  startMultipleProcessInstances();

  setupMultipleMixedVariables();

  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY_VARIABLE);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 14);

  deleteTask("one", true);
  deleteTask("two", true);
  deleteTask("three", true);
  deleteTask("four", true);
  deleteTask("five", true);
}
 
Example #18
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testMixedQueryWithReadHistoryVariablePermissionOnProcessDefinition() {
  setReadHistoryVariableAsDefaultReadPermission();

  startMultipleProcessInstances();

  setupMultipleMixedVariables();

  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY_VARIABLE);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 10);

  deleteTask("one", true);
  deleteTask("two", true);
  deleteTask("three", true);
  deleteTask("four", true);
  deleteTask("five", true);
}
 
Example #19
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 #20
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testMixedQueryWithReadHistoryPermissionOnProcessDefinition() {
  startMultipleProcessInstances();

  setupMultipleMixedVariables();

  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 10);

  deleteTask("one", true);
  deleteTask("two", true);
  deleteTask("three", true);
  deleteTask("four", true);
  deleteTask("five", true);
}
 
Example #21
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testMixedQueryWithoutAuthorization() {
  startMultipleProcessInstances();

  setupMultipleMixedVariables();

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 7);

  deleteTask("one", true);
  deleteTask("two", true);
  deleteTask("three", true);
  deleteTask("four", true);
  deleteTask("five", true);
}
 
Example #22
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadPermissionOnHistoricProcessInstance_LocalVariable() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

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

  createGrantAuthorization(HISTORIC_PROCESS_INSTANCE, processInstanceId, userId,
      HistoricProcessInstancePermissions.READ);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  assertThat(query.list())
      .extracting("processInstanceId")
      .containsExactly(processInstanceId);
}
 
Example #23
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCheckReadPermissionOnCompletedHistoricProcessInstance() {
  // given
  processEngineConfiguration.setEnableHistoricInstancePermissions(true);

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

  createGrantAuthorization(HISTORIC_PROCESS_INSTANCE, processInstanceId, userId,
      HistoricProcessInstancePermissions.READ);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  assertThat(query.list())
      .extracting("processInstanceId")
      .containsExactly(processInstanceId);
}
 
Example #24
Source File: HistoricVariableInstanceScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSetVariableLocalOnServiceTaskInsideSubProcess() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

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

  String activityInstanceId = historyService.createHistoricActivityInstanceQuery()
      .activityId("SubProcess_1")
      .singleResult()
      .getId();

  HistoricVariableInstance variable = query.singleResult();
  // the variable is in the sub process scope
  assertEquals(activityInstanceId, variable.getActivityInstanceId());

  assertProcessEnded(pi.getId());
}
 
Example #25
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/api/oneTaskProcess.bpmn20.xml"})
public void testSetVariableOnProcessInstanceStart() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("testVar", "testValue");
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);

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

  HistoricVariableInstance variable = query.singleResult();
  assertNotNull(variable);

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

  taskService.complete(taskService.createTaskQuery().singleResult().getId());
  assertProcessEnded(pi.getId());
}
 
Example #26
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSimpleQueryWithReadHistoryVariablePermissionOnProcessDefinition() {
  // given
  setReadHistoryVariableAsDefaultReadPermission();

  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY_VARIABLE);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 1);
}
 
Example #27
Source File: ProcessEngineRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void testHistoryServiceEngineAccess_HistoricVariableInstanceBinaryFile() {

  HistoricVariableInstanceQuery query = mock(HistoricVariableInstanceQuery.class);
  HistoricVariableInstance instance = mock(HistoricVariableInstance.class);
  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();
  when(instance.getTypedValue()).thenReturn(variableValue);
  when(query.singleResult()).thenReturn(instance);
  when(mockHistoryService.createHistoricVariableInstanceQuery()).thenReturn(query);

  given()
    .pathParam("name", EXAMPLE_ENGINE_NAME)
    .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
  .then().expect()
    .statusCode(Status.OK.getStatusCode())
    . body(is(equalTo(new String(byteContent))))
    .and()
      .header("Content-Disposition", "attachment; filename=\"" + filename + "\"")
      .contentType(CoreMatchers.<String>either(equalTo(ContentType.TEXT.toString() + ";charset=UTF-8")).or(equalTo(ContentType.TEXT.toString() + " ;charset=UTF-8")))
    .when()
      .get(HISTORY_BINARY_VARIABLE_INSTANCE_URL);

  verify(mockHistoryService).createHistoricVariableInstanceQuery();
  verifyZeroInteractions(processEngine);
}
 
Example #28
Source File: HistoricVariableInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTestData() {
  historyServiceMock = mock(HistoryService.class);
  variableInstanceQueryMock = mock(HistoricVariableInstanceQuery.class);

  // mock engine service.
  when(processEngine.getHistoryService()).thenReturn(historyServiceMock);
  when(historyServiceMock.createHistoricVariableInstanceQuery()).thenReturn(variableInstanceQueryMock);
}
 
Example #29
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSimpleQueryWithMultiple() {
  // given
  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY);
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 1);
}
 
Example #30
Source File: HistoricVariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSimpleQueryWithReadHistoryPermissionOnProcessDefinition() {
  // given
  startProcessInstanceByKey(PROCESS_KEY, getVariables());
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_HISTORY);

  // when
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();

  // then
  verifyQueryResults(query, 1);
}