use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class ApplicationRepositoryTest method testSearch_wildcard.
@Test
public void testSearch_wildcard() {
final String domain = "domain";
// create app
Application app = new Application();
app.setDomain(domain);
app.setName("clientId");
applicationRepository.create(app).blockingGet();
Application app2 = new Application();
app2.setDomain(domain);
app2.setName("clientId2");
applicationRepository.create(app2).blockingGet();
Application app3 = new Application();
app3.setDomain(domain);
app3.setName("test");
applicationRepository.create(app3).blockingGet();
Application app4 = new Application();
app4.setDomain(domain);
app4.setName("test");
ApplicationSettings settings = new ApplicationSettings();
app4.setSettings(settings);
ApplicationOAuthSettings oauth = new ApplicationOAuthSettings();
settings.setOauth(oauth);
oauth.setClientId("clientId4");
applicationRepository.create(app4).blockingGet();
// fetch apps
TestObserver<Page<Application>> testObserver = applicationRepository.search(domain, "clientId*", 0, Integer.MAX_VALUE).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(apps -> apps.getData().size() == 3);
testObserver.assertValue(apps -> apps.getTotalCount() == 3);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class AccessPolicyRepositoryTest method findByDomain_Paging.
@Test
public void findByDomain_Paging() throws Exception {
final int totalCount = 10;
final String DOMAIN10 = DOMAIN_ID + "-10";
for (int i = 0; i < totalCount; i++) {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setName("accessPolicyName" + i);
accessPolicy.setDomain(DOMAIN10);
accessPolicy.setCreatedAt(new Date());
accessPolicy.setUpdatedAt(new Date());
repository.create(accessPolicy).blockingGet();
Thread.sleep(100l);
}
AccessPolicy accessPolicyOtherDomain = new AccessPolicy();
accessPolicyOtherDomain.setName("accessPolicyName");
accessPolicyOtherDomain.setDomain(DOMAIN_ID + "-other");
repository.create(accessPolicyOtherDomain).blockingGet();
// list all in one page
TestObserver<Page<AccessPolicy>> testObserver = repository.findByDomain(DOMAIN10, 0, totalCount + 1).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(p -> p.getTotalCount() == totalCount);
testObserver.assertValue(p -> p.getCurrentPage() == 0);
testObserver.assertValue(p -> p.getData().size() == totalCount);
testObserver = repository.findByDomain(DOMAIN10, 0, totalCount / 2).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(p -> p.getTotalCount() == totalCount);
testObserver.assertValue(p -> p.getCurrentPage() == 0);
testObserver.assertValue(p -> p.getData().size() == totalCount / 2);
// ordered by updated_at desc so last are returned first
testObserver.assertValue(p -> p.getData().stream().map(AccessPolicy::getName).filter(name -> name.matches("accessPolicyName[56789]")).count() == totalCount / 2);
testObserver = repository.findByDomain(DOMAIN10, 1, totalCount / 2).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(p -> p.getTotalCount() == totalCount);
testObserver.assertValue(p -> p.getCurrentPage() == 1);
testObserver.assertValue(p -> p.getData().size() == totalCount / 2);
// ordered by updated_at desc so first are returned last
testObserver.assertValue(p -> p.getData().stream().map(AccessPolicy::getName).filter(name -> name.matches("accessPolicyName[01234]")).count() == totalCount / 2);
}
use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.
the class AccessPolicyRepositoryTest method findByDomain.
@Test
public void findByDomain() throws TechnicalException {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setName("accessPolicyName");
final String DOMAIN_SINGLE = DOMAIN_ID + "single";
accessPolicy.setDomain(DOMAIN_SINGLE);
repository.create(accessPolicy).blockingGet();
AccessPolicy accessPolicyOtherDomain = new AccessPolicy();
accessPolicyOtherDomain.setName("accessPolicyName");
accessPolicyOtherDomain.setDomain(DOMAIN_ID + "-other");
repository.create(accessPolicyOtherDomain).blockingGet();
TestObserver<Page<AccessPolicy>> testObserver = repository.findByDomain(DOMAIN_SINGLE, 0, 20).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(p -> p.getTotalCount() == 1);
}
Aggregations