Search in sources :

Example 46 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class JsonSerializationTest method testFailingDeserialization.

@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingDeserialization() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    FailingDeserializationBean failingBean = new FailingDeserializationBean("a String", 42, true);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(failingBean).serializationDataFormat(JSON_FORMAT_NAME));
    try {
        runtimeService.getVariable(instance.getId(), "simpleBean");
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // happy path
    }
    try {
        runtimeService.getVariableTyped(instance.getId(), "simpleBean");
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // happy path
    }
    // However, I can access the serialized value
    ObjectValue objectValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean", false);
    assertFalse(objectValue.isDeserialized());
    assertNotNull(objectValue.getObjectTypeName());
    assertNotNull(objectValue.getValueSerialized());
    // but not the deserialized properties
    try {
        objectValue.getValue();
        fail("exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("Object is not deserialized", e.getMessage());
    }
    try {
        objectValue.getValue(JsonSerializable.class);
        fail("exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("Object is not deserialized", e.getMessage());
    }
    try {
        objectValue.getObjectType();
        fail("exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("Object is not deserialized", e.getMessage());
    }
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 47 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class JsonSerializationTest method testSetSerializedVariableValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSetSerializedVariableValue() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    JsonSerializable bean = new JsonSerializable("a String", 42, true);
    String beanAsJson = bean.toExpectedJsonString();
    SerializedObjectValueBuilder serializedValue = serializedObjectValue(beanAsJson).serializationDataFormat(JSON_FORMAT_NAME).objectTypeName(bean.getClass().getCanonicalName());
    runtimeService.setVariable(instance.getId(), "simpleBean", serializedValue);
    // java object can be retrieved
    JsonSerializable returnedBean = (JsonSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
    assertEquals(bean, returnedBean);
    // validate typed value metadata
    ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
    assertEquals(bean, typedValue.getValue());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    assertEquals(bean.getClass().getCanonicalName(), typedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Variables.serializedObjectValue(org.camunda.bpm.engine.variable.Variables.serializedObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) SerializedObjectValueBuilder(org.camunda.bpm.engine.variable.value.builder.SerializedObjectValueBuilder) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 48 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class JsonValueTest method testGetTypedJsonValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetTypedJsonValue() throws JSONException {
    // given
    JsonValue jsonValue = jsonValue(jsonString).create();
    VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
    // when
    JsonValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);
    // then
    SpinJsonNode value = typedValue.getValue();
    JSONAssert.assertEquals(jsonString, value.toString(), true);
    assertTrue(typedValue.isDeserialized());
    assertEquals(JSON, typedValue.getType());
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    JSONAssert.assertEquals(jsonString, typedValue.getValueSerialized(), true);
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 49 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class JsonValueTest method testTransientJsonValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testTransientJsonValue() throws JSONException {
    // given
    JsonValue jsonValue = jsonValue(jsonString).setTransient(true).create();
    VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
    // when
    runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
    // then
    List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
    assertEquals(0, variableInstances.size());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 50 with Deployment

use of org.camunda.bpm.engine.test.Deployment in project camunda-bpm-platform by camunda.

the class JsonValueTest method testGetUntypedJsonValue.

@Deployment(resources = ONE_TASK_PROCESS)
public void testGetUntypedJsonValue() throws JSONException {
    // given
    JsonValue jsonValue = jsonValue(jsonString).create();
    VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);
    String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();
    // when
    SpinJsonNode value = (SpinJsonNode) runtimeService.getVariable(processInstanceId, variableName);
    // then
    JSONAssert.assertEquals(jsonString, value.toString(), true);
    assertEquals(json().getName(), value.getDataFormatName());
}
Also used : SpinJsonNode(org.camunda.spin.json.SpinJsonNode) VariableMap(org.camunda.bpm.engine.variable.VariableMap) JsonValue(org.camunda.spin.plugin.variable.value.JsonValue) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Deployment (org.camunda.bpm.engine.test.Deployment)3376 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1325 Task (org.camunda.bpm.engine.task.Task)788 Test (org.junit.Test)635 HashMap (java.util.HashMap)441 Job (org.camunda.bpm.engine.runtime.Job)310 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)277 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)265 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)256 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)251 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)230 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)206 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)195 Execution (org.camunda.bpm.engine.runtime.Execution)189 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)175 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)161 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)149 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)143 ExecutionAssert.describeExecutionTree (org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree)134 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)134