Search in sources :

Example 6 with AuthorizationQuery

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

the class AuthorizationRestServiceInteractionTest method testCreateGlobalAuthorization.

@Test
public void testCreateGlobalAuthorization() {
    Authorization authorization = MockProvider.createMockGlobalAuthorization();
    when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL)).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_GLOBAL);
    verify(authorization).setUserId(Authorization.ANY);
    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 7 with AuthorizationQuery

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

the class AuthorizationRestServiceInteractionTest method testDeleteAuthorizationThrowsAuthorizationException.

@Test
public void testDeleteAuthorizationThrowsAuthorizationException() {
    Authorization authorization = MockProvider.createMockGlobalAuthorization();
    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";
    doThrow(new AuthorizationException(message)).when(authorizationServiceMock).deleteAuthorization(MockProvider.EXAMPLE_AUTHORIZATION_ID);
    given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().delete(AUTH_RESOURCE_PATH);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with AuthorizationQuery

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

the class AuthorizationRestServiceInteractionTest method testCreateGrantAuthorization.

@Test
public void testCreateGrantAuthorization() {
    Authorization authorization = MockProvider.createMockGrantAuthorization();
    when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GRANT)).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_GRANT);
    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 9 with AuthorizationQuery

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

the class AuthorizationRestServiceInteractionTest method testGetNonExistingAuthorizationById.

@Test
public void testGetNonExistingAuthorizationById() {
    AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
    when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
    when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
    when(authorizationQuery.singleResult()).thenReturn(null);
    given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("message", equalTo("Authorization with id " + MockProvider.EXAMPLE_AUTHORIZATION_ID + " does not exist.")).when().get(AUTH_RESOURCE_PATH);
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) Test(org.junit.Test)

Example 10 with AuthorizationQuery

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

the class AuthorizationRestServiceInteractionTest method testUpdateAuthorization.

@Test
public void testUpdateAuthorization() {
    Authorization authorization = MockProvider.createMockGlobalAuthorization();
    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().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(AUTH_RESOURCE_PATH);
    verify(authorizationQuery).authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID);
    verify(authorization).setGroupId(dto.getGroupId());
    verify(authorization).setUserId(dto.getUserId());
    verify(authorization).setResourceId(dto.getResourceId());
    verify(authorization).setResourceType(dto.getResourceType());
    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)

Aggregations

AuthorizationQuery (org.camunda.bpm.engine.authorization.AuthorizationQuery)23 Test (org.junit.Test)19 Authorization (org.camunda.bpm.engine.authorization.Authorization)16 AuthorizationDto (org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto)6 Matchers.anyString (org.mockito.Matchers.anyString)5 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)2 Response (com.jayway.restassured.response.Response)1 RequestSpecification (com.jayway.restassured.specification.RequestSpecification)1 Deployment (org.camunda.bpm.engine.repository.Deployment)1 CountResultDto (org.camunda.bpm.engine.rest.dto.CountResultDto)1 InOrder (org.mockito.InOrder)1