use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class AccessPolicyRepositoryTest method delete.
@Test
public void delete() throws TechnicalException {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setName("accessPolicyName");
AccessPolicy apCreated = repository.create(accessPolicy).blockingGet();
// fetch resource_set
TestObserver<Void> testObserver = repository.delete(apCreated.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertNoValues();
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class AccessPolicyRepositoryTest method testFindByResources.
@Test
public void testFindByResources() throws TechnicalException {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setName("accessPolicyName");
accessPolicy.setDomain(DOMAIN_ID);
accessPolicy.setResource(RESOURCE_ID);
repository.create(accessPolicy).blockingGet();
AccessPolicy accessPolicy2 = new AccessPolicy();
accessPolicy2.setName("accessPolicyName");
accessPolicy2.setDomain(DOMAIN_ID);
accessPolicy2.setResource(RESOURCE_ID + "2");
repository.create(accessPolicy2).blockingGet();
AccessPolicy accessPolicy3 = new AccessPolicy();
accessPolicy3.setName("accessPolicyName");
accessPolicy3.setDomain(DOMAIN_ID + "-other");
accessPolicy3.setResource(RESOURCE_ID + "-other");
repository.create(accessPolicy3).blockingGet();
TestObserver<List<AccessPolicy>> testObserver = repository.findByResources(Arrays.asList(RESOURCE_ID, RESOURCE_ID + "2")).toList().test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(accessPolicies -> accessPolicies.size() == 2);
}
use of io.gravitee.am.model.uma.policy.AccessPolicy 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.uma.policy.AccessPolicy 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);
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class AccessPolicyRepositoryTest method testFindById.
@Test
public void testFindById() throws TechnicalException {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setName("accessPolicyName");
accessPolicy.setCondition("Condition");
accessPolicy.setCreatedAt(new Date());
accessPolicy.setUpdatedAt(new Date());
accessPolicy.setDescription("description");
accessPolicy.setDomain(DOMAIN_ID);
accessPolicy.setEnabled(true);
accessPolicy.setOrder(Integer.MAX_VALUE);
accessPolicy.setResource("resource");
accessPolicy.setType(AccessPolicyType.GROOVY);
AccessPolicy apCreated = repository.create(accessPolicy).blockingGet();
TestObserver<AccessPolicy> testObserver = repository.findById(apCreated.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(ap -> ap.getName().equals(accessPolicy.getName()));
testObserver.assertValue(ap -> ap.getCondition().equals(accessPolicy.getCondition()));
testObserver.assertValue(ap -> ap.getDescription().equals(accessPolicy.getDescription()));
testObserver.assertValue(ap -> ap.getDomain().equals(accessPolicy.getDomain()));
testObserver.assertValue(ap -> ap.getId().equals(apCreated.getId()));
testObserver.assertValue(ap -> ap.getResource().equals(accessPolicy.getResource()));
testObserver.assertValue(ap -> ap.getType().equals(accessPolicy.getType()));
testObserver.assertValue(ap -> ap.getOrder() == accessPolicy.getOrder());
}
Aggregations