@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(); }
@Test public void testGetSingleVariableInstanceForBinaryVariable() { MockHistoricVariableInstanceBuilder builder = MockProvider.mockHistoricVariableInstance(); HistoricVariableInstance variableInstanceMock = builder .typedValue(Variables.byteArrayValue(null)) .build(); when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock); when(variableInstanceQueryMock.disableBinaryFetching()).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() .body("type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.BYTES))) .body("value", nullValue()) .when().get(VARIABLE_INSTANCE_URL); verify(variableInstanceQueryMock, times(1)).disableBinaryFetching(); }
@Test public void testBinaryDataForBinaryVariable() { final byte[] byteContent = "some bytes".getBytes(); HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance() .typedValue(Variables.byteArrayValue(byteContent)) .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()) .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(variableInstanceQueryMock, never()).disableBinaryFetching(); }
@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(); }
@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); }
@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()); }
public Void execute(CommandContext commandContext) { historyService.createHistoricVariableInstanceQuery() .singleResult() .getId(); // cache monitor.sync(); commandContext.getProcessEngineConfiguration() .getRuntimeService() .setVariable(processInstanceId, VARIABLE_NAME, ANOTHER_VARIABLE_VALUE); return null; }
public Void execute(CommandContext commandContext) { historyService.createHistoricVariableInstanceQuery() .singleResult() .getId(); // cache monitor.sync(); commandContext.getProcessEngineConfiguration() .getRuntimeService() .setVariable(processInstanceId, VARIABLE_NAME, ANOTHER_VARIABLE_VALUE); return null; }
@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); }
public void execute(DelegateExecution execution) throws Exception { HistoryService historyService = execution.getProcessEngineServices().getHistoryService(); HistoricVariableInstance variableInstance = historyService .createHistoricVariableInstanceQuery() .variableName("listVar") .singleResult(); HistoricVariableUpdate initialUpdate = (HistoricVariableUpdate) historyService .createHistoricDetailQuery() .variableUpdates() .variableInstanceId(variableInstance.getId()) .orderPartiallyByOccurrence().asc() .list() .get(0); List<String> list = (List<String>) initialUpdate.getValue(); // implicit update of the list, should not trigger an update // of the value since we deal with historic variables list.add(NEW_ELEMENT); }
@Test public void deleteHistoricVariableInstanceWithDisabledTenantCheck() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); testRule.deployForTenant(TENANT_TWO, BPMN_ONETASK_PROCESS); String processInstanceIdOne = startProcessInstance(TENANT_ONE); String processInstanceIdTwo = startProcessInstance(TENANT_TWO); runtimeService.setVariable(processInstanceIdOne, "myVariable", "testValue"); runtimeService.setVariable(processInstanceIdTwo, "myVariable", "testValue"); HistoricVariableInstanceQuery variableQueryOne = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdOne); HistoricVariableInstanceQuery variableQueryTwo = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceIdTwo); assertThat(variableQueryOne.count(), is(1L)); assertThat(variableQueryTwo.count(), is(1L)); String variableInstanceIdOne = variableQueryOne.singleResult().getId(); String variableInstanceIdTwo = variableQueryTwo.singleResult().getId(); identityService.setAuthentication("user", null, null); processEngineConfiguration.setTenantCheckEnabled(false); historyService.deleteHistoricVariableInstance(variableInstanceIdOne); historyService.deleteHistoricVariableInstance(variableInstanceIdTwo); assertThat(variableQueryOne.count(), is(0L)); assertThat(variableQueryTwo.count(), is(0L));; cleanUpAfterVariableInstanceTest(processInstanceIdOne, processInstanceIdTwo); }
public void testDeleteHistoricCaseVariableInstance() { // given createCaseInstanceByKey(CASE_KEY, getVariables()); disableAuthorization(); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().singleResult().getId(); assertEquals(1L, historyService.createHistoricDetailQuery().count()); enableAuthorization(); // when historyService.deleteHistoricVariableInstance(variableInstanceId); // then verifyVariablesDeleted(); }
@Test public void failToDeleteHistoricVariableInstanceNoAuthenticatedTenants() { testRule.deployForTenant(TENANT_ONE, BPMN_ONETASK_PROCESS); String processInstanceId = startProcessInstance(null); runtimeService.setVariable(processInstanceId, "myVariable", "testValue"); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).singleResult().getId(); identityService.setAuthentication("user", null, null); thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot delete the historic variable instance '" + variableInstanceId + "' because it belongs to no authenticated tenant."); try { historyService.deleteHistoricVariableInstance(variableInstanceId); } finally { cleanUpAfterVariableInstanceTest(processInstanceId); } }
public void testDeleteHistoricProcessVariableInstanceWithDeleteHistoryPermissionOnProcessDefinition() { // given startProcessInstanceByKey(PROCESS_KEY, getVariables()); createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, DELETE_HISTORY); disableAuthorization(); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().singleResult().getId(); assertEquals(1L, historyService.createHistoricDetailQuery().count()); enableAuthorization(); try { // when historyService.deleteHistoricVariableInstance(variableInstanceId); } catch (AuthorizationException e) { fail("It should be possible to delete the historic variable instance with granted permissions"); } // then verifyVariablesDeleted(); }
public void testDeleteHistoricStandaloneTaskVariableInstance() { // given String taskId = "myTask"; createTask(taskId); disableAuthorization(); taskService.setVariables(taskId, getVariables()); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().singleResult().getId(); assertEquals(1L, historyService.createHistoricDetailQuery().count()); enableAuthorization(); // when historyService.deleteHistoricVariableInstance(variableInstanceId); // then verifyVariablesDeleted(); deleteTask(taskId, true); // XXX if CAM-6570 is implemented, there should be a check for variables of standalone tasks here as well }
public static HistoricVariableInstanceDto fromHistoricVariableInstance(HistoricVariableInstance historicVariableInstance) { HistoricVariableInstanceDto dto = new HistoricVariableInstanceDto(); dto.id = historicVariableInstance.getId(); dto.name = historicVariableInstance.getName(); dto.processDefinitionKey = historicVariableInstance.getProcessDefinitionKey(); dto.processDefinitionId = historicVariableInstance.getProcessDefinitionId(); dto.processInstanceId = historicVariableInstance.getProcessInstanceId(); dto.executionId = historicVariableInstance.getExecutionId(); dto.activityInstanceId = historicVariableInstance.getActivityInstanceId(); dto.caseDefinitionKey = historicVariableInstance.getCaseDefinitionKey(); dto.caseDefinitionId = historicVariableInstance.getCaseDefinitionId(); dto.caseInstanceId = historicVariableInstance.getCaseInstanceId(); dto.caseExecutionId = historicVariableInstance.getCaseExecutionId(); dto.taskId = historicVariableInstance.getTaskId(); dto.tenantId = historicVariableInstance.getTenantId(); dto.state = historicVariableInstance.getState(); dto.createTime = historicVariableInstance.getCreateTime(); dto.removalTime = historicVariableInstance.getRemovalTime(); dto.rootProcessInstanceId = historicVariableInstance.getRootProcessInstanceId(); if(historicVariableInstance.getErrorMessage() == null) { VariableValueDto.fromTypedValue(dto, historicVariableInstance.getTypedValue()); } else { dto.errorMessage = historicVariableInstance.getErrorMessage(); dto.type = VariableValueDto.toRestApiTypeName(historicVariableInstance.getTypeName()); } return dto; }
public void testDeleteHistoricProcessVariableInstanceWithoutAuthorization() { // given startProcessInstanceByKey(PROCESS_KEY, getVariables()); disableAuthorization(); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().singleResult().getId(); assertEquals(1L, historyService.createHistoricDetailQuery().count()); enableAuthorization(); try { // when historyService.deleteHistoricVariableInstance(variableInstanceId); fail("Exception expected: It should not be possible to delete the historic variable instance"); } catch (AuthorizationException e) { // then String message = e.getMessage(); assertTextPresent(userId, message); assertTextPresent(DELETE_HISTORY.getName(), message); assertTextPresent(PROCESS_KEY, message); assertTextPresent(PROCESS_DEFINITION.resourceName(), message); } }
public void testDeleteHistoricProcessVariableInstanceAfterDeletingDeployment() { // given startProcessInstanceByKey(PROCESS_KEY, getVariables()); String taskId = selectSingleTask().getId(); disableAuthorization(); taskService.complete(taskId); enableAuthorization(); createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, DELETE_HISTORY); disableAuthorization(); repositoryService.deleteDeployment(deploymentId); String variableInstanceId = historyService.createHistoricVariableInstanceQuery().singleResult().getId(); assertEquals(1L, historyService.createHistoricDetailQuery().count()); enableAuthorization(); try { // when historyService.deleteHistoricVariableInstance(variableInstanceId); } catch (AuthorizationException e) { fail("It should be possible to delete the historic variable instance with granted permissions after the process definition is deleted"); } // then verifyVariablesDeleted(); cleanUpAfterDeploymentDeletion(); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"}) public void testCmmnActivityInstanceIdOnTask() { // given CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase"); String taskExecutionId = caseService .createCaseExecutionQuery() .activityId("PI_HumanTask_1") .singleResult() .getId(); Task task = taskService .createTaskQuery() .singleResult(); // when taskService.setVariable(task.getId(), "foo", "bar"); // then HistoricVariableInstance variable = historyService .createHistoricVariableInstanceQuery() .variableName("foo") .singleResult(); assertNotNull(variable); assertEquals(caseInstance.getId(), variable.getActivityInstanceId()); if(processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) { HistoricDetail variableDetail = historyService .createHistoricDetailQuery() .variableUpdates() .variableInstanceId(variable.getId()) .singleResult(); assertEquals(taskExecutionId, variableDetail.getActivityInstanceId()); } }
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS) public void testHistoricVariableInstanceForSingleActivityInstantiation() { // when ProcessInstance instance = runtimeService .createProcessInstanceByKey("exclusiveGateway") .startBeforeActivity("task1") .setVariable("aVar", "aValue") .execute(); ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId()); // then 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()); }