@Test public void testPutSingleBinaryVariableThrowsAuthorizationException() { byte[] bytes = "someContent".getBytes(); String variableKey = "aVariableKey"; String message = "expected exception"; doThrow(new AuthorizationException(message)).when(runtimeServiceMock).setVariable(anyString(), anyString(), any()); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID) .pathParam("varId", variableKey) .multiPart("data", "unspecified", bytes) .expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); }
@Test public void testPutSingleSerializableVariable() throws Exception { ArrayList<String> serializable = new ArrayList<String>(); serializable.add("foo"); ObjectMapper mapper = new ObjectMapper(); String jsonBytes = mapper.writeValueAsString(serializable); String typeName = TypeFactory.defaultInstance().constructType(serializable.getClass()).toCanonical(); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .multiPart("data", jsonBytes, MediaType.APPLICATION_JSON) .multiPart("type", typeName, MediaType.TEXT_PLAIN) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsObjectValue.objectValueMatcher().isDeserialized().value(serializable))); }
@Test public void testPutVariableForNonExistingInstance() { String variableKey = "aVariableKey"; String variableValue = "aVariableValue"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue); doThrow(new ProcessEngineException("expected exception")) .when(runtimeServiceMock) .setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), any()); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()) .body("type", is(RestException.class.getSimpleName())) .body("message", is("Cannot put process instance variable " + variableKey + ": expected exception")) .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL); }
@Test public void testPutSingleBinaryVariable() throws Exception { byte[] bytes = "someContent".getBytes(); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .multiPart("data", null, bytes) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsPrimitiveValue.bytesValue(bytes))); }
@Test public void testPutSingleVariableWithTypeDate() throws Exception { Date now = new Date(); String variableKey = "aVariableKey"; String variableValue = DATE_FORMAT_WITH_TIMEZONE.format(now); String type = "Date"; Date expectedValue = DATE_FORMAT_WITH_TIMEZONE.parse(variableValue); Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.dateValue(expectedValue))); }
@Test public void testPostSingleFileVariableOnlyFilename() throws Exception { String variableKey = "aVariableKey"; String filename = "test.txt"; given() .pathParam("id", EXAMPLE_TASK_ID).pathParam("varId", variableKey) .multiPart("data", filename, new byte[0]) .multiPart("valueType", "File", "text/plain") .header("accept", MediaType.APPLICATION_JSON) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); ArgumentCaptor<FileValue> captor = ArgumentCaptor.forClass(FileValue.class); verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey), captor.capture()); FileValue captured = captor.getValue(); assertThat(captured.getEncoding(), is(nullValue())); assertThat(captured.getFilename(), is(filename)); assertThat(captured.getMimeType(), is(MediaType.APPLICATION_OCTET_STREAM)); assertThat(captured.getValue().available(), is(0)); }
@Test public void testPutSingleBinaryVariableWithNoValue() throws Exception { byte[] bytes = new byte[0]; String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .multiPart("data", null, bytes) .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsPrimitiveValue.bytesValue(bytes))); }
@Test public void testPutSingleVariableThrowsAuthorizationException() { String variableKey = "aVariableKey"; String variableValue = "1abc"; String type = "String"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); String message = "expected exception"; doThrow(new AuthorizationException(message)).when(runtimeServiceMock).setVariable(anyString(), anyString(), any()); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID) .pathParam("varId", variableKey) .contentType(ContentType.JSON) .body(variableJson) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL); }
@Test public void testPutSingleBinaryVariableWithValueType() throws Exception { byte[] bytes = "someContent".getBytes(); String variableKey = "aVariableKey"; given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .multiPart("data", null, bytes) .multiPart("valueType", "Bytes", "text/plain") .expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .post(SINGLE_PROCESS_INSTANCE_BINARY_VARIABLE_URL); verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey), argThat(EqualsPrimitiveValue.bytesValue(bytes))); }
@Test public void testPutSingleVariableWithTypeLong() { String variableKey = "aVariableKey"; Long variableValue = Long.valueOf(123); String type = "Long"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.longValue(variableValue))); }
@Test public void testPutSingleVariableWithNoValue() { String variableKey = "aVariableKey"; given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(EMPTY_JSON_OBJECT) .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(EqualsNullValue.matcher())); }
@Test public void testPutSingleVariableWithTypeString() { String variableKey = "aVariableKey"; String variableValue = "aVariableValue"; String type = "String"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.stringValue(variableValue))); }
@Test public void testPutSingleVariable() { String variableKey = "aVariableKey"; String variableValue = "aVariableValue"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsUntypedValue.matcher().value(variableValue))); }
@Test public void testSetDateVariable() throws Exception { String variableValue = testDateFormat.format(testDate); Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, "Date"); given() .pathParam("id", EXAMPLE_PROCESS_INSTANCE_ID) .pathParam("varId", EXAMPLE_VARIABLE_KEY) .contentType(ContentType.JSON) .body(variableJson) .then().expect() .statusCode(Status.NO_CONTENT.getStatusCode()) .when() .put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL); verify(runtimeServiceMock).setVariable(eq(EXAMPLE_PROCESS_INSTANCE_ID), eq(EXAMPLE_VARIABLE_KEY), argThat(EqualsPrimitiveValue.dateValue(testDate))); }
@Test public void testPutSingleVariableWithTypeDouble() { String variableKey = "aVariableKey"; Double variableValue = 123.456; String type = "Double"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.doubleValue(variableValue))); }
@Test public void testPutSingleVariableWithTypeInteger() { String variableKey = "aVariableKey"; Integer variableValue = 123; String type = "Integer"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.integerValue(variableValue))); }
@Test public void testPutSingleVariableWithTypeShort() { String variableKey = "aVariableKey"; Short variableValue = 123; String type = "Short"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.shortValue(variableValue))); }
@Test public void testPutSingleVariableWithTypeBoolean() { String variableKey = "aVariableKey"; Boolean variableValue = true; String type = "Boolean"; Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey) .contentType(ContentType.JSON).body(variableJson) .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(EqualsPrimitiveValue.booleanValue(variableValue))); }
@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 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"))); }