Search in sources :

Example 31 with Project

use of io.lumeer.api.model.Project in project engine by Lumeer.

the class ProjectServiceIT method testGetProjects.

@Test
public void testGetProjects() {
    createProject(CODE1);
    createProject(CODE2);
    Response response = client.target(PROJECT_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonProject> projects = response.readEntity(new GenericType<List<JsonProject>>() {
    });
    assertThat(projects).extracting(Resource::getCode).containsOnly(CODE1, CODE2);
    Project project1 = projects.get(0);
    assertThat(project1.getName()).isEqualTo(NAME);
    assertThat(project1.getIcon()).isEqualTo(ICON);
    assertThat(project1.getColor()).isEqualTo(COLOR);
    Permissions permissions1 = project1.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());
    Project project2 = projects.get(1);
    assertThat(project2.getName()).isEqualTo(NAME);
    assertThat(project2.getIcon()).isEqualTo(ICON);
    assertThat(project2.getColor()).isEqualTo(COLOR);
    Permissions permissions2 = project2.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());
}
Also used : Response(javax.ws.rs.core.Response) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) List(java.util.List) Response(javax.ws.rs.core.Response) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) List(java.util.List) JsonProject(io.lumeer.api.dto.JsonProject) Test(org.junit.Test)

Example 32 with Project

use of io.lumeer.api.model.Project in project engine by Lumeer.

the class ViewServiceIT method configureProject.

@Before
public void configureProject() {
    MorphiaOrganization organization = new MorphiaOrganization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new MorphiaPermissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    User user = new User(USER);
    userDao.createUser(user);
    MorphiaProject project = new MorphiaProject();
    project.setCode(PROJECT_CODE);
    project.setPermissions(new MorphiaPermissions());
    Project storedProject = projectDao.createProject(project);
    viewDao.setProject(storedProject);
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) Organization(io.lumeer.api.model.Organization) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Before(org.junit.Before)

Example 33 with Project

use of io.lumeer.api.model.Project in project engine by Lumeer.

the class OrganizationServicePermissionsIT method testCreateProjectInOrganizationNoRole.

@Test
public void testCreateProjectInOrganizationNoRole() {
    String name = "testRemoveGroupPermissionNoRole";
    String code = "testRemoveGroupPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    String projectCode = "proj1";
    String projectName = "proj1_code";
    Project project = new JsonProject(projectCode, projectName, "a", "b", null, null);
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/projects").request(MediaType.APPLICATION_JSON).buildPost(Entity.json(project)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
Also used : Response(javax.ws.rs.core.Response) JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonProject(io.lumeer.api.dto.JsonProject) Test(org.junit.Test)

Example 34 with Project

use of io.lumeer.api.model.Project in project engine by Lumeer.

the class ProjectServicePermissionsIT method createProject.

private Project createProject(String code, String name) {
    Project project = new JsonProject(code, name, "a", "b", null, null);
    project.getPermissions().updateUserPermissions(new SimplePermission(userEmail, Project.ROLES));
    return projectDao.createProject(project);
}
Also used : JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission)

Example 35 with Project

use of io.lumeer.api.model.Project in project engine by Lumeer.

the class ProjectServicePermissionsIT method testGetProjectsSomeReadRoles.

@Test
public void testGetProjectsSomeReadRoles() {
    String projectCode1 = "ProjectServiceTestProject_code1";
    String projectName1 = "ProjectServiceTestProject1";
    String projectCode2 = "ProjectServiceTestProject_code2";
    String projectName2 = "ProjectServiceTestProject2";
    String projectCode3 = "ProjectServiceTestProject_code3";
    String projectName3 = "ProjectServiceTestProject3";
    String projectCode4 = "ProjectServiceTestProject_code4";
    String projectName4 = "ProjectServiceTestProject4";
    List<String> projectCodes = Arrays.asList(projectCode1, projectCode2, projectCode3, projectCode4);
    List<String> projectNames = Arrays.asList(projectName1, projectName2, projectName3, projectName4);
    for (int i = 0; i < projectCodes.size(); i++) {
        createProject(projectCodes.get(i), projectNames.get(i));
        if (i % 2 == 0) {
            projectFacade.removeUserPermission(projectCodes.get(i), userEmail);
        } else {
            projectFacade.updateUserPermissions(projectCodes.get(i), new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ)))));
        }
    }
    Response response = client.target(TARGET_URI).path(PATH_PREFIX).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<Project> projects = response.readEntity(new GenericType<List<Project>>(List.class) {
    });
    assertThat(projects).extracting("code").containsOnly(projectCode2, projectCode4);
    assertThat(projects).extracting("name").containsOnly(projectName2, projectName4);
}
Also used : Response(javax.ws.rs.core.Response) JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) List(java.util.List) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Aggregations

Project (io.lumeer.api.model.Project)46 JsonProject (io.lumeer.api.dto.JsonProject)28 Test (org.junit.Test)17 Organization (io.lumeer.api.model.Organization)16 Before (org.junit.Before)16 JsonPermission (io.lumeer.api.dto.JsonPermission)14 User (io.lumeer.api.model.User)14 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)14 JsonOrganization (io.lumeer.api.dto.JsonOrganization)13 JsonPermissions (io.lumeer.api.dto.JsonPermissions)12 Response (javax.ws.rs.core.Response)9 JsonCollection (io.lumeer.api.dto.JsonCollection)8 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)7 SoftAssertions (org.assertj.core.api.SoftAssertions)7 SimplePermission (io.lumeer.core.model.SimplePermission)4 Permission (io.lumeer.api.model.Permission)3 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)3 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)3 Entity (javax.ws.rs.client.Entity)3 LinkType (io.lumeer.api.model.LinkType)2