Search in sources :

Example 66 with Page

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);
}
Also used : ApplicationOAuthSettings(io.gravitee.am.model.application.ApplicationOAuthSettings) ApplicationSettings(io.gravitee.am.model.application.ApplicationSettings) Page(io.gravitee.am.model.common.Page) Application(io.gravitee.am.model.Application) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 67 with Page

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);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Page(io.gravitee.am.model.common.Page) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest) AccessPolicyType(io.gravitee.am.model.uma.policy.AccessPolicyType) Page(io.gravitee.am.model.common.Page) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Date(java.util.Date) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 68 with Page

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);
}
Also used : Page(io.gravitee.am.model.common.Page) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Aggregations

Page (io.gravitee.am.model.common.Page)68 Test (org.junit.Test)51 User (io.gravitee.am.model.User)29 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)26 FilterCriteria (io.gravitee.am.repository.management.api.search.FilterCriteria)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 Maybe (io.reactivex.Maybe)12 Single (io.reactivex.Single)12 ReferenceType (io.gravitee.am.model.ReferenceType)11 Flowable (io.reactivex.Flowable)11 Response (javax.ws.rs.core.Response)11 Domain (io.gravitee.am.model.Domain)10 List (java.util.List)10 Application (io.gravitee.am.model.Application)9 Scope (io.gravitee.am.model.oauth2.Scope)8 Completable (io.reactivex.Completable)8 LocalDateTime (java.time.LocalDateTime)8 InitializingBean (org.springframework.beans.factory.InitializingBean)8 Criteria.where (org.springframework.data.relational.core.query.Criteria.where)8 Query (org.springframework.data.relational.core.query.Query)8