Search in sources :

Example 26 with NotFoundException

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

the class ProcessDefinitionRestServiceInteractionTest method testDeleteNonExistingDeployment.

@Test
public void testDeleteNonExistingDeployment() {
    doThrow(new NotFoundException("No process definition found with id 'NON_EXISTING_ID'")).when(repositoryServiceMock).deleteProcessDefinition("NON_EXISTING_ID", false, false);
    given().pathParam("id", "NON_EXISTING_ID").expect().statusCode(Status.NOT_FOUND.getStatusCode()).body(containsString("No process definition found with id 'NON_EXISTING_ID'")).when().delete(SINGLE_PROCESS_DEFINITION_URL);
}
Also used : NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) Test(org.junit.Test)

Example 27 with NotFoundException

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

the class ExternalTaskRestServiceInteractionTest method testSetRetriesNonExistingTask.

@Test
public void testSetRetriesNonExistingTask() {
    doThrow(new NotFoundException()).when(externalTaskService).setRetries(any(String.class), anyInt());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("retries", "5");
    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters).pathParam("id", "anExternalTaskId").then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo("External task with id anExternalTaskId does not exist")).when().put(RETRIES_EXTERNAL_TASK_URL);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 28 with NotFoundException

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

the class ExternalTaskRestServiceInteractionTest method testCompleteNonExistingTask.

@Test
public void testCompleteNonExistingTask() {
    doThrow(new NotFoundException()).when(externalTaskService).complete(any(String.class), any(String.class), anyMapOf(String.class, Object.class), anyMapOf(String.class, Object.class));
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("workerId", "aWorkerId");
    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters).pathParam("id", "anExternalTaskId").then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo("External task with id anExternalTaskId does not exist")).when().post(COMPLETE_EXTERNAL_TASK_URL);
}
Also used : HashMap(java.util.HashMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 29 with NotFoundException

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

the class CaseDefinitionResourceImpl method getCaseDefinitionCmmnXml.

@Override
public CaseDefinitionDiagramDto getCaseDefinitionCmmnXml() {
    InputStream caseModelInputStream = null;
    try {
        caseModelInputStream = engine.getRepositoryService().getCaseModel(caseDefinitionId);
        byte[] caseModel = IoUtil.readInputStream(caseModelInputStream, "caseModelCmmnXml");
        return CaseDefinitionDiagramDto.create(caseDefinitionId, new String(caseModel, "UTF-8"));
    } catch (NotFoundException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e, e.getMessage());
    } catch (NotValidException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } catch (UnsupportedEncodingException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } finally {
        IoUtil.closeSilently(caseModelInputStream);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) InputStream(java.io.InputStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 30 with NotFoundException

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

the class CaseDefinitionResourceImpl method createCaseInstance.

public CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters) {
    CaseService caseService = engine.getCaseService();
    CaseInstance instance = null;
    try {
        String businessKey = parameters.getBusinessKey();
        VariableMap variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
        instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    } catch (NotFoundException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.NOT_FOUND, e, errorMessage);
    } catch (NotValidException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.BAD_REQUEST, e, errorMessage);
    } catch (NotAllowedException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new InvalidRequestException(Status.FORBIDDEN, e, errorMessage);
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    }
    CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(CaseInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) VariableMap(org.camunda.bpm.engine.variable.VariableMap) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) CaseService(org.camunda.bpm.engine.CaseService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) CreateCaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CreateCaseInstanceDto) CaseInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.CaseInstanceDto) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)44 Test (org.junit.Test)20 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)17 NotValidException (org.camunda.bpm.engine.exception.NotValidException)17 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)17 RestException (org.camunda.bpm.engine.rest.exception.RestException)17 Matchers.anyString (org.mockito.Matchers.anyString)15 HashMap (java.util.HashMap)11 CaseService (org.camunda.bpm.engine.CaseService)9 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)9 CaseExecutionCommandBuilder (org.camunda.bpm.engine.runtime.CaseExecutionCommandBuilder)8 InputStream (java.io.InputStream)4 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 RepositoryService (org.camunda.bpm.engine.RepositoryService)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 FileNotFoundException (java.io.FileNotFoundException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2