Search in sources :

Example 16 with AuthorizationException

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

the class DeploymentRestServiceInteractionTest method testCreateDeploymentThrowsAuthorizationException.

@Test
public void testCreateDeploymentThrowsAuthorizationException() {
    String message = "expected exception";
    when(mockDeploymentBuilder.deployWithResult()).thenThrow(new AuthorizationException(message));
    resourceNames.addAll(Arrays.asList("data", "more-data"));
    given().multiPart("data", "unspecified", createMockDeploymentResourceByteData()).multiPart("more-data", "unspecified", createMockDeploymentResourceBpmnData()).multiPart("deployment-name", MockProvider.EXAMPLE_DEPLOYMENT_ID).multiPart("enable-duplicate-filtering", "true").then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(message)).when().post(CREATE_DEPLOYMENT_URL);
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 17 with AuthorizationException

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

the class StatisticsRestTest method testActivtyStatisticsByIdThrowsAuthorizationExceptionByKey.

@Test
public void testActivtyStatisticsByIdThrowsAuthorizationExceptionByKey() {
    String message = "expected exception";
    when(activityQueryMock.list()).thenThrow(new AuthorizationException(message));
    given().pathParam("key", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().get(ACTIVITY_STATISTICS_BY_KEY_URL);
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with AuthorizationException

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

the class TaskRestServiceInteractionTest method testSaveNewTaskThrowsAuthorizationException.

@Test
public void testSaveNewTaskThrowsAuthorizationException() {
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("id", "anyTaskId");
    Task newTask = mock(Task.class);
    when(taskServiceMock.newTask(anyString())).thenReturn(newTask);
    String message = "expected exception";
    doThrow(new AuthorizationException(message)).when(taskServiceMock).saveTask(newTask);
    given().body(json).contentType(ContentType.JSON).header("accept", MediaType.APPLICATION_JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(TASK_CREATE_URL);
}
Also used : Task(org.camunda.bpm.engine.task.Task) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with AuthorizationException

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

the class TaskRestServiceInteractionTest method testDeleteUserIdentityLinkThrowsAuthorizationException.

@Test
public void testDeleteUserIdentityLinkThrowsAuthorizationException() {
    String deleteIdentityLinkUrl = TASK_IDENTITY_LINKS_URL + "/delete";
    String taskId = EXAMPLE_TASK_ID;
    String userId = MockProvider.EXAMPLE_USER_ID;
    String type = "someIdentityLinkType";
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("userId", userId);
    json.put("type", type);
    String message = "expected exception";
    doThrow(new AuthorizationException(message)).when(taskServiceMock).deleteUserIdentityLink(anyString(), anyString(), anyString());
    given().pathParam("id", taskId).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(deleteIdentityLinkUrl);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with AuthorizationException

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

the class TaskRestServiceInteractionTest method testGetTaskFormVariablesThrowsAuthorizationException.

@Test
public void testGetTaskFormVariablesThrowsAuthorizationException() {
    String message = "expected exception";
    doThrow(new AuthorizationException(message)).when(formServiceMock).getTaskFormVariables(anyString(), Matchers.<Collection<String>>any(), anyBoolean());
    given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().get(FORM_VARIABLES_URL);
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

AuthorizationException (org.camunda.bpm.engine.AuthorizationException)213 Test (org.junit.Test)142 Matchers.anyString (org.mockito.Matchers.anyString)116 Matchers.containsString (org.hamcrest.Matchers.containsString)55 HashMap (java.util.HashMap)50 Authorization (org.camunda.bpm.engine.authorization.Authorization)22 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)21 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)21 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)20 RestException (org.camunda.bpm.engine.rest.exception.RestException)14 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)13 User (org.camunda.bpm.engine.identity.User)12 Group (org.camunda.bpm.engine.identity.Group)10 Tenant (org.camunda.bpm.engine.identity.Tenant)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 ArrayList (java.util.ArrayList)8 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ExampleVariableObject (org.camunda.bpm.engine.rest.helper.ExampleVariableObject)7 ManagementService (org.camunda.bpm.engine.ManagementService)6