Search in sources :

Example 41 with Scope

use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.

the class ScopeUpgraderTest method shouldNotCreateScopes_clientsAndRolesHaveNoScopes.

@Test
public void shouldNotCreateScopes_clientsAndRolesHaveNoScopes() {
    final Scope domainScope = new Scope();
    domainScope.setId("domain-scope-key");
    domainScope.setKey("domain-scope-key");
    final String domainId = "domain-id";
    final String domainName = "domain-name";
    final Domain domain = new Domain();
    domain.setId(domainId);
    domain.setName(domainName);
    final Application app = new Application();
    app.setId("client-id");
    final Role role = new Role();
    role.setId("role-id");
    role.setPermissionAcls(null);
    when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
    when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.emptySet(), 0, Integer.MAX_VALUE))).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, Integer.MAX_VALUE)));
    when(applicationService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(app)));
    when(roleService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(role)));
    scopeUpgrader.upgrade();
    verify(domainService, times(1)).findAll();
    verify(scopeService, times(1)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
    verify(applicationService, times(1)).findByDomain(domain.getId());
    verify(roleService, times(1)).findByDomain(domain.getId());
    verify(scopeService, never()).create(any(String.class), any(NewScope.class));
}
Also used : Role(io.gravitee.am.model.Role) NewScope(io.gravitee.am.service.model.NewScope) Scope(io.gravitee.am.model.oauth2.Scope) NewScope(io.gravitee.am.service.model.NewScope) Page(io.gravitee.am.model.common.Page) Domain(io.gravitee.am.model.Domain) Application(io.gravitee.am.model.Application) Test(org.junit.Test)

Example 42 with Scope

use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.

the class ScopeUpgraderTest method shouldCreateScopes_withRoleAndClientScopes.

@Test
public void shouldCreateScopes_withRoleAndClientScopes() {
    final Scope domainScope = new Scope();
    domainScope.setId("domain-scope-key");
    domainScope.setKey("domain-scope-key");
    final String domainId = "domain-id";
    final String domainName = "domain-name";
    final Domain domain = new Domain();
    domain.setId(domainId);
    domain.setName(domainName);
    final Scope clientScope = new Scope();
    clientScope.setId("client-scope-key");
    clientScope.setKey("client-scope-key");
    final Application app = new Application();
    app.setId("client-id");
    ApplicationSettings settings = new ApplicationSettings();
    ApplicationOAuthSettings oauth = new ApplicationOAuthSettings();
    oauth.setScopes(Collections.singletonList(clientScope.getKey()));
    settings.setOauth(oauth);
    app.setSettings(settings);
    final Scope roleScope = new Scope();
    roleScope.setId("role-scope-key");
    roleScope.setKey("role-scope-key");
    final Role role = new Role();
    role.setId("role-id");
    role.setOauthScopes(Collections.singletonList(roleScope.getKey()));
    when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
    when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.emptySet(), 0, 0))).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, 1)));
    when(applicationService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(app)));
    when(roleService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(role)));
    when(scopeService.create(any(String.class), any(NewScope.class))).thenReturn(Single.just(new Scope()));
    scopeUpgrader.upgrade();
    verify(domainService, times(1)).findAll();
    verify(scopeService, times(3)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
    verify(applicationService, times(1)).findByDomain(domain.getId());
    verify(roleService, times(1)).findByDomain(domain.getId());
    verify(scopeService, times(2)).create(any(String.class), any(NewScope.class));
}
Also used : ApplicationOAuthSettings(io.gravitee.am.model.application.ApplicationOAuthSettings) Role(io.gravitee.am.model.Role) ApplicationSettings(io.gravitee.am.model.application.ApplicationSettings) NewScope(io.gravitee.am.service.model.NewScope) Scope(io.gravitee.am.model.oauth2.Scope) NewScope(io.gravitee.am.service.model.NewScope) Page(io.gravitee.am.model.common.Page) Domain(io.gravitee.am.model.Domain) Application(io.gravitee.am.model.Application) Test(org.junit.Test)

Example 43 with Scope

use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.

the class ScopeUpgraderTest method shouldNotCreateScopes_domainHasScopes.

@Test
public void shouldNotCreateScopes_domainHasScopes() {
    final Scope domainScope = new Scope();
    domainScope.setId("domain-scope-key");
    domainScope.setKey("domain-scope-key");
    final String domainId = "domain-id";
    final String domainName = "domain-name";
    final Domain domain = new Domain();
    domain.setId(domainId);
    domain.setName(domainName);
    when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
    when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, 1)));
    scopeUpgrader.upgrade();
    verify(domainService, times(1)).findAll();
    verify(scopeService, times(1)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
    verify(applicationService, never()).findByDomain(domain.getId());
    verify(roleService, never()).findByDomain(domain.getId());
    verify(scopeService, never()).create(any(String.class), any(NewScope.class));
}
Also used : NewScope(io.gravitee.am.service.model.NewScope) Scope(io.gravitee.am.model.oauth2.Scope) NewScope(io.gravitee.am.service.model.NewScope) Page(io.gravitee.am.model.common.Page) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 44 with Scope

use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.

the class ScopeRepositoryTest method testFindByDomainAndKey.

@Test
public void testFindByDomainAndKey() {
    // create scope
    Scope scope = new Scope();
    scope.setName("firstOne");
    scope.setKey("one");
    scope.setDomain("testDomain");
    scopeRepository.create(scope).blockingGet();
    scope.setId(null);
    scope.setName("anotherOne");
    scope.setDomain("another");
    scopeRepository.create(scope).blockingGet();
    // fetch scopes
    TestObserver<Scope> testObserver = scopeRepository.findByDomainAndKey("testDomain", "one").test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(result -> "firstOne".equals(result.getName()));
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 45 with Scope

use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.

the class ScopeRepositoryTest method testFindById.

@Test
public void testFindById() {
    // create scope
    Scope scope = buildScope();
    Scope scopeCreated = scopeRepository.create(scope).blockingGet();
    // fetch scope
    TestObserver<Scope> testObserver = scopeRepository.findById(scopeCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    assertEqualsTo(scope, testObserver);
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Aggregations

Scope (io.gravitee.am.model.oauth2.Scope)63 Test (org.junit.Test)43 TestObserver (io.reactivex.observers.TestObserver)25 Event (io.gravitee.am.model.common.event.Event)16 Page (io.gravitee.am.model.common.Page)15 Domain (io.gravitee.am.model.Domain)10 NewScope (io.gravitee.am.service.model.NewScope)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)8 Maybe (io.reactivex.Maybe)8 Single (io.reactivex.Single)8 RandomString (io.gravitee.am.common.utils.RandomString)7 ScopeRepository (io.gravitee.am.repository.management.api.ScopeRepository)7 Completable (io.reactivex.Completable)7 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)6 ApplicationOAuthSettings (io.gravitee.am.model.application.ApplicationOAuthSettings)6 Observable (io.reactivex.Observable)6 User (io.gravitee.am.identityprovider.api.User)5 ReferenceType (io.gravitee.am.model.ReferenceType)5 ApplicationScopeSettings (io.gravitee.am.model.application.ApplicationScopeSettings)5