use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class ResourceServiceTest method updateAccessPolicy_resourceNotFound.
@Test
public void updateAccessPolicy_resourceNotFound() {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setId(POLICY_ID);
accessPolicy.setResource(RESOURCE_ID);
accessPolicy.setDomain(DOMAIN_ID);
when(repository.findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID)).thenReturn(Maybe.empty());
TestObserver<AccessPolicy> testObserver = service.updateAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID, POLICY_ID).test();
testObserver.assertNotComplete().assertError(ResourceNotFoundException.class);
verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
verify(accessPolicyRepository, never()).findById(POLICY_ID);
verify(accessPolicyRepository, never()).update(any());
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class ResourceServiceTest method updateAccessPolicy.
@Test
public void updateAccessPolicy() {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setId(POLICY_ID);
accessPolicy.setResource(RESOURCE_ID);
accessPolicy.setDomain(DOMAIN_ID);
when(accessPolicyRepository.findById(POLICY_ID)).thenReturn(Maybe.just(accessPolicy));
when(accessPolicyRepository.update(any())).thenReturn(Single.just(accessPolicy));
TestObserver<AccessPolicy> testObserver = service.updateAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID, POLICY_ID).test();
testObserver.assertComplete().assertNoErrors();
testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
verify(accessPolicyRepository, times(1)).findById(POLICY_ID);
verify(accessPolicyRepository, times(1)).update(any());
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class ResourceServiceTest method findAccessPolicy_byId.
@Test
public void findAccessPolicy_byId() {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setId(POLICY_ID);
accessPolicy.setResource(RESOURCE_ID);
accessPolicy.setDomain(DOMAIN_ID);
when(accessPolicyRepository.findById(POLICY_ID)).thenReturn(Maybe.just(accessPolicy));
TestObserver<AccessPolicy> testObserver = service.findAccessPolicy(POLICY_ID).test();
testObserver.assertComplete().assertNoErrors();
testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
verify(accessPolicyRepository, times(1)).findById(POLICY_ID);
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class ResourceServiceTest method createAccessPolicy.
@Test
public void createAccessPolicy() {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setId(POLICY_ID);
accessPolicy.setResource(RESOURCE_ID);
accessPolicy.setDomain(DOMAIN_ID);
when(accessPolicyRepository.create(accessPolicy)).thenReturn(Single.just(accessPolicy));
TestObserver<AccessPolicy> testObserver = service.createAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID).test();
testObserver.assertComplete().assertNoErrors();
testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
verify(accessPolicyRepository, times(1)).create(accessPolicy);
}
use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.
the class ResourceServiceTest method findAccessPoliciesByResources.
@Test
public void findAccessPoliciesByResources() {
AccessPolicy accessPolicy = new AccessPolicy();
accessPolicy.setId(POLICY_ID);
accessPolicy.setResource(RESOURCE_ID);
accessPolicy.setDomain(DOMAIN_ID);
List<String> resourceIds = Collections.singletonList(RESOURCE_ID);
when(accessPolicyRepository.findByResources(resourceIds)).thenReturn(Flowable.just(accessPolicy));
TestObserver<List<AccessPolicy>> testObserver = service.findAccessPoliciesByResources(resourceIds).toList().test();
testObserver.assertComplete().assertNoErrors();
testObserver.assertValue(accessPolicies -> accessPolicies.size() == 1);
verify(accessPolicyRepository, times(1)).findByResources(resourceIds);
}
Aggregations