Search in sources :

Example 6 with JsonOrganization

use of io.lumeer.api.dto.JsonOrganization 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());
}
Also used : Response(javax.ws.rs.core.Response) PaymentGatewayFacade(io.lumeer.core.facade.PaymentGatewayFacade) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) Arquillian(org.jboss.arquillian.junit.Arquillian) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) JsonPermission(io.lumeer.api.dto.JsonPermission) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) OrganizationFacade(io.lumeer.core.facade.OrganizationFacade) 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) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) CompanyContact(io.lumeer.api.model.CompanyContact) ServiceLimits(io.lumeer.api.model.ServiceLimits) Organization(io.lumeer.api.model.Organization) Permission(io.lumeer.api.model.Permission) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) ZoneId(java.time.ZoneId) Payment(io.lumeer.api.model.Payment) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Response(javax.ws.rs.core.Response) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) List(java.util.List) Test(org.junit.Test)

Example 7 with JsonOrganization

use of io.lumeer.api.dto.JsonOrganization in project engine by Lumeer.

the class OrganizationServiceIT method testUpdateOrganization.

@Test
public void testUpdateOrganization() {
    createOrganization(CODE1);
    Organization updatedOrganization = new JsonOrganization(CODE2, NAME, ICON, COLOR, null, null);
    Entity entity = Entity.json(updatedOrganization);
    Response response = client.target(ORGANIZATION_URL).path(CODE1).request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Organization returnedOrganization = response.readEntity(JsonOrganization.class);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(returnedOrganization.getCode()).isEqualTo(CODE2);
    assertions.assertThat(returnedOrganization.getName()).isEqualTo(NAME);
    assertions.assertThat(returnedOrganization.getIcon()).isEqualTo(ICON);
    assertions.assertThat(returnedOrganization.getColor()).isEqualTo(COLOR);
    assertions.assertThat(returnedOrganization.getPermissions().getUserPermissions()).containsOnly(USER_PERMISSION);
    assertions.assertThat(returnedOrganization.getPermissions().getGroupPermissions()).isEmpty();
    assertions.assertAll();
    Organization storedOrganization = organizationFacade.getOrganization(CODE2);
    assertThat(storedOrganization).isNotNull();
    assertions = new SoftAssertions();
    assertions.assertThat(storedOrganization.getCode()).isEqualTo(CODE2);
    assertions.assertThat(storedOrganization.getName()).isEqualTo(NAME);
    assertions.assertThat(storedOrganization.getIcon()).isEqualTo(ICON);
    assertions.assertThat(storedOrganization.getColor()).isEqualTo(COLOR);
    assertions.assertThat(storedOrganization.getPermissions().getUserPermissions()).containsOnly(USER_PERMISSION);
    assertions.assertThat(returnedOrganization.getPermissions().getGroupPermissions()).isEmpty();
    assertions.assertAll();
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) Test(org.junit.Test)

Example 8 with JsonOrganization

use of io.lumeer.api.dto.JsonOrganization in project engine by Lumeer.

the class OrganizationServicePermissionsIT method testUpdateUserPermissionManageRole.

@Test
public void testUpdateUserPermissionManageRole() {
    String name = "testUpdateUserPermissionNoRole";
    String code = "testUpdateUserPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/users").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 9 with JsonOrganization

use of io.lumeer.api.dto.JsonOrganization in project engine by Lumeer.

the class OrganizationServicePermissionsIT method testUpdateUserPermissionNoRole.

@Test
public void testUpdateUserPermissionNoRole() {
    String name = "testUpdateUserPermissionNoRole";
    String code = "testUpdateUserPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/users").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 10 with JsonOrganization

use of io.lumeer.api.dto.JsonOrganization in project engine by Lumeer.

the class OrganizationServicePermissionsIT method testGetOrganizationPermissionsNoRole.

@Test
public void testGetOrganizationPermissionsNoRole() {
    String name = "testGetOrganizationPermissionsNoRole";
    String code = "testGetOrganizationPermissionsNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions").request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) Test(org.junit.Test)

Aggregations

JsonOrganization (io.lumeer.api.dto.JsonOrganization)45 Organization (io.lumeer.api.model.Organization)40 JsonPermission (io.lumeer.api.dto.JsonPermission)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)21 JsonPermissions (io.lumeer.api.dto.JsonPermissions)18 Before (org.junit.Before)16 JsonProject (io.lumeer.api.dto.JsonProject)14 Project (io.lumeer.api.model.Project)13 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)13 User (io.lumeer.api.model.User)12 JsonCollection (io.lumeer.api.dto.JsonCollection)8 Permission (io.lumeer.api.model.Permission)6 Role (io.lumeer.api.model.Role)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Entity (javax.ws.rs.client.Entity)3 LinkType (io.lumeer.api.model.LinkType)2 SimplePermission (io.lumeer.core.model.SimplePermission)2 List (java.util.List)2 CompanyContact (io.lumeer.api.model.CompanyContact)1