use of io.lumeer.api.model.Resource in project engine by Lumeer.
the class PermissionsCheckerTest method testCheckDifferentRole.
@Test
public void testCheckDifferentRole() {
Resource resource = prepareResource(Collections.singleton(Role.WRITE), Collections.singleton(Role.READ));
assertThatThrownBy(() -> permissionsChecker.checkRole(resource, Role.MANAGE)).isInstanceOf(NoPermissionException.class).hasFieldOrPropertyWithValue("resource", resource);
}
use of io.lumeer.api.model.Resource in project engine by Lumeer.
the class PermissionsCheckerTest method testGetActualRolesIntersection.
@Test
public void testGetActualRolesIntersection() {
Resource resource = prepareResource(Sets.newLinkedHashSet(Role.READ, Role.WRITE), Sets.newLinkedHashSet(Role.READ, Role.SHARE));
Set<Role> roles = permissionsChecker.getActualRoles(resource);
assertThat(roles).containsOnly(Role.READ, Role.WRITE, Role.SHARE);
}
use of io.lumeer.api.model.Resource in project engine by Lumeer.
the class PermissionsCheckerTest method testGetActualRolesEmpty.
@Test
public void testGetActualRolesEmpty() {
Resource resource = prepareResource(Collections.emptySet(), Collections.emptySet());
Set<Role> roles = permissionsChecker.getActualRoles(resource);
assertThat(roles).isEmpty();
}
use of io.lumeer.api.model.Resource in project engine by Lumeer.
the class PermissionsCheckerTest method prepareResource.
private Resource prepareResource(Set<Role> userRoles, Set<Role> groupRoles) {
Permission userPermission = Mockito.mock(Permission.class);
Mockito.when(userPermission.getName()).thenReturn(USER);
Mockito.when(userPermission.getRoles()).thenReturn(userRoles);
Permission groupPermission = Mockito.mock(Permission.class);
Mockito.when(groupPermission.getName()).thenReturn(GROUP);
Mockito.when(groupPermission.getRoles()).thenReturn(groupRoles);
Permissions permissions = Mockito.mock(Permissions.class);
Mockito.when(permissions.getUserPermissions()).thenReturn(Collections.singleton(userPermission));
Mockito.when(permissions.getGroupPermissions()).thenReturn(Collections.singleton(groupPermission));
Resource resource = Mockito.mock(Resource.class);
Mockito.when(resource.getPermissions()).thenReturn(permissions);
Mockito.when(resource.getType()).thenReturn(ResourceType.PROJECT);
return resource;
}
use of io.lumeer.api.model.Resource in project engine by Lumeer.
the class OrganizationServiceIT method testGetOrganizations.
@Test
public void testGetOrganizations() {
createOrganization(CODE1);
createOrganization(CODE2);
Response response = client.target(ORGANIZATION_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
assertThat(response).isNotNull();
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
List<JsonOrganization> organizations = response.readEntity(new GenericType<List<JsonOrganization>>() {
});
assertThat(organizations).extracting(Resource::getCode).containsOnly(CODE1, CODE2);
Permissions permissions1 = organizations.get(0).getPermissions();
assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
Permissions permissions2 = organizations.get(1).getPermissions();
assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Aggregations