use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testAuthorizationResourceOptions.
@Test
public void testAuthorizationResourceOptions() {
String fullAuthorizationUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + AuthorizationRestService.PATH + "/" + MockProvider.EXAMPLE_AUTHORIZATION_ID;
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);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(null);
when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullAuthorizationUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullAuthorizationUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2].href", equalTo(fullAuthorizationUrl)).body("links[2].method", equalTo(HttpMethod.PUT)).body("links[2].rel", equalTo("update")).when().options(AUTH_RESOURCE_PATH);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery 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);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testDeleteNonExistingAuthorization.
@Test
public void testDeleteNonExistingAuthorization() {
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().delete(AUTH_RESOURCE_PATH);
verify(authorizationServiceMock, never()).deleteAuthorization(MockProvider.EXAMPLE_AUTHORIZATION_ID);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class DeploymentAuthorizationTest method testClearAuthorizationOnDeleteDeployment.
// clear authorization /////////////////////////////////////
public void testClearAuthorizationOnDeleteDeployment() {
// given
createGrantAuthorization(DEPLOYMENT, ANY, userId, CREATE);
Deployment deployment = repositoryService.createDeployment().addClasspathResource(FIRST_RESOURCE).deploy();
String deploymentId = deployment.getId();
AuthorizationQuery query = authorizationService.createAuthorizationQuery().userIdIn(userId).resourceId(deploymentId);
Authorization authorization = query.singleResult();
assertNotNull(authorization);
// when
repositoryService.deleteDeployment(deploymentId);
authorization = query.singleResult();
assertNull(authorization);
deleteDeployment(deploymentId);
}
use of org.camunda.bpm.engine.authorization.AuthorizationQuery in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceQueryTest method testNoParametersQuery.
@Test
public void testNoParametersQuery() {
AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());
expect().statusCode(Status.OK.getStatusCode()).when().get(SERVICE_PATH);
verify(mockQuery).list();
verifyNoMoreInteractions(mockQuery);
}
Aggregations