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());
}
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();
}
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);
}
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);
}
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);
}
Aggregations