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();
}
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());
}
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);
}
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);
}
Aggregations