Search in sources :

Example 61 with BadUserRequestException

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

the class ExternalTaskRestServiceInteractionTest method testHandleFailureThrowsBadUserRequestException.

@Test
public void testHandleFailureThrowsBadUserRequestException() {
    doThrow(new BadUserRequestException("aMessage")).when(externalTaskService).handleFailure(any(String.class), any(String.class), any(String.class), any(String.class), anyInt(), anyLong());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("workerId", "aWorkerId");
    parameters.put("errorMessage", "anErrorMessage");
    parameters.put("retries", 5);
    parameters.put("retryTimeout", 12345);
    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters).pathParam("id", "anExternalTaskId").then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo("aMessage")).when().post(HANDLE_EXTERNAL_TASK_FAILURE_URL);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 62 with BadUserRequestException

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

the class BatchRestServiceInteractionTest method deleteNonExistingBatchNotCascade.

@Test
public void deleteNonExistingBatchNotCascade() {
    String nonExistingId = MockProvider.NON_EXISTING_ID;
    doThrow(new BadUserRequestException("Batch for id '" + nonExistingId + "' cannot be found")).when(managementServiceMock).deleteBatch(eq(nonExistingId), eq(false));
    given().pathParam("id", nonExistingId).queryParam("cascade", false).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Unable to delete batch with id '" + nonExistingId + "'")).when().delete(SINGLE_BATCH_RESOURCE_URL);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 63 with BadUserRequestException

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

the class BatchRestServiceInteractionTest method deleteNonExistingBatchCascade.

@Test
public void deleteNonExistingBatchCascade() {
    String nonExistingId = MockProvider.NON_EXISTING_ID;
    doThrow(new BadUserRequestException("Batch for id '" + nonExistingId + "' cannot be found")).when(managementServiceMock).deleteBatch(eq(nonExistingId), eq(true));
    given().pathParam("id", nonExistingId).queryParam("cascade", true).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Unable to delete batch with id '" + nonExistingId + "'")).when().delete(SINGLE_BATCH_RESOURCE_URL);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 64 with BadUserRequestException

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

the class AbstractVariablesResource method putVariable.

@Override
public void putVariable(String variableName, VariableValueDto variable) {
    try {
        TypedValue typedValue = variable.toTypedValue(engine, objectMapper);
        setVariableEntity(variableName, typedValue);
    } catch (RestException e) {
        throw new InvalidRequestException(e.getStatus(), e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    } catch (BadUserRequestException e) {
        throw new RestException(Status.BAD_REQUEST, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, String.format("Cannot put %s variable %s: %s", getResourceTypeName(), variableName, e.getMessage()));
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 65 with BadUserRequestException

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

the class ProcessInstanceRestServiceImpl method setRetriesByProcessHistoricQueryBased.

@Override
public BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) {
    List<String> processInstanceIds = new ArrayList<String>();
    HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.getHistoricProcessInstanceQuery();
    if (queryDto != null) {
        HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
        List<HistoricProcessInstance> historicProcessInstances = query.list();
        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
            processInstanceIds.add(historicProcessInstance.getId());
        }
    }
    if (setJobRetriesDto.getProcessInstances() != null) {
        processInstanceIds.addAll(setJobRetriesDto.getProcessInstances());
    }
    try {
        ManagementService managementService = getProcessEngine().getManagementService();
        Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery) null, setJobRetriesDto.getRetries());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) ManagementService(org.camunda.bpm.engine.ManagementService) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) Batch(org.camunda.bpm.engine.batch.Batch) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Aggregations

BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)105 Test (org.junit.Test)68 Matchers.anyString (org.mockito.Matchers.anyString)43 HashMap (java.util.HashMap)22 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)19 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)16 MigrationExecutionDtoBuilder (org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder)16 ArrayList (java.util.ArrayList)14 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)13 Batch (org.camunda.bpm.engine.batch.Batch)12 Deployment (org.camunda.bpm.engine.test.Deployment)9 FluentAnswer (org.camunda.bpm.engine.rest.helper.FluentAnswer)8 JoinedMigrationPlanBuilderMock (org.camunda.bpm.engine.rest.helper.MockMigrationPlanBuilder.JoinedMigrationPlanBuilderMock)8 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)8 Map (java.util.Map)7 RestException (org.camunda.bpm.engine.rest.exception.RestException)6 List (java.util.List)5 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)5 DecisionDefinition (org.camunda.bpm.engine.repository.DecisionDefinition)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5