Search in sources :

Example 36 with BadUserRequestException

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

the class BatchRestServiceInteractionTest method activateNonExistingBatch.

@Test
public void activateNonExistingBatch() {
    String nonExistingId = MockProvider.NON_EXISTING_ID;
    doThrow(new BadUserRequestException("Batch for id '" + nonExistingId + "' cannot be found")).when(managementServiceMock).activateBatchById(eq(nonExistingId));
    given().pathParam("id", nonExistingId).contentType(ContentType.JSON).body(singletonMap("suspended", false)).then().expect().statusCode(Status.BAD_REQUEST.getStatusCode()).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Unable to activate batch with id '" + nonExistingId + "'")).when().put(SUSPENDED_BATCH_RESOURCE_URL);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Test(org.junit.Test)

Example 37 with BadUserRequestException

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

the class AbstractGetDeployedFormCmd method execute.

public InputStream execute(final CommandContext commandContext) {
    checkAuthorization(commandContext);
    final FormData formData = getFormData(commandContext);
    String formKey = formData.getFormKey();
    if (formKey == null) {
        throw new BadUserRequestException("The form key is not set.");
    }
    final String resourceName = getResourceName(formKey);
    try {
        return commandContext.runWithoutAuthorization(new Callable<InputStream>() {

            @Override
            public InputStream call() throws Exception {
                return new GetDeploymentResourceCmd(formData.getDeploymentId(), resourceName).execute(commandContext);
            }
        });
    } catch (DeploymentResourceNotFoundException e) {
        throw new NotFoundException("The form with the resource name '" + resourceName + "' cannot be found in deployment.", e);
    }
}
Also used : FormData(org.camunda.bpm.engine.form.FormData) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException) InputStream(java.io.InputStream) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) DeploymentResourceNotFoundException(org.camunda.bpm.engine.exception.DeploymentResourceNotFoundException)

Example 38 with BadUserRequestException

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

the class ExternalTaskServiceTest method testExtendLockTimeWithDifferentWorkerId.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testExtendLockTimeWithDifferentWorkerId() {
    // given
    runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, 1L).execute();
    assertNotNull(lockedTasks);
    assertEquals(1, lockedTasks.size());
    LockedExternalTask task = lockedTasks.get(0);
    // when
    try {
        externalTaskService.extendLock(task.getId(), "anAnotherWorkerId", 100);
        fail("Exception expected");
    } catch (BadUserRequestException e) {
        assertTrue(e.getMessage().contains("The lock of the External Task " + task.getId() + " cannot be extended by worker 'anAnotherWorkerId'"));
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 39 with BadUserRequestException

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

the class SetExternalTasksRetriesTest method shouldFailForNullExternalTaskIdAsync.

@Test
public void shouldFailForNullExternalTaskIdAsync() {
    List<ExternalTask> externalTasks = externalTaskService.createExternalTaskQuery().list();
    ArrayList<String> externalTaskIds = new ArrayList<String>();
    for (ExternalTask task : externalTasks) {
        externalTaskIds.add(task.getId());
    }
    externalTaskIds.add(null);
    Batch batch = null;
    try {
        batch = externalTaskService.setRetriesAsync(externalTaskIds, null, 10);
        executeSeedAndBatchJobs(batch);
        fail("exception expected");
    } catch (BadUserRequestException e) {
        Assert.assertThat(e.getMessage(), containsString("External task id cannot be null"));
    }
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Test(org.junit.Test)

Example 40 with BadUserRequestException

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

the class SetExternalTasksRetriesTest method shouldFailForNullExternalTaskIdSync.

@Test
public void shouldFailForNullExternalTaskIdSync() {
    List<ExternalTask> externalTasks = externalTaskService.createExternalTaskQuery().list();
    ArrayList<String> externalTaskIds = new ArrayList<String>();
    for (ExternalTask task : externalTasks) {
        externalTaskIds.add(task.getId());
    }
    externalTaskIds.add(null);
    try {
        externalTaskService.setRetries(externalTaskIds, 10);
        fail("exception expected");
    } catch (BadUserRequestException e) {
        Assert.assertThat(e.getMessage(), containsString("External task id cannot be null"));
    }
}
Also used : ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Test(org.junit.Test)

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