Search in sources :

Example 21 with AuthorizationQuery

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

the class AuthorizationRestServiceQueryTest method setUpMockQuery.

private AuthorizationQuery setUpMockQuery(List<Authorization> list) {
    AuthorizationQuery query = mock(AuthorizationQuery.class);
    when(query.list()).thenReturn(list);
    when(query.count()).thenReturn((long) list.size());
    when(processEngine.getAuthorizationService().createAuthorizationQuery()).thenReturn(query);
    return query;
}
Also used : AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery)

Example 22 with AuthorizationQuery

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

the class AuthorizationRestServiceQueryTest method testSimpleAuthorizationQuery.

@Test
public void testSimpleAuthorizationQuery() {
    List<Authorization> mockAuthorizations = MockProvider.createMockGlobalAuthorizations();
    AuthorizationQuery mockQuery = setUpMockQuery(mockAuthorizations);
    Response response = given().queryParam("type", Authorization.AUTH_TYPE_GLOBAL).then().expect().statusCode(Status.OK.getStatusCode()).when().get(SERVICE_PATH);
    InOrder inOrder = inOrder(mockQuery);
    inOrder.verify(mockQuery).authorizationType(Authorization.AUTH_TYPE_GLOBAL);
    inOrder.verify(mockQuery).list();
    String content = response.asString();
    List<String> instances = from(content).getList("");
    Assert.assertEquals("There should be one authorization returned.", 1, instances.size());
    Assert.assertNotNull("The returned authorization should not be null.", instances.get(0));
    Authorization mockAuthorization = mockAuthorizations.get(0);
    Assert.assertEquals(mockAuthorization.getId(), from(content).getString("[0].id"));
    Assert.assertEquals(mockAuthorization.getAuthorizationType(), from(content).getInt("[0].type"));
    Assert.assertEquals(Permissions.READ.getName(), from(content).getString("[0].permissions[0]"));
    Assert.assertEquals(Permissions.UPDATE.getName(), from(content).getString("[0].permissions[1]"));
    Assert.assertEquals(mockAuthorization.getUserId(), from(content).getString("[0].userId"));
    Assert.assertEquals(mockAuthorization.getGroupId(), from(content).getString("[0].groupId"));
    Assert.assertEquals(mockAuthorization.getResourceType(), from(content).getInt("[0].resourceType"));
    Assert.assertEquals(mockAuthorization.getResourceId(), from(content).getString("[0].resourceId"));
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) Response(com.jayway.restassured.response.Response) AuthorizationQuery(org.camunda.bpm.engine.authorization.AuthorizationQuery) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 23 with AuthorizationQuery

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

the class AuthorizationRestServiceQueryTest method testQueryCount.

@Test
public void testQueryCount() {
    AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());
    expect().statusCode(Status.OK.getStatusCode()).body("count", equalTo(3)).when().get(SERVICE_COUNT_PATH);
    verify(mockQuery).count();
}
Also used : 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