Search in sources :

Example 41 with AuthorizationException

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

the class JobRestServiceInteractionTest method testSuspendJobByProcessDefinitionKeyThrowsAuthorizationException.

@Test
public void testSuspendJobByProcessDefinitionKeyThrowsAuthorizationException() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("suspended", true);
    params.put("processDefinitionKey", MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY);
    String expectedException = "expectedException";
    doThrow(new AuthorizationException(expectedException)).when(mockSuspensionStateBuilder).suspend();
    given().contentType(ContentType.JSON).body(params).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(expectedException)).when().put(JOB_SUSPENDED_URL);
}
Also used : HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 42 with AuthorizationException

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

the class JobRestServiceInteractionTest method testActivateJobByJobDefinitionIdThrowsAuthorizationException.

@Test
public void testActivateJobByJobDefinitionIdThrowsAuthorizationException() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("suspended", false);
    params.put("jobDefinitionId", MockProvider.EXAMPLE_JOB_DEFINITION_ID);
    String expectedException = "expectedException";
    doThrow(new AuthorizationException(expectedException)).when(mockSuspensionStateBuilder).activate();
    given().contentType(ContentType.JSON).body(params).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(expectedException)).when().put(JOB_SUSPENDED_URL);
}
Also used : HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 43 with AuthorizationException

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

the class JobRestServiceInteractionTest method deleteJobThrowAuthorizationException.

@Test
public void deleteJobThrowAuthorizationException() {
    String jobId = MockProvider.EXAMPLE_JOB_ID;
    String expectedMessage = "Missing permissions";
    doThrow(new AuthorizationException(expectedMessage)).when(mockManagementService).deleteJob(jobId);
    given().pathParam("id", jobId).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(expectedMessage)).when().delete(SINGLE_JOB_RESOURCE_URL);
    verify(mockManagementService).deleteJob(jobId);
    verifyNoMoreInteractions(mockManagementService);
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 44 with AuthorizationException

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

the class JobRestServiceInteractionTest method testSuspendJobByProcessInstanceIdThrowsAuthorizationException.

@Test
public void testSuspendJobByProcessInstanceIdThrowsAuthorizationException() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("suspended", true);
    params.put("processInstanceId", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID);
    String expectedException = "expectedException";
    doThrow(new AuthorizationException(expectedException)).when(mockSuspensionStateBuilder).suspend();
    given().contentType(ContentType.JSON).body(params).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", is(AuthorizationException.class.getSimpleName())).body("message", is(expectedException)).when().put(JOB_SUSPENDED_URL);
}
Also used : HashMap(java.util.HashMap) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 45 with AuthorizationException

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

the class HistoricJobLogRestServiceInteractionTest method testGetStacktraceThrowsAuthorizationException.

@Test
public void testGetStacktraceThrowsAuthorizationException() {
    String exceptionMessage = "expected exception";
    doThrow(new AuthorizationException(exceptionMessage)).when(mockHistoryService).getHistoricJobLogExceptionStacktrace(MockProvider.EXAMPLE_HISTORIC_JOB_LOG_ID);
    given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_JOB_LOG_ID).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(exceptionMessage)).when().get(HISTORIC_JOB_LOG_RESOURCE_GET_STACKTRACE_URL);
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

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