Search in sources :

Example 21 with TaskServiceImpl

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

the class TaskAuthorizationTest method testProcessTaskUpdateVariablesLocalWithUpdatePermissionOnTask.

public void testProcessTaskUpdateVariablesLocalWithUpdatePermissionOnTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    String taskId = selectSingleTask().getId();
    createGrantAuthorization(TASK, taskId, userId, UPDATE);
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    // when (1)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), null);
    // then (1)
    disableAuthorization();
    verifyQueryResults(query, 1);
    enableAuthorization();
    // when (2)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, null, Arrays.asList(VARIABLE_NAME));
    // then (2)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
    // when (3)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), Arrays.asList(VARIABLE_NAME));
    // then (3)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
}
Also used : VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) TaskServiceImpl(org.camunda.bpm.engine.impl.TaskServiceImpl)

Example 22 with TaskServiceImpl

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

the class TaskAuthorizationTest method testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask.

@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask() {
    // given
    String taskId = "myTask";
    createTask(taskId);
    createGrantAuthorization(TASK, taskId, userId, UPDATE);
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    // when (1)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), null);
    // then (1)
    disableAuthorization();
    verifyQueryResults(query, 1);
    enableAuthorization();
    // when (2)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, null, Arrays.asList(VARIABLE_NAME));
    // then (2)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
    // when (3)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), Arrays.asList(VARIABLE_NAME));
    // then (3)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
    deleteTask(taskId, true);
    List<HistoricVariableInstance> deletedVariables = historyService.createHistoricVariableInstanceQuery().includeDeleted().list();
    Assert.assertEquals("DELETED", deletedVariables.get(0).getState());
    Assert.assertEquals("DELETED", deletedVariables.get(1).getState());
}
Also used : VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) TaskServiceImpl(org.camunda.bpm.engine.impl.TaskServiceImpl) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 23 with TaskServiceImpl

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

the class TaskVariableLocalRestResourceInteractionTest method testVariableModificationThrowsAuthorizationException.

@Test
public void testVariableModificationThrowsAuthorizationException() {
    String variableKey = "aKey";
    int variableValue = 123;
    Map<String, Object> messageBodyJson = new HashMap<String, Object>();
    Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables();
    messageBodyJson.put("modifications", modifications);
    TaskServiceImpl taskServiceMock = mockTaskServiceImpl();
    String message = "excpected exception";
    doThrow(new AuthorizationException(message)).when(taskServiceMock).updateVariablesLocal(anyString(), any(Map.class), any(List.class));
    given().pathParam("id", EXAMPLE_TASK_ID).contentType(ContentType.JSON).body(messageBodyJson).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(message)).when().post(SINGLE_TASK_MODIFY_VARIABLES_URL);
}
Also used : HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) TaskServiceImpl(org.camunda.bpm.engine.impl.TaskServiceImpl) List(java.util.List) EqualsList(org.camunda.bpm.engine.rest.helper.EqualsList) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap) EqualsMap(org.camunda.bpm.engine.rest.helper.EqualsMap) Test(org.junit.Test)

Example 24 with TaskServiceImpl

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

the class TaskVariableLocalRestResourceInteractionTest method testLocalVariableModificationForNonExistingTaskId.

@Test
public void testLocalVariableModificationForNonExistingTaskId() {
    TaskServiceImpl taskServiceMock = mockTaskServiceImpl();
    doThrow(new ProcessEngineException("Cannot find task with id " + NON_EXISTING_ID)).when(taskServiceMock).updateVariablesLocal(anyString(), any(Map.class), any(List.class));
    Map<String, Object> messageBodyJson = new HashMap<String, Object>();
    String variableKey = "aKey";
    int variableValue = 123;
    Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables();
    messageBodyJson.put("modifications", modifications);
    given().pathParam("id", NON_EXISTING_ID).contentType(ContentType.JSON).body(messageBodyJson).header("accept", MediaType.APPLICATION_JSON).then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo("Cannot modify variables for task " + NON_EXISTING_ID + ": Cannot find task with id " + NON_EXISTING_ID)).when().post(SINGLE_TASK_MODIFY_VARIABLES_URL);
}
Also used : HashMap(java.util.HashMap) TaskServiceImpl(org.camunda.bpm.engine.impl.TaskServiceImpl) RestException(org.camunda.bpm.engine.rest.exception.RestException) List(java.util.List) EqualsList(org.camunda.bpm.engine.rest.helper.EqualsList) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap) EqualsMap(org.camunda.bpm.engine.rest.helper.EqualsMap) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Aggregations

TaskServiceImpl (org.camunda.bpm.engine.impl.TaskServiceImpl)24 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)12 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 EqualsList (org.camunda.bpm.engine.rest.helper.EqualsList)6 EqualsMap (org.camunda.bpm.engine.rest.helper.EqualsMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 List (java.util.List)4 Map (java.util.Map)4 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)2 RestException (org.camunda.bpm.engine.rest.exception.RestException)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Task (org.camunda.bpm.engine.task.Task)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)2