use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testReadOnlyGroupCreateFails.
@Test
public void testReadOnlyGroupCreateFails() {
Group newGroup = MockProvider.createMockGroup();
when(identityServiceMock.isReadOnly()).thenReturn(true);
given().body(GroupDto.fromGroup(newGroup)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Identity service implementation is read-only.")).when().post(GROUP_CREATE_URL);
verify(identityServiceMock, never()).newGroup(MockProvider.EXAMPLE_GROUP_ID);
}
use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testGroupResourceOptionsUnauthorized.
@Test
public void testGroupResourceOptionsUnauthorized() {
String fullGroupUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/group/" + MockProvider.EXAMPLE_GROUP_ID;
Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);
when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, MockProvider.EXAMPLE_GROUP_ID)).thenReturn(false);
Group sampleGroup = MockProvider.createMockGroup();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId(MockProvider.EXAMPLE_GROUP_ID)).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.singleResult()).thenReturn(sampleGroup);
when(processEngineConfigurationMock.isAuthorizationEnabled()).thenReturn(true);
given().pathParam("id", MockProvider.EXAMPLE_GROUP_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("links[0].href", equalTo(fullGroupUrl)).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1]", nullValue()).body("links[2]", nullValue()).when().options(GROUP_URL);
verify(identityServiceMock, times(2)).getCurrentAuthentication();
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, GROUP, MockProvider.EXAMPLE_GROUP_ID);
verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, GROUP, MockProvider.EXAMPLE_GROUP_ID);
}
use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testSaveGroupThrowsAuthorizationException.
@Test
public void testSaveGroupThrowsAuthorizationException() {
Group newGroup = MockProvider.createMockGroup();
String message = "exception expected";
when(identityServiceMock.newGroup(newGroup.getId())).thenReturn(newGroup);
doThrow(new AuthorizationException(message)).when(identityServiceMock).saveGroup(newGroup);
given().body(GroupDto.fromGroup(newGroup)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(GROUP_CREATE_URL);
}
use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.
the class GroupRestServiceInteractionTest method testUpdateNonExistingGroup.
@Test
public void testUpdateNonExistingGroup() {
Group groupUpdate = MockProvider.createMockGroupUpdate();
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
when(identityServiceMock.createGroupQuery()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.groupId("aNonExistingGroup")).thenReturn(sampleGroupQuery);
// this time the query returns null
when(sampleGroupQuery.singleResult()).thenReturn(null);
given().pathParam("id", "aNonExistingGroup").body(GroupDto.fromGroup(groupUpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Group with id aNonExistingGroup does not exist")).when().put(GROUP_URL);
verify(identityServiceMock, never()).saveGroup(any(Group.class));
}
use of org.camunda.bpm.engine.identity.Group in project camunda-bpm-platform by camunda.
the class IdentityRestServiceQueryTest method createMockIdentityQueries.
private void createMockIdentityQueries() {
UserQuery sampleUserQuery = mock(UserQuery.class);
List<User> mockUsers = new ArrayList<User>();
mockUser = MockProvider.createMockUser();
mockUsers.add(mockUser);
when(sampleUserQuery.list()).thenReturn(mockUsers);
when(sampleUserQuery.memberOfGroup(anyString())).thenReturn(sampleUserQuery);
when(sampleUserQuery.count()).thenReturn((long) mockUsers.size());
GroupQuery sampleGroupQuery = mock(GroupQuery.class);
List<Group> mockGroups = MockProvider.createMockGroups();
when(sampleGroupQuery.list()).thenReturn(mockGroups);
when(sampleGroupQuery.groupMember(anyString())).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.orderByGroupName()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.orderByGroupId()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.orderByGroupType()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.asc()).thenReturn(sampleGroupQuery);
when(sampleGroupQuery.desc()).thenReturn(sampleGroupQuery);
when(processEngine.getIdentityService().createGroupQuery()).thenReturn(sampleGroupQuery);
when(processEngine.getIdentityService().createUserQuery()).thenReturn(sampleUserQuery);
}
Aggregations