@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testGetValueOfSerializableVar() { // given List<String> serializable = new ArrayList<String>(); serializable.add("one"); serializable.add("two"); serializable.add("three"); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("serializableVar", serializable); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); // when VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()); // then List<VariableInstance> result = query.list(); assertFalse(result.isEmpty()); assertEquals(1, result.size()); VariableInstance instance = result.get(0); assertEquals("serializableVar", instance.getName()); assertNotNull(instance.getValue()); assertEquals(serializable, instance.getValue()); assertEquals(ValueType.OBJECT.getName(), instance.getTypeName()); }
@Test public void testPutSingleLocalVariableFromSerializedWithNoValue() { String variableKey = "aVariableKey"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null); given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(requestJson) .then().expect().statusCode(Status.NO_CONTENT.getStatusCode()) .when().put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL); verify(taskServiceMock).setVariableLocal( eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher())); }
@Test public void testPutSingleVariableFromSerializedWithNoValue() { String variableKey = "aVariableKey"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null); given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(requestJson) .then().expect().statusCode(Status.NO_CONTENT.getStatusCode()) .when().put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL); verify(taskServiceMock).setVariable( eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher())); }
@Test public void testPutSingleVariableFromSerializedWithNoValue() { String variableKey = "aVariableKey"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(requestJson) .then().expect().statusCode(Status.NO_CONTENT.getStatusCode()) .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL); verify(runtimeServiceMock).setVariable( eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher())); }
@Test public void testPutSingleLocalVariableFromSerializedWithNoValue() { String variableKey = "aVariableKey"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null); given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(requestJson) .then().expect().statusCode(Status.NO_CONTENT.getStatusCode()) .when().put(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); verify(runtimeServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), argThat(EqualsObjectValue .objectValueMatcher() .serializationFormat(null) .objectTypeName(null) .serializedValue(null))); }
@Test public void testPutSingleLocalVariableFromSerialized() { String serializedValue = "{\"prop\" : \"value\"}"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(serializedValue, ValueType.OBJECT.getName(), "aDataFormat", "aRootType"); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON) .body(requestJson) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .put(SINGLE_EXECUTION_LOCAL_VARIABLE_URL); verify(runtimeServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey), argThat(EqualsObjectValue .objectValueMatcher() .serializationFormat("aDataFormat") .objectTypeName("aRootType") .serializedValue(serializedValue))); }
@Test public void testPutSingleVariableFromSerialized() throws Exception { String serializedValue = "{\"prop\" : \"value\"}"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(serializedValue, ValueType.OBJECT.getName(), "aDataFormat", "aRootType"); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON) .body(requestJson) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL); verify(runtimeServiceMock).setVariable( eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher() .serializedValue(serializedValue) .serializationFormat("aDataFormat") .objectTypeName("aRootType"))); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml"}) @Test public void testChangeTypeFromSerializableUsingApi() { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("aVariable", new SerializableVariable("foo")); ProcessInstance pi = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables); VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable"); VariableInstance variable = query.singleResult(); assertEquals(ValueType.OBJECT.getName(), variable.getTypeName()); runtimeService.setVariable(pi.getId(), "aVariable", null); variable = query.singleResult(); assertEquals(ValueType.NULL.getName(), variable.getTypeName()); }
@Test public void testPutSingleLocalVariableFromSerialized() throws Exception { String serializedValue = "{\"prop\" : \"value\"}"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(serializedValue, ValueType.OBJECT.getName(), "aDataFormat", "aRootType"); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON) .body(requestJson) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL); verify(taskServiceMock).setVariableLocal( eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher() .serializedValue(serializedValue) .serializationFormat("aDataFormat") .objectTypeName("aRootType"))); }
.variable("var1", "val1") .variable("var2", "val2", "String") .variable("var3", ValueType.OBJECT.getName(), "val3", "aFormat", "aRootType") .getVariables(); parameters.put("variables", variables);
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml"}) @Test public void testChangeToSerializableUsingApi() { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("aVariable", "test"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables); VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable"); VariableInstance variable = query.singleResult(); assertEquals(ValueType.STRING.getName(), variable.getTypeName()); runtimeService.setVariable(processInstance.getId(), "aVariable", new SerializableVariable("foo")); variable = query.singleResult(); assertEquals(ValueType.OBJECT.getName(), variable.getTypeName()); }
@Test public void testPutSingleVariableFromSerialized() throws Exception { String serializedValue = "{\"prop\" : \"value\"}"; Map<String, Object> requestJson = VariablesBuilder .getObjectValueMap(serializedValue, ValueType.OBJECT.getName(), "aDataFormat", "aRootType"); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON) .body(requestJson) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL); verify(taskServiceMock).setVariable( eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher() .serializedValue(serializedValue) .serializationFormat("aDataFormat") .objectTypeName("aRootType"))); }
@Test public void testSubmitStartFormWithSerializedVariableValue() { String jsonValue = "{}"; Map<String, Object> variables = VariablesBuilder.create() .variable("aVariable", "aStringValue") .variable("aSerializedVariable", ValueType.OBJECT.getName(), jsonValue, "aFormat", "aRootType") .getVariables(); Map<String, Object> json = new HashMap<String, Object>(); json.put("variables", variables); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .contentType(POST_JSON_CONTENT_TYPE).body(json) .then().expect() .statusCode(Status.OK.getStatusCode()) .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)) .body("definitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)) .body("businessKey", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY)) .body("ended", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_IS_ENDED)) .body("suspended", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_IS_SUSPENDED)) .when().post(SUBMIT_FORM_URL); verify(formServiceMock).submitStartForm(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID), argThat( new EqualsVariableMap() .matcher("aVariable", EqualsUntypedValue.matcher().value("aStringValue")) .matcher("aSerializedVariable", EqualsObjectValue .objectValueMatcher() .serializedValue(jsonValue) .serializationFormat("aFormat") .objectTypeName("aRootType")))); }
.variable("var1", "val1") .variable("var2", "val2", "String") .variable("var3", ValueType.OBJECT.getName(), "val3", "aFormat", "aRootType") .getVariables(); parameters.put("localVariables", variables);
@SuppressWarnings("unchecked") protected void verifySerializedValue(Map<String, Object> serializedValue) { ObjectValue exampleValue = MockProvider.EXAMPLE_HISTORIC_DECISION_SERIALIZED_VALUE; assertThat(serializedValue, hasEntry("type", (Object) VariableValueDto.toRestApiTypeName(exampleValue.getType().getName()))); assertThat(serializedValue, hasEntry("value", exampleValue.getValue())); Map<String, String> valueInfo = (Map<String, String>) serializedValue.get("valueInfo"); assertThat(valueInfo, hasEntry("serializationDataFormat", exampleValue.getSerializationDataFormat())); assertThat(valueInfo, hasEntry("objectTypeName", exampleValue.getObjectTypeName())); }
.variable("var1", "val1") .variable("var2", "val2", "String") .variable("var3", ValueType.OBJECT.getName(), "val3", "aFormat", "aRootType") .getVariables(); parameters.put("variables", variables);
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testGetValueOfSerializableVar() { // given List<String> serializable = new ArrayList<String>(); serializable.add("one"); serializable.add("two"); serializable.add("three"); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("serializableVar", serializable); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables); // when VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()); // then List<VariableInstance> result = query.list(); assertFalse(result.isEmpty()); assertEquals(1, result.size()); VariableInstance instance = result.get(0); assertEquals("serializableVar", instance.getName()); assertNotNull(instance.getValue()); assertEquals(serializable, instance.getValue()); assertEquals(ValueType.OBJECT.getName(), instance.getTypeName()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml"}) @Test public void testChangeTypeFromSerializableUsingApi() { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("aVariable", new SerializableVariable("foo")); ProcessInstance pi = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables); VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable"); VariableInstance variable = query.singleResult(); assertEquals(ValueType.OBJECT.getName(), variable.getTypeName()); runtimeService.setVariable(pi.getId(), "aVariable", null); variable = query.singleResult(); assertEquals(ValueType.NULL.getName(), variable.getTypeName()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/RuntimeServiceTest.testBasicVariableOperations.bpmn20.xml"}) @Test public void testChangeToSerializableUsingApi() { Map<String, Object> variables = new HashMap<String, Object>(); variables.put("aVariable", "test"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess", variables); VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableName("aVariable"); VariableInstance variable = query.singleResult(); assertEquals(ValueType.STRING.getName(), variable.getTypeName()); runtimeService.setVariable(processInstance.getId(), "aVariable", new SerializableVariable("foo")); variable = query.singleResult(); assertEquals(ValueType.OBJECT.getName(), variable.getTypeName()); }