Search in sources :

Example 1 with MockHistoricVariableUpdateBuilder

use of org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest 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();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(variableValue).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_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) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 2 with MockHistoricVariableUpdateBuilder

use of org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testGetSingleVariableUpdateSerialized.

@Test
public void testGetSingleVariableUpdateSerialized() {
    ObjectValue serializedValue = Variables.serializedObjectValue("a serialized value").serializationDataFormat("aDataFormat").objectTypeName("aTypeName").create();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate().typedValue(serializedValue);
    HistoricVariableUpdate variableInstanceMock = builder.build();
    when(historicDetailQueryMock.detailId(variableInstanceMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(variableInstanceMock);
    given().pathParam("id", builder.getId()).queryParam("deserializeValue", false).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("variableName", equalTo(builder.getName())).body("variableInstanceId", equalTo(builder.getVariableInstanceId())).body("variableType", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo("a serialized value")).body("valueInfo.serializationDataFormat", equalTo("aDataFormat")).body("valueInfo.objectTypeName", equalTo("aTypeName")).body("processDefinitionKey", equalTo(builder.getProcessDefinitionKey())).body("processDefinitionId", equalTo(builder.getProcessDefinitionId())).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("errorMessage", equalTo(builder.getErrorMessage())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("revision", equalTo(builder.getRevision())).body("time", equalTo(builder.getTime())).body("taskId", equalTo(builder.getTaskId())).body("executionId", equalTo(builder.getExecutionId())).body("caseDefinitionKey", equalTo(builder.getCaseDefinitionKey())).body("caseDefinitionId", equalTo(builder.getCaseDefinitionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("tenantId", equalTo(builder.getTenantId())).when().get(HISTORIC_DETAIL_URL);
    verify(historicDetailQueryMock, times(1)).disableBinaryFetching();
    verify(historicDetailQueryMock, times(1)).disableCustomObjectDeserialization();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) MockObjectValue(org.camunda.bpm.engine.rest.helper.MockObjectValue) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 3 with MockHistoricVariableUpdateBuilder

use of org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testGetSingleVariableInstanceForBinaryVariable.

@Test
public void testGetSingleVariableInstanceForBinaryVariable() {
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(Variables.byteArrayValue(null)).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableBinaryFetching()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).and().body("id", equalTo(builder.getId())).body("variableName", equalTo(builder.getName())).body("variableInstanceId", equalTo(builder.getVariableInstanceId())).body("variableType", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType()))).body("value", equalTo(builder.getValue())).body("processDefinitionKey", equalTo(builder.getProcessDefinitionKey())).body("processDefinitionId", equalTo(builder.getProcessDefinitionId())).body("processInstanceId", equalTo(builder.getProcessInstanceId())).body("errorMessage", equalTo(builder.getErrorMessage())).body("activityInstanceId", equalTo(builder.getActivityInstanceId())).body("revision", equalTo(builder.getRevision())).body("time", equalTo(builder.getTime())).body("taskId", equalTo(builder.getTaskId())).body("executionId", equalTo(builder.getExecutionId())).body("caseDefinitionKey", equalTo(builder.getCaseDefinitionKey())).body("caseDefinitionId", equalTo(builder.getCaseDefinitionId())).body("caseInstanceId", equalTo(builder.getCaseInstanceId())).body("caseExecutionId", equalTo(builder.getCaseExecutionId())).body("tenantId", equalTo(builder.getTenantId())).when().get(HISTORIC_DETAIL_URL);
    verify(historicDetailQueryMock, times(1)).disableBinaryFetching();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 4 with MockHistoricVariableUpdateBuilder

use of org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testBinaryDataForFileVariable.

@Test
public void testBinaryDataForFileVariable() {
    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();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(variableValue).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID).then().expect().statusCode(Status.OK.getStatusCode()).body(is(equalTo(new String(byteContent)))).and().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(historicDetailQueryMock, never()).disableBinaryFetching();
}
Also used : FileValue(org.camunda.bpm.engine.variable.value.FileValue) HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Response(com.jayway.restassured.response.Response) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 5 with MockHistoricVariableUpdateBuilder

use of org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder in project camunda-bpm-platform by camunda.

the class HistoricDetailRestServiceInteractionTest method testBinaryDataForBinaryVariable.

@Test
public void testBinaryDataForBinaryVariable() {
    final byte[] byteContent = "some bytes".getBytes();
    MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
    HistoricVariableUpdate detailMock = builder.typedValue(Variables.byteArrayValue(byteContent)).build();
    when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
    when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
    Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_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(historicDetailQueryMock, never()).disableBinaryFetching();
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Response(com.jayway.restassured.response.Response) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHistoricVariableUpdateBuilder(org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Aggregations

AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)9 MockHistoricVariableUpdateBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder)9 Test (org.junit.Test)9 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)7 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Response (com.jayway.restassured.response.Response)2 ArrayList (java.util.ArrayList)2 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)2 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)2 FileValue (org.camunda.bpm.engine.variable.value.FileValue)2