@Before public void setUpRuntimeData() { runtimeServiceMock = mock(RuntimeServiceImpl.class); mockManagementService = mock(ManagementServiceImpl.class); historyServiceMock = mock(HistoryServiceImpl.class); // variables when(runtimeServiceMock.getVariablesTyped(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, true)).thenReturn(EXAMPLE_VARIABLES); when(runtimeServiceMock.getVariablesTyped(MockProvider.ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID, true)).thenReturn(EXAMPLE_OBJECT_VARIABLES); when(runtimeServiceMock.getVariablesTyped(EXAMPLE_PROCESS_INSTANCE_ID_WITH_NULL_VALUE_AS_VARIABLE, true)).thenReturn(EXAMPLE_VARIABLES_WITH_NULL_VALUE); // activity instances when(runtimeServiceMock.getActivityInstance(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).thenReturn(EXAMPLE_ACTIVITY_INSTANCE); mockUpdateSuspensionStateSelectBuilder = mock(UpdateProcessInstanceSuspensionStateSelectBuilder.class); when(runtimeServiceMock.updateProcessInstanceSuspensionState()).thenReturn(mockUpdateSuspensionStateSelectBuilder); mockUpdateSuspensionStateBuilder = mock(UpdateProcessInstanceSuspensionStateTenantBuilder.class); when(mockUpdateSuspensionStateSelectBuilder.byProcessInstanceId(anyString())).thenReturn(mockUpdateSuspensionStateBuilder); when(mockUpdateSuspensionStateSelectBuilder.byProcessDefinitionId(anyString())).thenReturn(mockUpdateSuspensionStateBuilder); when(mockUpdateSuspensionStateSelectBuilder.byProcessDefinitionKey(anyString())).thenReturn(mockUpdateSuspensionStateBuilder); mockUpdateProcessInstancesSuspensionStateBuilder = mock(UpdateProcessInstancesSuspensionStateBuilder.class); when(mockUpdateSuspensionStateSelectBuilder.byProcessInstanceIds(anyList())).thenReturn(mockUpdateProcessInstancesSuspensionStateBuilder); when(mockUpdateSuspensionStateSelectBuilder.byProcessInstanceQuery(any(ProcessInstanceQuery.class))).thenReturn(mockUpdateProcessInstancesSuspensionStateBuilder); when(mockUpdateSuspensionStateSelectBuilder.byHistoricProcessInstanceQuery(any(HistoricProcessInstanceQuery.class))).thenReturn(mockUpdateProcessInstancesSuspensionStateBuilder); // runtime service when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock); when(processEngine.getManagementService()).thenReturn(mockManagementService); when(processEngine.getHistoryService()).thenReturn(historyServiceMock); }
@Test public void testGetActivityInstanceTreeForNonExistingProcessInstance() { when(runtimeServiceMock.getActivityInstance(anyString())).thenReturn(null); given().pathParam("id", "aNonExistingProcessInstanceId") .then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(InvalidRequestException.class.getSimpleName())) .body("message", equalTo("Process instance with id aNonExistingProcessInstanceId does not exist")) .when().get(PROCESS_INSTANCE_ACTIVIY_INSTANCES_URL); }
@Test public void testGetActivityInstanceTreeWithInternalError() { when(runtimeServiceMock.getActivityInstance(anyString())).thenThrow(new ProcessEngineException("expected exception")); given().pathParam("id", "aNonExistingProcessInstanceId") .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(InvalidRequestException.class.getSimpleName())) .body("message", equalTo("expected exception")) .when().get(PROCESS_INSTANCE_ACTIVIY_INSTANCES_URL); }
@Test public void testGetActivityInstanceTreeThrowsAuthorizationException() { String message = "expected exception"; when(runtimeServiceMock.getActivityInstance(anyString())).thenThrow(new AuthorizationException(message)); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo(message)) .when() .get(PROCESS_INSTANCE_ACTIVIY_INSTANCES_URL); }