Search in sources :

Example 6 with FetchExternalTasksExtendedDto

use of org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldThrowProcessEngineExceptionDuringTimeout.

@Test
public void shouldThrowProcessEngineExceptionDuringTimeout() {
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    when(fetchTopicBuilder.execute()).thenReturn(Collections.<LockedExternalTask>emptyList()).thenReturn(Collections.<LockedExternalTask>emptyList()).thenThrow(new ProcessEngineException("anExceptionMessage"));
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().body("type", equalTo(ProcessEngineException.class.getSimpleName())).body("message", equalTo("anExceptionMessage")).statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
    verify(fetchTopicBuilder, atLeastOnce()).execute();
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 7 with FetchExternalTasksExtendedDto

use of org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldResponseImmediatelyDueToAvailableTasks.

@Test
public void shouldResponseImmediatelyDueToAvailableTasks() {
    when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).then().expect().body("size()", is(1)).statusCode(Status.OK.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL);
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 8 with FetchExternalTasksExtendedDto

use of org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldSetAuthenticationProperly.

@Ignore
@Test
public void shouldSetAuthenticationProperly() {
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(new Authentication(MockProvider.EXAMPLE_USER_ID, groupIds, tenantIds));
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
    ArgumentCaptor<Authentication> argumentCaptor = ArgumentCaptor.forClass(Authentication.class);
    verify(identityServiceMock, atLeastOnce()).setAuthentication(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getUserId(), is(MockProvider.EXAMPLE_USER_ID));
    assertThat(argumentCaptor.getValue().getGroupIds(), is(groupIds));
    assertThat(argumentCaptor.getValue().getTenantIds(), is(tenantIds));
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 9 with FetchExternalTasksExtendedDto

use of org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldFetchAndLock.

@Test
public void shouldFetchAndLock() {
    when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null, true, true, false);
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().statusCode(Status.OK.getStatusCode()).body("[0].id", equalTo(MockProvider.EXTERNAL_TASK_ID)).body("[0].topicName", equalTo(MockProvider.EXTERNAL_TASK_TOPIC_NAME)).body("[0].workerId", equalTo(MockProvider.EXTERNAL_TASK_WORKER_ID)).body("[0].lockExpirationTime", equalTo(MockProvider.EXTERNAL_TASK_LOCK_EXPIRATION_TIME)).body("[0].processInstanceId", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("[0].executionId", equalTo(MockProvider.EXAMPLE_EXECUTION_ID)).body("[0].activityId", equalTo(MockProvider.EXAMPLE_ACTIVITY_ID)).body("[0].activityInstanceId", equalTo(MockProvider.EXAMPLE_ACTIVITY_INSTANCE_ID)).body("[0].processDefinitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("[0].processDefinitionKey", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)).body("[0].tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID)).body("[0].retries", equalTo(MockProvider.EXTERNAL_TASK_RETRIES)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].priority", equalTo(MockProvider.EXTERNAL_TASK_PRIORITY)).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME, notNullValue()).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_PRIMITIVE_VARIABLE_VALUE.getValue())).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type", equalTo("String")).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
    InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService);
    inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", true);
    inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L);
    inOrder.verify(fetchTopicBuilder).variables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME));
    inOrder.verify(fetchTopicBuilder).execute();
    verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService);
}
Also used : InOrder(org.mockito.InOrder) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 10 with FetchExternalTasksExtendedDto

use of org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method createDto.

private FetchExternalTasksExtendedDto createDto(Long responseTimeout, boolean usePriority, boolean withVariables, boolean withDeserialization) {
    FetchExternalTasksExtendedDto fetchExternalTasksDto = new FetchExternalTasksExtendedDto();
    if (responseTimeout != null) {
        fetchExternalTasksDto.setAsyncResponseTimeout(responseTimeout);
    }
    fetchExternalTasksDto.setMaxTasks(5);
    fetchExternalTasksDto.setWorkerId("aWorkerId");
    fetchExternalTasksDto.setUsePriority(usePriority);
    FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto topicDto = new FetchExternalTasksExtendedDto.FetchExternalTaskTopicDto();
    fetchExternalTasksDto.setTopics(Collections.singletonList(topicDto));
    topicDto.setTopicName("aTopicName");
    topicDto.setLockDuration(12354L);
    if (withVariables) {
        topicDto.setVariables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME));
    }
    topicDto.setDeserializeValues(withDeserialization);
    fetchExternalTasksDto.setTopics(Collections.singletonList(topicDto));
    return fetchExternalTasksDto;
}
Also used : FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto)

Aggregations

FetchExternalTasksExtendedDto (org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto)12 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)8 Test (org.junit.Test)8 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 InOrder (org.mockito.InOrder)3 IdentityService (org.camunda.bpm.engine.IdentityService)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)1 LockedExternalTaskDto (org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto)1 Ignore (org.junit.Ignore)1