use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class RolesResourceTest method shouldSearchRoles.
@Test
public void shouldSearchRoles() {
final String domainId = "domain-1";
final Domain mockDomain = new Domain();
mockDomain.setId(domainId);
final Role mockRole = new Role();
mockRole.setId("role-1-id");
mockRole.setName("role-1-name");
mockRole.setReferenceId(domainId);
final Role mockRole2 = new Role();
mockRole2.setId("role-2-id");
mockRole2.setName("role-2-name");
mockRole2.setReferenceId(domainId);
final Set<Role> roles = new HashSet<>(Arrays.asList(mockRole, mockRole2));
final Page<Role> pagedRoles = new Page<>(roles, 0, 2);
doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
doReturn(Single.just(roles)).when(roleService).findByDomain(domainId);
doReturn(Single.just(pagedRoles)).when(roleService).searchByDomain(domainId, "*role-2-name*", 0, 50);
final Response response = target("domains").path(domainId).path("roles").queryParam("q", "*role-2-name*").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
JsonArray pageArray = new JsonObject(readEntity(response, String.class)).getJsonArray("data");
assertTrue(pageArray.size() == 2);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class RolesResourceTest method shouldGetRoles.
@Test
public void shouldGetRoles() {
final String domainId = "domain-1";
final Domain mockDomain = new Domain();
mockDomain.setId(domainId);
final Role mockRole = new Role();
mockRole.setId("role-1-id");
mockRole.setName("role-1-name");
mockRole.setReferenceId(domainId);
final Role mockRole2 = new Role();
mockRole2.setId("role-2-id");
mockRole2.setName("role-2-name");
mockRole2.setReferenceId(domainId);
final Set<Role> roles = new HashSet<>(Arrays.asList(mockRole, mockRole2));
final Page<Role> pagedRoles = new Page<>(roles, 0, 2);
doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
doReturn(Single.just(pagedRoles)).when(roleService).findByDomain(domainId, 0, 50);
final Response response = target("domains").path(domainId).path("roles").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
JsonArray pageArray = new JsonObject(readEntity(response, String.class)).getJsonArray("data");
assertTrue(pageArray.size() == 2);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class ScopesResourceTest method shouldGetScopes.
@Test
public void shouldGetScopes() {
final String domainId = "domain-1";
final Scope mockScope = new Scope();
mockScope.setId("scope-1-id");
mockScope.setKey("scope-1-id");
mockScope.setName("scope-1-name");
mockScope.setDomain(domainId);
final Scope mockScope2 = new Scope();
mockScope2.setId("scope-2-id");
mockScope2.setKey("scope-2-id");
mockScope2.setName("scope-2-name");
mockScope2.setDomain(domainId);
final Set<Scope> scopes = new HashSet<>(Arrays.asList(mockScope, mockScope2));
doReturn(Single.just(new Page<>(scopes, 0, 2))).when(scopeService).findByDomain(domainId, 0, 50);
final Response response = target("domains").path(domainId).path("scopes").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
String body = response.readEntity(String.class);
JsonArray data = new JsonObject(body).getJsonArray("data");
assertTrue(data.size() == 2);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class UsersResourceTest method shouldGetUsers.
@Test
public void shouldGetUsers() {
final String domainId = "domain-1";
final Domain mockDomain = new Domain();
mockDomain.setId(domainId);
final User mockUser = new User();
mockUser.setId("user-id-1");
mockUser.setUsername("username-1");
mockUser.setReferenceType(ReferenceType.DOMAIN);
mockUser.setReferenceId(domainId);
final User mockUser2 = new User();
mockUser2.setId("domain-id-2");
mockUser2.setUsername("username-2");
mockUser2.setReferenceType(ReferenceType.DOMAIN);
mockUser2.setReferenceId(domainId);
final Set<User> users = new HashSet<>(Arrays.asList(mockUser, mockUser2));
final Page<User> pagedUsers = new Page<>(users, 0, 2);
doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
doReturn(Single.just(pagedUsers)).when(userService).findAll(ReferenceType.DOMAIN, domainId, 0, 10);
final Response response = target("domains").path(domainId).path("users").queryParam("page", 0).queryParam("size", 10).request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class JdbcOrganizationUserRepository method search.
@Override
public Single<Page<User>> search(ReferenceType referenceType, String referenceId, FilterCriteria criteria, int page, int size) {
LOGGER.debug("search({}, {}, {}, {}, {})", referenceType, referenceId, criteria, page, size);
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append(" FROM organization_users WHERE reference_id = :refId AND reference_type = :refType AND ");
ScimUserSearch search = this.databaseDialectHelper.prepareScimSearchUserQuery(queryBuilder, criteria, page, size);
// execute query
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeSelect = template.getDatabaseClient().sql(search.getSelectQuery()).bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeSelect = executeSelect.bind(entry.getKey(), entry.getValue());
}
Flux<JdbcOrganizationUser> userFlux = executeSelect.map(row -> rowMapper.read(JdbcOrganizationUser.class, row)).all();
// execute count to provide total in the Page
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeCount = template.getDatabaseClient().sql(search.getCountQuery());
executeCount = executeCount.bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeCount = executeCount.bind(entry.getKey(), entry.getValue());
}
Mono<Long> userCount = executeCount.map(row -> row.get(0, Long.class)).first();
return fluxToFlowable(userFlux).map(this::toEntity).flatMap(user -> completeUser(user).toFlowable()).toList().flatMap(list -> monoToSingle(userCount).map(total -> new Page<User>(list, page, total)));
}
Aggregations