Search in sources :

Example 6 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceRestServiceInteractionTest method testGetBinaryDataForNullFileVariable.

@Test
public void testGetBinaryDataForNullFileVariable() {
    String filename = "test.txt";
    byte[] byteContent = null;
    FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).create();
    MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance();
    VariableInstance variableInstanceMock = builder.typedValue(variableValue).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().contentType(ContentType.TEXT).and().body(is(equalTo(new String()))).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockVariableInstanceBuilder(org.camunda.bpm.engine.rest.helper.MockVariableInstanceBuilder) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 7 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceRestServiceInteractionTest method testGetSingleVariableInstanceSerialized.

@Test
public void testGetSingleVariableInstanceSerialized() {
    ObjectValue serializedValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("aDataFormat").objectTypeName("aTypeName").create();
    MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance().typedValue(serializedValue);
    VariableInstance variableInstanceMock = builder.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).queryParam("deserializeValue", false).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("name", equalTo(builder.getName())).body("type", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo("a serialized value")).body("valueInfo.serializationDataFormat", equalTo("aDataFormat")).body("valueInfo.objectTypeName", equalTo("aTypeName")).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("executionId", equalTo(builder.getExecutionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("taskId", equalTo(builder.getTaskId())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("tenantId", equalTo(builder.getTenantId())).body("errorMessage", equalTo(builder.getErrorMessage())).when().get(VARIABLE_INSTANCE_URL);
    verify(variableInstanceQueryMock, times(1)).disableBinaryFetching();
    verify(variableInstanceQueryMock, times(1)).disableCustomObjectDeserialization();
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) MockVariableInstanceBuilder(org.camunda.bpm.engine.rest.helper.MockVariableInstanceBuilder) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 8 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceRestServiceInteractionTest method testBinaryDataForNonBinaryVariable.

@Test
public void testBinaryDataForNonBinaryVariable() {
    VariableInstance variableInstanceMock = MockProvider.createMockVariableInstance();
    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 aVariableInstanceId is not a binary value")).when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
    verify(variableInstanceQueryMock, never()).disableBinaryFetching();
    verify(variableInstanceQueryMock).disableCustomObjectDeserialization();
}
Also used : VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 9 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceRestServiceInteractionTest method testGetSingleVariableInstanceDeserialized.

@Test
public void testGetSingleVariableInstanceDeserialized() {
    ObjectValue serializedValue = MockObjectValue.fromObjectValue(Variables.objectValue("a value").serializationDataFormat("aDataFormat").create()).objectTypeName("aTypeName");
    MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance().typedValue(serializedValue);
    VariableInstance variableInstanceMock = builder.build();
    when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
    when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock);
    when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
    given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("name", equalTo(builder.getName())).body("type", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo("a value")).body("valueInfo.serializationDataFormat", equalTo("aDataFormat")).body("valueInfo.objectTypeName", equalTo("aTypeName")).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("executionId", equalTo(builder.getExecutionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("taskId", equalTo(builder.getTaskId())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("tenantId", equalTo(builder.getTenantId())).body("errorMessage", equalTo(builder.getErrorMessage())).when().get(VARIABLE_INSTANCE_URL);
    verify(variableInstanceQueryMock, times(1)).disableBinaryFetching();
    verify(variableInstanceQueryMock, never()).disableCustomObjectDeserialization();
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) MockVariableInstanceBuilder(org.camunda.bpm.engine.rest.helper.MockVariableInstanceBuilder) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 10 with VariableInstance

use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.

the class VariableInstanceQueryImpl method executeList.

@Override
public List<VariableInstance> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();
    List<VariableInstance> result = commandContext.getVariableInstanceManager().findVariableInstanceByQueryCriteria(this, page);
    if (result == null) {
        return result;
    }
    // iterate over the result array to initialize the value and serialized value of the variable
    for (VariableInstance variableInstance : result) {
        VariableInstanceEntity variableInstanceEntity = (VariableInstanceEntity) variableInstance;
        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 result;
}
Also used : VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance)

Aggregations

VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)374 Deployment (org.camunda.bpm.engine.test.Deployment)265 Test (org.junit.Test)167 HashMap (java.util.HashMap)136 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)122 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)93 Task (org.camunda.bpm.engine.task.Task)67 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)39 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)33 Execution (org.camunda.bpm.engine.runtime.Execution)33 VariableMap (org.camunda.bpm.engine.variable.VariableMap)30 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)27 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)26 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)23 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)21 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)17 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)13 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 List (java.util.List)10