Search in sources :

Example 6 with AuthorizationDto

use of org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testSaveAuthorizationThrowsAuthorizationException.

@Test
public void testSaveAuthorizationThrowsAuthorizationException() {
    String message = "expected authorization exception";
    when(authorizationServiceMock.saveAuthorization(any(Authorization.class))).thenThrow(new AuthorizationException(message));
    Authorization authorization = MockProvider.createMockGrantAuthorization();
    when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GRANT)).thenReturn(authorization);
    AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
    given().body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(AUTH_CREATE_PATH);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationDto(org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with AuthorizationDto

use of org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testCreateRevokeAuthorization.

@Test
public void testCreateRevokeAuthorization() {
    Authorization authorization = MockProvider.createMockRevokeAuthorization();
    when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_REVOKE)).thenReturn(authorization);
    when(authorizationServiceMock.saveAuthorization(authorization)).thenReturn(authorization);
    AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
    when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
    when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
    when(authorizationQuery.singleResult()).thenReturn(authorization);
    AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
    given().body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.OK.getStatusCode()).when().post(AUTH_CREATE_PATH);
    verify(authorizationServiceMock).createNewAuthorization(Authorization.AUTH_TYPE_REVOKE);
    verify(authorization, times(2)).setUserId(authorization.getUserId());
    verify(authorization, times(4)).setResourceType(authorization.getAuthorizationType());
    verify(authorization, times(2)).setResourceId(authorization.getResourceId());
    verify(authorization, times(2)).setPermissions(authorization.getPermissions(Permissions.values()));
    verify(authorizationServiceMock).saveAuthorization(authorization);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationDto(org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Test(org.junit.Test)

Example 8 with AuthorizationDto

use of org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto in project camunda-bpm-platform by camunda.

the class AuthorizationRestServiceInteractionTest method testUpdateAuthorizationThrowsAuthorizationException.

@Test
public void testUpdateAuthorizationThrowsAuthorizationException() {
    Authorization authorization = MockProvider.createMockGlobalAuthorization();
    AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
    AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
    when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
    when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
    when(authorizationQuery.singleResult()).thenReturn(authorization);
    String message = "expected authorization exception";
    when(authorizationServiceMock.saveAuthorization(any(Authorization.class))).thenThrow(new AuthorizationException(message));
    given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(AUTH_RESOURCE_PATH);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationDto(org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Authorization (org.camunda.bpm.engine.authorization.Authorization)8 AuthorizationDto (org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto)8 Test (org.junit.Test)8 AuthorizationQuery (org.camunda.bpm.engine.authorization.AuthorizationQuery)6 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)3 Matchers.anyString (org.mockito.Matchers.anyString)3